mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
LibWeb: Do lighter style invalidation for style
attribute changes
When the `style` attribute changes, we only need to update style on the element itself (unless there are [style] attribute selectors somewhere). Descendants of the element don't need a full style update, a simple inheritance propagation is enough.
This commit is contained in:
parent
6983c65c54
commit
d5bbf8dcf8
Notes:
github-actions[bot]
2024-12-23 16:06:01 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/d5bbf8dcf80 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3023
1 changed files with 15 additions and 1 deletions
|
@ -1902,7 +1902,21 @@ ErrorOr<void> Element::scroll_into_view(Optional<Variant<bool, ScrollIntoViewOpt
|
|||
void Element::invalidate_style_after_attribute_change(FlyString const& attribute_name)
|
||||
{
|
||||
// FIXME: Only invalidate if the attribute can actually affect style.
|
||||
(void)attribute_name;
|
||||
|
||||
// OPTIMIZATION: For the `style` attribute, unless it's referenced by an attribute selector,
|
||||
// only invalidate the element itself, then let inheritance propagate to descendants.
|
||||
if (attribute_name == HTML::AttributeNames::style
|
||||
&& !document().style_computer().has_attribute_selector(HTML::AttributeNames::style)) {
|
||||
set_needs_style_update(true);
|
||||
for_each_shadow_including_descendant([](Node& node) {
|
||||
if (!node.is_element())
|
||||
return TraversalDecision::Continue;
|
||||
auto& element = static_cast<Element&>(node);
|
||||
element.set_needs_inherited_style_update(true);
|
||||
return TraversalDecision::Continue;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
invalidate_style(StyleInvalidationReason::ElementAttributeChange);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue