Truly independent web browser
LibWeb: Update animations' finished state upon style duration changes
Zaggy1024eeac27d9264c
diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cppindex 0e94edca694..ea76721152a 100644--- a/Libraries/LibWeb/Animations/Animation.cpp+++ b/Libraries/LibWeb/Animations/Animation.cpp@@ -1429,6 +1429,11 @@ void Animation::effect_timing_changed(Badge<AnimationEffect>)update_finished_state(DidSeek::No, SynchronouslyNotify::Yes);}+void Animation::effect_timing_changed_by_style()+{+ update_finished_state(DidSeek::No, SynchronouslyNotify::No);+}+// https://www.w3.org/TR/web-animations-1/#associated-effect-endTimeValue Animation::associated_effect_end() const{diff --git a/Libraries/LibWeb/Animations/Animation.h b/Libraries/LibWeb/Animations/Animation.hindex cb317003f4f..c8cc1dddc2b 100644--- a/Libraries/LibWeb/Animations/Animation.h+++ b/Libraries/LibWeb/Animations/Animation.h@@ -193,6 +193,8 @@ protected:void set_provisional_effect(GC::Ref<AnimationEffect>);void discard_provisional_effect();+ void effect_timing_changed_by_style();+virtual void visit_edges(Cell::Visitor&) override;virtual void finalize() override;diff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cppindex 7ee3a138a07..09d4e2ae531 100644--- a/Libraries/LibWeb/CSS/CSSAnimation.cpp+++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp@@ -268,6 +268,10 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_proeffect.set_fill_mode(Animations::css_fill_mode_to_bindings_fill_mode(animation_properties.fill_mode));effect.set_playback_direction(Animations::css_animation_direction_to_bindings_playback_direction(animation_properties.direction));effect.set_composite(Animations::css_animation_composition_to_composite_operation(animation_properties.composition));+ {+ HTML::TemporaryExecutionContext context(relevant_settings_object());+ effect_timing_changed_by_style();+ }if (animation_properties.play_state != last_css_animation_play_state()) {if (!m_script_overrode_play_state) {diff --git a/Tests/LibWeb/Text/expected/css/css-animation-duration-change-after-zero-duration-finish.txt b/Tests/LibWeb/Text/expected/css/css-animation-duration-change-after-zero-duration-finish.txtnew file mode 100644index 00000000000..17e2ba732b5--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/css-animation-duration-change-after-zero-duration-finish.txt@@ -0,0 +1,3 @@+animations after the zero-duration animation finished: 0+play state after lengthening the duration: running+current time advances: truediff --git a/Tests/LibWeb/Text/input/css/css-animation-duration-change-after-zero-duration-finish.html b/Tests/LibWeb/Text/input/css/css-animation-duration-change-after-zero-duration-finish.htmlnew file mode 100644index 00000000000..ef078a29c95--- /dev/null+++ b/Tests/LibWeb/Text/input/css/css-animation-duration-change-after-zero-duration-finish.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ @keyframes fade {+ from { opacity: 0; }+ }+ #target {+ animation-name: fade;+ }+</style>+<div id="target"></div>+<script>+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(() => resolve()));++ asyncTest(async done => {+ const target = document.getElementById("target");+ await nextFrame();+ await nextFrame();+ println(`animations after the zero-duration animation finished: ${target.getAnimations().length}`);++ await new Promise(resolve => setTimeout(resolve, 0));++ // Let a rendering update apply the change, rather than a style flush from script.+ target.style.animationDuration = "100s";+ await nextFrame();+ const animation = target.getAnimations()[0];+ println(`play state after lengthening the duration: ${animation?.playState}`);+ const timeBefore = animation?.currentTime;+ await nextFrame();+ await nextFrame();+ println(`current time advances: ${animation?.currentTime > timeBefore}`);+ done();+ });+</script>