mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Optimize style invalidation caused by DOM structural changes
With this change, siblings of an inserted node are no longer invalidated unless the insertion could potentially affect their style. By "potentially affected," we mean elements that are evaluated against the following selectors during matching: - Sibling combinators (+ or ~) - Pseudo-classes :first-child and :last-child - Pseudo-classes :nth-child, :nth-last-child, :nth-of-type, and :nth-last-of-type
This commit is contained in:
parent
eef678223a
commit
61c952fb43
Notes:
github-actions[bot]
2025-02-06 19:08:36 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 61c952fb43
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3476
Reviewed-by: https://github.com/AtkinsSJ
4 changed files with 42 additions and 4 deletions
|
@ -439,14 +439,14 @@ void Node::invalidate_style(StyleInvalidationReason reason)
|
|||
|
||||
if (reason == StyleInvalidationReason::NodeInsertBefore || reason == StyleInvalidationReason::NodeRemove) {
|
||||
for (auto* sibling = previous_sibling(); sibling; sibling = sibling->previous_sibling()) {
|
||||
if (sibling->is_element())
|
||||
sibling->set_entire_subtree_needs_style_update(true);
|
||||
if (auto* element = as_if<Element>(sibling); element && element->style_affected_by_structural_changes())
|
||||
element->set_entire_subtree_needs_style_update(true);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
|
||||
if (sibling->is_element())
|
||||
sibling->set_entire_subtree_needs_style_update(true);
|
||||
if (auto* element = as_if<Element>(sibling); element && element->style_affected_by_structural_changes())
|
||||
element->set_entire_subtree_needs_style_update(true);
|
||||
}
|
||||
|
||||
for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = ancestor->parent_or_shadow_host())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue