Bug 1349004 part 3 - Use UpdateProperties with ServoComputedValues. r?hiro draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Mon, 10 Apr 2017 15:14:17 +0900
changeset 559454 b2ada2221fab35ec74604e5627289a34de1b9844
parent 559451 edae685da2271e729ffd66f408599e43eb9041b7
child 623399 d60701b11e1b712a33f656fd0893cbdda3767d92
push id53099
push userbmo:mantaroh@gmail.com
push dateMon, 10 Apr 2017 06:14:55 +0000
reviewershiro
bugs1349004
milestone55.0a1
Bug 1349004 part 3 - Use UpdateProperties with ServoComputedValues. r?hiro MozReview-Commit-ID: I9KPHu9cORP
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffectReadOnly.cpp
dom/animation/KeyframeEffectReadOnly.h
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -105,22 +105,17 @@ KeyframeEffect::SetTarget(const Nullable
       nsNodeUtils::AnimationRemoved(mAnimation);
     }
   }
 
   mTarget = newTarget;
 
   if (mTarget) {
     UpdateTargetRegistration();
-    RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
-    if (styleContext) {
-      UpdateProperties(styleContext);
-    } else if (mEffectOptions.mSpacingMode == SpacingMode::paced) {
-      KeyframeUtils::ApplyDistributeSpacing(mKeyframes);
-    }
+    UpdatePropertiesFromCurrentStyle();
 
     MaybeUpdateFrameForCompositor();
 
     RequestRestyle(EffectCompositor::RestyleType::Layer);
 
     nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
     if (mAnimation) {
       nsNodeUtils::AnimationAdded(mAnimation);
@@ -168,20 +163,17 @@ KeyframeEffect::SetComposite(const Compo
 
   mEffectOptions.mComposite = aComposite;
 
   if (mAnimation && mAnimation->IsRelevant()) {
     nsNodeUtils::AnimationChanged(mAnimation);
   }
 
   if (mTarget) {
-    RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
-    if (styleContext) {
-      UpdateProperties(styleContext);
-    }
+    UpdatePropertiesFromCurrentStyle();
   }
 }
 
 void
 KeyframeEffect::SetSpacing(JSContext* aCx,
                            const nsAString& aSpacing,
                            CallerType aCallerType,
                            ErrorResult& aRv)
@@ -224,17 +216,14 @@ KeyframeEffect::SetSpacing(JSContext* aC
     KeyframeUtils::ApplyDistributeSpacing(mKeyframes);
   }
 
   if (mAnimation && mAnimation->IsRelevant()) {
     nsNodeUtils::AnimationChanged(mAnimation);
   }
 
   if (mTarget) {
-    RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
-    if (styleContext) {
-      UpdateProperties(styleContext);
-    }
+    UpdatePropertiesFromCurrentStyle();
   }
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -5,16 +5,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/KeyframeEffectReadOnly.h"
 
 #include "gfxPrefs.h"
 #include "mozilla/dom/KeyframeAnimationOptionsBinding.h"
   // For UnrestrictedDoubleOrKeyframeAnimationOptions;
 #include "mozilla/dom/CSSPseudoElement.h"
+#include "mozilla/dom/ElementInlines.h"
 #include "mozilla/dom/KeyframeEffectBinding.h"
 #include "mozilla/AnimValuesStyleRule.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EffectSet.h"
 #include "mozilla/FloatingPoint.h" // For IsFinite
 #include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
 #include "mozilla/KeyframeUtils.h"
@@ -179,18 +180,17 @@ KeyframeEffectReadOnly::SetKeyframes(JSC
                                      ErrorResult& aRv)
 {
   nsTArray<Keyframe> keyframes =
     KeyframeUtils::GetKeyframesFromObject(aContext, mDocument, aKeyframes, aRv);
   if (aRv.Failed()) {
     return;
   }
 
-  RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
-  SetKeyframes(Move(keyframes), styleContext);
+  SetKeyframes(Move(keyframes), nullptr);
 }
 
 void
 KeyframeEffectReadOnly::SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
                                      nsStyleContext* aStyleContext)
 {
   DoSetKeyframes(Move(aKeyframes), Move(aStyleContext));
 }
@@ -229,16 +229,21 @@ KeyframeEffectReadOnly::DoSetKeyframes(n
   }
 
   // We need to call UpdateProperties() if the StyleType is
   // 'const ServoComputedValuesWithParent&' (i.e. not a pointer) or
   // nsStyleContext* is not nullptr.
   if (!IsPointer<StyleType>::value || aStyle) {
     UpdateProperties(aStyle);
     MaybeUpdateFrameForCompositor();
+  } else {
+    // If it doesn't specify the StyleType, we try getting it from current
+    // style and call UpdateProperties() with this StyleType.
+    UpdatePropertiesFromCurrentStyle();
+    MaybeUpdateFrameForCompositor();
   }
 }
 
 const AnimationProperty*
 KeyframeEffectReadOnly::GetEffectiveAnimationOfProperty(
   nsCSSPropertyID aProperty) const
 {
   EffectSet* effectSet =
@@ -295,32 +300,19 @@ SpecifiedKeyframeArraysAreEqual(const ns
   return true;
 }
 #endif
 
 void
 KeyframeEffectReadOnly::UpdateProperties(nsStyleContext* aStyleContext)
 {
   MOZ_ASSERT(aStyleContext);
-
-  if (!mDocument->IsStyledByServo()) {
-    DoUpdateProperties(Move(aStyleContext));
-    return;
-  }
+  MOZ_ASSERT(!mDocument->IsStyledByServo());
 
-  const ServoComputedValues* currentStyle =
-    aStyleContext->StyleSource().AsServoComputedValues();
-  // FIXME: Remove GetParentAllowServo() in Bug 1349004.
-  const ServoComputedValues* parentStyle =
-    aStyleContext->GetParentAllowServo()
-      ? aStyleContext->GetParentAllowServo()->StyleSource().AsServoComputedValues()
-      : nullptr;
-
-  const ServoComputedValuesWithParent servoValues = { currentStyle, parentStyle };
-  DoUpdateProperties(servoValues);
+  DoUpdateProperties(Move(aStyleContext));
 }
 
 void
 KeyframeEffectReadOnly::UpdateProperties(
   const ServoComputedValuesWithParent& aServoValues)
 {
   DoUpdateProperties(aServoValues);
 }
@@ -1869,16 +1861,56 @@ KeyframeEffectReadOnly::ContainsAnimated
         }
       }
     }
   }
 
   return false;
 }
 
