From 9e22233be9771fa912f620bb316e3360d5301a06 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 1 Aug 2024 16:08:21 +0300 Subject: [PATCH] LibWeb: Enable fast path of animation invalidation for pseudo-elements 3abd3ef5e2b7c35068058a58034f70ae843cec45 made possible using fast invalidation path for pseudo-element by saving previously computed style in DOM::Element. --- .../LibWeb/Animations/KeyframeEffect.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 8df9bb76e41..2f670f2a3ad 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -954,13 +954,12 @@ void KeyframeEffect::update_style_properties() if (!target) return; - if (pseudo_element_type().has_value()) { - // StyleProperties are not saved for pseudo-elements so there is nothing to patch - target->invalidate_style(); - return; - } + CSS::StyleProperties* style = nullptr; + if (!pseudo_element_type().has_value()) + style = target->computed_css_values(); + else + style = target->pseudo_element_computed_css_values(pseudo_element_type().value()); - auto* style = target->computed_css_values(); if (!style) return; @@ -988,8 +987,15 @@ void KeyframeEffect::update_style_properties() auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values()); - if (target->layout_node()) - target->layout_node()->apply_style(*style); + if (!pseudo_element_type().has_value()) { + if (target->layout_node()) + target->layout_node()->apply_style(*style); + } else { + auto pseudo_element_node = target->get_pseudo_element_node(pseudo_element_type().value()); + if (auto* node_with_style = dynamic_cast(pseudo_element_node.ptr())) { + node_with_style->apply_style(*style); + } + } if (invalidation.relayout) document.set_needs_layout();