From fbcef936a97fdce42f54fe011b64f38cb84fd30f Mon Sep 17 00:00:00 2001 From: Callum Law Date: Fri, 31 Oct 2025 01:14:05 +1300 Subject: [PATCH] LibWeb: Update style before getting animation play state Pending style updates can influence this value --- Libraries/LibWeb/Animations/Animation.cpp | 8 + Libraries/LibWeb/Animations/Animation.h | 1 + Libraries/LibWeb/Animations/Animation.idl | 2 +- .../CSSAnimation-canceling.tentative.txt | 15 ++ .../CSSAnimation-playState.tentative.txt | 10 + .../CSSAnimation-canceling.tentative.html | 196 ++++++++++++++++++ .../CSSAnimation-playState.tentative.html | 55 +++++ 7 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-playState.tentative.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-playState.tentative.html diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp index 75caac5b52e..936fef9811e 100644 --- a/Libraries/LibWeb/Animations/Animation.cpp +++ b/Libraries/LibWeb/Animations/Animation.cpp @@ -277,6 +277,14 @@ WebIDL::ExceptionOr Animation::set_playback_rate(double new_playback_rate) } // https://www.w3.org/TR/web-animations-1/#animation-play-state +Bindings::AnimationPlayState Animation::play_state_for_bindings() const +{ + if (m_owning_element) + m_owning_element->document().update_style(); + + return play_state(); +} + Bindings::AnimationPlayState Animation::play_state() const { // The play state of animation, animation, at a given moment is the state corresponding to the first matching diff --git a/Libraries/LibWeb/Animations/Animation.h b/Libraries/LibWeb/Animations/Animation.h index 277e888bfc5..d22829cba53 100644 --- a/Libraries/LibWeb/Animations/Animation.h +++ b/Libraries/LibWeb/Animations/Animation.h @@ -48,6 +48,7 @@ public: double playback_rate() const { return m_playback_rate; } WebIDL::ExceptionOr set_playback_rate(double value); + Bindings::AnimationPlayState play_state_for_bindings() const; Bindings::AnimationPlayState play_state() const; bool is_relevant() const; diff --git a/Libraries/LibWeb/Animations/Animation.idl b/Libraries/LibWeb/Animations/Animation.idl index fc1579f636c..2b5f4eecac1 100644 --- a/Libraries/LibWeb/Animations/Animation.idl +++ b/Libraries/LibWeb/Animations/Animation.idl @@ -14,7 +14,7 @@ interface Animation : EventTarget { attribute double? startTime; attribute double? currentTime; attribute double playbackRate; - readonly attribute AnimationPlayState playState; + [ImplementedAs=play_state_for_bindings] readonly attribute AnimationPlayState playState; readonly attribute AnimationReplaceState replaceState; readonly attribute boolean pending; readonly attribute Promise ready; diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.txt new file mode 100644 index 00000000000..941701a0c8b --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.txt @@ -0,0 +1,15 @@ +Harness status: OK + +Found 9 tests + +4 Pass +5 Fail +Fail Animated style is cleared after canceling a running CSS animation +Fail Animated style is cleared after canceling a filling CSS animation +Pass After canceling an animation, it can still be seeked +Fail After canceling an animation, it can still be re-used +Fail After canceling an animation, updating animation properties doesn't make it live again +Fail After canceling an animation, updating animation-play-state doesn't make it live again +Pass Setting animation-name to 'none' cancels the animation +Pass Setting display:none on an element cancel its animations +Pass Setting display:none on an ancestor element cancels animations on descendants \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-playState.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-playState.tentative.txt new file mode 100644 index 00000000000..c061881f71f --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/CSSAnimation-playState.tentative.txt @@ -0,0 +1,10 @@ +Harness status: OK + +Found 5 tests + +5 Pass +Pass A new CSS animation is initially play-pending +Pass Animation returns correct playState when paused +Pass Animation.playState updates when paused by script +Pass Animation.playState updates when resumed by setting style +Pass Animation returns correct playState when canceled \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.html b/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.html new file mode 100644 index 00000000000..5db420696d6 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-canceling.tentative.html @@ -0,0 +1,196 @@ + + +Canceling a CSS animation + + + + + + +
+ diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-playState.tentative.html b/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-playState.tentative.html new file mode 100644 index 00000000000..9033712b9c7 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-animations/CSSAnimation-playState.tentative.html @@ -0,0 +1,55 @@ + + +CSSAnimation.playState + + + + + + +
+