Bug 1420946 - Don't try to share style on quirks mode whenever two elements have different id. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Wed, 29 Nov 2017 17:34:37 -0600
changeset 705444 cd0ff2af2af2a90b0e3aced110e26c7b8e007e18
parent 704788 a7d930b2c45bbd80b5f3e9e430e68a3f78de588e
child 742355 a8f99d5f64302e2755e6bc4ff651e999a6135011
push id91463
push userxquan@mozilla.com
push dateThu, 30 Nov 2017 01:34:26 +0000
reviewersemilio
bugs1420946
milestone59.0a1
Bug 1420946 - Don't try to share style on quirks mode whenever two elements have different id. r?emilio MozReview-Commit-ID: FcHXGUoMMbD
layout/reftests/bugs/1420946-1-ref.html
layout/reftests/bugs/1420946-1.html
layout/reftests/bugs/reftest.list
servo/components/style/stylist.rs
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1420946-1-ref.html
@@ -0,0 +1,4 @@
+<!-- ~*quirks mode*~ -->
+<div></div>
+<p style="color: green">should be green
+<p>should be unstyled
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1420946-1.html
@@ -0,0 +1,9 @@
+<!-- ~*quirks mode*~ -->
+<style>
+#lolquirky {
+  color: green;
+}
+</style>
+<div></div>
+<p id="lolQuirky">should be green
+<p>should be unstyled
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -2044,8 +2044,9 @@ needs-focus != 1377447-1.html 1377447-2.
 == 1401992.html 1401992-ref.html
 == 1405878-1.xml 1405878-1-ref.xml
 == 1404057.html 1404057-ref.html
 != 1404057.html 1404057-noref.html
 == 1406183-1.html 1406183-1-ref.html
 == 1410028.html 1410028-ref.html
 test-pref(font.size.systemFontScale,200) == 1412743.html 1412743-ref.html
 == 1419820-1.html 1419820-1-ref.html
+== 1420946-1.html 1420946-1-ref.html
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -21,17 +21,17 @@ use malloc_size_of::{MallocShallowSizeOf
 use malloc_size_of::MallocUnconditionalShallowSizeOf;
 use media_queries::Device;
 use properties::{self, CascadeFlags, ComputedValues};
 use properties::{AnimationRules, PropertyDeclarationBlock};
 use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
 use selector_map::{PrecomputedHashMap, SelectorMap, SelectorMapEntry};
 use selector_parser::{SelectorImpl, PerPseudoElementMap, PseudoElement};
 use selectors::NthIndexCache;
-use selectors::attr::NamespaceConstraint;
+use selectors::attr::{CaseSensitivity, NamespaceConstraint};
 use selectors::bloom::{BloomFilter, NonCountingBloomFilter};
 use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode};
 use selectors::matching::VisitedHandlingMode;
 use selectors::parser::{AncestorHashes, Combinator, Component, Selector};
 use selectors::parser::{SelectorIter, SelectorMethods};
 use selectors::sink::Push;
 use selectors::visitor::SelectorVisitor;
 use servo_arc::{Arc, ArcBorrow};
@@ -1408,16 +1408,23 @@ impl Stylist {
     pub fn may_have_rules_for_id<E>(
         &self,
         id: &Atom,
         element: E,
     ) -> bool
     where
         E: TElement,
     {
+        // If id needs to be compared case-insensitively, the logic below
+        // wouldn't work. Just conservatively assume it may have such rules.
+        match self.quirks_mode().classes_and_ids_case_sensitivity() {
+            CaseSensitivity::AsciiCaseInsensitive => return true,
+            CaseSensitivity::CaseSensitive => {}
+        }
+
         let hash = id.get_hash();
         for (data, _) in self.cascade_data.iter_origins() {
             if data.mapped_ids.might_contain_hash(hash) {
                 return true;
             }
         }
 
         let mut xbl_rules_may_contain = false;