mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Move perform_pending_style_invalidations()
in StyleInvalidator
This change introduces StyleInvalidator as a preparation for upcoming change that will make `perform_pending_style_invalidations()` take care of pending invalidation sets.
This commit is contained in:
parent
03256a2543
commit
8cbe27b2f9
Notes:
github-actions[bot]
2025-07-16 22:44:32 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 8cbe27b2f9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5474
6 changed files with 74 additions and 29 deletions
44
Libraries/LibWeb/DOM/StyleInvalidator.cpp
Normal file
44
Libraries/LibWeb/DOM/StyleInvalidator.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/StyleInvalidator.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(StyleInvalidator);
|
||||
|
||||
// This function makes a full pass over the entire DOM and converts "entire subtree needs style update"
|
||||
// into "needs style update" for each inclusive descendant where it's found.
|
||||
void StyleInvalidator::perform_pending_style_invalidations(Node& node, bool invalidate_entire_subtree)
|
||||
{
|
||||
invalidate_entire_subtree |= node.entire_subtree_needs_style_update();
|
||||
|
||||
if (invalidate_entire_subtree) {
|
||||
node.set_needs_style_update_internal(true);
|
||||
if (node.has_child_nodes())
|
||||
node.set_child_needs_style_update(true);
|
||||
}
|
||||
|
||||
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
||||
perform_pending_style_invalidations(*child, invalidate_entire_subtree);
|
||||
}
|
||||
|
||||
if (node.is_element()) {
|
||||
auto& element = static_cast<Element&>(node);
|
||||
if (auto shadow_root = element.shadow_root()) {
|
||||
perform_pending_style_invalidations(*shadow_root, invalidate_entire_subtree);
|
||||
if (invalidate_entire_subtree)
|
||||
node.set_child_needs_style_update(true);
|
||||
}
|
||||
}
|
||||
|
||||
node.set_entire_subtree_needs_style_update(false);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue