Bug 1387905 part 2 - Use 10bit for specificity in Gecko as well. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Mon, 04 Sep 2017 12:07:24 +1000
changeset 658382 283eec0a06f3138c02d38d4f2ffde3cc2fe0adaa
parent 658381 13b1c85c19f7d35f2a8bebf0f912b0ff4b3c977f
child 729623 4806ae2e2f6417d0a320f5d4c303920a605c085a
push id77737
push userxquan@mozilla.com
push dateMon, 04 Sep 2017 02:08:05 +0000
reviewersheycam
bugs1387905
milestone57.0a1
Bug 1387905 part 2 - Use 10bit for specificity in Gecko as well. r?heycam MozReview-Commit-ID: G5qq0FY0HQ8
devtools/server/css-logic.js
devtools/server/tests/mochitest/chrome.ini
devtools/server/tests/mochitest/test_css-logic-specificity.html
layout/style/StyleRule.cpp
--- a/devtools/server/css-logic.js
+++ b/devtools/server/css-logic.js
@@ -1114,19 +1114,19 @@ CssSelector.prototype = {
    * @see http://www.w3.org/TR/CSS2/selector.html
    *
    * @return {Number} The selector's specificity.
    */
   get specificity() {
     if (this.elementStyle) {
       // We can't ask specificity from DOMUtils as element styles don't provide
       // CSSStyleRule interface DOMUtils expect. However, specificity of element
-      // style is constant, 1,0,0,0 or 0x01000000, just return the constant
+      // style is constant, 1,0,0,0 or 0x40000000, just return the constant
       // directly. @see http://www.w3.org/TR/CSS2/cascade.html#specificity
-      return 0x01000000;
+      return 0x40000000;
     }
 
     if (this._specificity) {
       return this._specificity;
     }
 
     this._specificity = domUtils.getSpecificity(this.cssRule.domRule,
                                                 this.selectorIndex);
--- a/devtools/server/tests/mochitest/chrome.ini
+++ b/devtools/server/tests/mochitest/chrome.ini
@@ -29,17 +29,16 @@ support-files =
   webconsole-helpers.js
   webextension-helpers.js
 [test_animation_actor-lifetime.html]
 [test_connection-manager.html]
 [test_connectToChild.html]
 [test_css-logic.html]
 [test_css-logic-media-queries.html]
 [test_css-logic-specificity.html]
-fail-if = stylo # bug 1387905
 [test_css-properties.html]
 [test_Debugger.Source.prototype.introductionScript.html]
 [test_Debugger.Source.prototype.introductionType.html]
 [test_Debugger.Source.prototype.element.html]
 [test_Debugger.Script.prototype.global.html]
 [test_device.html]
 [test_executeInGlobal-outerized_this.html]
 [test_framerate_01.html]
--- a/devtools/server/tests/mochitest/test_css-logic-specificity.html
+++ b/devtools/server/tests/mochitest/test_css-logic-specificity.html
@@ -20,28 +20,28 @@ Test that css-logic calculates CSS speci
     const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
                        .getService(Ci.inIDOMUtils);
 
     const TEST_DATA = [
       {text: "*", expected: 0},
       {text: "LI", expected: 1},
       {text: "UL LI", expected: 2},
       {text: "UL OL + LI", expected: 3},
-      {text: "H1 + [REL=\"up\"]", expected: 257},
-      {text: "UL OL LI.red", expected: 259},
-      {text: "LI.red.level", expected: 513},
-      {text: ".red .level", expected: 512},
-      {text: "#x34y", expected: 65536},
-      {text: "#s12:not(FOO)", expected: 65537},
-      {text: "body#home div#warning p.message", expected: 131331},
-      {text: "* body#home div#warning p.message", expected: 131331},
-      {text: "#footer :not(nav) li", expected: 65538},
-      {text: "bar:nth-child(n)", expected: 257},
+      {text: "H1 + [REL=\"up\"]", expected: 1025},
+      {text: "UL OL LI.red", expected: 1027},
+      {text: "LI.red.level", expected: 2049},
+      {text: ".red .level", expected: 2048},
+      {text: "#x34y", expected: 1048576},
+      {text: "#s12:not(FOO)", expected: 1048577},
+      {text: "body#home div#warning p.message", expected: 2098179},
+      {text: "* body#home div#warning p.message", expected: 2098179},
+      {text: "#footer :not(nav) li", expected: 1048578},
+      {text: "bar:nth-child(n)", expected: 1025},
       {text: "li::-moz-list-number", expected: 2},
-      {text: "a:hover", expected: 257}
+      {text: "a:hover", expected: 1025}
     ];
 
     function createDocument() {
       let text = TEST_DATA.map(i=>i.text).join(",");
       text = '<style type="text/css">' + text + " {color:red;}</style>";
       // eslint-disable-next-line no-unsanitized/property
       document.body.innerHTML = text;
     }
@@ -70,16 +70,16 @@ Test that css-logic calculates CSS speci
       let specificity = DOMUtils.getSpecificity(selector.cssRule,
                                                 selector.selectorIndex);
       is(specificity, expected,
         'Selector "' + selectorText + '" has a specificity of ' + expected);
     }
 
     info("Testing specificity of element.style");
     let colorProp = cssLogic.getPropertyInfo("background");
-    is(colorProp.matchedSelectors[0].specificity, 0x01000000,
-       "Element styles have specificity of 0x01000000 (16777216).");
+    is(colorProp.matchedSelectors[0].specificity, 0x40000000,
+       "Element styles have specificity of 0x40000000 (1073741824).");
 
     SimpleTest.finish();
   };
   </script>
 </body>
 </html>
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -499,51 +499,51 @@ int32_t nsCSSSelector::CalcWeightWithout
              "If pseudo-elements can have class selectors "
              "after them, specificity calculation must be updated");
 #endif
   MOZ_ASSERT(!(IsPseudoElement() && (mIDList || mAttrList)),
              "If pseudo-elements can have id or attribute selectors "
              "after them, specificity calculation must be updated");
 
   if (IsPseudoElement()) {
-    weight += 0x000001;
+    weight += 1;
   }
   if (nullptr != mCasedTag) {
-    weight += 0x000001;
+    weight += 1;
   }
   nsAtomList* list = mIDList;
   while (nullptr != list) {
-    weight += 0x010000;
+    weight += 1 << 20;
     list = list->mNext;
   }
   list = mClassList;
 #ifdef MOZ_XUL
   // XUL tree pseudo-elements abuse mClassList to store some private
   // data; ignore that.
   if (PseudoType() == CSSPseudoElementType::XULTree) {
     list = nullptr;
   }
 #endif
   while (nullptr != list) {
-    weight += 0x000100;
+    weight += 1 << 10;
     list = list->mNext;
   }
   // FIXME (bug 561154):  This is incorrect for :-moz-any(), which isn't
   // really a pseudo-class.  In order to handle :-moz-any() correctly,
   // we need to compute specificity after we match, based on which
   // option we matched with (and thus also need to try the
   // highest-specificity options first).
   nsPseudoClassList *plist = mPseudoClassList;
   while (nullptr != plist) {
-    weight += 0x000100;
+    weight += 1 << 10;
     plist = plist->mNext;
   }
   nsAttrSelector* attr = mAttrList;
   while (nullptr != attr) {
-    weight += 0x000100;
+    weight += 1 << 10;
     attr = attr->mNext;
   }
   return weight;
 }
 
 int32_t nsCSSSelector::CalcWeight() const
 {
   // Loop over this selector and all its negations.