diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 0484906257b..34ed4418b3d 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -182,6 +182,18 @@ pub struct Selector { pub specificity: u32, } +impl Selector { + /// Whether this selector (pseudo-element part excluded) matches every element. + /// + /// Used for "pre-computed" pseudo-elements in components/style/stylist.rs + pub fn is_universal(&self) -> bool { + self.inner.complex.iter_raw().all(|c| matches!(*c, + Component::ExplicitUniversalType | + Component::ExplicitAnyNamespace + )) + } +} + pub trait SelectorMethods { type Impl: SelectorImpl; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 8fe290c7e8e..80f41203321 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -1366,20 +1366,9 @@ impl SelectorMap { let mut rules_list = vec![]; for rule in self.other.iter() { - let mut iter = rule.selector.inner.complex.iter_raw(); - match iter.next() { - None => {} - Some(&Component::ExplicitUniversalType) => match iter.next() { - None => {} - Some(&Component::ExplicitAnyNamespace) => match iter.next() { - None => {} - _ => continue - }, - _ => continue - }, - _ => continue + if rule.selector.is_universal() { + rules_list.push(rule.to_applicable_declaration_block(cascade_level)) } - rules_list.push(rule.to_applicable_declaration_block(cascade_level)) } sort_by_key(&mut rules_list, diff --git a/tests/unit/style/stylist.rs b/tests/unit/style/stylist.rs index 073c003b0bb..3c136edcef3 100644 --- a/tests/unit/style/stylist.rs +++ b/tests/unit/style/stylist.rs @@ -212,9 +212,9 @@ fn test_insert() { #[test] fn test_get_universal_rules() { thread_state::initialize(thread_state::LAYOUT); - let (map, shared_lock) = get_mock_map(&["*|*", "#foo > *|*", ".klass", "#id"]); + let (map, shared_lock) = get_mock_map(&["*|*", "#foo > *|*", "*|* > *|*", ".klass", "#id"]); let decls = map.get_universal_rules(CascadeLevel::UserNormal); - assert_eq!(decls.len(), 1); + assert_eq!(decls.len(), 1, "{:?}", decls); }