Bug 1328787 - Part 2: Don't pass nsCSSKeyframesRule* to CSSAnimationBuild::Build. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 26 Jan 2017 20:13:29 +0900
changeset 467017 bcef5c679501fb1992cb7d0881d0a8ae07080dab
parent 467016 9203737586509d00700f00ee4f6b00cfaa8b2ffa
child 467018 4a032ac61d8e39fdb664a0fc4d5ca1e126ed8f9e
push id43089
push userhikezoe@mozilla.com
push dateFri, 27 Jan 2017 01:33:18 +0000
reviewersheycam
bugs1328787
milestone54.0a1
Bug 1328787 - Part 2: Don't pass nsCSSKeyframesRule* to CSSAnimationBuild::Build. r?heycam Because, in case of stylo, we don't have nsCSSKeyframesRule. MozReview-Commit-ID: uWlrFihjbx
layout/style/nsAnimationManager.cpp
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -532,24 +532,22 @@ public:
     , mTarget(aTarget)
     , mCollection(aCollection)
   {
     MOZ_ASSERT(aStyleContext);
     MOZ_ASSERT(aTarget);
     mTimeline = mTarget->OwnerDoc()->Timeline();
   }
 
-  // Returns a new animation set up with given StyleAnimation and
-  // keyframe rules.
+  // Returns a new animation set up with given StyleAnimation.
   // Or returns an existing animation matching StyleAnimation's name updated
-  // with the new StyleAnimation and keyframe rules.
+  // with the new StyleAnimation.
   already_AddRefed<CSSAnimation>
   Build(nsPresContext* aPresContext,
         const StyleAnimation& aSrc,
-        const nsCSSKeyframesRule* aRule,
         uint64_t aAnimationIndex);
 
 private:
   nsTArray<Keyframe> BuildAnimationFrames(nsPresContext* aPresContext,
                                           const StyleAnimation& aSrc,
                                           const nsCSSKeyframesRule* aRule);
   Maybe<ComputedTimingFunction> GetKeyframeTimingFunction(
     nsPresContext* aPresContext,
@@ -601,26 +599,30 @@ private:
 };
 
 static Maybe<ComputedTimingFunction>
 ConvertTimingFunction(const nsTimingFunction& aTimingFunction);
 
 already_AddRefed<CSSAnimation>
 CSSAnimationBuilder::Build(nsPresContext* aPresContext,
                            const StyleAnimation& aSrc,
-                           const nsCSSKeyframesRule* aRule,
                            uint64_t aAnimationIndex)
 {
   MOZ_ASSERT(aPresContext);
-  MOZ_ASSERT(aRule);
+
+  nsCSSKeyframesRule* rule =
+    aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
+  if (!rule) {
+    return nullptr;
+  }
 
   TimingParams timing = TimingParamsFrom(aSrc);
 
   nsTArray<Keyframe> keyframes =
-    BuildAnimationFrames(aPresContext, aSrc, aRule);
+    BuildAnimationFrames(aPresContext, aSrc, rule);
 
   bool isStylePaused =
     aSrc.GetPlayState() == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
 
   // Find the matching animation with animation name in the old list
   // of animations and remove the matched animation from the list.
   RefPtr<CSSAnimation> oldAnim =
     PopExistingAnimation(aSrc.GetName(), mCollection);
@@ -1086,26 +1088,27 @@ nsAnimationManager::BuildAnimations(nsSt
   for (size_t animIdx = disp->mAnimationNameCount; animIdx-- != 0;) {
     const StyleAnimation& src = disp->mAnimations[animIdx];
 
     // CSS Animations whose animation-name does not match a @keyframes rule do
     // 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;
+    }
+
     MOZ_ASSERT(mPresContext->StyleSet()->IsGecko(),
                "ServoStyleSet should not use nsAnimationManager for "
                "animations");
-    nsCSSKeyframesRule* rule =
-      src.GetName().IsEmpty()
-      ? nullptr
-      : mPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(src.GetName());
-    if (!rule) {
+
+    RefPtr<CSSAnimation> dest =
+      builder.Build(mPresContext, src, static_cast<uint64_t>(animIdx));
+    if (!dest) {
       continue;
     }
 
-    RefPtr<CSSAnimation> dest =
-      builder.Build(mPresContext, src, rule, static_cast<uint64_t>(animIdx));
     dest->SetAnimationIndex(static_cast<uint64_t>(animIdx));
     aAnimations.AppendElement(dest);
   }
 }