Bug 1269933 - Teach CounterStyles their name and remove the string member from the style structs. r=xidorn
authorBobby Holley <bobbyholley@gmail.com>
Wed, 04 May 2016 11:42:08 -0700
changeset 296326 922ba5fbebbea6536173b2d8e7f6ab60d50bd1a4
parent 296325 382ae5a4758827203896dc52b7fa37368386cd0a
child 296327 94fe66b7e3c201555440b00ecc900afb31954277
push id76300
push userbholley@mozilla.com
push dateFri, 06 May 2016 07:09:43 +0000
treeherdermozilla-inbound@94fe66b7e3c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1269933
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1269933 - Teach CounterStyles their name and remove the string member from the style structs. r=xidorn
layout/style/CounterStyleManager.cpp
layout/style/CounterStyleManager.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/CounterStyleManager.cpp
+++ b/layout/style/CounterStyleManager.cpp
@@ -585,16 +585,17 @@ public:
 
 protected:
   MOZ_CONSTEXPR explicit BuiltinCounterStyle(int32_t aStyle)
     : CounterStyle(aStyle)
   {
   }
 
 public:
+  virtual void GetStyleName(nsSubstring& aResult) override;
   virtual void GetPrefix(nsSubstring& aResult) override;
   virtual void GetSuffix(nsSubstring& aResult) override;
   virtual void GetSpokenCounterText(CounterValue aOrdinal,
                                     WritingMode aWritingMode,
                                     nsSubstring& aResult,
                                     bool& aIsBullet) override;
   virtual bool IsBullet() override;
 
@@ -612,16 +613,26 @@ public:
                                      bool& aIsRTL) override;
 
   // Builtin counter style does not need refcount at all
   NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return 2; }
   NS_IMETHOD_(MozExternalRefCountType) Release() override { return 2; }
 };
 
 /* virtual */ void
+BuiltinCounterStyle::GetStyleName(nsSubstring& aResult)
+{
+  MOZ_ASSERT(mStyle != NS_STYLE_LIST_STYLE_CUSTOM);
+  const nsAFlatCString& str =
+    nsCSSProps::ValueToKeyword(mStyle, nsCSSProps::kListStyleKTable);
+  MOZ_ASSERT(!str.IsEmpty());
+  aResult.Assign(NS_ConvertUTF8toUTF16(str));
+}
+
+/* virtual */ void
 BuiltinCounterStyle::GetPrefix(nsSubstring& aResult)
 {
   aResult.Truncate();
 }
 
 /* virtual */ void
 BuiltinCounterStyle::GetSuffix(nsSubstring& aResult)
 {
@@ -1016,19 +1027,21 @@ DependentBuiltinCounterStyle::GetFallbac
   }
 }
 
 class CustomCounterStyle final : public CounterStyle
 {
 private:
   ~CustomCounterStyle() {}
 public:
-  CustomCounterStyle(CounterStyleManager* aManager,
+  CustomCounterStyle(const nsAString& aName,
+                     CounterStyleManager* aManager,
                      nsCSSCounterStyleRule* aRule)
     : CounterStyle(NS_STYLE_LIST_STYLE_CUSTOM),
+      mName(aName),
       mManager(aManager),
       mRule(aRule),
       mRuleGeneration(aRule->GetGeneration()),
       mSystem(aRule->GetSystem()),
       mFlags(0),
       mFallback(nullptr),
       mSpeakAsCounter(nullptr),
       mExtends(nullptr),
@@ -1046,16 +1059,17 @@ public:
   // For counter style extends other, in addition, all fields will be
   // reset to uninitialized state. This method should be called when any
   // other counter style is added, removed, or changed.
   void ResetDependentData();
 
   nsCSSCounterStyleRule* GetRule() const { return mRule; }
   uint32_t GetRuleGeneration() const { return mRuleGeneration; }
 
+  virtual void GetStyleName(nsSubstring& aResult) override;
   virtual void GetPrefix(nsSubstring& aResult) override;
   virtual void GetSuffix(nsSubstring& aResult) override;
   virtual void GetSpokenCounterText(CounterValue aOrdinal,
                                     WritingMode aWritingMode,
                                     nsSubstring& aResult,
                                     bool& aIsBullet) override;
   virtual bool IsBullet() override;
 
@@ -1115,16 +1129,18 @@ private:
   void ComputeRawSpeakAs(uint8_t& aSpeakAs,
                          CounterStyle*& aSpeakAsCounter);
   CounterStyle* ComputeSpeakAs();
 
   CounterStyle* ComputeExtends();
   CounterStyle* GetExtends();
   CounterStyle* GetExtendsRoot();
 
+  nsString mName;
+
   // CounterStyleManager should always overlive any CounterStyle as it
   // is owned by nsPresContext, and will be released after all nodes and
   // frames are released.
   CounterStyleManager* mManager;
 
   RefPtr<nsCSSCounterStyleRule> mRule;
   uint32_t mRuleGeneration;
 
@@ -1210,16 +1226,22 @@ CustomCounterStyle::ResetDependentData()
     mFlags &= ~(FLAG_NEGATIVE_INITED |
                 FLAG_PREFIX_INITED |
                 FLAG_SUFFIX_INITED |
                 FLAG_PAD_INITED);
   }
 }
 
 /* virtual */ void
