mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibWeb: Implement Animation::set_current_time
This commit is contained in:
parent
f898b49c8e
commit
749462f3df
2 changed files with 75 additions and 2 deletions
|
@ -189,8 +189,31 @@ Optional<double> Animation::current_time() const
|
||||||
// https://www.w3.org/TR/web-animations-1/#animation-set-the-current-time
|
// https://www.w3.org/TR/web-animations-1/#animation-set-the-current-time
|
||||||
WebIDL::ExceptionOr<void> Animation::set_current_time(Optional<double> const& seek_time)
|
WebIDL::ExceptionOr<void> Animation::set_current_time(Optional<double> const& seek_time)
|
||||||
{
|
{
|
||||||
// FIXME: Implement
|
// 1. Run the steps to silently set the current time of animation to seek time.
|
||||||
(void)seek_time;
|
TRY(silently_set_current_time(seek_time));
|
||||||
|
|
||||||
|
// 2. If animation has a pending pause task, synchronously complete the pause operation by performing the following
|
||||||
|
// steps:
|
||||||
|
if (m_pending_pause_task == TaskState::Pending) {
|
||||||
|
// 1. Set animation’s hold time to seek time.
|
||||||
|
m_hold_time = seek_time;
|
||||||
|
|
||||||
|
// 2. Apply any pending playback rate to animation.
|
||||||
|
apply_any_pending_playback_rate();
|
||||||
|
|
||||||
|
// 3. Make animation’s start time unresolved.
|
||||||
|
m_start_time = {};
|
||||||
|
|
||||||
|
// 4. Cancel the pending pause task.
|
||||||
|
m_pending_pause_task = TaskState::None;
|
||||||
|
|
||||||
|
// 5 Resolve animation’s current ready promise with animation.
|
||||||
|
WebIDL::resolve_promise(realm(), current_ready_promise(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: 3. Run the procedure to update an animation’s finished state for animation with the did seek flag set to
|
||||||
|
// true, and the synchronously notify flag set to false.
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +247,52 @@ void Animation::apply_any_pending_playback_rate()
|
||||||
m_pending_playback_rate = {};
|
m_pending_playback_rate = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/web-animations-1/#animation-silently-set-the-current-time
|
||||||
|
WebIDL::ExceptionOr<void> Animation::silently_set_current_time(Optional<double> seek_time)
|
||||||
|
{
|
||||||
|
// 1. If seek time is an unresolved time value, then perform the following steps.
|
||||||
|
if (!seek_time.has_value()) {
|
||||||
|
// 1. If the current time is resolved, then throw a TypeError.
|
||||||
|
if (current_time().has_value()) {
|
||||||
|
return WebIDL::SimpleException {
|
||||||
|
WebIDL::SimpleExceptionType::TypeError,
|
||||||
|
"Cannot change an animation's current time from a resolve value to an unresolved value"sv
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Abort these steps.
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Update either animation’s hold time or start time as follows:
|
||||||
|
|
||||||
|
// -> If any of the following conditions are true:
|
||||||
|
// - animation’s hold time is resolved, or
|
||||||
|
// - animation’s start time is unresolved, or
|
||||||
|
// - animation has no associated timeline or the associated timeline is inactive, or
|
||||||
|
// - animation’s playback rate is 0,
|
||||||
|
if (m_hold_time.has_value() || !m_start_time.has_value() || !m_timeline || m_timeline->is_inactive() || m_playback_rate == 0.0) {
|
||||||
|
// Set animation’s hold time to seek time.
|
||||||
|
m_hold_time = seek_time;
|
||||||
|
}
|
||||||
|
// -> Otherwise,
|
||||||
|
else {
|
||||||
|
// Set animation’s start time to the result of evaluating timeline time - (seek time / playback rate) where
|
||||||
|
// timeline time is the current time value of timeline associated with animation.
|
||||||
|
m_start_time = m_timeline->current_time().value() - (seek_time.value() / m_playback_rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. If animation has no associated timeline or the associated timeline is inactive, make animation’s start time
|
||||||
|
// unresolved.
|
||||||
|
if (!m_timeline || m_timeline->is_inactive())
|
||||||
|
m_start_time = {};
|
||||||
|
|
||||||
|
// 4. Make animation’s previous current time unresolved.
|
||||||
|
m_previous_current_time = {};
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
JS::NonnullGCPtr<WebIDL::Promise> Animation::current_ready_promise() const
|
JS::NonnullGCPtr<WebIDL::Promise> Animation::current_ready_promise() const
|
||||||
{
|
{
|
||||||
if (!m_current_ready_promise) {
|
if (!m_current_ready_promise) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void apply_any_pending_playback_rate();
|
void apply_any_pending_playback_rate();
|
||||||
|
WebIDL::ExceptionOr<void> silently_set_current_time(Optional<double>);
|
||||||
|
|
||||||
JS::NonnullGCPtr<WebIDL::Promise> current_ready_promise() const;
|
JS::NonnullGCPtr<WebIDL::Promise> current_ready_promise() const;
|
||||||
JS::NonnullGCPtr<WebIDL::Promise> current_finished_promise() const;
|
JS::NonnullGCPtr<WebIDL::Promise> current_finished_promise() const;
|
||||||
|
@ -81,6 +82,9 @@ private:
|
||||||
// https://www.w3.org/TR/web-animations-1/#animation-hold-time
|
// https://www.w3.org/TR/web-animations-1/#animation-hold-time
|
||||||
Optional<double> m_hold_time {};
|
Optional<double> m_hold_time {};
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/web-animations-1/#previous-current-time
|
||||||
|
Optional<double> m_previous_current_time {};
|
||||||
|
|
||||||
// https://www.w3.org/TR/web-animations-1/#playback-rate
|
// https://www.w3.org/TR/web-animations-1/#playback-rate
|
||||||
double m_playback_rate { 1.0 };
|
double m_playback_rate { 1.0 };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue