LibWeb: Add mechanism to invalidate only inherited styles

We can now mark an element as needing an "inherited style update" rather
than a full "style update". This effectively means that the next style
update will visit the element and pull all of its inherited properties
from the relevant ancestor element.

This is now used for descendants of elements with animated style.
This commit is contained in:
Andreas Kling 2024-12-22 11:59:58 +01:00 committed by Andreas Kling
commit dc8343cc23
Notes: github-actions[bot] 2024-12-23 16:06:18 +00:00
7 changed files with 55 additions and 16 deletions

View file

@ -935,25 +935,14 @@ void KeyframeEffect::update_computed_properties()
auto& document = target->document();
document.style_computer().collect_animation_into(*target, pseudo_element_type(), *this, *style, CSS::StyleComputer::AnimationRefresh::Yes);
auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values());
// Traversal of the subtree is necessary to update the animated properties inherited from the target element.
target->for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
auto element_style = element.computed_properties();
if (!element_style || !element.layout_node())
return TraversalDecision::Continue;
for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
if (element_style->is_property_inherited(static_cast<CSS::PropertyID>(i))) {
auto new_value = CSS::StyleComputer::get_inherit_value(static_cast<CSS::PropertyID>(i), &element);
element_style->set_property(static_cast<CSS::PropertyID>(i), *new_value, CSS::ComputedProperties::Inherited::Yes);
}
}
element.layout_node()->apply_style(*element_style);
invalidation |= element.recompute_inherited_style();
return TraversalDecision::Continue;
});
auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values());
if (!pseudo_element_type().has_value()) {
if (target->layout_node())
target->layout_node()->apply_style(*style);