LibWeb/CSS: Make :heading() pseudo-class take integers not AN+B

Corresponds to 8eb3787e34
This commit is contained in:
Sam Atkins 2025-08-28 10:29:57 +01:00 committed by Jelle Raaijmakers
commit d461e96f40
Notes: github-actions[bot] 2025-08-28 10:41:31 +00:00
10 changed files with 79 additions and 161 deletions

View file

@ -1037,7 +1037,7 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
// The :heading pseudo-class must match all h1, h2, h3, h4, h5, and h6 elements.
// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-heading-functional
// The :heading(An+B#) pseudo-class must match all h1, h2, h3, h4, h5, and h6 elements that have a heading level among An+B. [CSSSYNTAX] [CSSVALUES]
// The :heading(integer#) pseudo-class must match all h1, h2, h3, h4, h5, and h6 elements that have a heading level of integer. [CSSSYNTAX] [CSSVALUES]
// NB: We combine the "is this an h* element?" and "what is it's level?" checks together here.
if (!element.is_html_element())
@ -1061,15 +1061,10 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
if (!heading_level.has_value())
return false;
if (pseudo_class.an_plus_b_patterns.is_empty())
if (pseudo_class.levels.is_empty())
return true;
for (auto const& an_plus_b_pattern : pseudo_class.an_plus_b_patterns) {
if (an_plus_b_pattern.matches(heading_level.value()))
return true;
}
return false;
return pseudo_class.levels.contains_slow(heading_level.value());
}
}