Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / layout / style / nsAnimationManager.h
blobf37fa0a7d1e32263e7341b87b2cee27b3152249e
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;
21 namespace mozilla {
22 class ComputedStyle;
24 enum class PseudoStyleType : uint8_t;
25 struct NonOwningAnimationTarget;
27 } /* namespace mozilla */
29 class nsAnimationManager final
30 : public mozilla::CommonAnimationManager<mozilla::dom::CSSAnimation> {
31 public:
32 explicit nsAnimationManager(nsPresContext* aPresContext)
33 : mozilla::CommonAnimationManager<mozilla::dom::CSSAnimation>(
34 aPresContext) {}
36 typedef mozilla::AnimationCollection<mozilla::dom::CSSAnimation>
37 CSSAnimationCollection;
38 typedef nsTArray<RefPtr<mozilla::dom::CSSAnimation>>
39 OwningCSSAnimationPtrArray;
41 ~nsAnimationManager() override = default;
43 /**
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
57 // within |aIter|.
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
63 // Keyframe.
64 template <class IterType>
65 static bool FindMatchingKeyframe(
66 IterType&& aIter, double aOffset,
67 const mozilla::StyleComputedTimingFunction& aTimingFunctionToMatch,
68 mozilla::dom::CompositeOperationOrAuto aCompositionToMatch,
69 size_t& aIndex) {
70 aIndex = 0;
71 for (mozilla::Keyframe& keyframe : aIter) {
72 if (keyframe.mOffset.value() != aOffset) {
73 break;
75 const bool matches = [&] {
76 if (keyframe.mComposite != aCompositionToMatch) {
77 return false;
79 return keyframe.mTimingFunction
80 ? *keyframe.mTimingFunction == aTimingFunctionToMatch
81 : aTimingFunctionToMatch.IsLinearKeyword();
82 }();
83 if (matches) {
84 return true;
86 ++aIndex;
88 return false;
91 bool AnimationMayBeReferenced(nsAtom* aName) const {
92 return mMaybeReferencedAnimations.Contains(aName);
95 private:
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_) */