From 33fed655978824c29dd4dcc4424b3148c3b2d26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 5 Nov 2018 00:05:12 +0000 Subject: [PATCH] style: Don't match document author rules if not needed for revalidation. When you're in a ShadowRoot and can share style with a sibling, the sharing code is smart enough to skip document author rules. But then it could get confused if you also include document rules, since revalidation selectors are matched against these. This is not a correctness issue, because we're matching more than what we need, and avoid sharing if we failed. Also fix the detection for user rules in any_applicable_rule_data. Differential Revision: https://phabricator.services.mozilla.com/D10117 --- components/style/stylist.rs | 53 +++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index fe96fd78ad8..2772891a3db 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -605,11 +605,11 @@ impl Stylist { maybe = maybe || f(&*data); }); - if maybe || !doc_author_rules_apply { - return maybe; + if maybe || f(&self.cascade_data.user) { + return true; } - f(&self.cascade_data.author) || f(&self.cascade_data.user) + doc_author_rules_apply && f(&self.cascade_data.author) } /// Computes the style for a given "precomputed" pseudo-element, taking the @@ -1491,7 +1491,33 @@ impl Stylist { // the lookups, which means that the bitvecs are comparable. We verify // this in the caller by asserting that the bitvecs are same-length. let mut results = SmallBitVec::new(); - for (data, _) in self.cascade_data.iter_origins() { + + let matches_document_rules = + element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| { + matching_context.with_shadow_host(host, |matching_context| { + data.selectors_for_cache_revalidation.lookup( + element, + quirks_mode, + |selector_and_hashes| { + results.push(matches_selector( + &selector_and_hashes.selector, + selector_and_hashes.selector_offset, + Some(&selector_and_hashes.hashes), + &element, + matching_context, + flags_setter, + )); + true + }, + ); + }) + }); + + for (data, origin) in self.cascade_data.iter_origins() { + if origin == Origin::Author && !matches_document_rules { + continue; + } + data.selectors_for_cache_revalidation.lookup( element, self.quirks_mode, @@ -1509,25 +1535,6 @@ impl Stylist { ); } - element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| { - matching_context.with_shadow_host(host, |matching_context| { - data.selectors_for_cache_revalidation.lookup( - element, - quirks_mode, - |selector_and_hashes| { - results.push(matches_selector( - &selector_and_hashes.selector, - selector_and_hashes.selector_offset, - Some(&selector_and_hashes.hashes), - &element, - matching_context, - flags_setter, - )); - true - }, - ); - }) - }); results }