1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 05:12:14 +00:00

LibWeb: Use Selectors instead of a String for :not() selectors

Rather than parsing the selector every time we want to check it, we
now parse it once at the beginning.

A bonus effect of this is that we now support a selector list in
:not(), instead of just a single selector, though only when using
the new parser.
This commit is contained in:
Sam Atkins 2021-07-12 17:58:47 +01:00 committed by Andreas Kling
parent 776b1f4548
commit ffc81cbfad
8 changed files with 40 additions and 19 deletions

View file

@ -113,15 +113,12 @@ static bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClass cons
if (!element.has_attribute("checked"))
return false;
return true;
case CSS::Selector::SimpleSelector::PseudoClass::Type::Not: {
if (pseudo_class.not_selector.is_empty())
return false;
auto not_selector = Web::parse_selector(CSS::DeprecatedParsingContext(element), pseudo_class.not_selector);
if (!not_selector)
return false;
auto not_matches = matches(not_selector.release_nonnull(), element);
return !not_matches;
}
case CSS::Selector::SimpleSelector::PseudoClass::Type::Not:
for (auto& selector : pseudo_class.not_selector) {
if (matches(selector, element))
return false;
}
return true;
case CSS::Selector::SimpleSelector::PseudoClass::Type::NthChild:
case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastChild:
auto const step_size = pseudo_class.nth_child_pattern.step_size;