Bug 1340322 - Part 9: Templatize functions that will be used with servo's computed values. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 06 Mar 2017 09:51:16 +0900
changeset 375005 7bacb513bfc1ead958300239eb00d347496f2118
parent 375004 7d02b6e56202ec621029de7991ffa21d3a68bc9e
child 375006 a04bbcdfda14751ed34095fd90a5b02e1574f1e1
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 9: Templatize functions that will be used with servo's computed values. r=birtles MozReview-Commit-ID: 8d5wHBhF4y9
layout/style/nsAnimationManager.cpp
layout/style/nsAnimationManager.h
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -468,23 +468,24 @@ private:
 
   ResolvedStyleCache mResolvedStyles;
   RefPtr<nsStyleContext> mStyleWithoutAnimation;
 };
 
 static Maybe<ComputedTimingFunction>
 ConvertTimingFunction(const nsTimingFunction& aTimingFunction);
 
+template<class BuilderType>
 static void
 UpdateOldAnimationPropertiesWithNew(
     CSSAnimation& aOld,
     TimingParams& aNewTiming,
     nsTArray<Keyframe>&& aNewKeyframes,
     bool aNewIsStylePaused,
-    CSSAnimationBuilder& aBuilder)
+    BuilderType& aBuilder)
 {
   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;
@@ -521,21 +522,22 @@ UpdateOldAnimationPropertiesWithNew(
   if (animationChanged && aOld.IsRelevant()) {
     nsNodeUtils::AnimationChanged(&aOld);
   }
 }
 
 // Returns a new animation set up with given StyleAnimation.
 // Or returns an existing animation matching StyleAnimation's name updated
 // with the new StyleAnimation.
+template<class BuilderType>
 static already_AddRefed<CSSAnimation>
 BuildAnimation(nsPresContext* aPresContext,
                const NonOwningAnimationTarget& aTarget,
                const StyleAnimation& aSrc,
-               CSSAnimationBuilder& aBuilder,
+               BuilderType& aBuilder,
                nsAnimationManager::CSSAnimationCollection* aCollection)
 {
   MOZ_ASSERT(aPresContext);
 
   nsTArray<Keyframe> keyframes;
   if (!aBuilder.BuildKeyframes(aPresContext, aSrc, keyframes)) {
     return nullptr;
   }
@@ -1025,22 +1027,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;
 }
 
+template<class BuilderType>
 static nsAnimationManager::OwningCSSAnimationPtrArray
 BuildAnimations(nsPresContext* aPresContext,
                 const NonOwningAnimationTarget& aTarget,
                 const nsStyleAutoArray<StyleAnimation>& aStyleAnimations,
                 uint32_t aStyleAnimationNameCount,
-                CSSAnimationBuilder& aBuilder,
+                BuilderType& aBuilder,
                 nsAnimationManager::CSSAnimationCollection* aCollection)
 {
   nsAnimationManager::OwningCSSAnimationPtrArray result;
 
   for (size_t animIdx = aStyleAnimationNameCount; animIdx-- != 0;) {
     const StyleAnimation& src = aStyleAnimations[animIdx];
 
     // CSS Animations whose animation-name does not match a @keyframes rule do
@@ -1084,21 +1087,22 @@ nsAnimationManager::UpdateAnimations(nsS
 
   NonOwningAnimationTarget target(aElement, aStyleContext->GetPseudoType());
   CSSAnimationBuilder builder(aStyleContext, target);
 
   const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
   DoUpdateAnimations(target, *disp, builder);
 }
 
+template<class BuilderType>
 void
 nsAnimationManager::DoUpdateAnimations(
   const NonOwningAnimationTarget& aTarget,
   const nsStyleDisplay& aStyleDisplay,
-  CSSAnimationBuilder& aBuilder)
+  BuilderType& aBuilder)
 {
   // 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.
 
   CSSAnimationCollection* collection =
     CSSAnimationCollection::GetAnimationCollection(aTarget.mElement,
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -10,17 +10,16 @@
 #include "mozilla/EventForwards.h"
 #include "AnimationCommon.h"
 #include "mozilla/dom/Animation.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/TimeStamp.h"
 
 class nsIGlobalObject;
 class nsStyleContext;
-class CSSAnimationBuilder; // tentative, will be removed
 struct nsStyleDisplay;
 
 namespace mozilla {
 namespace css {
 class Declaration;
 } /* namespace css */
 namespace dom {
 class KeyframeEffectReadOnly;
@@ -352,17 +351,18 @@ public:
   // ::before and ::after.
   void StopAnimationsForElement(mozilla::dom::Element* aElement,
                                 mozilla::CSSPseudoElementType aPseudoType);
 
 protected:
   ~nsAnimationManager() override = default;
 
 private:
+  template<class BuilderType>
   void DoUpdateAnimations(
     const mozilla::NonOwningAnimationTarget& aTarget,
     const nsStyleDisplay& aStyleDisplay,
-    CSSAnimationBuilder& aBuilder);
+    BuilderType& aBuilder);
 
   mozilla::DelayedEventDispatcher<mozilla::AnimationEventInfo> mEventDispatcher;
 };
 
 #endif /* !defined(nsAnimationManager_h_) */