Bug 1049975 - Part 6: Factor out the procedure of resetting an animation's pending tasks. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 15 Jul 2016 17:17:25 +0800
changeset 405234 7914562c12adec123e76f20b36fa29c91c644584
parent 405233 39dd12ce13c01282d19c8a533bcb2a9f68b180a4
child 405235 95b07957a6479b0ccc33d1fc47a6de8bfd1191ab
push id27442
push userbmo:boris.chiou@gmail.com
push dateThu, 25 Aug 2016 04:26:27 +0000
bugs1049975
milestone51.0a1
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
dom/animation/Animation.cpp
dom/animation/Animation.h
--- 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.