Bug 1340322 - Part 3: Make BuildAnimations static function. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 06 Mar 2017 09:48:36 +0900
changeset 374999 ce3017376156099b7218884c60817d1a3c07910f
parent 374998 9e162c4475cb182fed1178adb164c19ba9193790
child 375000 ab3ba7fa8608999e3c7107e7de0a4c48ca75915b
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1340322
milestone54.0a1
Bug 1340322 - Part 3: Make BuildAnimations static function. r=birtles This function will be also a template function. MozReview-Commit-ID: 4SbzEw8YzIZ
layout/style/nsAnimationManager.cpp
layout/style/nsAnimationManager.h
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -404,82 +404,16 @@ UpdateOldAnimationPropertiesWithNew(
   // 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::UpdateAnimations(nsStyleContext* aStyleContext,
-                                     mozilla::dom::Element* aElement)
-{
-  MOZ_ASSERT(mPresContext->IsDynamic(),
-             "Should not update animations for print or print preview");
-  MOZ_ASSERT(aElement->IsInComposedDoc(),
-             "Should not update animations that are not attached to the "
-             "document tree");
-
-  NonOwningAnimationTarget target(aElement, aStyleContext->GetPseudoType());
-
-  // Everything that causes our animation data to change triggers a
-  // style change, which in turn triggers a non-animation restyle.
-  // Likewise, when we initially construct frames, we're not in a
-  // style change, but also not in an animation restyle.
-
-  const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
-  CSSAnimationCollection* collection =
-    CSSAnimationCollection::GetAnimationCollection(target.mElement,
-                                                   target.mPseudoType);
-  if (!collection &&
-      disp->mAnimationNameCount == 1 &&
-      disp->mAnimations[0].GetName().IsEmpty()) {
-    return;
-  }
-
-  nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
-
-  // Build the updated animations list, extracting matching animations from
-  // the existing collection as we go.
-  OwningCSSAnimationPtrArray newAnimations;
-  if (!aStyleContext->IsInDisplayNoneSubtree()) {
-    BuildAnimations(aStyleContext, target, collection, newAnimations);
-  }
-
-  if (newAnimations.IsEmpty()) {
-    if (collection) {
-      collection->Destroy();
-    }
-    return;
-  }
-
-  if (!collection) {
-    bool createdCollection = false;
-    collection =
-      CSSAnimationCollection::GetOrCreateAnimationCollection(
-        target.mElement, target.mPseudoType, &createdCollection);
-    if (!collection) {
-      MOZ_ASSERT(!createdCollection, "outparam should agree with return value");
-      NS_WARNING("allocating collection failed");
-      return;
-    }
-
-    if (createdCollection) {
-      AddElementCollection(collection);
-    }
-  }
-  collection->mAnimations.SwapElements(newAnimations);
-
-  // Cancel removed animations
-  for (size_t newAnimIdx = newAnimations.Length(); newAnimIdx-- != 0; ) {
-    newAnimations[newAnimIdx]->CancelFromStyle();
-  }
-}
-
-void
 nsAnimationManager::StopAnimationsForElement(
   mozilla::dom::Element* aElement,
   mozilla::CSSPseudoElementType aPseudoType)
 {
   MOZ_ASSERT(aElement);
   CSSAnimationCollection* collection =
     CSSAnimationCollection::GetAnimationCollection(aElement, aPseudoType);
   if (!collection) {
@@ -1070,23 +1004,23 @@ CSSAnimationBuilder::GetComputedValue(ns
   // If we hit this assertion, it probably means we are fetching a value from
   // the computed style that we don't know how to represent as
   // a StyleAnimationValue.
   MOZ_ASSERT(result.GetUnit() != eCSSUnit_Null, "Got null computed value");
 
   return result;
 }
 
-void
-nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
-                                    const NonOwningAnimationTarget& aTarget,
-                                    CSSAnimationCollection* aCollection,
-                                    OwningCSSAnimationPtrArray& aAnimations)
+static nsAnimationManager::OwningCSSAnimationPtrArray
+BuildAnimations(nsPresContext* aPresContext,
+                nsStyleContext* aStyleContext,
+                const NonOwningAnimationTarget& aTarget,
+                nsAnimationManager::CSSAnimationCollection* aCollection)
 {
-  MOZ_ASSERT(aAnimations.IsEmpty(), "expect empty array");
+  nsAnimationManager::OwningCSSAnimationPtrArray result;
 
   const nsStyleDisplay *disp = aStyleContext->StyleDisplay();
 
   CSSAnimationBuilder builder(aStyleContext, aTarget);
 
   for (size_t animIdx = disp->mAnimationNameCount; animIdx-- != 0;) {
     const StyleAnimation& src = disp->mAnimations[animIdx];
 
@@ -1094,23 +1028,93 @@ nsAnimationManager::BuildAnimations(nsSt
     // not generate animation events. This includes when the animation-name is
     // "none" which is represented by an empty name in the StyleAnimation.
     // Since such animations neither affect style nor dispatch events, we do
     // not generate a corresponding CSSAnimation for them.
     if (src.GetName().IsEmpty()) {
       continue;
     }
 
-    RefPtr<CSSAnimation> dest = BuildAnimation(mPresContext,
+    RefPtr<CSSAnimation> dest = BuildAnimation(aPresContext,
                                                aStyleContext,
                                                aTarget,
                                                src,
                                                builder,
                                                aCollection);
     if (!dest) {
       continue;
     }
 
     dest->SetAnimationIndex(static_cast<uint64_t>(animIdx));
-    aAnimations.AppendElement(dest);
+    result.AppendElement(dest);
+  }
+  return result;
+}
+
+void
+nsAnimationManager::UpdateAnimations(nsStyleContext* aStyleContext,
+                                     mozilla::dom::Element* aElement)
+{
+  MOZ_ASSERT(mPresContext->IsDynamic(),
+             "Should not update animations for print or print preview");
+  MOZ_ASSERT(aElement->IsInComposedDoc(),
+             "Should not update animations that are not attached to the "
+             "document tree");
+
+  NonOwningAnimationTarget target(aElement, aStyleContext->GetPseudoType());
+
+  // Everything that causes our animation data to change triggers a
+  // style change, which in turn triggers a non-animation restyle.
+  // Likewise, when we initially construct frames, we're not in a
+  // style change, but also not in an animation restyle.
+
+  const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
+  CSSAnimationCollection* collection =
+    CSSAnimationCollection::GetAnimationCollection(target.mElement,
+                                                   target.mPseudoType);
+  if (!collection &&
+      disp->mAnimationNameCount == 1 &&
+      disp->mAnimations[0].GetName().IsEmpty()) {
+    return;
+  }
+
+  nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
+
+  // Build the updated animations list, extracting matching animations from
+  // the existing collection as we go.
+  OwningCSSAnimationPtrArray newAnimations;
+  if (!aStyleContext->IsInDisplayNoneSubtree()) {
+    newAnimations = BuildAnimations(mPresContext,
+                                    aStyleContext,
+                                    target,
+                                    collection);
+  }
+
+  if (newAnimations.IsEmpty()) {
+    if (collection) {
+      collection->Destroy();
+    }
+    return;
+  }
+
+  if (!collection) {
+    bool createdCollection = false;
+    collection =
+      CSSAnimationCollection::GetOrCreateAnimationCollection(
+        target.mElement, target.mPseudoType, &createdCollection);
+    if (!collection) {
+      MOZ_ASSERT(!createdCollection, "outparam should agree with return value");
+      NS_WARNING("allocating collection failed");
+      return;
+    }
+
+    if (createdCollection) {
+      AddElementCollection(collection);
+    }
+  }
+  collection->mAnimations.SwapElements(newAnimations);
+
+  // Cancel removed animations
+  for (size_t newAnimIdx = newAnimations.Length(); newAnimIdx-- != 0; ) {
+    newAnimations[newAnimIdx]->CancelFromStyle();
   }
 }
 
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -350,18 +350,12 @@ public:
   // ::before and ::after.
   void StopAnimationsForElement(mozilla::dom::Element* aElement,
                                 mozilla::CSSPseudoElementType aPseudoType);
 
 protected:
   ~nsAnimationManager() override = default;
 
 private:
-
-  void BuildAnimations(nsStyleContext* aStyleContext,
-                       const mozilla::NonOwningAnimationTarget& aTarget,
-                       CSSAnimationCollection* aCollection,
-                       OwningCSSAnimationPtrArray& aAnimations);
-
   mozilla::DelayedEventDispatcher<mozilla::AnimationEventInfo> mEventDispatcher;
 };
 
 #endif /* !defined(nsAnimationManager_h_) */