diff --git a/Userland/Libraries/LibWeb/Animations/Animation.cpp b/Userland/Libraries/LibWeb/Animations/Animation.cpp index 532650005c..9967744060 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animation.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -297,6 +298,44 @@ Bindings::AnimationPlayState Animation::play_state() const return Bindings::AnimationPlayState::Running; } +// https://www.w3.org/TR/web-animations-1/#replaceable-animation +bool Animation::is_replaceable() const +{ + // An animation is replaceable if all of the following conditions are true: + + // - The existence of the animation is not prescribed by markup. That is, it is not a CSS animation with an owning + // element, nor a CSS transition with an owning element. + // FIXME: Check for transitions + if (is_css_animation() && static_cast(this)->owning_element()) + return false; + + // - The animation's play state is finished. + if (play_state() != Bindings::AnimationPlayState::Finished) + return false; + + // - The animation's replace state is not removed. + if (replace_state() == Bindings::AnimationReplaceState::Removed) + return false; + + // - The animation is associated with a monotonically increasing timeline. + if (!m_timeline || !m_timeline->is_monotonically_increasing()) + return false; + + // - The animation has an associated effect. + if (!m_effect) + return false; + + // - The animation's associated effect is in effect. + if (!m_effect->is_in_effect()) + return false; + + // - The animation's associated effect has an effect target. + if (!m_effect->target()) + return false; + + return true; +} + // https://www.w3.org/TR/web-animations-1/#dom-animation-play WebIDL::ExceptionOr Animation::play() { diff --git a/Userland/Libraries/LibWeb/Animations/Animation.h b/Userland/Libraries/LibWeb/Animations/Animation.h index 8acce8e321..3b5b675045 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.h +++ b/Userland/Libraries/LibWeb/Animations/Animation.h @@ -50,6 +50,7 @@ public: Bindings::AnimationPlayState play_state() const; + bool is_replaceable() const; Bindings::AnimationReplaceState replace_state() const { return m_replace_state; } // https://www.w3.org/TR/web-animations-1/#dom-animation-pending diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp index 74f4bdf3f7..e8192630c5 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -264,6 +264,14 @@ Optional AnimationEffect::active_time_using_fill(Bindings::FillMode fill return {}; } +// https://www.w3.org/TR/web-animations-1/#in-effect +bool AnimationEffect::is_in_effect() const +{ + // An animation effect is in effect if its active time, as calculated according to the procedure in + // ยง4.8.3.1 Calculating the active time, is not unresolved. + return active_time().has_value(); +} + // https://www.w3.org/TR/web-animations-1/#before-active-boundary-time double AnimationEffect::before_active_boundary_time() const { diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h index a7abf938a2..d74af2557b 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h @@ -104,6 +104,7 @@ public: double active_duration() const; Optional active_time() const; Optional active_time_using_fill(Bindings::FillMode) const; + bool is_in_effect() const; double before_active_boundary_time() const; double after_active_boundary_time() const;