style: Parsing for relative selectors in :has()

Differential Revision: https://phabricator.services.mozilla.com/D171358
This commit is contained in:
David Shin 2023-03-07 18:04:27 +00:00 committed by Martin Robinson
parent b6db94bdf5
commit f7b29ac432
5 changed files with 208 additions and 65 deletions

View file

@ -835,10 +835,34 @@ where
.nest_for_negation(|context| !list_matches_complex_selector(list, element, context)),
Component::Has(ref list) => context
.shared
.nest(|context| has_children_matching(list, element, context)),
.nest_for_relative_selector(element.opaque(), |context| {
if cfg!(debug_assertions) {
for selector in list.iter() {
let mut selector_iter = selector.iter_raw_parse_order_from(0);
assert!(
matches!(selector_iter.next().unwrap(), Component::RelativeSelectorAnchor),
"Relative selector does not start with RelativeSelectorAnchor"
);
assert!(
selector_iter.next().unwrap().is_combinator(),
"Relative combinator does not exist"
);
}
}
// TODO(dshin): Proper matching for sibling relative combinators.
has_children_matching(list, element, context)
}),
Component::Combinator(_) => unsafe {
debug_unreachable!("Shouldn't try to selector-match combinators")
},
Component::RelativeSelectorAnchor => {
let anchor = context.shared.relative_selector_anchor();
debug_assert!(
anchor.is_some(),
"Relative selector outside of relative selector matching?"
);
anchor.map_or(false, |a| a == element.opaque())
},
}
}