Bug 1387905 part 1 - Count pseudo-element into specificity. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Mon, 04 Sep 2017 12:05:56 +1000
changeset 658381 13b1c85c19f7d35f2a8bebf0f912b0ff4b3c977f
parent 658362 f208c39b45fd7dc6f1ea83e75f0f1019c07f7408
child 658382 283eec0a06f3138c02d38d4f2ffde3cc2fe0adaa
push id77737
push userxquan@mozilla.com
push dateMon, 04 Sep 2017 02:08:05 +0000
reviewersheycam
bugs1387905
milestone57.0a1
Bug 1387905 part 1 - Count pseudo-element into specificity. r?heycam MozReview-Commit-ID: IWlINaYAhql
devtools/server/tests/mochitest/test_css-logic-specificity.html
layout/style/StyleRule.cpp
--- a/devtools/server/tests/mochitest/test_css-logic-specificity.html
+++ b/devtools/server/tests/mochitest/test_css-logic-specificity.html
@@ -30,17 +30,17 @@ Test that css-logic calculates CSS speci
       {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: "li::-moz-list-number", expected: 1},
+      {text: "li::-moz-list-number", expected: 2},
       {text: "a:hover", expected: 257}
     ];
 
     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;
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -498,16 +498,19 @@ int32_t nsCSSSelector::CalcWeightWithout
   MOZ_ASSERT(!(IsPseudoElement() && mClassList),
              "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;
+  }
   if (nullptr != mCasedTag) {
     weight += 0x000001;
   }
   nsAtomList* list = mIDList;
   while (nullptr != list) {
     weight += 0x010000;
     list = list->mNext;
   }