Bug 1309868 part 3 - Make NonOwningStyleContextSource store const ServoComputedValues. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Fri, 14 Oct 2016 00:10:08 +1100
changeset 424779 408ec47f7427e5850a4cabe2d2086019f3ae2075
parent 424778 3401c9c51c78c2ab5a9933206492ac5a32200ad4
child 424780 29e9f26a3c22119e765fb53064311b43f7a91869
push id32246
push userxquan@mozilla.com
push dateThu, 13 Oct 2016 13:37:33 +0000
reviewersheycam
bugs1309868
milestone52.0a1
Bug 1309868 part 3 - Make NonOwningStyleContextSource store const ServoComputedValues. r?heycam MozReview-Commit-ID: G84fYXLbQyt
layout/style/ServoStyleSet.cpp
layout/style/StyleAnimationValue.cpp
layout/style/StyleContextSource.h
layout/style/nsStyleContext.cpp
layout/style/nsStyleContext.h
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -141,34 +141,34 @@ ServoStyleSet::ResolveStyleForText(nsICo
   // TODO: We might want to just do this and skip styling nodes entirely from
   // Servo. This would accidentally fix the issue of having to stash
   // change-hints from children in the parent element just because of inherited
   // style struct changes.
   RefPtr<ServoComputedValues> computedValues;
   if (parent->IsGeneratedContentContainerForBefore() ||
       parent->IsGeneratedContentContainerForAfter()) {
     MOZ_ASSERT(aParentContext);
-    ServoComputedValues* parentComputedValues =
+    const ServoComputedValues* parentComputedValues =
       aParentContext->StyleSource().AsServoComputedValues();
     computedValues =
       Servo_ComputedValues_Inherit(parentComputedValues).Consume();
   } else {
     computedValues = Servo_ComputedValues_Get(aTextNode).Consume();
   }
 
   return GetContext(computedValues.forget(), aParentContext,
                     nsCSSAnonBoxes::mozText, CSSPseudoElementType::AnonBox);
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext)
 {
   // The parent context can be null if the non-element share a style context
   // with the root of an anonymous subtree.
-  ServoComputedValues* parent =
+  const ServoComputedValues* parent =
     aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr;
   RefPtr<ServoComputedValues> computedValues =
     Servo_ComputedValues_Inherit(parent).Consume();
   MOZ_ASSERT(computedValues);
 
   return GetContext(computedValues.forget(), aParentContext,
                     nsCSSAnonBoxes::mozOtherNonElement,
                     CSSPseudoElementType::AnonBox);
@@ -203,17 +203,17 @@ ServoStyleSet::ResolveAnonymousBoxStyle(
                                         uint32_t aFlags)
 {
   MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag));
 
   MOZ_ASSERT(aFlags == 0 ||
              aFlags == nsStyleSet::eSkipParentDisplayBasedStyleFixup);
   bool skipFixup = aFlags & nsStyleSet::eSkipParentDisplayBasedStyleFixup;
 
-  ServoComputedValues* parentStyle =
+  const ServoComputedValues* parentStyle =
     aParentContext ? aParentContext->StyleSource().AsServoComputedValues()
                    : nullptr;
   RefPtr<ServoComputedValues> computedValues =
     Servo_ComputedValues_GetForAnonymousBox(parentStyle, aPseudoTag,
                                             mRawSet.get()).Consume();
 #ifdef DEBUG
   if (!computedValues) {
     nsString pseudo;
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3256,17 +3256,17 @@ StyleAnimationValue::ComputeValues(
   MOZ_ASSERT(aStyleContext->PresContext()->StyleSet()->IsServo(),
              "Should be using ServoStyleSet if we have a"
              " ServoDeclarationBlock");
 
   if (!nsCSSProps::IsEnabled(aProperty, aEnabledState)) {
     return false;
   }
 
-  RefPtr<ServoComputedValues> previousStyle =
+  const ServoComputedValues* previousStyle =
     aStyleContext->StyleSource().AsServoComputedValues();
 
   // FIXME: Servo bindings don't yet represent const-ness so we just
   // cast it away for now.
   auto declarations = const_cast<ServoDeclarationBlock*>(&aDeclarations);
   RefPtr<ServoComputedValues> computedValues =
     Servo_RestyleWithAddedDeclaration(declarations, previousStyle).Consume();
   if (!computedValues) {
--- a/layout/style/StyleContextSource.h
+++ b/layout/style/StyleContextSource.h
@@ -24,17 +24,17 @@ namespace mozilla {
 // Servo ComputedValues struct, which is more or less the Servo equivalent
 // of an nsStyleContext.
 
 // Underlying pointer without any strong ownership semantics.
 struct NonOwningStyleContextSource
 {
   MOZ_IMPLICIT NonOwningStyleContextSource(nsRuleNode* aRuleNode)
     : mBits(reinterpret_cast<uintptr_t>(aRuleNode)) {}
-  explicit NonOwningStyleContextSource(ServoComputedValues* aComputedValues)
+  explicit NonOwningStyleContextSource(const ServoComputedValues* aComputedValues)
     : mBits(reinterpret_cast<uintptr_t>(aComputedValues) | 1) {}
 
   bool operator==(const NonOwningStyleContextSource& aOther) const {
     MOZ_ASSERT(IsServoComputedValues() == aOther.IsServoComputedValues(),
                "Comparing Servo to Gecko - probably a bug");
     return mBits == aOther.mBits;
   }
   bool operator!=(const NonOwningStyleContextSource& aOther) const {
@@ -60,17 +60,17 @@ struct NonOwningStyleContextSource
 #endif
   }
 
   nsRuleNode* AsGeckoRuleNode() const {
     MOZ_ASSERT(IsGeckoRuleNodeOrNull() && !IsNull());
     return reinterpret_cast<nsRuleNode*>(mBits);
   }
 
-  ServoComputedValues* AsServoComputedValues() const {
+  const ServoComputedValues* AsServoComputedValues() const {
     MOZ_ASSERT(IsServoComputedValues());
     return reinterpret_cast<ServoComputedValues*>(mBits & ~1);
   }
 
   bool MatchesNoRules() const {
     if (IsGeckoRuleNodeOrNull()) {
       return AsGeckoRuleNode()->IsRoot();
     }
@@ -142,17 +142,17 @@ struct OwningStyleContextSource
     MOZ_ASSERT(!mRaw.IsNull());
     return mRaw.IsGeckoRuleNodeOrNull();
   }
   bool IsServoComputedValues() const { return mRaw.IsServoComputedValues(); }
 
   NonOwningStyleContextSource AsRaw() const { return mRaw; }
   nsRuleNode* AsGeckoRuleNode() const { return mRaw.AsGeckoRuleNode(); }
   ServoComputedValues* AsServoComputedValues() const {
-    return mRaw.AsServoComputedValues();
+    return const_cast<ServoComputedValues*>(mRaw.AsServoComputedValues());
   }
 
   bool MatchesNoRules() const { return mRaw.MatchesNoRules(); }
 
 private:
   NonOwningStyleContextSource mRaw;
 };
 
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -1276,17 +1276,17 @@ nsStyleContext::CalcStyleDifference(nsSt
 {
   return CalcStyleDifferenceInternal(aNewContext, aParentHintsNotHandledForDescendants,
                                      aEqualStructs, aSamePointerStructs);
 }
 
 class MOZ_STACK_CLASS FakeStyleContext
 {
 public:
-  explicit FakeStyleContext(ServoComputedValues* aComputedValues)
+  explicit FakeStyleContext(const ServoComputedValues* aComputedValues)
     : mComputedValues(aComputedValues) {}
 
   mozilla::NonOwningStyleContextSource StyleSource() const {
     return mozilla::NonOwningStyleContextSource(mComputedValues);
   }
 
   nsStyleContext* GetStyleIfVisited() {
     // XXXbholley: This is wrong. Need to implement to get visited handling
@@ -1297,21 +1297,21 @@ public:
   #define STYLE_STRUCT(name_, checkdata_cb_)                                  \
   const nsStyle##name_ * Style##name_() {                                     \
     return Servo_GetStyle##name_(mComputedValues);                            \
   }
   #include "nsStyleStructList.h"
   #undef STYLE_STRUCT
 
 private:
-  ServoComputedValues* MOZ_NON_OWNING_REF mComputedValues;
+  const ServoComputedValues* MOZ_NON_OWNING_REF mComputedValues;
 };
 
 nsChangeHint
-nsStyleContext::CalcStyleDifference(ServoComputedValues* aNewComputedValues,
+nsStyleContext::CalcStyleDifference(const ServoComputedValues* aNewComputedValues,
                                     nsChangeHint aParentHintsNotHandledForDescendants,
                                     uint32_t* aEqualStructs,
                                     uint32_t* aSamePointerStructs)
 {
   FakeStyleContext newContext(aNewComputedValues);
   return CalcStyleDifferenceInternal(&newContext, aParentHintsNotHandledForDescendants,
                                      aEqualStructs, aSamePointerStructs);
 }
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -378,17 +378,17 @@ public:
                                    nsChangeHint aParentHintsNotHandledForDescendants,
                                    uint32_t* aEqualStructs,
                                    uint32_t* aSamePointerStructs);
 
   /**
    * Like the above, but allows comparing ServoComputedValues instead of needing
    * a full-fledged style context.
    */
-  nsChangeHint CalcStyleDifference(ServoComputedValues* aNewComputedValues,
+  nsChangeHint CalcStyleDifference(const ServoComputedValues* aNewComputedValues,
                                    nsChangeHint aParentHintsNotHandledForDescendants,
                                    uint32_t* aEqualStructs,
                                    uint32_t* aSamePointerStructs);
 
 private:
   template<class StyleContextLike>
   nsChangeHint CalcStyleDifferenceInternal(StyleContextLike* aNewContext,
                                            nsChangeHint aParentHintsNotHandledForDescendants,