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

LibWeb: Implement Animation.reverse()

This commit is contained in:
Matthew Olsson 2024-02-10 16:00:08 -07:00 committed by Andreas Kling
parent 9ab73f2675
commit 2dd5d0c310
3 changed files with 31 additions and 1 deletions

View file

@ -765,6 +765,35 @@ WebIDL::ExceptionOr<void> Animation::update_playback_rate(double new_playback_ra
return {};
}
// https://www.w3.org/TR/web-animations-1/#dom-animation-reverse
WebIDL::ExceptionOr<void> Animation::reverse()
{
auto& realm = this->realm();
// 1. If there is no timeline associated with animation, or the associated timeline is inactive throw an
// "InvalidStateError" DOMException and abort these steps.
if (!m_timeline || m_timeline->is_inactive())
return WebIDL::InvalidStateError::create(realm, "Cannot reverse an animation with an inactive timeline"_fly_string);
// 2. Let original pending playback rate be animations pending playback rate.
auto original_pending_playback_rate = m_pending_playback_rate;
// 3. Let animations pending playback rate be the additive inverse of its effective playback rate (i.e.
// -effective playback rate).
m_pending_playback_rate = -effective_playback_rate();
// 4. Run the steps to play an animation for animation with the auto-rewind flag set to true.
// If the steps to play an animation throw an exception, set animations pending playback rate to original
// pending playback rate and propagate the exception.
auto result = play_an_animation(AutoRewind::Yes);
if (result.is_error()) {
m_pending_playback_rate = original_pending_playback_rate;
return result;
}
return {};
}
// https://www.w3.org/TR/web-animations-1/#dom-animation-persist
void Animation::persist()
{