Bug 1367904 - Part 5: stylo: Make GetBaseComputedValuesForElement return a style context; r?bholley draft
authorManish Goregaokar <manishearth@gmail.com>
Mon, 17 Jul 2017 11:41:44 -0700
changeset 610214 e275d55a9b6690bd3b9cabdb2d134d7386bda835
parent 610213 000f1e7a3ebf82a3071bd535f3ad877a6b75a049
child 610215 fe2cdd0514bea246cbde7f0720914372c897bffc
push id68805
push userbmo:manishearth@gmail.com
push dateTue, 18 Jul 2017 00:30:54 +0000
reviewersbholley
bugs1367904
milestone56.0a1
Bug 1367904 - Part 5: stylo: Make GetBaseComputedValuesForElement return a style context; r?bholley MozReview-Commit-ID: K5WpWc26xNZ
dom/animation/KeyframeEffectReadOnly.cpp
dom/animation/KeyframeEffectReadOnly.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsStyleContext.cpp
layout/style/nsStyleContext.h
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -508,56 +508,59 @@ KeyframeEffectReadOnly::EnsureBaseStyles
 
   nsPresContext* presContext =
     nsContentUtils::GetContextForContent(mTarget->mElement);
   MOZ_ASSERT(presContext,
              "nsPresContext should not be nullptr since this EnsureBaseStyles "
              "supposed to be called right after getting computed values with "
              "a valid nsPresContext");
 
