mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move "is universal" logic from stylist.rs to selectors/parser.rs
This commit is contained in:
parent
390e688058
commit
685b9efed6
3 changed files with 16 additions and 15 deletions
|
@ -182,6 +182,18 @@ pub struct Selector<Impl: SelectorImpl> {
|
||||||
pub specificity: u32,
|
pub specificity: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Impl: SelectorImpl> Selector<Impl> {
|
||||||
|
/// 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 {
|
pub trait SelectorMethods {
|
||||||
type Impl: SelectorImpl;
|
type Impl: SelectorImpl;
|
||||||
|
|
||||||
|
|
|
@ -1366,20 +1366,9 @@ impl SelectorMap<Rule> {
|
||||||
|
|
||||||
let mut rules_list = vec![];
|
let mut rules_list = vec![];
|
||||||
for rule in self.other.iter() {
|
for rule in self.other.iter() {
|
||||||
let mut iter = rule.selector.inner.complex.iter_raw();
|
if rule.selector.is_universal() {
|
||||||
match iter.next() {
|
rules_list.push(rule.to_applicable_declaration_block(cascade_level))
|
||||||
None => {}
|
|
||||||
Some(&Component::ExplicitUniversalType) => match iter.next() {
|
|
||||||
None => {}
|
|
||||||
Some(&Component::ExplicitAnyNamespace) => match iter.next() {
|
|
||||||
None => {}
|
|
||||||
_ => continue
|
|
||||||
},
|
|
||||||
_ => continue
|
|
||||||
},
|
|
||||||
_ => continue
|
|
||||||
}
|
}
|
||||||
rules_list.push(rule.to_applicable_declaration_block(cascade_level))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_by_key(&mut rules_list,
|
sort_by_key(&mut rules_list,
|
||||||
|
|
|
@ -212,9 +212,9 @@ fn test_insert() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_universal_rules() {
|
fn test_get_universal_rules() {
|
||||||
thread_state::initialize(thread_state::LAYOUT);
|
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);
|
let decls = map.get_universal_rules(CascadeLevel::UserNormal);
|
||||||
|
|
||||||
assert_eq!(decls.len(), 1);
|
assert_eq!(decls.len(), 1, "{:?}", decls);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue