1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibWeb: Make document-level style invalidation fast

Add a flag to DOM::Document that means the whole document needs a style
update. This saves us the trouble of traversing the entire DOM to mark
all nodes as needing a style update.
This commit is contained in:
Andreas Kling 2022-03-19 18:10:59 +01:00
parent f87edd4c14
commit 0b861e0c9d
3 changed files with 18 additions and 4 deletions

View file

@ -595,6 +595,7 @@ void Document::update_layout()
[[nodiscard]] static bool update_style_recursively(DOM::Node& node)
{
bool const needs_full_style_update = node.document().needs_full_style_update();
bool needs_relayout = false;
if (is<Element>(node)) {
@ -602,15 +603,15 @@ void Document::update_layout()
}
node.set_needs_style_update(false);
if (node.child_needs_style_update()) {
if (needs_full_style_update || node.child_needs_style_update()) {
if (node.is_element()) {
if (auto* shadow_root = static_cast<DOM::Element&>(node).shadow_root()) {
if (shadow_root->needs_style_update() || shadow_root->child_needs_style_update())
if (needs_full_style_update || shadow_root->needs_style_update() || shadow_root->child_needs_style_update())
needs_relayout |= update_style_recursively(*shadow_root);
}
}
node.for_each_child([&](auto& child) {
if (child.needs_style_update() || child.child_needs_style_update())
if (needs_full_style_update || child.needs_style_update() || child.child_needs_style_update())
needs_relayout |= update_style_recursively(child);
return IterationDecision::Continue;
});
@ -624,10 +625,11 @@ void Document::update_style()
{
if (!browsing_context())
return;
if (!needs_style_update() && !child_needs_style_update())
if (!needs_full_style_update() && !needs_style_update() && !child_needs_style_update())
return;
if (update_style_recursively(*this))
invalidate_layout();
m_needs_full_style_update = false;
m_style_update_timer->stop();
}