-  RefPtr<const ServoComputedValues> baseComputedValues;
+  RefPtr<ServoStyleContext> baseStyleContext;
   for (const AnimationProperty& property : aProperties) {
     EnsureBaseStyle(property,
                     mTarget->mPseudoType,
                     presContext,
                     aComputedValues,
-                    baseComputedValues);
+                    baseStyleContext);
   }
 }
 
 void
 KeyframeEffectReadOnly::EnsureBaseStyle(
   const AnimationProperty& aProperty,
   CSSPseudoElementType aPseudoType,
   nsPresContext* aPresContext,
   const ServoComputedValues* aComputedStyle,
-  RefPtr<const ServoComputedValues>& aBaseComputedValues)
+ RefPtr<ServoStyleContext>& aBaseStyleContext)
 {
   bool hasAdditiveValues = false;
 
   for (const AnimationPropertySegment& segment : aProperty.mSegments) {
     if (!segment.HasReplaceableValues()) {
       hasAdditiveValues = true;
       break;
     }
   }
 
   if (!hasAdditiveValues) {
     return;
   }
 
-  if (!aBaseComputedValues) {
-    aBaseComputedValues =
-      aPresContext->StyleSet()->AsServo()->GetBaseComputedValuesForElement(
+  if (!aBaseStyleContext) {
+    aBaseStyleContext =
+      aPresContext->StyleSet()->AsServo()->GetBaseContextForElement(
           mTarget->mElement,
+          nullptr,
+          aPresContext,
+          nullptr,
           aPseudoType,
           aComputedStyle);
   }
   RefPtr<RawServoAnimationValue> baseValue =
-    Servo_ComputedValues_ExtractAnimationValue(aBaseComputedValues,
+    Servo_ComputedValues_ExtractAnimationValue(aBaseStyleContext->ComputedValues(),
                                                aProperty.mProperty).Consume();
   mBaseStyleValuesForServo.Put(aProperty.mProperty, baseValue);
 }
 
 void
 KeyframeEffectReadOnly::WillComposeStyle()
 {
   ComputedTiming computedTiming = GetComputedTiming();
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -40,16 +40,17 @@ class nsIPresShell;
 namespace mozilla {
 
 class AnimValuesStyleRule;
 enum class CSSPseudoElementType : uint8_t;
 class ErrorResult;
 struct AnimationRule;
 struct TimingParams;
 class EffectSet;
+class ServoStyleContext;
 
 namespace dom {
 class ElementOrCSSPseudoElement;
 class GlobalObject;
 class OwningElementOrCSSPseudoElement;
 class UnrestrictedDoubleOrKeyframeAnimationOptions;
 class UnrestrictedDoubleOrKeyframeEffectOptions;
 enum class IterationCompositeOperation : uint8_t;
@@ -380,17 +381,17 @@ protected:
                        nsStyleContext* aStyleContext,
                        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,
                        CSSPseudoElementType aPseudoType,
                        nsPresContext* aPresContext,
                        const ServoComputedValues* aComputedValues,
-                       RefPtr<const ServoComputedValues>& aBaseComputedValues);
+                       RefPtr<mozilla::ServoStyleContext>& aBaseComputedValues);
 
   Maybe<OwningAnimationTarget> mTarget;
 
   KeyframeEffectParams mEffectOptions;
 
   // The specified keyframes.
   nsTArray<Keyframe>          mKeyframes;
 
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1088,27 +1088,32 @@ ServoStyleSet::GetAnimationValues(
 {
   Servo_GetAnimationValues(aDeclarations,
                            aElement,
                            aComputedValues,
                            mRawSet.get(),
                            &aAnimationValues);
 }
 
-already_AddRefed<ServoComputedValues>
-ServoStyleSet::GetBaseComputedValuesForElement(
+already_AddRefed<ServoStyleContext>
+ServoStyleSet::GetBaseContextForElement(
   Element* aElement,
+  nsStyleContext* aParentContext,
+  nsPresContext* aPresContext,
+  nsIAtom* aPseudoTag,
   CSSPseudoElementType aPseudoType,
   ServoComputedValuesBorrowed aStyle)
 {
-  return Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
+  RefPtr<ServoComputedValues> cv = Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
                                                         aElement,
                                                         aStyle,
                                                         &Snapshots(),
                                                         aPseudoType).Consume();
+  return ServoStyleContext::Create(nullptr, aPresContext, aPseudoTag,
+                                   aPseudoType, cv.forget());
 }
 
 already_AddRefed<RawServoAnimationValue>
 ServoStyleSet::ComputeAnimationValue(
   Element* aElement,
   RawServoDeclarationBlock* aDeclarations,
   ServoComputedValuesBorrowed aComputedValues)
 {
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -377,20 +377,23 @@ public:
                      dom::Element* aElement,
                      ServoComputedValuesBorrowed aComputedValues,
                      nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
 
   bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
 
   nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName);
 
-  already_AddRefed<ServoComputedValues>
-  GetBaseComputedValuesForElement(dom::Element* aElement,
-                                  CSSPseudoElementType aPseudoType,
-                                  ServoComputedValuesBorrowed aStyle);
+  already_AddRefed<ServoStyleContext>
+  GetBaseContextForElement(dom::Element* aElement,
+                           nsStyleContext* aParentContext,
+                           nsPresContext* aPresContext,
+                           nsIAtom* aPseudoTag,
+                           CSSPseudoElementType aPseudoType,
+                           ServoComputedValuesBorrowed aStyle);
 
   /**
    * Resolve style for a given declaration block with/without the parent style.
    * If the parent style is not specified, the document default computed values
    * is used.
    */
   already_AddRefed<ServoComputedValues>
   ResolveForDeclarations(ServoComputedValuesBorrowedOrNull aParentOrNull,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -635,22 +635,19 @@ nsComputedDOMStyle::DoGetStyleContextNoF
         if (aAnimationFlag == eWithoutAnimation) {
           nsPresContext* presContext = presShell->GetPresContext();
           MOZ_ASSERT(presContext, "Should have a prescontext if we have a frame");
           if (presContext && presContext->StyleSet()->IsGecko()) {
             nsStyleSet* styleSet = presContext->StyleSet()->AsGecko();
             return styleSet->ResolveStyleByRemovingAnimation(
                      aElement, result, eRestyle_AllHintsWithAnimations);
           } else {
-            RefPtr<ServoComputedValues> baseComputedValues =
-              presContext->StyleSet()->AsServo()->
-                GetBaseComputedValuesForElement(
-                    aElement, pseudoType, result->ComputedValues());
-            return ServoStyleContext::Create(nullptr, presContext, aPseudo,
-                                             pseudoType, baseComputedValues.forget());
+              return presContext->StyleSet()->AsServo()->
+                GetBaseContextForElement(aElement, nullptr, presContext,
+                                         aPseudo, pseudoType, result->ComputedValues());
           }
         }
 
         // this function returns an addrefed style context
         RefPtr<nsStyleContext> ret = result;
         return ret.forget();
       }
     }
@@ -672,21 +669,18 @@ nsComputedDOMStyle::DoGetStyleContextNoF
                                ? StyleRuleInclusion::DefaultOnly
                                : StyleRuleInclusion::All;
     RefPtr<nsStyleContext> result =
        servoSet->ResolveTransientStyle(aElement, aPseudo, pseudoType, rules);
     if (aAnimationFlag == eWithAnimation) {
       return result.forget();
     }
 
-    RefPtr<ServoComputedValues> baseComputedValues =
-      servoSet->GetBaseComputedValuesForElement(
-          aElement, pseudoType, result->ComputedValues());
-    return ServoStyleContext::Create(nullptr, presContext, aPseudo,
-                                     pseudoType, baseComputedValues.forget());
+    return servoSet->GetBaseContextForElement(aElement, nullptr, presContext,
+                                              aPseudo, pseudoType, result->ComputedValues());
   }
 
   RefPtr<nsStyleContext> parentContext;
   nsIContent* parent = aPseudo ? aElement : aElement->GetParent();
   // Don't resolve parent context for document fragments.
   if (parent && parent->IsElement()) {
     parentContext = GetStyleContextNoFlush(parent->AsElement(), nullptr,
                                            aPresShell, aStyleType);
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -617,25 +617,25 @@ nsStyleContext::Destroy()
     // instead. Don't call the global operator delete.
     presContext->PresShell()->
       FreeByObjectID(eArenaObjectID_GeckoStyleContext, this);
   } else {
     delete static_cast<ServoStyleContext*>(this);
   }
 }
 
-already_AddRefed<nsStyleContext>
+already_AddRefed<GeckoStyleContext>
 NS_NewStyleContext(nsStyleContext* aParentContext,
                    nsIAtom* aPseudoTag,
                    CSSPseudoElementType aPseudoType,
                    nsRuleNode* aRuleNode,
                    bool aSkipParentDisplayBasedStyleFixup)
 {
   RefPtr<nsRuleNode> node = aRuleNode;
-  RefPtr<nsStyleContext> context =
+  RefPtr<GeckoStyleContext> context =
     new (aRuleNode->PresContext())
     GeckoStyleContext(aParentContext, aPseudoTag, aPseudoType, node.forget(),
                    aSkipParentDisplayBasedStyleFixup);
   return context.forget();
 }
 
 namespace mozilla {
 
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -462,16 +462,16 @@ protected:
     return !!(sDependencyTable[aOuterSID] &
               nsCachedStyleData::GetBitForSID(aInnerSID));
   }
 
   static const uint32_t sDependencyTable[];
 #endif
 };
 
-already_AddRefed<nsStyleContext>
+already_AddRefed<mozilla::GeckoStyleContext>
 NS_NewStyleContext(nsStyleContext* aParentContext,
                    nsIAtom* aPseudoTag,
                    mozilla::CSSPseudoElementType aPseudoType,
                    nsRuleNode* aRuleNode,
                    bool aSkipParentDisplayBasedStyleFixup);
 
 #endif