Bug 1474247 - Factor out Animation::ReschedulePendingAnimations and make it public. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 12 Jul 2018 17:05:13 +0900
changeset 817225 721c9ea67538310b8c1467f5fd0e370e4576d305
parent 817183 4f924344e05eb747097fc47929293d7c8fa7cf37
child 817226 271e2a75da1fc01b5fa5ebce0a4e7a33c4f18b43
push id115993
push userhikezoe@mozilla.com
push dateThu, 12 Jul 2018 08:06:50 +0000
reviewersbirtles
bugs1474247
milestone63.0a1
Bug 1474247 - Factor out Animation::ReschedulePendingAnimations and make it public. r?birtles The function will be used in the case of KeyframeEffect::SetTarget too. MozReview-Commit-ID: G6ipjxaIJsW
dom/animation/Animation.cpp
dom/animation/Animation.h
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -184,38 +184,17 @@ Animation::SetEffectNoUpdate(AnimationEf
 
     // Notify possible add or change.
     // If the target is different, the change notification will be ignored by
     // AutoMutationBatchForAnimation.
     if (wasRelevant && mIsRelevant) {
       nsNodeUtils::AnimationChanged(this);
     }
 
-    // Reschedule pending pause or pending play tasks.
-    // If we have a pending animation, it will either be registered
-    // in the pending animation tracker and have a null pending ready time,
-    // or, after it has been painted, it will be removed from the tracker
-    // and assigned a pending ready time.
-    // After updating the effect we'll typically need to repaint so if we've
-    // already been assigned a pending ready time, we should clear it and put
-    // the animation back in the tracker.
-    if (!mPendingReadyTime.IsNull()) {
-      mPendingReadyTime.SetNull();
-
-      nsIDocument* doc = GetRenderedDocument();
-      if (doc) {
-        PendingAnimationTracker* tracker =
-          doc->GetOrCreatePendingAnimationTracker();
-        if (mPendingState == PendingState::PlayPending) {
-          tracker->AddPlayPending(*this);
-        } else {
-          tracker->AddPausePending(*this);
-        }
-      }
-    }
+    ReschedulePendingTasks();
   }
 
   UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
 }
 
 void
 Animation::SetTimeline(AnimationTimeline* aTimeline)
 {
@@ -1477,16 +1456,37 @@ Animation::ResetPendingTasks()
   ApplyPendingPlaybackRate();
 
   if (mReady) {
     mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
     mReady = nullptr;
   }
 }
 
+void
+Animation::ReschedulePendingTasks()
+{
+  if (mPendingReadyTime.IsNull()) {
+    return;
+  }
+
+  mPendingReadyTime.SetNull();
+
+  nsIDocument* doc = GetRenderedDocument();
+  if (doc) {
+    PendingAnimationTracker* tracker =
+      doc->GetOrCreatePendingAnimationTracker();
+    if (mPendingState == PendingState::PlayPending) {
+      tracker->AddPlayPending(*this);
+    } else {
+      tracker->AddPausePending(*this);
+    }
+  }
+}
+
 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
@@ -376,16 +376,31 @@ public:
    */
   void ComposeStyle(RawServoAnimationValueMap& aComposeResult,
                     const nsCSSPropertyIDSet& aPropertiesToSkip);
 
   void NotifyEffectTimingUpdated();
   void NotifyGeometricAnimationsStartingThisFrame();
 
   /**
+   * Reschedule pending pause or pending play tasks when updating the target
+   * effect.
+   *
+   * If we are pending, we will either be registered in the pending animation
+   * tracker and have a null pending ready time, or, after our effect has been
+   * painted, we will be removed from the tracker and assigned a pending ready
+   * time.
+   *
+   * When the target effect is updated, we'll typically need to repaint so for
+   * the latter case where we already have a pending ready time, clear it and put
+   * ourselves back in the pending animation tracker.
+   */
+  void ReschedulePendingTasks();
+
+  /**
    * Used by subclasses to synchronously queue a cancel event in situations
    * where the Animation may have been cancelled.
    *
    * We need to do this synchronously because after a CSS animation/transition
    * is canceled, it will be released by its owning element and may not still
    * exist when we would normally go to queue events on the next tick.
    */
   virtual void MaybeQueueCancelEvent(const StickyTimeDuration& aActiveTime) {};