Bug 1834993 - Fix nursery allocatable flag for objects with foreground finalizers...
[gecko.git] / dom / animation / Animation.h
blobbbe2ab7a3ec1fe50e863ddac489b453e3ee8b578
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/. */
7 #ifndef mozilla_dom_Animation_h
8 #define mozilla_dom_Animation_h
10 #include "X11UndefineNone.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "mozilla/AnimationPerformanceWarning.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/BasePrincipal.h"
15 #include "mozilla/DOMEventTargetHelper.h"
16 #include "mozilla/EffectCompositor.h" // For EffectCompositor::CascadeLevel
17 #include "mozilla/LinkedList.h"
18 #include "mozilla/Maybe.h"
19 #include "mozilla/PostRestyleMode.h"
20 #include "mozilla/StickyTimeDuration.h"
21 #include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
22 #include "mozilla/dom/AnimationBinding.h" // for AnimationPlayState
23 #include "mozilla/dom/AnimationTimeline.h"
25 struct JSContext;
26 class nsCSSPropertyIDSet;
27 class nsIFrame;
28 class nsIGlobalObject;
30 namespace mozilla {
32 struct AnimationRule;
33 class MicroTaskRunnable;
35 namespace dom {
37 class AnimationEffect;
38 class AsyncFinishNotification;
39 class CSSAnimation;
40 class CSSTransition;
41 class Document;
42 class Promise;
44 class Animation : public DOMEventTargetHelper,
45 public LinkedListElement<Animation> {
46 protected:
47 virtual ~Animation();
49 public:
50 explicit Animation(nsIGlobalObject* aGlobal);
52 // Constructs a copy of |aOther| with a new effect and timeline.
53 // This is only intended to be used while making a static clone of a document
54 // during printing, and does not assume that |aOther| is in the same document
55 // as any of the other arguments.
56 static already_AddRefed<Animation> ClonePausedAnimation(
57 nsIGlobalObject* aGlobal, const Animation& aOther,
58 AnimationEffect& aEffect, AnimationTimeline& aTimeline);
60 NS_DECL_ISUPPORTS_INHERITED
61 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Animation, DOMEventTargetHelper)
63 nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
65 /**
66 * Utility function to get the target (pseudo-)element associated with an
67 * animation.
69 NonOwningAnimationTarget GetTargetForAnimation() const;
71 virtual JSObject* WrapObject(JSContext* aCx,
72 JS::Handle<JSObject*> aGivenProto) override;
74 virtual CSSAnimation* AsCSSAnimation() { return nullptr; }
75 virtual const CSSAnimation* AsCSSAnimation() const { return nullptr; }
76 virtual CSSTransition* AsCSSTransition() { return nullptr; }
77 virtual const CSSTransition* AsCSSTransition() const { return nullptr; }
79 /**
80 * Flag to pass to Play to indicate whether or not it should automatically
81 * rewind the current time to the start point if the animation is finished.
82 * For regular calls to play() from script we should do this, but when a CSS
83 * animation's animation-play-state changes we shouldn't rewind the animation.
85 enum class LimitBehavior { AutoRewind, Continue };
87 // Animation interface methods
88 static already_AddRefed<Animation> Constructor(
89 const GlobalObject& aGlobal, AnimationEffect* aEffect,
90 const Optional<AnimationTimeline*>& aTimeline, ErrorResult& aRv);
92 void GetId(nsAString& aResult) const { aResult = mId; }
93 void SetId(const nsAString& aId);
95 AnimationEffect* GetEffect() const { return mEffect; }
96 virtual void SetEffect(AnimationEffect* aEffect);
97 void SetEffectNoUpdate(AnimationEffect* aEffect);
99 // FIXME: Bug 1676794. This is a tentative solution before we implement
100 // ScrollTimeline interface. If the timeline is scroll/view timeline, we
101 // return null. Once we implement ScrollTimeline interface, we can drop this.
102 already_AddRefed<AnimationTimeline> GetTimelineFromJS() const {
103 return mTimeline && mTimeline->IsScrollTimeline() ? nullptr
104 : do_AddRef(mTimeline);
106 void SetTimelineFromJS(AnimationTimeline* aTimeline) {
107 SetTimeline(aTimeline);
110 AnimationTimeline* GetTimeline() const { return mTimeline; }
111 void SetTimeline(AnimationTimeline* aTimeline);
112 void SetTimelineNoUpdate(AnimationTimeline* aTimeline);
114 Nullable<TimeDuration> GetStartTime() const { return mStartTime; }
115 Nullable<double> GetStartTimeAsDouble() const;
116 void SetStartTime(const Nullable<TimeDuration>& aNewStartTime);
117 virtual void SetStartTimeAsDouble(const Nullable<double>& aStartTime);
119 // This is deliberately _not_ called GetCurrentTime since that would clash
120 // with a macro defined in winbase.h
121 Nullable<TimeDuration> GetCurrentTimeAsDuration() const {
122 return GetCurrentTimeForHoldTime(mHoldTime);
124 Nullable<double> GetCurrentTimeAsDouble() const;
125 void SetCurrentTime(const TimeDuration& aSeekTime);
126 void SetCurrentTimeNoUpdate(const TimeDuration& aSeekTime);
127 void SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
128 ErrorResult& aRv);
130 double PlaybackRate() const { return mPlaybackRate; }
131 void SetPlaybackRate(double aPlaybackRate);
133 AnimationPlayState PlayState() const;
134 virtual AnimationPlayState PlayStateFromJS() const { return PlayState(); }
136 bool Pending() const { return mPendingState != PendingState::NotPending; }
137 virtual bool PendingFromJS() const { return Pending(); }
138 AnimationReplaceState ReplaceState() const { return mReplaceState; }
140 virtual Promise* GetReady(ErrorResult& aRv);
141 Promise* GetFinished(ErrorResult& aRv);
143 IMPL_EVENT_HANDLER(finish);
144 IMPL_EVENT_HANDLER(cancel);
145 IMPL_EVENT_HANDLER(remove);
147 void Cancel(PostRestyleMode aPostRestyle = PostRestyleMode::IfNeeded);
149 void Finish(ErrorResult& aRv);
151 void Play(ErrorResult& aRv, LimitBehavior aLimitBehavior);
152 virtual void PlayFromJS(ErrorResult& aRv) {
153 Play(aRv, LimitBehavior::AutoRewind);
156 void Pause(ErrorResult& aRv);
157 virtual void PauseFromJS(ErrorResult& aRv) { Pause(aRv); }
159 void UpdatePlaybackRate(double aPlaybackRate);
160 virtual void Reverse(ErrorResult& aRv);
162 void Persist();
163 MOZ_CAN_RUN_SCRIPT void CommitStyles(ErrorResult& aRv);
165 bool IsRunningOnCompositor() const;
167 virtual void Tick();
168 bool NeedsTicks() const {
169 return Pending() ||
170 (PlayState() == AnimationPlayState::Running &&
171 // An animation with a zero playback rate doesn't need ticks even if
172 // it is running since it effectively behaves as if it is paused.
174 // It's important we return false in this case since a zero playback
175 // rate animation in the before or after phase that doesn't fill
176 // won't be relevant and hence won't be returned by GetAnimations().
177 // We don't want its timeline to keep it alive (which would happen
178 // if we return true) since otherwise it will effectively be leaked.
179 PlaybackRate() != 0.0) ||
180 // Always return true for not idle animations attached to not
181 // monotonically increasing timelines even if the animation is
182 // finished. This is required to accommodate cases where timeline
183 // ticks back in time.
184 (mTimeline && !mTimeline->IsMonotonicallyIncreasing() &&
185 PlayState() != AnimationPlayState::Idle);
189 * Set the time to use for starting or pausing a pending animation.
191 * Typically, when an animation is played, it does not start immediately but
192 * is added to a table of pending animations on the document of its effect.
193 * In the meantime it sets its hold time to the time from which playback
194 * should begin.
196 * When the document finishes painting, any pending animations in its table
197 * are marked as being ready to start by calling TriggerOnNextTick.
198 * The moment when the paint completed is also recorded, converted to a
199 * timeline time, and passed to StartOnTick. This is so that when these
200 * animations do start, they can be timed from the point when painting
201 * completed.
203 * After calling TriggerOnNextTick, animations remain in the pending state
204 * until the next refresh driver tick. At that time they transition out of
205 * the pending state using the time passed to TriggerOnNextTick as the
206 * effective time at which they resumed.
208 * This approach means that any setup time required for performing the
209 * initial paint of an animation such as layerization is not deducted from
210 * the running time of the animation. Without this we can easily drop the
211 * first few frames of an animation, or, on slower devices, the whole
212 * animation.
214 * Furthermore:
216 * - Starting the animation immediately when painting finishes is problematic
217 * because the start time of the animation will be ahead of its timeline
218 * (since the timeline time is based on the refresh driver time).
219 * That's a problem because the animation is playing but its timing
220 * suggests it starts in the future. We could update the timeline to match
221 * the start time of the animation but then we'd also have to update the
222 * timing and style of all animations connected to that timeline or else be
223 * stuck in an inconsistent state until the next refresh driver tick.
225 * - If we simply use the refresh driver time on its next tick, the lag
226 * between triggering an animation and its effective start is unacceptably
227 * long.
229 * For pausing, we apply the same asynchronous approach. This is so that we
230 * synchronize with animations that are running on the compositor. Otherwise
231 * if the main thread lags behind the compositor there will be a noticeable
232 * jump backwards when the main thread takes over. Even though main thread
233 * animations could be paused immediately, we do it asynchronously for
234 * consistency and so that animations paused together end up in step.
236 * Note that the caller of this method is responsible for removing the
237 * animation from any PendingAnimationTracker it may have been added to.
239 void TriggerOnNextTick(const Nullable<TimeDuration>& aReadyTime);
241 * For the monotonically increasing timeline, we use this only for testing:
242 * Start or pause a pending animation using the current timeline time. This
243 * is used to support existing tests that expect animations to begin
244 * immediately. Ideally we would rewrite the those tests and get rid of this
245 * method, but there are a lot of them.
247 * As with TriggerOnNextTick, the caller of this method is responsible for
248 * removing the animation from any PendingAnimationTracker it may have been
249 * added to.
251 void TriggerNow();
253 * For the non-monotonically increasing timeline (e.g. ScrollTimeline), we try
254 * to trigger it in ScrollTimelineAnimationTracker by this method. This uses
255 * the current scroll position as the ready time. Return true if we don't need
256 * to trigger it or we trigger it successfully.
258 bool TryTriggerNowForFiniteTimeline();
260 * When TriggerOnNextTick is called, we store the ready time but we don't
261 * apply it until the next tick. In the meantime, GetStartTime() will return
262 * null.
264 * However, if we build layer animations again before the next tick, we
265 * should initialize them with the start time that GetStartTime() will return
266 * on the next tick.
268 * If we were to simply set the start time of layer animations to null, their
269 * start time would be updated to the current wallclock time when rendering
270 * finishes, thus making them out of sync with the start time stored here.
271 * This, in turn, will make the animation jump backwards when we build
272 * animations on the next tick and apply the start time stored here.
274 * This method returns the start time, if resolved. Otherwise, if we have
275 * a pending ready time, it returns the corresponding start time. If neither
276 * of those are available, it returns null.
278 Nullable<TimeDuration> GetCurrentOrPendingStartTime() const;
281 * As with the start time, we should use the pending playback rate when
282 * producing layer animations.
284 double CurrentOrPendingPlaybackRate() const {
285 return mPendingPlaybackRate.valueOr(mPlaybackRate);
287 bool HasPendingPlaybackRate() const { return mPendingPlaybackRate.isSome(); }
290 * The following relationship from the definition of the 'current time' is
291 * re-used in many algorithms so we extract it here into a static method that
292 * can be re-used:
294 * current time = (timeline time - start time) * playback rate
296 * As per https://drafts.csswg.org/web-animations-1/#current-time
298 static TimeDuration CurrentTimeFromTimelineTime(
299 const TimeDuration& aTimelineTime, const TimeDuration& aStartTime,
300 float aPlaybackRate) {
301 return (aTimelineTime - aStartTime).MultDouble(aPlaybackRate);
305 * As with calculating the current time, we often need to calculate a start
306 * time from a current time. The following method simply inverts the current
307 * time relationship.
309 * In each case where this is used, the desired behavior for playbackRate ==
310 * 0 is to return the specified timeline time (often referred to as the ready
311 * time).
313 static TimeDuration StartTimeFromTimelineTime(
314 const TimeDuration& aTimelineTime, const TimeDuration& aCurrentTime,
315 float aPlaybackRate) {
316 TimeDuration result = aTimelineTime;
317 if (aPlaybackRate == 0) {
318 return result;
321 result -= aCurrentTime.MultDouble(1.0 / aPlaybackRate);
322 return result;
326 * Converts a time in the timescale of this Animation's currentTime, to a
327 * TimeStamp. Returns a null TimeStamp if the conversion cannot be performed
328 * because of the current state of this Animation (e.g. it has no timeline, a
329 * zero playbackRate, an unresolved start time etc.) or the value of the time
330 * passed-in (e.g. an infinite time).
332 TimeStamp AnimationTimeToTimeStamp(const StickyTimeDuration& aTime) const;
334 // Converts an AnimationEvent's elapsedTime value to an equivalent TimeStamp
335 // that can be used to sort events by when they occurred.
336 TimeStamp ElapsedTimeToTimeStamp(
337 const StickyTimeDuration& aElapsedTime) const;
339 bool IsPausedOrPausing() const {
340 return PlayState() == AnimationPlayState::Paused;
343 bool HasCurrentEffect() const;
344 bool IsInEffect() const;
346 bool IsPlaying() const {
347 return mPlaybackRate != 0.0 && mTimeline &&
348 !mTimeline->GetCurrentTimeAsDuration().IsNull() &&
349 PlayState() == AnimationPlayState::Running;
352 bool ShouldBeSynchronizedWithMainThread(
353 const nsCSSPropertyIDSet& aPropertySet, const nsIFrame* aFrame,
354 AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const;
356 bool IsRelevant() const { return mIsRelevant; }
357 void UpdateRelevance();
359 // https://drafts.csswg.org/web-animations-1/#replaceable-animation
360 bool IsReplaceable() const;
363 * Returns true if this Animation satisfies the requirements for being
364 * removed when it is replaced.
366 * Returning true does not imply this animation _should_ be removed.
367 * Determining that depends on the other effects in the same EffectSet to
368 * which this animation's effect, if any, contributes.
370 bool IsRemovable() const;
373 * Make this animation's target effect no-longer part of the effect stack
374 * while preserving its timing information.
376 void Remove();
379 * Returns true if this Animation has a lower composite order than aOther.
381 bool HasLowerCompositeOrderThan(const Animation& aOther) const;
384 * Returns the level at which the effect(s) associated with this Animation
385 * are applied to the CSS cascade.
387 virtual EffectCompositor::CascadeLevel CascadeLevel() const {
388 return EffectCompositor::CascadeLevel::Animations;
392 * Returns true if this animation does not currently need to update
393 * style on the main thread (e.g. because it is empty, or is
394 * running on the compositor).
396 bool CanThrottle() const;
399 * Updates various bits of state that we need to update as the result of
400 * running ComposeStyle().
401 * See the comment of KeyframeEffect::WillComposeStyle for more detail.
403 void WillComposeStyle();
406 * Updates |aComposeResult| with the animation values of this animation's
407 * effect, if any.
408 * Any properties contained in |aPropertiesToSkip| will not be added or
409 * updated in |aComposeResult|.
411 void ComposeStyle(StyleAnimationValueMap& aComposeResult,
412 const nsCSSPropertyIDSet& aPropertiesToSkip);
414 void NotifyEffectTimingUpdated();
415 void NotifyEffectPropertiesUpdated();
416 void NotifyEffectTargetUpdated();
417 void NotifyGeometricAnimationsStartingThisFrame();
420 * Reschedule pending pause or pending play tasks when updating the target
421 * effect.
423 * If we are pending, we will either be registered in the pending animation
424 * tracker and have a null pending ready time, or, after our effect has been
425 * painted, we will be removed from the tracker and assigned a pending ready
426 * time.
428 * When the target effect is updated, we'll typically need to repaint so for
429 * the latter case where we already have a pending ready time, clear it and
430 * put ourselves back in the pending animation tracker.
432 void ReschedulePendingTasks();
435 * Used by subclasses to synchronously queue a cancel event in situations
436 * where the Animation may have been cancelled.
438 * We need to do this synchronously because after a CSS animation/transition
439 * is canceled, it will be released by its owning element and may not still
440 * exist when we would normally go to queue events on the next tick.
442 virtual void MaybeQueueCancelEvent(const StickyTimeDuration& aActiveTime){};
444 Maybe<uint32_t>& CachedChildIndexRef() { return mCachedChildIndex; }
446 void SetPartialPrerendered(uint64_t aIdOnCompositor) {
447 mIdOnCompositor = aIdOnCompositor;
448 mIsPartialPrerendered = true;
450 bool IsPartialPrerendered() const { return mIsPartialPrerendered; }
451 uint64_t IdOnCompositor() const { return mIdOnCompositor; }
453 * Needs to be called when the pre-rendered animation is going to no longer
454 * run on the compositor.
456 void ResetPartialPrerendered() {
457 MOZ_ASSERT(mIsPartialPrerendered);
458 mIsPartialPrerendered = false;
459 mIdOnCompositor = 0;
462 * Called via NotifyJankedAnimations IPC call from the compositor to update
463 * pre-rendered area on the main-thread.
465 void UpdatePartialPrerendered() {
466 ResetPartialPrerendered();
467 PostUpdate();
470 bool UsingScrollTimeline() const {
471 return mTimeline && mTimeline->IsScrollTimeline();
475 * Returns true if this is at the progress timeline boundary.
476 * https://drafts.csswg.org/web-animations-2/#at-progress-timeline-boundary
478 enum class ProgressTimelinePosition : uint8_t { Boundary, NotBoundary };
479 static ProgressTimelinePosition AtProgressTimelineBoundary(
480 const Nullable<TimeDuration>& aTimelineDuration,
481 const Nullable<TimeDuration>& aCurrentTime,
482 const TimeDuration& aEffectStartTime, const double aPlaybackRate);
483 ProgressTimelinePosition AtProgressTimelineBoundary() const {
484 Nullable<TimeDuration> currentTime = GetUnconstrainedCurrentTime();
485 return AtProgressTimelineBoundary(
486 mTimeline ? mTimeline->TimelineDuration() : nullptr,
487 // Set unlimited current time based on the first matching condition:
488 // 1. start time is resolved:
489 // (timeline time - start time) × playback rate
490 // 2. Otherwise:
491 // animation’s current time
492 !currentTime.IsNull() ? currentTime : GetCurrentTimeAsDuration(),
493 mStartTime.IsNull() ? TimeDuration() : mStartTime.Value(),
494 mPlaybackRate);
497 void SetHiddenByContentVisibility(bool hidden);
498 bool IsHiddenByContentVisibility() const {
499 return mHiddenByContentVisibility;
502 DocGroup* GetDocGroup();
504 protected:
505 void SilentlySetCurrentTime(const TimeDuration& aNewCurrentTime);
506 void CancelNoUpdate();
507 void PlayNoUpdate(ErrorResult& aRv, LimitBehavior aLimitBehavior);
508 void ResumeAt(const TimeDuration& aReadyTime);
509 void PauseAt(const TimeDuration& aReadyTime);
510 void FinishPendingAt(const TimeDuration& aReadyTime) {
511 if (mPendingState == PendingState::PlayPending) {
512 ResumeAt(aReadyTime);
513 } else if (mPendingState == PendingState::PausePending) {
514 PauseAt(aReadyTime);
515 } else {
516 MOZ_ASSERT_UNREACHABLE(
517 "Can't finish pending if we're not in a pending state");
520 void ApplyPendingPlaybackRate() {
521 if (mPendingPlaybackRate) {
522 mPlaybackRate = *mPendingPlaybackRate;
523 mPendingPlaybackRate.reset();
528 * Finishing behavior depends on if changes to timing occurred due
529 * to a seek or regular playback.
531 enum class SeekFlag { NoSeek, DidSeek };
533 enum class SyncNotifyFlag { Sync, Async };
535 virtual void UpdateTiming(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag);
536 void UpdateFinishedState(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag);
537 void UpdateEffect(PostRestyleMode aPostRestyle);
539 * Flush all pending styles other than throttled animation styles (e.g.
540 * animations running on the compositor).
542 void FlushUnanimatedStyle() const;
543 void PostUpdate();
544 void ResetFinishedPromise();
545 void MaybeResolveFinishedPromise();
546 void DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag);
547 friend class AsyncFinishNotification;
548 void DoFinishNotificationImmediately(MicroTaskRunnable* aAsync = nullptr);
549 void QueuePlaybackEvent(const nsAString& aName,
550 TimeStamp&& aScheduledEventTime);
553 * Remove this animation from the pending animation tracker and reset
554 * mPendingState as necessary. The caller is responsible for resolving or
555 * aborting the mReady promise as necessary.
557 void CancelPendingTasks();
560 * Performs the same steps as CancelPendingTasks and also rejects and
561 * recreates the ready promise if the animation was pending.
563 void ResetPendingTasks();
566 * Returns true if this animation is not only play-pending, but has
567 * yet to be given a pending ready time. This roughly corresponds to
568 * animations that are waiting to be painted (since we set the pending
569 * ready time at the end of painting). Identifying such animations is
570 * useful because in some cases animations that are painted together
571 * may need to be synchronized.
573 * We don't, however, want to include animations with a fixed start time such
574 * as animations that are simply having their playbackRate updated or which
575 * are resuming from an aborted pause.
577 bool IsNewlyStarted() const {
578 return mPendingState == PendingState::PlayPending &&
579 mPendingReadyTime.IsNull() && mStartTime.IsNull();
581 bool IsPossiblyOrphanedPendingAnimation() const;
582 StickyTimeDuration EffectEnd() const;
584 Nullable<TimeDuration> GetCurrentTimeForHoldTime(
585 const Nullable<TimeDuration>& aHoldTime) const;
586 Nullable<TimeDuration> GetUnconstrainedCurrentTime() const {
587 return GetCurrentTimeForHoldTime(Nullable<TimeDuration>());
590 void ScheduleReplacementCheck();
591 void MaybeScheduleReplacementCheck();
593 // Earlier side of the elapsed time range reported in CSS Animations and CSS
594 // Transitions events.
596 // https://drafts.csswg.org/css-animations-2/#interval-start
597 // https://drafts.csswg.org/css-transitions-2/#interval-start
598 StickyTimeDuration IntervalStartTime(
599 const StickyTimeDuration& aActiveDuration) const;
601 // Later side of the elapsed time range reported in CSS Animations and CSS
602 // Transitions events.
604 // https://drafts.csswg.org/css-animations-2/#interval-end
605 // https://drafts.csswg.org/css-transitions-2/#interval-end
606 StickyTimeDuration IntervalEndTime(
607 const StickyTimeDuration& aActiveDuration) const;
609 TimeStamp GetTimelineCurrentTimeAsTimeStamp() const {
610 return mTimeline ? mTimeline->GetCurrentTimeAsTimeStamp() : TimeStamp();
613 Document* GetRenderedDocument() const;
614 Document* GetTimelineDocument() const;
616 bool HasFiniteTimeline() const {
617 return mTimeline && !mTimeline->IsMonotonicallyIncreasing();
620 void UpdatePendingAnimationTracker(AnimationTimeline* aOldTimeline,
621 AnimationTimeline* aNewTimeline);
623 RefPtr<AnimationTimeline> mTimeline;
624 RefPtr<AnimationEffect> mEffect;
625 // The beginning of the delay period.
626 Nullable<TimeDuration> mStartTime; // Timeline timescale
627 Nullable<TimeDuration> mHoldTime; // Animation timescale
628 Nullable<TimeDuration> mPendingReadyTime; // Timeline timescale
629 Nullable<TimeDuration> mPreviousCurrentTime; // Animation timescale
630 double mPlaybackRate = 1.0;
631 Maybe<double> mPendingPlaybackRate;
633 // A Promise that is replaced on each call to Play()
634 // and fulfilled when Play() is successfully completed.
635 // This object is lazily created by GetReady.
636 // See http://drafts.csswg.org/web-animations/#current-ready-promise
637 RefPtr<Promise> mReady;
639 // A Promise that is resolved when we reach the end of the effect, or
640 // 0 when playing backwards. The Promise is replaced if the animation is
641 // finished but then a state change makes it not finished.
642 // This object is lazily created by GetFinished.
643 // See http://drafts.csswg.org/web-animations/#current-finished-promise
644 RefPtr<Promise> mFinished;
646 static uint64_t sNextAnimationIndex;
648 // The relative position of this animation within the global animation list.
650 // Note that subclasses such as CSSTransition and CSSAnimation may repurpose
651 // this member to implement their own brand of sorting. As a result, it is
652 // possible for two different objects to have the same index.
653 uint64_t mAnimationIndex;
655 // While ordering Animation objects for event dispatch, the index of the
656 // target node in its parent may be cached in mCachedChildIndex.
657 Maybe<uint32_t> mCachedChildIndex;
659 // Indicates if the animation is in the pending state (and what state it is
660 // waiting to enter when it finished pending). We use this rather than
661 // checking if this animation is tracked by a PendingAnimationTracker because
662 // the animation will continue to be pending even after it has been removed
663 // from the PendingAnimationTracker while it is waiting for the next tick
664 // (see TriggerOnNextTick for details).
665 enum class PendingState : uint8_t { NotPending, PlayPending, PausePending };
666 PendingState mPendingState = PendingState::NotPending;
668 // Handling of this animation's target effect when filling while finished.
669 AnimationReplaceState mReplaceState = AnimationReplaceState::Active;
671 bool mFinishedAtLastComposeStyle = false;
672 bool mWasReplaceableAtLastTick = false;
674 bool mHiddenByContentVisibility = false;
676 // Indicates that the animation should be exposed in an element's
677 // getAnimations() list.
678 bool mIsRelevant = false;
680 // True if mFinished is resolved or would be resolved if mFinished has
681 // yet to be created. This is not set when mFinished is rejected since
682 // in that case mFinished is immediately reset to represent a new current
683 // finished promise.
684 bool mFinishedIsResolved = false;
686 // True if this animation was triggered at the same time as one or more
687 // geometric animations and hence we should run any transform animations on
688 // the main thread.
689 bool mSyncWithGeometricAnimations = false;
691 RefPtr<MicroTaskRunnable> mFinishNotificationTask;
693 nsString mId;
695 bool mResetCurrentTimeOnResume = false;
697 // Whether the Animation is System, ResistFingerprinting, or neither
698 RTPCallerType mRTPCallerType;
700 private:
701 // The id for this animaiton on the compositor.
702 uint64_t mIdOnCompositor = 0;
703 bool mIsPartialPrerendered = false;
706 } // namespace dom
707 } // namespace mozilla
709 #endif // mozilla_dom_Animation_h