Bug 1340322 - Part 3: Make UpdateOldAnimationPropertiesWithNew as a member function of CSSAnimationBuilder. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 28 Feb 2017 09:16:34 +0900
changeset 490274 4cd574c1832c5b7aa7422351f7bd2ab2028f2de3
parent 490273 11431b3682bf7bf87a9d41a7a3e72990659697e2
child 490275 35006169282422128857af1f6a5a43fff878767c
push id47049
push userhikezoe@mozilla.com
push dateTue, 28 Feb 2017 00:17:16 +0000
reviewersbirtles
bugs1340322
milestone54.0a1
Bug 1340322 - Part 3: Make UpdateOldAnimationPropertiesWithNew as a member function of CSSAnimationBuilder. r?birtles MozReview-Commit-ID: C1eEwD2LQR9
layout/style/nsAnimationManager.cpp
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -350,66 +350,16 @@ PopExistingAnimation(const nsAString& aN
       aCollection->mAnimations.RemoveElementAt(idx);
       return match.forget();
     }
   }
 
   return nullptr;
 }
 
-static void
-UpdateOldAnimationPropertiesWithNew(
-    CSSAnimation& aOld,
-    TimingParams& aNewTiming,
-    nsTArray<Keyframe>&& aNewKeyframes,
-    bool aNewIsStylePaused,
-    nsStyleContext* aStyleContext)
-{
-  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()) {
-    dom::AnimationEffectReadOnly* oldEffect = aOld.GetEffect();
-    animationChanged = oldEffect->SpecifiedTiming() != aNewTiming;
-    oldEffect->SetSpecifiedTiming(aNewTiming);
-
-    KeyframeEffectReadOnly* oldKeyframeEffect = oldEffect->AsKeyframeEffect();
-    if (oldKeyframeEffect) {
-      oldKeyframeEffect->SetKeyframes(Move(aNewKeyframes), aStyleContext);
-    }
-  }
-
-  // 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() && aNewIsStylePaused) {
-      aOld.PauseFromStyle();
-      animationChanged = true;
-    } else if (aOld.IsStylePaused() && !aNewIsStylePaused) {
-      aOld.PlayFromStyle();
-      animationChanged = true;
-    }
-  }
-
-  // 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);
-  }
-}
-
 void
 nsAnimationManager::StopAnimationsForElement(
   mozilla::dom::Element* aElement,
   mozilla::CSSPseudoElementType aPseudoType)
 {
   MOZ_ASSERT(aElement);
   CSSAnimationCollection* collection =
     CSSAnimationCollection::GetAnimationCollection(aElement, aPseudoType);
@@ -488,16 +438,22 @@ public:
 private:
   // Returns a new animation set up with given StyleAnimation.
   // Or returns an existing animation matching StyleAnimation's name updated
   // with the new StyleAnimation.
   already_AddRefed<CSSAnimation>
   Build(nsPresContext* aPresContext,
         const StyleAnimation& aSrc);
 
+  void
+  UpdateOldAnimationPropertiesWithNew(CSSAnimation& aOld,
+                                      TimingParams& aNewTiming,
+                                      nsTArray<Keyframe>&& aNewKeyframes,
+                                      bool aNewIsStylePaused);
+
   nsTArray<Keyframe> BuildAnimationFrames(nsPresContext* aPresContext,
                                           const StyleAnimation& aSrc,
                                           const nsCSSKeyframesRule* aRule);
   Maybe<ComputedTimingFunction> GetKeyframeTimingFunction(
     nsPresContext* aPresContext,
     nsCSSKeyframeRule* aKeyframeRule,
     const Maybe<ComputedTimingFunction>& aInheritedTimingFunction);
   nsTArray<PropertyValuePair> GetKeyframePropertyValues(
@@ -535,16 +491,65 @@ private:
   RefPtr<nsStyleContext> mStyleWithoutAnimation;
   // Existing collection, nullptr if the target element has no animations.
   nsAnimationManager::CSSAnimationCollection* mCollection;
 };
 
 static Maybe<ComputedTimingFunction>
 ConvertTimingFunction(const nsTimingFunction& aTimingFunction);
 
+void
+CSSAnimationBuilder::UpdateOldAnimationPropertiesWithNew(
+  CSSAnimation& aOld,
+  TimingParams& aNewTiming,
+  nsTArray<Keyframe>&& aNewKeyframes,
+  bool aNewIsStylePaused)
+{
+  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()) {
+    dom::AnimationEffectReadOnly* oldEffect = aOld.GetEffect();
+    animationChanged = oldEffect->SpecifiedTiming() != aNewTiming;
+    oldEffect->SetSpecifiedTiming(aNewTiming);
+
+    KeyframeEffectReadOnly* oldKeyframeEffect = oldEffect->AsKeyframeEffect();
+    if (oldKeyframeEffect) {
+      oldKeyframeEffect->SetKeyframes(Move(aNewKeyframes), mStyleContext);
+    }
+  }
+
+  // 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() && aNewIsStylePaused) {
+      aOld.PauseFromStyle();
+      animationChanged = true;
+    } else if (aOld.IsStylePaused() && !aNewIsStylePaused) {
+      aOld.PlayFromStyle();
+      animationChanged = true;
+    }
+  }
+
+  // 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);
+  }
+}
+
 already_AddRefed<CSSAnimation>
 CSSAnimationBuilder::Build(nsPresContext* aPresContext,
                            const StyleAnimation& aSrc)
 {
   MOZ_ASSERT(aPresContext);
 
   nsTArray<Keyframe> keyframes;
   if (aPresContext->StyleSet()->IsServo()) {
@@ -586,18 +591,17 @@ CSSAnimationBuilder::Build(nsPresContext
     // This means that we honor dynamic changes, which isn't what the
     // spec says to do, but WebKit seems to honor at least some of
     // them.  See
     // http://lists.w3.org/Archives/Public/www-style/2011Apr/0079.html
     // In order to honor what the spec said, we'd copy more data over.
     UpdateOldAnimationPropertiesWithNew(*oldAnim,
                                         timing,
                                         Move(keyframes),
-                                        isStylePaused,
-                                        mStyleContext);
+                                        isStylePaused);
     return oldAnim.forget();
   }
 
   // mTarget is non-null here, so we emplace it directly.
   Maybe<OwningAnimationTarget> target;
   target.emplace(mTarget, mPseudoType);
   KeyframeEffectParams effectOptions;
   RefPtr<KeyframeEffectReadOnly> effect =