mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-01 22:29:13 +00:00
LibWeb: Avoid full tree traversal for non-subject :has() invalidation
Instead of checking all elements in a document for containment in `:has()` invalidation set, we could narrow this down to ancestors and ancestor siblings, like we already do for subject `:has()` invalidation. This change brings great improvement on GitHub that has selectors with non-subject `:has()` and sibling combinators (e.g., `.a:has(.b) ~ .c`) which prior to this change meant style invalidation for whole document.
This commit is contained in:
committed by
Andreas Kling
parent
604400f758
commit
327dc8e82a
@@ -498,6 +498,8 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style()
|
||||
VERIFY(parent());
|
||||
|
||||
m_affected_by_has_pseudo_class_in_subject_position = false;
|
||||
m_affected_by_has_pseudo_class_in_non_subject_position = false;
|
||||
m_affected_by_has_pseudo_class_with_relative_selector_that_has_sibling_combinator = false;
|
||||
m_affected_by_sibling_combinator = false;
|
||||
m_affected_by_first_or_last_child_pseudo_class = false;
|
||||
m_affected_by_nth_child_pseudo_class = false;
|
||||
@@ -1312,6 +1314,16 @@ bool Element::includes_properties_from_invalidation_set(CSS::InvalidationSet con
|
||||
return includes_any;
|
||||
}
|
||||
|
||||
void Element::invalidate_style_if_affected_by_has()
|
||||
{
|
||||
if (affected_by_has_pseudo_class_in_subject_position()) {
|
||||
set_needs_style_update(true);
|
||||
}
|
||||
if (affected_by_has_pseudo_class_in_non_subject_position()) {
|
||||
invalidate_style(StyleInvalidationReason::Other, { { CSS::InvalidationSet::Property::Type::PseudoClass, CSS::PseudoClass::Has } }, {});
|
||||
}
|
||||
}
|
||||
|
||||
bool Element::has_pseudo_elements() const
|
||||
{
|
||||
if (m_pseudo_element_data) {
|
||||
|
||||
Reference in New Issue
Block a user