Bug 1242872 - Part 4: Factor updating animation properties process out. r?dbaron draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sat, 13 Feb 2016 11:42:07 +0900
changeset 330824 33f46ef817562be8149e2f0e3626a1825afb83cc
parent 330823 754f7d035a29bb4d58fc56fbc819e6d6401ea5ce
child 330825 b6996591aeef8a6743eab1384e5b47b41905941a
push id10851
push userbmo:hiikezoe@mozilla-japan.org
push dateSat, 13 Feb 2016 11:34:41 +0000
reviewersdbaron
bugs1242872
milestone47.0a1
Bug 1242872 - Part 4: Factor updating animation properties process out. r?dbaron MozReview-Commit-ID: JtOMluIM09X
layout/style/nsAnimationManager.cpp
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -321,16 +321,62 @@ PullOutOldAnimationInCollection(const ns
     if (a->AnimationName() == aName) {
       aCollection->mAnimations.RemoveElementAt(oldIdx);
       return a.forget();
     }
   }
   return nullptr;
 }
 
+static void
+UpdateOldAnimationPropertiesWithNew(CSSAnimation& aOld, Animation& aNew)
+{
+  bool animationChanged = false;
+
+  // Update the old from the new so we can keep the original object
+  // identity (and any expando properties attached to it).
+  if (aOld.GetEffect() && aNew.GetEffect()) {
+    KeyframeEffectReadOnly* oldEffect = aOld.GetEffect();
+    KeyframeEffectReadOnly* newEffect = aNew.GetEffect();
+    animationChanged =
+      oldEffect->SpecifiedTiming() != newEffect->SpecifiedTiming() ||
+      oldEffect->Properties() != newEffect->Properties();
+    oldEffect->SetSpecifiedTiming(newEffect->SpecifiedTiming());
+    oldEffect->CopyPropertiesFrom(*newEffect);
+  }
+
+  // Handle changes in play state. If the animation is idle, however,
+  // changes to animation-play-state should *not* restart it.
+  if (aOld.PlayState() != AnimationPlayState::Idle) {
+    // CSSAnimation takes care of override behavior so that,
+    // for example, if the author has called pause(), that will
+    // override the animation-play-state.
+    // (We should check aNew->IsStylePaused() but that requires
+    //  downcasting to CSSAnimation and we happen to know that
+    //  aNew will only ever be paused by calling PauseFromStyle
+    //  making IsPausedOrPausing synonymous in this case.)
+    if (!aOld.IsStylePaused() && aNew.IsPausedOrPausing()) {
+      aOld.PauseFromStyle();
+      animationChanged = true;
+    } else if (aOld.IsStylePaused() && !aNew.IsPausedOrPausing()) {
+      aOld.PlayFromStyle();
+      animationChanged = true;
+    }
+  }
+
+  aOld.CopyAnimationIndex(*aNew.AsCSSAnimation());
+
+  // Updating the effect timing above might already have caused the
+  // animation to become irrelevant so only add a changed record if
+  // the animation is still relevant.
+  if (animationChanged && aOld.IsRelevant()) {
+    nsNodeUtils::AnimationChanged(&aOld);
+  }
+}
+
 nsIStyleRule*
 nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext,
                                        mozilla::dom::Element* aElement)
 {
   // Ignore animations for print or print preview, and for elements
   // that are not attached to the document tree.
   if (!mPresContext->IsDynamic() || !aElement->IsInComposedDoc()) {
     return nullptr;
@@ -404,59 +450,17 @@ nsAnimationManager::CheckAnimationRule(n
           // until the animation is actually ready to run. However, we
           // currently have some tests that assume that these events are
           // dispatched within the same tick as the animation is added
           // so we need to queue up any animationstart events from newly-created
           // animations.
           newAnim->AsCSSAnimation()->QueueEvents();
           continue;
         }
-
-        bool animationChanged = false;
-
-        // Update the old from the new so we can keep the original object
-        // identity (and any expando properties attached to it).
-        if (oldAnim->GetEffect() && newAnim->GetEffect()) {
-          KeyframeEffectReadOnly* oldEffect = oldAnim->GetEffect();
-          KeyframeEffectReadOnly* newEffect = newAnim->GetEffect();
-          animationChanged =
-            oldEffect->SpecifiedTiming() != newEffect->SpecifiedTiming() ||
-            oldEffect->Properties() != newEffect->Properties();
-          oldEffect->SetSpecifiedTiming(newEffect->SpecifiedTiming());
-          oldEffect->CopyPropertiesFrom(*newEffect);
-        }
-
-        // Handle changes in play state. If the animation is idle, however,
-        // changes to animation-play-state should *not* restart it.
-        if (oldAnim->PlayState() != AnimationPlayState::Idle) {
-          // CSSAnimation takes care of override behavior so that,
-          // for example, if the author has called pause(), that will
-          // override the animation-play-state.
-          // (We should check newAnim->IsStylePaused() but that requires
-          //  downcasting to CSSAnimation and we happen to know that
-          //  newAnim will only ever be paused by calling PauseFromStyle
-          //  making IsPausedOrPausing synonymous in this case.)
-          if (!oldAnim->IsStylePaused() && newAnim->IsPausedOrPausing()) {
-            oldAnim->PauseFromStyle();
-            animationChanged = true;
-          } else if (oldAnim->IsStylePaused() &&
-                    !newAnim->IsPausedOrPausing()) {
-            oldAnim->PlayFromStyle();
-            animationChanged = true;
-          }
-        }
-
-        oldAnim->CopyAnimationIndex(*newAnim->AsCSSAnimation());
-
-        // Updating the effect timing above might already have caused the
-        // animation to become irrelevant so only add a changed record if
-        // the animation is still relevant.
-        if (animationChanged && oldAnim->IsRelevant()) {
-          nsNodeUtils::AnimationChanged(oldAnim);
-        }
+        UpdateOldAnimationPropertiesWithNew(*oldAnim, *newAnim);
 
         // Replace new animation with the (updated) old one.
         //
         // Although we're doing this while iterating this is safe because
         // we're not changing the length of newAnimations.
         newAnim->CancelFromStyle();
         newAnim = nullptr;
         newAnimations.ReplaceElementAt(newIdx, oldAnim);