From d6fb1c24f6a514b75ba72f436cdb385efe527f6d Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 4 Nov 2023 11:25:29 -0700 Subject: [PATCH] LibWeb: Implement AnimationEffect::animation_direction() --- .../Libraries/LibWeb/Animations/AnimationEffect.cpp | 11 +++++++++++ .../Libraries/LibWeb/Animations/AnimationEffect.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp index 5d0ac80e4a..ee99d98a93 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -151,6 +152,16 @@ WebIDL::ExceptionOr AnimationEffect::update_timing(OptionalEffectTiming ti return {}; } +// https://www.w3.org/TR/web-animations-1/#animation-direction +AnimationDirection AnimationEffect::animation_direction() const +{ + // "backwards" if the effect is associated with an animation and the associated animation’s playback rate is less + // than zero; in all other cases, the animation direction is "forwards". + if (m_associated_animation && m_associated_animation->playback_rate() < 0.0) + return AnimationDirection::Backwards; + return AnimationDirection::Forwards; +} + AnimationEffect::AnimationEffect(JS::Realm& realm) : Bindings::PlatformObject(realm) { diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h index 769246d41e..46263fffbc 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h @@ -49,6 +49,11 @@ struct ComputedEffectTiming : public EffectTiming { Optional current_iteration; }; +enum class AnimationDirection { + Forwards, + Backwards, +}; + // https://www.w3.org/TR/web-animations-1/#the-animationeffect-interface class AnimationEffect : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(AnimationEffect, Bindings::PlatformObject); @@ -87,6 +92,8 @@ public: JS::GCPtr associated_animation() const { return m_associated_animation; } void set_associated_animation(JS::GCPtr value) { m_associated_animation = value; } + AnimationDirection animation_direction() const; + protected: AnimationEffect(JS::Realm&);