1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

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
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()
{