Bug 1340322 - Part 13: Update CSS Animations with servo's computed values. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 06 Mar 2017 10:09:47 +0900
changeset 493784 0462ca873355c4817fb7cb6ab432181756f1906f
parent 493783 11b1bf587972ff10223b7336b8bebb1de5466190
child 493831 e2ec7152d9a3cc75a36f8529442750ec135beb7b
push id47837
push userhikezoe@mozilla.com
push dateMon, 06 Mar 2017 01:11:14 +0000
reviewersbirtles
bugs1340322
milestone54.0a1
Bug 1340322 - Part 13: Update CSS Animations with servo's computed values. r?birtles MozReview-Commit-ID: B7uSH7wrx3b
layout/style/ServoStyleSet.cpp
layout/style/nsAnimationManager.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -163,23 +163,29 @@ ServoStyleSet::GetContext(already_AddRef
 
   // Ignore animations for print or print preview, and for elements
   // that are not attached to the document tree.
   if (mPresContext->IsDynamic() &&
       aElementForAnimation &&
       aElementForAnimation->IsInComposedDoc()) {
     // Update/build CSS animations in the case where animation properties are
     // changed.
-    // FIXME: This isn't right place to update CSS animations. We should do it
-    // , presumably, in cascade_node() in servo side and process the initial
-    // restyle there too.
-    // To do that we need to make updating CSS animations process independent
-    // from nsStyleContext. Also we need to make the process thread safe.
-    mPresContext->AnimationManager()->UpdateAnimations(result,
-                                                       aElementForAnimation);
+    // FIXME: Bug 1341985: This isn't right place to update CSS animations.
+    // We should do it in a SequentialTask and trigger the second traversal for
+    // the animation's restyle after the SequentialTask.
+    const ServoComputedValues* currentStyle =
+      result->StyleSource().AsServoComputedValues();
+    const ServoComputedValues* parentStyle =
+      result->GetParent()
+        ? result->GetParent()->StyleSource().AsServoComputedValues()
+        : nullptr;
+    mPresContext->AnimationManager()->UpdateAnimations(aElementForAnimation,
+                                                       aPseudoTag,
+                                                       currentStyle,
+                                                       parentStyle);
   }
 
   return result.forget();
 }
 
 void
 ServoStyleSet::ResolveMappedAttrDeclarationBlocks()
 {
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -635,38 +635,26 @@ BuildAnimation(nsPresContext* aPresConte
 }
 
 bool
 GeckoCSSAnimationBuilder::BuildKeyframes(nsPresContext* aPresContext,
                                          const StyleAnimation& aSrc,
                                          nsTArray<Keyframe>& aKeyframes)
 {
   MOZ_ASSERT(aPresContext);
+  MOZ_ASSERT(aPresContext->StyleSet()->IsGecko());
 
-  if (aPresContext->StyleSet()->IsServo()) {
-    ServoStyleSet* styleSet = aPresContext->StyleSet()->AsServo();
-    MOZ_ASSERT(styleSet);
-    const ServoComputedValues* computedValues =
-      mStyleContext->StyleSource().AsServoComputedValues();
-    const nsTimingFunction& timingFunction = aSrc.GetTimingFunction();
-    if (!styleSet->FillKeyframesForName(aSrc.GetName(),
-                                        timingFunction,
-                                        computedValues,
-                                        aKeyframes)) {
-      return false;
-    }
-  } else {
-    nsCSSKeyframesRule* rule =
-      aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
-    if (!rule) {
-      return false;
-    }
-    aKeyframes = BuildAnimationFrames(aPresContext, aSrc, rule);
+  nsCSSKeyframesRule* rule =
+    aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
+  if (!rule) {
+    return false;
   }
 
+  aKeyframes = BuildAnimationFrames(aPresContext, aSrc, rule);
+
   return true;
 }
 
 nsTArray<Keyframe>
 GeckoCSSAnimationBuilder::BuildAnimationFrames(nsPresContext* aPresContext,
                                                const StyleAnimation& aSrc,
                                                const nsCSSKeyframesRule* aRule)
 {