mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibWeb: Add a few Animation/AnimationEffect getters
This commit is contained in:
parent
06a8674eec
commit
145ae54718
Notes:
sideshowbarker
2024-07-17 03:45:48 +09:00
Author: https://github.com/mattco98
Commit: 145ae54718
Pull-request: https://github.com/SerenityOS/serenity/pull/23257
5 changed files with 55 additions and 1 deletions
|
@ -298,6 +298,15 @@ Bindings::AnimationPlayState Animation::play_state() const
|
|||
return Bindings::AnimationPlayState::Running;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#animation-relevant
|
||||
bool Animation::is_relevant() const
|
||||
{
|
||||
// An animation is relevant if:
|
||||
// - Its associated effect is current or in effect, and
|
||||
// - Its replace state is not removed.
|
||||
return (m_effect->is_current() || m_effect->is_in_effect()) && replace_state() != Bindings::AnimationReplaceState::Removed;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#replaceable-animation
|
||||
bool Animation::is_replaceable() const
|
||||
{
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
|
||||
Bindings::AnimationPlayState play_state() const;
|
||||
|
||||
bool is_relevant() const;
|
||||
|
||||
bool is_replaceable() const;
|
||||
Bindings::AnimationReplaceState replace_state() const { return m_replace_state; }
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Animations/Animation.h>
|
||||
#include <LibWeb/Animations/AnimationEffect.h>
|
||||
#include <LibWeb/Animations/AnimationTimeline.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
@ -264,6 +265,46 @@ Optional<double> AnimationEffect::active_time_using_fill(Bindings::FillMode fill
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#in-play
|
||||
bool AnimationEffect::is_in_play() const
|
||||
{
|
||||
// An animation effect is in play if all of the following conditions are met:
|
||||
// - the animation effect is in the active phase, and
|
||||
// - the animation effect is associated with an animation that is not finished.
|
||||
return is_in_the_active_phase() && m_associated_animation && !m_associated_animation->is_finished();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#current
|
||||
bool AnimationEffect::is_current() const
|
||||
{
|
||||
// An animation effect is current if any of the following conditions are true:
|
||||
|
||||
// - the animation effect is in play, or
|
||||
if (is_in_play())
|
||||
return true;
|
||||
|
||||
if (auto animation = m_associated_animation) {
|
||||
auto playback_rate = animation->playback_rate();
|
||||
|
||||
// - the animation effect is associated with an animation with a playback rate > 0 and the animation effect is
|
||||
// in the before phase, or
|
||||
if (playback_rate > 0.0 && is_in_the_before_phase())
|
||||
return true;
|
||||
|
||||
// - the animation effect is associated with an animation with a playback rate < 0 and the animation effect is
|
||||
// in the after phase, or
|
||||
if (playback_rate < 0.0 && is_in_the_after_phase())
|
||||
return true;
|
||||
|
||||
// - the animation effect is associated with an animation not in the idle play state with a non-null associated
|
||||
// timeline that is not monotonically increasing.
|
||||
if (animation->play_state() != Bindings::AnimationPlayState::Idle && animation->timeline() && !animation->timeline()->is_monotonically_increasing())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#in-effect
|
||||
bool AnimationEffect::is_in_effect() const
|
||||
{
|
||||
|
|
|
@ -104,6 +104,9 @@ public:
|
|||
double active_duration() const;
|
||||
Optional<double> active_time() const;
|
||||
Optional<double> active_time_using_fill(Bindings::FillMode) const;
|
||||
|
||||
bool is_in_play() const;
|
||||
bool is_current() const;
|
||||
bool is_in_effect() const;
|
||||
|
||||
double before_active_boundary_time() const;
|
||||
|
|
|
@ -23,7 +23,6 @@ void AnimationTimeline::set_current_time(Optional<double> value)
|
|||
}
|
||||
|
||||
m_current_time = value;
|
||||
|
||||
for (auto& animation : m_associated_animations)
|
||||
animation->notify_timeline_time_did_change();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue