LibWeb: Add Animation::is_replaceable()

This commit is contained in:
Matthew Olsson 2024-02-03 17:00:59 -07:00 committed by Andreas Kling
parent 4e6c74dcf6
commit 2ade834655
Notes: sideshowbarker 2024-07-17 06:09:44 +09:00
4 changed files with 49 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <LibWeb/Animations/AnimationPlaybackEvent.h>
#include <LibWeb/Animations/DocumentTimeline.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSAnimation.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/Window.h>
@ -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<CSS::CSSAnimation const*>(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<void> Animation::play()
{

View File

@ -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

View File

@ -264,6 +264,14 @@ Optional<double> 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
{

View File

@ -104,6 +104,7 @@ public:
double active_duration() const;
Optional<double> active_time() const;
Optional<double> active_time_using_fill(Bindings::FillMode) const;
bool is_in_effect() const;
double before_active_boundary_time() const;
double after_active_boundary_time() const;