+CustomCounterStyle::GetStyleName(nsSubstring& aResult)
+{
+  aResult.Assign(mName);
+}
+
+/* virtual */ void
 CustomCounterStyle::GetPrefix(nsSubstring& aResult)
 {
   if (!(mFlags & FLAG_PREFIX_INITED)) {
     mFlags |= FLAG_PREFIX_INITED;
 
     const nsCSSValue& value = mRule->GetDesc(eCSSCounterDesc_Prefix);
     if (value.UnitHasStringValue()) {
       value.GetStringValue(mPrefix);
@@ -1712,16 +1734,22 @@ AnonymousCounterStyle::AnonymousCounterS
   for (const nsCSSValueList* item = aParams->Item(1).GetListValue();
        item; item = item->mNext) {
     item->mValue.GetStringValue(*mSymbols.AppendElement());
   }
   mSymbols.Compact();
 }
 
 /* virtual */ void
+AnonymousCounterStyle::GetStyleName(nsAString& aResult)
+{
+  aResult.Truncate();
+}
+
+/* virtual */ void
 AnonymousCounterStyle::GetPrefix(nsAString& aResult)
 {
   aResult.Truncate();
 }
 
 /* virtual */ void
 AnonymousCounterStyle::GetSuffix(nsAString& aResult)
 {
@@ -2003,17 +2031,17 @@ CounterStyleManager::BuildCounterStyle(c
   // XXXheycam ServoStyleSets do not support custom counter styles yet.
   StyleSetHandle styleSet = mPresContext->StyleSet();
   NS_ASSERTION(styleSet->IsGecko(),
                "stylo: ServoStyleSets do not support custom counter "
                "styles yet");
   nsCSSCounterStyleRule* rule = styleSet->IsGecko() ?
     styleSet->AsGecko()->CounterStyleRuleForName(aName) : nullptr;
   if (rule) {
-    data = new (mPresContext) CustomCounterStyle(this, rule);
+    data = new (mPresContext) CustomCounterStyle(aName, this, rule);
   } else {
     int32_t type;
     nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aName);
     if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kListStyleKTable, type)) {
       if (gBuiltinStyleTable[type].IsDependentStyle()) {
         data = new (mPresContext) DependentBuiltinCounterStyle(type, this);
       } else {
         data = GetBuiltinStyle(type);
--- a/layout/style/CounterStyleManager.h
+++ b/layout/style/CounterStyleManager.h
@@ -46,16 +46,17 @@ public:
   int32_t GetStyle() const { return mStyle; }
   bool IsNone() const { return mStyle == NS_STYLE_LIST_STYLE_NONE; }
   bool IsCustomStyle() const { return mStyle == NS_STYLE_LIST_STYLE_CUSTOM; }
   // A style is dependent if it depends on the counter style manager.
   // Custom styles are certainly dependent. In addition, some builtin
   // styles are dependent for fallback.
   bool IsDependentStyle() const;
 
+  virtual void GetStyleName(nsSubstring& aResult) = 0;
   virtual void GetPrefix(nsSubstring& aResult) = 0;
   virtual void GetSuffix(nsSubstring& aResult) = 0;
   void GetCounterText(CounterValue aOrdinal,
                       WritingMode aWritingMode,
                       nsSubstring& aResult,
                       bool& aIsRTL);
   virtual void GetSpokenCounterText(CounterValue aOrdinal,
                                     WritingMode aWritingMode,
@@ -103,16 +104,17 @@ protected:
 };
 
 class AnonymousCounterStyle final : public CounterStyle
 {
 public:
   explicit AnonymousCounterStyle(const nsSubstring& aContent);
   explicit AnonymousCounterStyle(const nsCSSValue::Array* aValue);
 
+  virtual void GetStyleName(nsAString& aResult) override;
   virtual void GetPrefix(nsAString& aResult) override;
   virtual void GetSuffix(nsAString& aResult) override;
   virtual bool IsBullet() override;
 
   virtual void GetNegative(NegativeType& aResult) override;
   virtual bool IsOrdinalInRange(CounterValue aOrdinal) override;
   virtual bool IsOrdinalInAutoRange(CounterValue aOrdinal) override;
   virtual void GetPad(PadType& aResult) override;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7804,35 +7804,32 @@ nsRuleNode::ComputeListData(void* aStart
   }
 
   // list-style-type: string, none, inherit, initial
   const nsCSSValue* typeValue = aRuleData->ValueForListStyleType();
   switch (typeValue->GetUnit()) {
     case eCSSUnit_Unset:
     case eCSSUnit_Inherit: {
       conditions.SetUncacheable();
-      nsString type;
-      parentList->GetListStyleType(type);
-      list->SetListStyleType(type, parentList->GetCounterStyle());
+      list->SetCounterStyle(parentList->GetCounterStyle());
       break;
     }
     case eCSSUnit_Initial:
       list->SetListStyleType(NS_LITERAL_STRING("disc"), mPresContext);
       break;
     case eCSSUnit_Ident: {
       nsString typeIdent;
       typeValue->GetStringValue(typeIdent);
       list->SetListStyleType(typeIdent, mPresContext);
       break;
     }
     case eCSSUnit_String: {
       nsString str;
       typeValue->GetStringValue(str);
-      list->SetListStyleType(NS_LITERAL_STRING(""),
-                             new AnonymousCounterStyle(str));
+      list->SetCounterStyle(new AnonymousCounterStyle(str));
       break;
     }
     case eCSSUnit_Enumerated: {
       // For compatibility with html attribute map.
       // This branch should never be called for value from CSS.
       int32_t intValue = typeValue->GetIntValue();
       nsAutoString name;
       switch (intValue) {
@@ -7852,19 +7849,17 @@ nsRuleNode::ComputeListData(void* aStart
           CopyASCIItoUTF16(nsCSSProps::ValueToKeyword(
                   intValue, nsCSSProps::kListStyleKTable), name);
           break;
       }
       list->SetListStyleType(name, mPresContext);
       break;
     }
     case eCSSUnit_Symbols:
-      list->SetListStyleType(
-        NS_LITERAL_STRING(""),
-        new AnonymousCounterStyle(typeValue->GetArrayValue()));
+      list->SetCounterStyle(new AnonymousCounterStyle(typeValue->GetArrayValue()));
       break;
     case eCSSUnit_Null:
       break;
     default:
       NS_NOTREACHED("Unexpected value unit");
   }
 
   // list-style-image: url, none, inherit
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -592,31 +592,29 @@ nsChangeHint nsStyleOutline::CalcDiffere
   return NS_STYLE_HINT_NONE;
 }
 
 // --------------------
 // nsStyleList
 //
 nsStyleList::nsStyleList(StyleStructContext aContext) 
   : mListStylePosition(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE),
-    mListStyleType(NS_LITERAL_STRING("disc")),
-    mCounterStyle(aContext.BuildCounterStyle(mListStyleType))
+    mCounterStyle(aContext.BuildCounterStyle(NS_LITERAL_STRING("disc")))
 {
   MOZ_COUNT_CTOR(nsStyleList);
   SetQuotesInitial();
 }
 
 nsStyleList::~nsStyleList() 
 {
   MOZ_COUNT_DTOR(nsStyleList);
 }
 
 nsStyleList::nsStyleList(const nsStyleList& aSource)
   : mListStylePosition(aSource.mListStylePosition),
-    mListStyleType(aSource.mListStyleType),
     mCounterStyle(aSource.mCounterStyle),
     mQuotes(aSource.mQuotes),
     mImageRegion(aSource.mImageRegion)
 {
   SetListStyleImage(aSource.GetListStyleImage());
   MOZ_COUNT_CTOR(nsStyleList);
 }
 
@@ -681,18 +679,16 @@ nsStyleList::CalcDifference(const nsStyl
       GetQuotePairs() != aOther.GetQuotePairs()) {
     return NS_STYLE_HINT_FRAMECHANGE;
   }
   if (mListStylePosition != aOther.mListStylePosition)
     return NS_STYLE_HINT_FRAMECHANGE;
   if (EqualImages(mListStyleImage, aOther.mListStyleImage) &&
       mCounterStyle == aOther.mCounterStyle) {
     if (mImageRegion.IsEqualInterior(aOther.mImageRegion)) {
-      if (mListStyleType != aOther.mListStyleType)
-        return nsChangeHint_NeutralChange;
       return NS_STYLE_HINT_NONE;
     }
     if (mImageRegion.width == aOther.mImageRegion.width &&
         mImageRegion.height == aOther.mImageRegion.height)
       return NS_STYLE_HINT_VISUAL;
   }
   return NS_STYLE_HINT_REFLOW;
 }
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1436,44 +1436,40 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   {
     if (mListStyleImage)
       mListStyleImage->UnlockImage();
     mListStyleImage = aReq;
     if (mListStyleImage)
       mListStyleImage->LockImage();
   }
 
-  void GetListStyleType(nsSubstring& aType) const { aType = mListStyleType; }
+  void GetListStyleType(nsSubstring& aType) const { mCounterStyle->GetStyleName(aType); }
   mozilla::CounterStyle* GetCounterStyle() const
   {
     return mCounterStyle.get();
   }
-  void SetListStyleType(const nsSubstring& aType,
-                        mozilla::CounterStyle* aStyle)
+  void SetCounterStyle(mozilla::CounterStyle* aStyle)
   {
-    mListStyleType = aType;
     mCounterStyle = aStyle;
   }
   void SetListStyleType(const nsSubstring& aType,
                         nsPresContext* aPresContext)
   {
-    SetListStyleType(aType, aPresContext->
-                     CounterStyleManager()->BuildCounterStyle(aType));
+    SetCounterStyle(aPresContext->CounterStyleManager()->BuildCounterStyle(aType));
   }
 
   const nsStyleQuoteValues::QuotePairArray& GetQuotePairs() const;
 
   void SetQuotesInherit(const nsStyleList* aOther);
   void SetQuotesInitial();
   void SetQuotesNone();
   void SetQuotes(nsStyleQuoteValues::QuotePairArray&& aValues);
 
   uint8_t   mListStylePosition;         // [inherited]
 private:
-  nsString  mListStyleType;             // [inherited]
   RefPtr<mozilla::CounterStyle> mCounterStyle; // [inherited]
   RefPtr<imgRequestProxy> mListStyleImage; // [inherited]
   RefPtr<nsStyleQuoteValues> mQuotes;   // [inherited]
   nsStyleList& operator=(const nsStyleList& aOther) = delete;
 public:
   nsRect        mImageRegion;           // [inherited] the rect to use within an image
 
 private: