mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Implement Animation.reverse()
This commit is contained in:
parent
9ab73f2675
commit
2dd5d0c310
3 changed files with 31 additions and 1 deletions
|
@ -765,6 +765,35 @@ WebIDL::ExceptionOr<void> Animation::update_playback_rate(double new_playback_ra
|
||||||
return {};
|
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 animation’s pending playback rate.
|
||||||
|
auto original_pending_playback_rate = m_pending_playback_rate;
|
||||||
|
|
||||||
|
// 3. Let animation’s 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 animation’s 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
|
// https://www.w3.org/TR/web-animations-1/#dom-animation-persist
|
||||||
void Animation::persist()
|
void Animation::persist()
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,6 +76,7 @@ public:
|
||||||
WebIDL::ExceptionOr<void> play_an_animation(AutoRewind);
|
WebIDL::ExceptionOr<void> play_an_animation(AutoRewind);
|
||||||
WebIDL::ExceptionOr<void> pause();
|
WebIDL::ExceptionOr<void> pause();
|
||||||
WebIDL::ExceptionOr<void> update_playback_rate(double);
|
WebIDL::ExceptionOr<void> update_playback_rate(double);
|
||||||
|
WebIDL::ExceptionOr<void> reverse();
|
||||||
void persist();
|
void persist();
|
||||||
|
|
||||||
Optional<double> convert_an_animation_time_to_timeline_time(Optional<double>) const;
|
Optional<double> convert_an_animation_time_to_timeline_time(Optional<double>) const;
|
||||||
|
|
|
@ -29,7 +29,7 @@ interface Animation : EventTarget {
|
||||||
undefined play();
|
undefined play();
|
||||||
undefined pause();
|
undefined pause();
|
||||||
undefined updatePlaybackRate(double playbackRate);
|
undefined updatePlaybackRate(double playbackRate);
|
||||||
// FIXME: undefined reverse();
|
undefined reverse();
|
||||||
undefined persist();
|
undefined persist();
|
||||||
// FIXME: [CEReactions] undefined commitStyles();
|
// FIXME: [CEReactions] undefined commitStyles();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue