Bug 1860712 [wpt PR 42705] - Port popover test to WPT and adjust for close requests...
[gecko.git] / dom / animation / AnimationEffect.h
blob7dbd51c2bf380a6697ea7c66ff37b2c3dc88cc12
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_AnimationEffect_h
8 #define mozilla_dom_AnimationEffect_h
10 #include "mozilla/ComputedTiming.h"
11 #include "mozilla/dom/Animation.h"
12 #include "mozilla/dom/Nullable.h"
13 #include "mozilla/dom/ScrollTimeline.h"
14 #include "mozilla/TimeStamp.h"
15 #include "mozilla/TimingParams.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsWrapperCache.h"
19 namespace mozilla {
20 class ErrorResult;
22 namespace dom {
24 class KeyframeEffect;
25 struct ComputedEffectTiming;
26 struct EffectTiming;
27 struct OptionalEffectTiming;
28 class Document;
30 class AnimationEffect : public nsISupports, public nsWrapperCache {
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(AnimationEffect)
35 AnimationEffect(Document* aDocument, TimingParams&& aTiming);
37 virtual KeyframeEffect* AsKeyframeEffect() { return nullptr; }
39 nsISupports* GetParentObject() const;
41 bool IsCurrent() const;
42 bool IsInEffect() const;
43 bool HasFiniteActiveDuration() const {
44 return NormalizedTiming().ActiveDuration() != TimeDuration::Forever();
47 // AnimationEffect interface
48 virtual void GetTiming(EffectTiming& aRetVal) const;
49 virtual void GetComputedTimingAsDict(ComputedEffectTiming& aRetVal) const;
50 virtual void UpdateTiming(const OptionalEffectTiming& aTiming,
51 ErrorResult& aRv);
53 const TimingParams& SpecifiedTiming() const { return mTiming; }
54 void SetSpecifiedTiming(TimingParams&& aTiming);
56 const TimingParams& NormalizedTiming() const {
57 MOZ_ASSERT((mAnimation && mAnimation->UsingScrollTimeline() &&
58 mNormalizedTiming) ||
59 !mNormalizedTiming,
60 "We do normalization only for progress-based timeline");
61 return mNormalizedTiming ? *mNormalizedTiming : mTiming;
64 // There are 3 conditions where we have to update the normalized timing:
65 // 1. mAnimation is changed, or
66 // 2. the timeline of mAnimation is changed, or
67 // 3. mTiming is changed.
68 void UpdateNormalizedTiming();
70 // This function takes as input the timing parameters of an animation and
71 // returns the computed timing at the specified local time.
73 // The local time may be null in which case only static parameters such as the
74 // active duration are calculated. All other members of the returned object
75 // are given a null/initial value.
77 // This function returns a null mProgress member of the return value
78 // if the animation should not be run
79 // (because it is not currently active and is not filling at this time).
80 static ComputedTiming GetComputedTimingAt(
81 const Nullable<TimeDuration>& aLocalTime, const TimingParams& aTiming,
82 double aPlaybackRate,
83 Animation::ProgressTimelinePosition aProgressTimelinePosition);
84 // Shortcut that gets the computed timing using the current local time as
85 // calculated from the timeline time.
86 ComputedTiming GetComputedTiming(const TimingParams* aTiming = nullptr) const;
88 virtual void SetAnimation(Animation* aAnimation) = 0;
89 Animation* GetAnimation() const { return mAnimation; };
91 /**
92 * Returns true if this effect animates one of the properties we consider
93 * geometric properties, e.g. properties such as 'width' or 'margin-left'
94 * that we try to synchronize with transform animations, on a valid target
95 * element.
97 virtual bool AffectsGeometry() const = 0;
99 protected:
100 virtual ~AnimationEffect();
102 Nullable<TimeDuration> GetLocalTime() const;
104 protected:
105 RefPtr<Document> mDocument;
106 RefPtr<Animation> mAnimation;
107 TimingParams mTiming;
108 Maybe<TimingParams> mNormalizedTiming;
110 // Whether the Animation is System, ResistFingerprinting, or neither
111 enum RTPCallerType mRTPCallerType;
114 } // namespace dom
115 } // namespace mozilla
117 #endif // mozilla_dom_AnimationEffect_h