From 94b3b84dd808b6607e8fd0aead1796709f3a8721 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 2 Oct 2024 05:53:03 +0200 Subject: [PATCH] LibWeb: Make sure style is up-to-date in getAnimations() StyleComputer is responsible for assigning animation targets, so we have to make sure there are no pending style updates before querying animations of an element. This change also introduces a version of getAnimations() that does not check style updates and used by StyleComputer to avoid mutual recursion. --- ...ions-should-make-sure-style-is-updated.txt | 1 + ...ons-should-make-sure-style-is-updated.html | 26 +++++++++++++++++++ .../LibWeb/Animations/Animatable.cpp | 6 +++++ .../Libraries/LibWeb/Animations/Animatable.h | 1 + .../Libraries/LibWeb/CSS/StyleComputer.cpp | 2 +- 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.txt create mode 100644 Tests/LibWeb/Text/input/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.html diff --git a/Tests/LibWeb/Text/expected/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.txt b/Tests/LibWeb/Text/expected/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.txt new file mode 100644 index 00000000000..5d24743029f --- /dev/null +++ b/Tests/LibWeb/Text/expected/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.txt @@ -0,0 +1 @@ +This is a animated div animation count: 1 diff --git a/Tests/LibWeb/Text/input/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.html b/Tests/LibWeb/Text/input/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.html new file mode 100644 index 00000000000..4eb6398404b --- /dev/null +++ b/Tests/LibWeb/Text/input/WebAnimations/misc/get-animations-should-make-sure-style-is-updated.html @@ -0,0 +1,26 @@ + + + +
This is a animated div
+ diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.cpp b/Userland/Libraries/LibWeb/Animations/Animatable.cpp index 9ab44faa9d4..c495a2205e0 100644 --- a/Userland/Libraries/LibWeb/Animations/Animatable.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animatable.cpp @@ -60,6 +60,12 @@ WebIDL::ExceptionOr> Animatable::animate(Optional> Animatable::get_animations(GetAnimationsOptions options) +{ + verify_cast(*this).document().update_style(); + return get_animations_internal(options); +} + +Vector> Animatable::get_animations_internal(GetAnimationsOptions options) { // Returns the set of relevant animations for this object, or, if an options parameter is passed with subtree set to // true, returns the set of relevant animations for a subtree for this object. diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.h b/Userland/Libraries/LibWeb/Animations/Animatable.h index cbd419d645e..a7ff426a57c 100644 --- a/Userland/Libraries/LibWeb/Animations/Animatable.h +++ b/Userland/Libraries/LibWeb/Animations/Animatable.h @@ -41,6 +41,7 @@ public: WebIDL::ExceptionOr> animate(Optional> keyframes, Variant options = {}); Vector> get_animations(GetAnimationsOptions options = {}); + Vector> get_animations_internal(GetAnimationsOptions options = {}); void associate_with_animation(JS::NonnullGCPtr); void disassociate_with_animation(JS::NonnullGCPtr); diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 6c886e5b851..17dc234ed34 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1563,7 +1563,7 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element } } - auto animations = element.get_animations({ .subtree = false }); + auto animations = element.get_animations_internal({ .subtree = false }); for (auto& animation : animations) { if (auto effect = animation->effect(); effect && effect->is_keyframe_effect()) { auto& keyframe_effect = *static_cast(effect.ptr());