LibWeb: Use invalidation sets for :has() invalidation

Prior to this change, we invalidated all elements in the document if it
used any selectors with :has(). This change aims to improve that by
applying a combination of techniques:
- Collect metadata for each element if it was matched against a selector
  with :has() in the subject position. This is needed to invalidate all
  elements that could be affected by selectors like `div:has(.a:empty)`
  because they are not covered by the invalidation sets.
- Use invalidation sets to invalidate elements that are affected by
  selectors with :has() in a non-subject position.

Selectors like `.a:has(.b) + .c` still cause whole-document invalidation
because invalidation sets cover only descendants, not siblings. As a
result, there is no performance improvement on github.com due to this
limitation. However, youtube.com and discord.com benefit from this
change.
This commit is contained in:
Aliaksandr Kalenik 2025-01-29 03:31:46 +01:00 committed by Andreas Kling
commit d762d16938
Notes: github-actions[bot] 2025-01-29 08:31:17 +00:00
8 changed files with 56 additions and 9 deletions

View file

@ -1166,6 +1166,8 @@ bool Element::includes_properties_from_invalidation_set(CSS::InvalidationSet con
}
case CSS::InvalidationSet::Property::Type::PseudoClass: {
switch (property.value.get<CSS::PseudoClass>()) {
case CSS::PseudoClass::Has:
return true;
case CSS::PseudoClass::Enabled: {
return (is<HTML::HTMLButtonElement>(*this) || is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLSelectElement>(*this) || is<HTML::HTMLTextAreaElement>(*this) || is<HTML::HTMLOptGroupElement>(*this) || is<HTML::HTMLOptionElement>(*this) || is<HTML::HTMLFieldSetElement>(*this))
&& !is_actually_disabled();