From 2358f64d00609802c7613f813fa33d91c56e52a3 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 4 Nov 2023 11:24:21 -0700 Subject: [PATCH] LibWeb: Implement Animation::set_effect() --- .../Libraries/LibWeb/Animations/Animation.cpp | 34 +++++++++++++++++-- .../LibWeb/Animations/AnimationEffect.h | 6 ++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Animations/Animation.cpp b/Userland/Libraries/LibWeb/Animations/Animation.cpp index 789c552330..fbd423ff7e 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animation.cpp @@ -44,8 +44,38 @@ WebIDL::ExceptionOr> Animation::construct_impl(JS::R // https://www.w3.org/TR/web-animations-1/#animation-set-the-associated-effect-of-an-animation void Animation::set_effect(JS::GCPtr new_effect) { - // FIXME: Implement - (void)new_effect; + // Setting this attribute updates the object’s associated effect using the procedure to set the associated effect of + // an animation. + + // 1. Let old effect be the current associated effect of animation, if any. + auto old_effect = m_effect; + + // 2. If new effect is the same object as old effect, abort this procedure. + if (new_effect == old_effect) + return; + + // FIXME: 3. If animation has a pending pause task, reschedule that task to run as soon as animation is ready. + + // FIXME: 4. If animation has a pending play task, reschedule that task to run as soon as animation is ready to play + // new effect. + + // 5. If new effect is not null and if new effect is the associated effect of another animation, previous animation, + // run the procedure to set the associated effect of an animation (this procedure) on previous animation passing + // null as new effect. + if (new_effect && new_effect->associated_animation() != this) { + if (auto animation = new_effect->associated_animation()) + animation->set_effect({}); + } + + // 6. Let the associated effect of animation be new effect. + if (new_effect) + new_effect->set_associated_animation(this); + if (m_effect) + m_effect->set_associated_animation({}); + m_effect = new_effect; + + // FIXME: 7. Run the procedure to update an animation’s finished state for animation with the did seek flag set to + // false, and the synchronously notify flag set to false. } // https://www.w3.org/TR/web-animations-1/#animation-set-the-timeline-of-an-animation diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h index 3634613835..769246d41e 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h @@ -84,6 +84,9 @@ public: String const& easing_function() const { return m_easing_function; } void set_easing_function(String easing_function) { m_easing_function = move(easing_function); } + JS::GCPtr associated_animation() const { return m_associated_animation; } + void set_associated_animation(JS::GCPtr value) { m_associated_animation = value; } + protected: AnimationEffect(JS::Realm&); @@ -112,6 +115,9 @@ protected: // https://www.w3.org/TR/css-easing-1/#easing-function String m_easing_function { "linear"_string }; + + // https://www.w3.org/TR/web-animations-1/#animation-associated-effect + JS::GCPtr m_associated_animation {}; }; }