+void
+KeyframeEffectReadOnly::UpdatePropertiesFromCurrentStyle()
+{
+  MOZ_ASSERT(mTarget,
+             "Should update only have a animation target");
+
+  if (mDocument->IsStyledByServo()) {
+    nsPresContext* presContext =
+      nsContentUtils::GetContextForContent(mTarget->mElement);
+    if (presContext) {
+      // If we don't have presContext(e.g. The target element don't belong with
+      // any document), we will not need to call UpdateProperties.
+      return;
+    }
+
+    ServoStyleSet* styleSet = presContext->StyleSet()->AsServo();
+    MOZ_ASSERT(styleSet);
+
+    nsIAtom* pseudo = mTarget->mPseudoType < CSSPseudoElementType::Count
+                    ? nsCSSPseudoElements::GetPseudoAtom(mTarget->mPseudoType)
+                    : nullptr;
+    RefPtr<ServoComputedValues> currentValue =
+      styleSet->ResolveServoStyle(mTarget->mElement, pseudo);
+
+    dom::Element* parent = pseudo
+                         ? mTarget->mElement.get()
+                         : mTarget->mElement->GetFlattenedTreeParentElementForStyle();
+    RefPtr<ServoComputedValues> parentValue;
+    if (parent) {
+      parentValue = styleSet->ResolveServoStyle(parent, nullptr);
+    }
+
+    const ServoComputedValuesWithParent value = { currentValue, parentValue };
+    UpdateProperties(value);
+  } else {
+    RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
+    UpdateProperties(styleContext);
+  }
+}
+
 template
 void
 KeyframeEffectReadOnly::ComposeStyle<RefPtr<AnimValuesStyleRule>&>(
   RefPtr<AnimValuesStyleRule>& aAnimationRule,
   const nsCSSPropertyIDSet& aPropertiesToSkip);
 
 template
 void
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -382,16 +382,18 @@ protected:
                        RefPtr<nsStyleContext>& aCachedBaseStyleContext);
   // Stylo version of the above function that also first checks for an additive
   // value in |aProperty|'s list of segments.
   void EnsureBaseStyle(const AnimationProperty& aProperty,
                        nsIAtom* aPseudoAtom,
                        nsPresContext* aPresContext,
                        RefPtr<ServoComputedValues>& aBaseComputedValues);
 
+  void UpdatePropertiesFromCurrentStyle();
+
   Maybe<OwningAnimationTarget> mTarget;
 
   KeyframeEffectParams mEffectOptions;
 
   // The specified keyframes.
   nsTArray<Keyframe>          mKeyframes;
 
   // A set of per-property value arrays, derived from |mKeyframes|.