LibWeb: Skip invalidating :first-child and :last-child if possible

There is no need to invalidate siblings affected by these pseudo classes
if invalidation reason is not insertion or removal of tree nodes.
This commit is contained in:
Aliaksandr Kalenik 2025-03-09 16:38:34 +01:00 committed by Alexander Kalenik
parent 0e057d3a36
commit 92a3419799
Notes: github-actions[bot] 2025-03-09 17:41:38 +00:00

View file

@ -461,8 +461,16 @@ void Node::invalidate_style(StyleInvalidationReason reason)
}
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
if (auto* element = as_if<Element>(sibling); element && element->style_affected_by_structural_changes())
element->set_entire_subtree_needs_style_update(true);
if (auto* element = as_if<Element>(sibling)) {
bool needs_to_invalidate = false;
if (reason == StyleInvalidationReason::NodeInsertBefore || reason == StyleInvalidationReason::NodeRemove) {
needs_to_invalidate = element->style_affected_by_structural_changes();
} else {
needs_to_invalidate = element->affected_by_sibling_combinator() || element->affected_by_nth_child_pseudo_class();
}
if (needs_to_invalidate)
element->set_entire_subtree_needs_style_update(true);
}
}
for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = ancestor->parent_or_shadow_host())