From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- layout/style/nsAnimationManager.h | 109 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 layout/style/nsAnimationManager.h (limited to 'layout/style/nsAnimationManager.h') diff --git a/layout/style/nsAnimationManager.h b/layout/style/nsAnimationManager.h new file mode 100644 index 0000000000..f37fa0a7d1 --- /dev/null +++ b/layout/style/nsAnimationManager.h @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef nsAnimationManager_h_ +#define nsAnimationManager_h_ + +#include "mozilla/Attributes.h" +#include "AnimationCommon.h" +#include "mozilla/dom/CSSAnimation.h" +#include "mozilla/Keyframe.h" +#include "mozilla/MemoryReporting.h" +#include "nsISupportsImpl.h" +#include "nsTHashSet.h" + +class ServoCSSAnimationBuilder; + +struct nsStyleUIReset; + +namespace mozilla { +class ComputedStyle; + +enum class PseudoStyleType : uint8_t; +struct NonOwningAnimationTarget; + +} /* namespace mozilla */ + +class nsAnimationManager final + : public mozilla::CommonAnimationManager { + public: + explicit nsAnimationManager(nsPresContext* aPresContext) + : mozilla::CommonAnimationManager( + aPresContext) {} + + typedef mozilla::AnimationCollection + CSSAnimationCollection; + typedef nsTArray> + OwningCSSAnimationPtrArray; + + ~nsAnimationManager() override = default; + + /** + * This function does the same thing as the above UpdateAnimations() + * but with servo's computed values. + */ + void UpdateAnimations(mozilla::dom::Element* aElement, + mozilla::PseudoStyleType aPseudoType, + const mozilla::ComputedStyle* aComputedValues); + + // Utility function to walk through |aIter| to find the Keyframe with + // matching offset and timing function but stopping as soon as the offset + // differs from |aOffset| (i.e. it assumes a sorted iterator). + // + // If a matching Keyframe is found, + // Returns true and sets |aIndex| to the index of the matching Keyframe + // within |aIter|. + // + // If no matching Keyframe is found, + // Returns false and sets |aIndex| to the index in the iterator of the + // first Keyframe with an offset differing to |aOffset| or, if the end + // of the iterator is reached, sets |aIndex| to the index after the last + // Keyframe. + template + static bool FindMatchingKeyframe( + IterType&& aIter, double aOffset, + const mozilla::StyleComputedTimingFunction& aTimingFunctionToMatch, + mozilla::dom::CompositeOperationOrAuto aCompositionToMatch, + size_t& aIndex) { + aIndex = 0; + for (mozilla::Keyframe& keyframe : aIter) { + if (keyframe.mOffset.value() != aOffset) { + break; + } + const bool matches = [&] { + if (keyframe.mComposite != aCompositionToMatch) { + return false; + } + return keyframe.mTimingFunction + ? *keyframe.mTimingFunction == aTimingFunctionToMatch + : aTimingFunctionToMatch.IsLinearKeyword(); + }(); + if (matches) { + return true; + } + ++aIndex; + } + return false; + } + + bool AnimationMayBeReferenced(nsAtom* aName) const { + return mMaybeReferencedAnimations.Contains(aName); + } + + private: + // This includes all animation names referenced regardless of whether a + // corresponding `@keyframes` rule is available. + // + // It may contain names which are no longer referenced, but it should always + // contain names which are currently referenced, so that it is usable for + // style invalidation. + nsTHashSet> mMaybeReferencedAnimations; + + void DoUpdateAnimations(const mozilla::NonOwningAnimationTarget& aTarget, + const nsStyleUIReset& aStyle, + ServoCSSAnimationBuilder& aBuilder); +}; + +#endif /* !defined(nsAnimationManager_h_) */ -- cgit v1.2.3