diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-14 21:40:34 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-15 20:02:30 +0100 |
commit | 03d6e1953f91552d78b50540ac267fa3413459f8 (patch) | |
tree | 29f6e19a932801548adb8fc3f92bc45006769b7b /Userland/Libraries/LibWeb/DOM | |
parent | 544c796bcf384cc10d5485e242a42ad2e7b3cfcf (diff) | |
download | serenity-03d6e1953f91552d78b50540ac267fa3413459f8.zip |
LibWeb: Improvements to Node::invalidate_style()
- Access members directly instead of going through accessors,
avoiding a lot of redundant traversal done by accessors.
- Cross shadow boundaries and make sure that shadow trees get their
dirty bits updated as well.
- Do the minimum amount of traversal needed when setting the "child
needs style update" bit upwards through ancestors.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index c55999285a..3c147f58f7 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -176,10 +176,22 @@ void Node::set_node_value(const String& value) void Node::invalidate_style() { - for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) { - element.set_needs_style_update(true); + for_each_in_inclusive_subtree([&](Node& node) { + node.m_needs_style_update = true; + if (node.has_children()) + node.m_child_needs_style_update = true; + if (auto* shadow_root = node.is_element() ? static_cast<DOM::Element&>(node).shadow_root() : nullptr) { + shadow_root->m_needs_style_update = true; + if (shadow_root->has_children()) + shadow_root->m_child_needs_style_update = true; + } return IterationDecision::Continue; }); + for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = parent_or_shadow_host()) { + if (ancestor->m_child_needs_style_update) + break; + ancestor->m_child_needs_style_update = true; + } document().schedule_style_update(); } |