Bug 1420928 - BuildKeyframes takes animation name and timing function instead of StyleAnimation. r?boris draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 05 Jan 2018 06:24:07 +0900
changeset 715986 1beec1299ea9bf830c4326146e5c1fabd1458c95
parent 715985 cdc28b8713941554dad3415bcbfb7995c7e2701e
child 715987 15ae495e68b1d6902691ff7e33d1b2ddabe316fa
push id94292
push userhikezoe@mozilla.com
push dateThu, 04 Jan 2018 22:06:10 +0000
reviewersboris
bugs1420928
milestone59.0a1
Bug 1420928 - BuildKeyframes takes animation name and timing function instead of StyleAnimation. r?boris This is a prerequisite to use repeated values for the used value of the each animation property instead of the computed values. In a subsequent patch in this patch series, the timing function will be replaced with the one which may be a repeated value in computed animation timing function values list. MozReview-Commit-ID: GOKHE3MH0Ue
layout/style/nsAnimationManager.cpp
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -417,24 +417,24 @@ class MOZ_STACK_CLASS ServoCSSAnimationB
 public:
   explicit ServoCSSAnimationBuilder(const ServoStyleContext* aStyleContext)
     : mStyleContext(aStyleContext)
   {
     MOZ_ASSERT(aStyleContext);
   }
 
   bool BuildKeyframes(nsPresContext* aPresContext,
-                      const StyleAnimation& aSrc,
+                      nsAtom* aName,
+                      const nsTimingFunction& aTimingFunction,
                       nsTArray<Keyframe>& aKeyframes)
   {
     ServoStyleSet* styleSet = aPresContext->StyleSet()->AsServo();
     MOZ_ASSERT(styleSet);
-    const nsTimingFunction& timingFunction = aSrc.GetTimingFunction();
-    return styleSet->GetKeyframesForName(aSrc.GetName(),
-                                         timingFunction,
+    return styleSet->GetKeyframesForName(aName,
+                                         aTimingFunction,
                                          aKeyframes);
   }
   void SetKeyframes(KeyframeEffectReadOnly& aEffect,
                     nsTArray<Keyframe>&& aKeyframes)
   {
     aEffect.SetKeyframes(Move(aKeyframes), mStyleContext);
   }
 
@@ -488,29 +488,30 @@ public:
     : mStyleContext(aStyleContext)
     , mTarget(aTarget)
   {
     MOZ_ASSERT(aStyleContext);
     MOZ_ASSERT(aTarget.mElement);
   }
 
   bool BuildKeyframes(nsPresContext* aPresContext,
-                      const StyleAnimation& aSrc,
+                      nsAtom* aName,
+                      const nsTimingFunction& aTimingFunction,
                       nsTArray<Keyframe>& aKeyframs);
   void SetKeyframes(KeyframeEffectReadOnly& aEffect,
                     nsTArray<Keyframe>&& aKeyframes)
   {
     aEffect.SetKeyframes(Move(aKeyframes), mStyleContext);
   }
 
   void NotifyNewOrRemovedAnimation(const Animation&) {}
 
 private:
   nsTArray<Keyframe> BuildAnimationFrames(nsPresContext* aPresContext,
-                                          const StyleAnimation& aSrc,
+                                          const nsTimingFunction& aTimingFunction,
                                           const nsCSSKeyframesRule* aRule);
   Maybe<ComputedTimingFunction> GetKeyframeTimingFunction(
     nsPresContext* aPresContext,
     nsCSSKeyframeRule* aKeyframeRule,
     const Maybe<ComputedTimingFunction>& aInheritedTimingFunction);
   nsTArray<PropertyValuePair> GetKeyframePropertyValues(
     nsPresContext* aPresContext,
     nsCSSKeyframeRule* aKeyframeRule,
@@ -591,17 +592,20 @@ BuildAnimation(nsPresContext* aPresConte
                const NonOwningAnimationTarget& aTarget,
                const StyleAnimation& aSrc,
                BuilderType& aBuilder,
                nsAnimationManager::CSSAnimationCollection* aCollection)
 {
   MOZ_ASSERT(aPresContext);
 
   nsTArray<Keyframe> keyframes;
-  if (!aBuilder.BuildKeyframes(aPresContext, aSrc, keyframes)) {
+  if (!aBuilder.BuildKeyframes(aPresContext,
+                               aSrc.GetName(),
+                               aSrc.GetTimingFunction(),
+                               keyframes)) {
     return nullptr;
   }
 
   TimingParams timing = TimingParamsFromCSSParams(aSrc.GetDuration(),
                                                   aSrc.GetDelay(),
                                                   aSrc.GetIterationCount(),
                                                   aSrc.GetDirection(),
                                                   aSrc.GetFillMode());
@@ -658,37 +662,39 @@ BuildAnimation(nsPresContext* aPresConte
 
   aBuilder.NotifyNewOrRemovedAnimation(*animation);
 
   return animation.forget();
 }
 
 bool
 GeckoCSSAnimationBuilder::BuildKeyframes(nsPresContext* aPresContext,
-                                         const StyleAnimation& aSrc,
+                                         nsAtom* aName,
+                                         const nsTimingFunction& aTimingFunction,
                                          nsTArray<Keyframe>& aKeyframes)
 {
   MOZ_ASSERT(aPresContext);
   MOZ_ASSERT(aPresContext->StyleSet()->IsGecko());
 
   nsCSSKeyframesRule* rule =
-    aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
+    aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aName);
   if (!rule) {
     return false;
   }
 
-  aKeyframes = BuildAnimationFrames(aPresContext, aSrc, rule);
+  aKeyframes = BuildAnimationFrames(aPresContext, aTimingFunction, rule);
 
   return true;
 }
 
 nsTArray<Keyframe>
-GeckoCSSAnimationBuilder::BuildAnimationFrames(nsPresContext* aPresContext,
-                                               const StyleAnimation& aSrc,
-                                               const nsCSSKeyframesRule* aRule)
+GeckoCSSAnimationBuilder::BuildAnimationFrames(
+  nsPresContext* aPresContext,
+  const nsTimingFunction& aTimingFunction,
+  const nsCSSKeyframesRule* aRule)
 {
   // Ideally we'd like to build up a set of Keyframe objects that more-or-less
   // reflect the keyframes as-specified in the @keyframes rule(s) so that
   // authors get something intuitive when they call anim.effect.getKeyframes().
   //
   // That, however, proves to be difficult because the way CSS declarations are
   // processed differs from how we are able to represent keyframes as
   // JavaScript objects in the Web Animations API.
@@ -728,17 +734,17 @@ GeckoCSSAnimationBuilder::BuildAnimation
   // for that matter) we resolve values on @keyframes down to computed values
   // (thereby expanding shorthands and variable references) and then pick up the
   // last value for each longhand property at each offset.
 
   // FIXME: There is a pending spec change to make multiple @keyframes
   // rules with the same name cascade but we don't support that yet.
 
   Maybe<ComputedTimingFunction> inheritedTimingFunction =
-    ConvertTimingFunction(aSrc.GetTimingFunction());
+    ConvertTimingFunction(aTimingFunction);
 
   // First, make up Keyframe objects for each rule
   nsTArray<Keyframe> keyframes;
   nsCSSPropertyIDSet animatedProperties;
 
   for (auto ruleIdx = 0, ruleEnd = aRule->StyleRuleCount();
        ruleIdx != ruleEnd; ++ruleIdx) {
     css::Rule* cssRule = aRule->GetStyleRuleAt(ruleIdx);