Bug 1393189 part 3 - Replace all uses of nsCSSProps::kListStyleKTable with gBuiltinStyleTable. r=dholbert
☠☠ backed out by 095109d7ba80 ☠ ☠
authorXidorn Quan <me@upsuper.org>
Tue, 29 Aug 2017 15:36:32 +1000
changeset 377754 986b0a6f71736c6c134e9fa44cfeec0032342171
parent 377753 1200482baf04a5d9bea563be0c2ce4e7a4e47a50
child 377755 d0cff01a73a03876c775ac97ea07cb8b428108a4
push id94338
push userkwierso@gmail.com
push dateThu, 31 Aug 2017 02:58:58 +0000
treeherdermozilla-inbound@9ca18987dabb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1393189
milestone57.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 1393189 part 3 - Replace all uses of nsCSSProps::kListStyleKTable with gBuiltinStyleTable. r=dholbert The change in CounterStyleManager::BuildCounterStyle converts a case- insensitive comparison to a case-sensitive comparison by comparing atom pointer directly. But this is fine because all names of builtin counter styles should have been lowercased by the parser. For Gecko, it is done in CSSParserImpl::ParseCounterStyleName, and for Servo, it is done in counter_style::parse_counter_style_name. MozReview-Commit-ID: JHHmzEaNIpn
layout/style/CounterStyleManager.cpp
layout/style/CounterStyleManager.h
layout/style/nsRuleNode.cpp
--- a/layout/style/CounterStyleManager.cpp
+++ b/layout/style/CounterStyleManager.cpp
@@ -2029,32 +2029,31 @@ CounterStyle*
 CounterStyleManager::BuildCounterStyle(nsIAtom* aName)
 {
   MOZ_ASSERT(NS_IsMainThread());
   CounterStyle* data = GetCounterStyle(aName);
   if (data) {
     return data;
   }
 
-  // It is intentional that the predefined names are case-insensitive
-  // but the user-defined names case-sensitive.
+  // Names are compared case-sensitively here. Predefined names should
+  // have been lowercased by the parser.
   StyleSetHandle styleSet = mPresContext->StyleSet();
   nsCSSCounterStyleRule* rule = styleSet->CounterStyleRuleForName(aName);
   if (rule) {
     MOZ_ASSERT(rule->Name() == aName);
     data = new (mPresContext) CustomCounterStyle(aName, this, rule);
   } else {
-    int32_t type;
-    nsDependentAtomString name(aName);
-    nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(name);
-    if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kListStyleKTable, type)) {
-      if (gBuiltinStyleTable[type].IsDependentStyle()) {
-        data = new (mPresContext) DependentBuiltinCounterStyle(type, this);
-      } else {
-        data = GetBuiltinStyle(type);
+    for (const BuiltinCounterStyle& item : gBuiltinStyleTable) {
+      if (item.GetStyleName() == aName) {
+        int32_t style = item.GetStyle();
+        data = item.IsDependentStyle()
+          ? new (mPresContext) DependentBuiltinCounterStyle(style, this)
+          : GetBuiltinStyle(style);
+        break;
       }
     }
   }
   if (!data) {
     data = GetDecimalStyle();
   }
   mStyles.Put(aName, data);
   return data;
@@ -2067,16 +2066,24 @@ CounterStyleManager::GetBuiltinStyle(int
              "Require a valid builtin style constant");
   MOZ_ASSERT(!gBuiltinStyleTable[aStyle].IsDependentStyle(),
              "Cannot get dependent builtin style");
   // No method of BuiltinCounterStyle mutates the struct itself, so it
   // should be fine to cast const away.
   return const_cast<BuiltinCounterStyle*>(&gBuiltinStyleTable[aStyle]);
 }
 
+/* static */ nsIAtom*
+CounterStyleManager::GetStyleNameFromType(int32_t aStyle)
+{
+  MOZ_ASSERT(0 <= aStyle && size_t(aStyle) < sizeof(gBuiltinStyleTable),
+             "Require a valid builtin style constant");
+  return gBuiltinStyleTable[aStyle].GetStyleName();
+}
+
 bool
 CounterStyleManager::NotifyRuleChanged()
 {
   bool changed = false;
   for (auto iter = mStyles.Iter(); !iter.Done(); iter.Next()) {
     CounterStyle* style = iter.Data();
     bool toBeUpdated = false;
     bool toBeRemoved = false;
--- a/layout/style/CounterStyleManager.h
+++ b/layout/style/CounterStyleManager.h
@@ -340,16 +340,18 @@ public:
   {
     return GetBuiltinStyle(NS_STYLE_LIST_STYLE_DECIMAL);
   }
   static CounterStyle* GetDiscStyle()
   {
     return GetBuiltinStyle(NS_STYLE_LIST_STYLE_DISC);
   }
 
+  static nsIAtom* GetStyleNameFromType(int32_t aStyle);
+
   // This method will scan all existing counter styles generated by this
   // manager, and remove or mark data dirty accordingly. It returns true
   // if any counter style is changed, false elsewise. This method should
   // be called when any counter style may be affected.
   bool NotifyRuleChanged();
   // NotifyRuleChanged will evict no longer needed counter styles into
   // mRetiredStyles, and this function destroys all objects listed there.
   // It should be called only after no one may ever use those objects.
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -8088,36 +8088,37 @@ nsRuleNode::ComputeListData(void* aStart
     }
     case eCSSUnit_String: {
       nsString str;
       typeValue->GetStringValue(str);
       list->mCounterStyle = new AnonymousCounterStyle(str);
       break;
     }
     case eCSSUnit_Enumerated: {
-      // For compatibility with html attribute map.
-      // This branch should never be called for value from CSS.
+      // For compatibility with html attribute map. This branch should
+      // never be called for value from CSS. The values can only come
+      // from the items in EnumTable listed in HTMLLIElement.cpp and
+      // HTMLSharedListElement.cpp.
       int32_t intValue = typeValue->GetIntValue();
       nsCOMPtr<nsIAtom> name;
       switch (intValue) {
         case NS_STYLE_LIST_STYLE_LOWER_ROMAN:
           name = nsGkAtoms::lowerRoman;
           break;
         case NS_STYLE_LIST_STYLE_UPPER_ROMAN:
           name = nsGkAtoms::upperRoman;
           break;
         case NS_STYLE_LIST_STYLE_LOWER_ALPHA:
           name = nsGkAtoms::lowerAlpha;
           break;
         case NS_STYLE_LIST_STYLE_UPPER_ALPHA:
           name = nsGkAtoms::upperAlpha;
           break;
         default:
-          name = NS_Atomize(nsCSSProps::ValueToKeyword(
-                  intValue, nsCSSProps::kListStyleKTable));
+          name = CounterStyleManager::GetStyleNameFromType(intValue);
           break;
       }
       setListStyleType(name);
       break;
     }
     case eCSSUnit_Symbols:
       list->mCounterStyle =
         new AnonymousCounterStyle(typeValue->GetArrayValue());