Bug 1366735 part 2 - Use the new struct in stylo. r=heycam draft
authorXidorn Quan <me@upsuper.org>
Tue, 23 May 2017 00:32:05 +1000
changeset 584112 8216769c7ee2a323d2af2080dd97cac3489af82d
parent 584111 0a2ef777045603fe591ba3a74259699a2339cede
child 584113 2adf7b64484746a5f416b7902df2ac718a3fdeab
push id60638
push userxquan@mozilla.com
push dateWed, 24 May 2017 22:57:13 +0000
reviewersheycam
bugs1366735
milestone55.0a1
Bug 1366735 part 2 - Use the new struct in stylo. r=heycam MozReview-Commit-ID: trgd0lKLP1
js/src/devtools/rootAnalysis/analyzeHeapWrites.js
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoBindings.toml
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
+++ b/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
@@ -180,16 +180,17 @@ function treatAsSafeArgument(entry, varN
         ["Gecko_ClearPODTArray", "aArray", null],
         ["Gecko_SetStyleGridTemplateArrayLengths", "aValue", null],
         ["Gecko_ResizeTArrayForStrings", "aArray", null],
         ["Gecko_ClearAndResizeStyleContents", "aContent", null],
         [/Gecko_ClearAndResizeCounter/, "aContent", null],
         [/Gecko_CopyCounter.*?From/, "aContent", null],
         [/Gecko_SetContentDataImageValue/, "aList", null],
         [/Gecko_SetContentData/, "aContent", null],
+        ["Gecko_SetCounterFunction", "aContent", null],
         [/Gecko_EnsureStyle.*?ArrayLength/, "aArray", null],
         ["Gecko_GetOrCreateKeyframeAtStart", "aKeyframes", null],
         ["Gecko_GetOrCreateInitialKeyframe", "aKeyframes", null],
         ["Gecko_GetOrCreateFinalKeyframe", "aKeyframes", null],
         ["Gecko_SetStyleCoordCalcValue", null, null],
         ["Gecko_StyleClipPath_SetURLValue", "aClip", null],
         ["Gecko_nsStyleFilter_SetURLValue", "aEffects", null],
         ["Gecko_nsStyleSVGPaint_CopyFrom", "aDest", null],
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1257,22 +1257,24 @@ Gecko_SetContentDataImageValue(nsStyleCo
 {
   MOZ_ASSERT(aContent && aImageValue);
 
   RefPtr<nsStyleImageRequest> req =
     CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aImageValue);
   aContent->SetImageRequest(req.forget());
 }
 
-void
-Gecko_SetContentDataArray(nsStyleContentData* aContent,
-                          nsStyleContentType aType, uint32_t aLen)
+nsStyleContentData::CounterFunction*
+Gecko_SetCounterFunction(nsStyleContentData* aContent, nsStyleContentType aType)
 {
-  nsCSSValue::Array* arr = nsCSSValue::Array::Create(aLen);
-  aContent->SetCounters(aType, arr);
+  RefPtr<nsStyleContentData::CounterFunction>
+    counterFunc = new nsStyleContentData::CounterFunction();
+  nsStyleContentData::CounterFunction* ptr = counterFunc;
+  aContent->SetCounters(aType, counterFunc.forget());
+  return ptr;
 }
 
 nsStyleGradient*
 Gecko_CreateGradient(uint8_t aShape,
                      uint8_t aSize,
                      bool aRepeating,
                      bool aLegacySyntax,
                      uint32_t aStopCount)
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -302,17 +302,18 @@ void Gecko_CopyListStyleImageFrom(nsStyl
 void Gecko_SetCursorArrayLength(nsStyleUserInterface* ui, size_t len);
 void Gecko_SetCursorImageValue(nsCursorImage* aCursor,
                                mozilla::css::ImageValue* aImageValue);
 void Gecko_CopyCursorArrayFrom(nsStyleUserInterface* dest,
                                const nsStyleUserInterface* src);
 
 void Gecko_SetContentDataImageValue(nsStyleContentData* aList,
                                     mozilla::css::ImageValue* aImageValue);
-void Gecko_SetContentDataArray(nsStyleContentData* content_data, nsStyleContentType type, uint32_t len);
+nsStyleContentData::CounterFunction* Gecko_SetCounterFunction(
+    nsStyleContentData* content_data, nsStyleContentType type);
 
 // Dirtiness tracking.
 uint32_t Gecko_GetNodeFlags(RawGeckoNodeBorrowed node);
 void Gecko_SetNodeFlags(RawGeckoNodeBorrowed node, uint32_t flags);
 void Gecko_UnsetNodeFlags(RawGeckoNodeBorrowed node, uint32_t flags);
 void Gecko_SetOwnerDocumentNeedsStyleFlush(RawGeckoElementBorrowed element);
 
 // Incremental restyle.
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -368,16 +368,17 @@ structs-types = [
     "nsMediaFeature",
     "nsRestyleHint",
     "nsStyleBackground",
     "nsStyleBorder",
     "nsStyleColor",
     "nsStyleColumn",
     "nsStyleContent",
     "nsStyleContentData",
+    "nsStyleContentData_CounterFunction",
     "nsStyleContentType",
     "nsStyleContext",
     "nsStyleCoord",
     "nsStyleCoord_Calc",
     "nsStyleCoord_CalcValue",
     "nsStyleDisplay",
     "nsStyleEffects",
     "nsStyleFilter",
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3809,17 +3809,18 @@ nsStyleContentData::nsStyleContentData(c
 }
 
 bool
 nsStyleContentData::
 CounterFunction::operator==(const CounterFunction& aOther) const
 {
   return mIdent == aOther.mIdent &&
     mSeparator == aOther.mSeparator &&
-    mCounterStyle == aOther.mCounterStyle;
+    mCounterStyle == aOther.mCounterStyle &&
+    mCounterStyleName == aOther.mCounterStyleName;
 }
 
 nsStyleContentData&
 nsStyleContentData::operator=(const nsStyleContentData& aOther)
 {
   if (this == &aOther) {
     return *this;
   }
@@ -3840,16 +3841,41 @@ nsStyleContentData::operator==(const nsS
   }
   if (mType == eStyleContentType_Counter ||
       mType == eStyleContentType_Counters) {
     return *mContent.mCounters == *aOther.mContent.mCounters;
   }
   return safe_strcmp(mContent.mString, aOther.mContent.mString) == 0;
 }
 
+void
+nsStyleContentData::Resolve(nsPresContext* aPresContext)
+{
+  switch (mType) {
+    case eStyleContentType_Image:
+      if (!mContent.mImage->IsResolved()) {
+        mContent.mImage->Resolve(aPresContext);
+      }
+      break;
+    case eStyleContentType_Counter:
+    case eStyleContentType_Counters: {
+      CounterFunction* counters = mContent.mCounters;
+      if (counters->mCounterStyleName) {
+        MOZ_ASSERT(!counters->mCounterStyle);
+        counters->mCounterStyle = aPresContext->CounterStyleManager()->
+          BuildCounterStyle(counters->mCounterStyleName);
+        counters->mCounterStyleName = nullptr;
+      }
+      break;
+    }
+    default:
+      break;
+  }
+}
+
 
 //-----------------------
 // nsStyleContent
 //
 
 nsStyleContent::nsStyleContent(const nsPresContext* aContext)
 {
   MOZ_COUNT_CTOR(nsStyleContent);
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3043,32 +3043,37 @@ public:
     return mContent.mString;
   }
 
   struct CounterFunction
   {
     nsString mIdent;
     // This is only used when it is a counters() function.
     nsString mSeparator;
+    // One and only one of mCounterStyle and mCounterStyleName must be
+    // non-null at any time.
     mozilla::CounterStylePtr mCounterStyle;
+    nsCOMPtr<nsIAtom> mCounterStyleName;
 
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CounterFunction)
 
     bool operator==(const CounterFunction& aOther) const;
     bool operator!=(const CounterFunction& aOther) const {
       return !(*this == aOther);
     }
   private:
     ~CounterFunction() {}
   };
 
   CounterFunction* GetCounters() const
   {
     MOZ_ASSERT(mType == eStyleContentType_Counter ||
                mType == eStyleContentType_Counters);
+    MOZ_ASSERT(mContent.mCounters->mCounterStyle,
+               "Counter style should have been resolved");
     return mContent.mCounters;
   }
 
   nsStyleImageRequest* GetImageRequest() const
   {
     MOZ_ASSERT(mType == eStyleContentType_Image);
     return mContent.mImage;
   }
@@ -3117,21 +3122,17 @@ public:
   {
     MOZ_ASSERT(mType == eStyleContentType_Uninitialized,
                "should only initialize nsStyleContentData once");
     mType = eStyleContentType_Image;
     mContent.mImage = aRequest.take();
     MOZ_ASSERT(mContent.mImage);
   }
 
-  void Resolve(nsPresContext* aPresContext) {
-    if (mType == eStyleContentType_Image && !mContent.mImage->IsResolved()) {
-      mContent.mImage->Resolve(aPresContext);
-    }
-  }
+  void Resolve(nsPresContext* aPresContext);
 
 private:
   nsStyleContentType mType;
   union {
     char16_t *mString;
     nsStyleImageRequest* mImage;
     CounterFunction* mCounters;
   } mContent;