style: Skip state pseudo-classes when finding a pseudo-element. r?heycam
draft
style: Skip state pseudo-classes when finding a pseudo-element. r?heycam
MozReview-Commit-ID: 1ICBijtcf2b
--- a/servo/components/style/invalidation/element/invalidator.rs
+++ b/servo/components/style/invalidation/element/invalidator.rs
@@ -590,25 +590,47 @@ impl<'a, 'b: 'a, E> TreeStyleInvalidator
invalidated_self = true;
}
CompoundSelectorMatchingResult::Matched { next_combinator_offset } => {
let next_combinator =
invalidation.selector.combinator_at(next_combinator_offset);
matched = true;
if matches!(next_combinator, Combinator::PseudoElement) {
- let pseudo_selector =
+ // This will usually be the very next component, except for
+ // the fact that we store compound selectors the other way
+ // around, so there could also be state pseudo-classes.
+ let pseudo =
invalidation.selector
.iter_raw_parse_order_from(next_combinator_offset - 1)
- .next()
- .unwrap();
- let pseudo = match *pseudo_selector {
- Component::PseudoElement(ref pseudo) => pseudo,
- _ => unreachable!("Someone seriously messed up selector parsing"),
- };
+ .flat_map(|component| {
+ match *component {
+ Component::PseudoElement(ref pseudo) => {
+ Some(pseudo)
+ },
+ Component::Combinator(ref combinator) => {
+ unreachable!(
+ "Someone seriously messed up selector parsing: \
+ {:?} at offset {:?}: {:?}",
+ invalidation.selector,
+ next_combinator_offset,
+ combinator,
+ )
+ },
+ ref other => {
+ debug_assert!(matches!(
+ *other,
+ Component::NonTSPseudoClass(..)
+ ));
+
+ None
+ }
+ }
+ })
+ .next().unwrap();
// FIXME(emilio): This is not ideal, and could not be
// accurate if we ever have stateful element-backed eager
// pseudos.
//
// Ideally, we'd just remove element-backed eager pseudos
// altogether, given they work fine without it. Only gotcha
// is that we wouldn't style them in parallel, which may or