1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsAnimationManager_h_
7 #define nsAnimationManager_h_
9 #include "mozilla/Attributes.h"
10 #include "AnimationCommon.h"
11 #include "mozilla/dom/CSSAnimation.h"
12 #include "mozilla/Keyframe.h"
13 #include "mozilla/MemoryReporting.h"
14 #include "nsISupportsImpl.h"
15 #include "nsTHashSet.h"
17 class ServoCSSAnimationBuilder
;
19 struct nsStyleUIReset
;
24 enum class PseudoStyleType
: uint8_t;
25 struct NonOwningAnimationTarget
;
27 } /* namespace mozilla */
29 class nsAnimationManager final
30 : public mozilla::CommonAnimationManager
<mozilla::dom::CSSAnimation
> {
32 explicit nsAnimationManager(nsPresContext
* aPresContext
)
33 : mozilla::CommonAnimationManager
<mozilla::dom::CSSAnimation
>(
36 typedef mozilla::AnimationCollection
<mozilla::dom::CSSAnimation
>
37 CSSAnimationCollection
;
38 typedef nsTArray
<RefPtr
<mozilla::dom::CSSAnimation
>>
39 OwningCSSAnimationPtrArray
;
41 ~nsAnimationManager() override
= default;
44 * This function does the same thing as the above UpdateAnimations()
45 * but with servo's computed values.
47 void UpdateAnimations(mozilla::dom::Element
* aElement
,
48 mozilla::PseudoStyleType aPseudoType
,
49 const mozilla::ComputedStyle
* aComputedValues
);
51 // Utility function to walk through |aIter| to find the Keyframe with
52 // matching offset and timing function but stopping as soon as the offset
53 // differs from |aOffset| (i.e. it assumes a sorted iterator).
55 // If a matching Keyframe is found,
56 // Returns true and sets |aIndex| to the index of the matching Keyframe
59 // If no matching Keyframe is found,
60 // Returns false and sets |aIndex| to the index in the iterator of the
61 // first Keyframe with an offset differing to |aOffset| or, if the end
62 // of the iterator is reached, sets |aIndex| to the index after the last
64 template <class IterType
>
65 static bool FindMatchingKeyframe(
66 IterType
&& aIter
, double aOffset
,
67 const mozilla::StyleComputedTimingFunction
& aTimingFunctionToMatch
,
68 mozilla::dom::CompositeOperationOrAuto aCompositionToMatch
,
71 for (mozilla::Keyframe
& keyframe
: aIter
) {
72 if (keyframe
.mOffset
.value() != aOffset
) {
75 const bool matches
= [&] {
76 if (keyframe
.mComposite
!= aCompositionToMatch
) {
79 return keyframe
.mTimingFunction
80 ? *keyframe
.mTimingFunction
== aTimingFunctionToMatch
81 : aTimingFunctionToMatch
.IsLinearKeyword();
91 bool AnimationMayBeReferenced(nsAtom
* aName
) const {
92 return mMaybeReferencedAnimations
.Contains(aName
);
96 // This includes all animation names referenced regardless of whether a
97 // corresponding `@keyframes` rule is available.
99 // It may contain names which are no longer referenced, but it should always
100 // contain names which are currently referenced, so that it is usable for
101 // style invalidation.
102 nsTHashSet
<RefPtr
<nsAtom
>> mMaybeReferencedAnimations
;
104 void DoUpdateAnimations(const mozilla::NonOwningAnimationTarget
& aTarget
,
105 const nsStyleUIReset
& aStyle
,
106 ServoCSSAnimationBuilder
& aBuilder
);
109 #endif /* !defined(nsAnimationManager_h_) */