1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

LibWeb: Expose Animation::is_finished()

This will be required to handle forward-fill state in StyleComputer
This commit is contained in:
Matthew Olsson 2024-02-03 18:25:04 -07:00 committed by Andreas Kling
parent 5eea53f27a
commit 1e37ba5515
2 changed files with 11 additions and 7 deletions

View file

@ -703,7 +703,7 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync
// 5. If current finished state is true and the current finished promise is not yet resolved, perform the following // 5. If current finished state is true and the current finished promise is not yet resolved, perform the following
// steps: // steps:
if (current_finished_state && !m_current_finished_promise_resolved) { if (current_finished_state && !m_is_finished) {
// 1. Let finish notification steps refer to the following procedure: // 1. Let finish notification steps refer to the following procedure:
JS::SafeFunction<void()> finish_notification_steps = [&]() { JS::SafeFunction<void()> finish_notification_steps = [&]() {
if (m_should_abort_finish_notification_microtask) { if (m_should_abort_finish_notification_microtask) {
@ -717,8 +717,11 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync
return; return;
// 2. Resolve animations current finished promise object with animation. // 2. Resolve animations current finished promise object with animation.
{
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm()) };
WebIDL::resolve_promise(realm(), current_finished_promise(), this); WebIDL::resolve_promise(realm(), current_finished_promise(), this);
m_current_finished_promise_resolved = true; }
m_is_finished = true;
// 3. Create an AnimationPlaybackEvent, finishEvent. // 3. Create an AnimationPlaybackEvent, finishEvent.
// 4. Set finishEvents type attribute to finish. // 4. Set finishEvents type attribute to finish.
@ -726,7 +729,7 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync
auto& realm = this->realm(); auto& realm = this->realm();
AnimationPlaybackEventInit init; AnimationPlaybackEventInit init;
init.current_time = current_time(); init.current_time = current_time();
auto finish_event = heap().allocate<AnimationPlaybackEvent>(realm, realm, "finish"_fly_string, init); auto finish_event = AnimationPlaybackEvent::create(realm, "finish"_fly_string, init);
// 6. Set finishEvents timelineTime attribute to the current time of the timeline with which animation is // 6. Set finishEvents timelineTime attribute to the current time of the timeline with which animation is
// associated. If animation is not associated with a timeline, or the timeline is inactive, let // associated. If animation is not associated with a timeline, or the timeline is inactive, let
@ -775,9 +778,9 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync
// 6. If current finished state is false and animations current finished promise is already resolved, set // 6. If current finished state is false and animations current finished promise is already resolved, set
// animations current finished promise to a new promise in the relevant Realm of animation. // animations current finished promise to a new promise in the relevant Realm of animation.
if (!current_finished_state && m_current_finished_promise_resolved) { if (!current_finished_state && m_is_finished) {
m_current_finished_promise = WebIDL::create_promise(realm()); m_current_finished_promise = WebIDL::create_promise(realm());
m_current_finished_promise_resolved = false; m_is_finished = false;
} }
// Invalidate the style of our target element, if applicable // Invalidate the style of our target element, if applicable

View file

@ -61,6 +61,7 @@ public:
// https://www.w3.org/TR/web-animations-1/#dom-animation-finished // https://www.w3.org/TR/web-animations-1/#dom-animation-finished
JS::NonnullGCPtr<JS::Object> finished() const { return *current_finished_promise()->promise(); } JS::NonnullGCPtr<JS::Object> finished() const { return *current_finished_promise()->promise(); }
bool is_finished() const { return m_is_finished; }
enum class AutoRewind { enum class AutoRewind {
Yes, Yes,
@ -155,7 +156,7 @@ private:
// https://www.w3.org/TR/web-animations-1/#current-finished-promise // https://www.w3.org/TR/web-animations-1/#current-finished-promise
mutable JS::GCPtr<WebIDL::Promise> m_current_finished_promise; mutable JS::GCPtr<WebIDL::Promise> m_current_finished_promise;
bool m_current_finished_promise_resolved { false }; bool m_is_finished { false };
// https://www.w3.org/TR/web-animations-1/#pending-play-task // https://www.w3.org/TR/web-animations-1/#pending-play-task
TaskState m_pending_play_task { TaskState::None }; TaskState m_pending_play_task { TaskState::None };