Bug 1049975 - Part 6: Factor out the procedure of resetting an animation's pending tasks.
Both Cancel() and SetEffect() need the procedure of "Reset an animation's
pending tasks", so factor it out and then we can reuse it.
MozReview-Commit-ID: C7Q5kF9aPrV
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -665,22 +665,17 @@ Animation::SilentlySetPlaybackRate(doubl
SilentlySetCurrentTime(previousTime.Value());
}
}
// https://w3c.github.io/web-animations/#cancel-an-animation
void
Animation::CancelNoUpdate()
{
- if (mPendingState != PendingState::NotPending) {
- CancelPendingTasks();
- if (mReady) {
- mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
- }
- }
+ ResetPendingTasks();
if (mFinished) {
mFinished->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}
ResetFinishedPromise();
DispatchPlaybackEvent(NS_LITERAL_STRING("cancel"));
@@ -1167,16 +1162,30 @@ Animation::CancelPendingTasks()
}
}
}
mPendingState = PendingState::NotPending;
mPendingReadyTime.SetNull();
}
+// https://w3c.github.io/web-animations/#reset-an-animations-pending-tasks
+void
+Animation::ResetPendingTasks()
+{
+ if (mPendingState == PendingState::NotPending) {
+ return;
+ }
+
+ CancelPendingTasks();
+ if (mReady) {
+ mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
+ }
+}
+
bool
Animation::IsPossiblyOrphanedPendingAnimation() const
{
// Check if we are pending but might never start because we are not being
// tracked.
//
// This covers the following cases:
//
--- a/dom/animation/Animation.h
+++ b/dom/animation/Animation.h
@@ -365,16 +365,22 @@ protected:
/**
* Remove this animation from the pending animation tracker and reset
* mPendingState as necessary. The caller is responsible for resolving or
* aborting the mReady promise as necessary.
*/
void CancelPendingTasks();
+ /**
+ * Performs the same steps as CancelPendingTasks and also rejects and
+ * recreates the ready promise if the animation was pending.
+ */
+ void ResetPendingTasks();
+
bool IsPossiblyOrphanedPendingAnimation() const;
StickyTimeDuration EffectEnd() const;
nsIDocument* GetRenderedDocument() const;
RefPtr<AnimationTimeline> mTimeline;
RefPtr<AnimationEffectReadOnly> mEffect;
// The beginning of the delay period.