From 4efbb10a36a53d8678236ad3b47d05365f97ccda Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 4 Nov 2023 11:58:09 -0700 Subject: [PATCH] LibWeb: Keep track of associated Animations in AnimationTimeline This allows the timeline to propagate changes in time to any relevant animation objects. --- Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp | 6 ++++++ Userland/Libraries/LibWeb/Animations/AnimationTimeline.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp index 1b7096307bd..d794f07807b 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -21,6 +22,9 @@ WebIDL::ExceptionOr AnimationTimeline::set_current_time(Optional v m_current_time = value; + for (auto& animation : m_associated_animations) + TRY(animation->set_current_time(value)); + return {}; } @@ -61,6 +65,8 @@ void AnimationTimeline::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_associated_document); + for (auto const& animation : m_associated_animations) + visitor.visit(animation); } } diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h index 8f8c0c9eb09..48a34a15c3f 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h @@ -28,6 +28,10 @@ public: virtual Optional convert_a_timeline_time_to_an_original_relative_time(Optional) { VERIFY_NOT_REACHED(); } virtual bool can_convert_a_timeline_time_to_an_original_relative_time() const { return false; } + void associate_with_animation(JS::NonnullGCPtr value) { m_associated_animations.set(value); } + void disassociate_with_animation(JS::NonnullGCPtr value) { m_associated_animations.remove(value); } + HashTable> const& associated_animations() const; + protected: AnimationTimeline(JS::Realm&); virtual ~AnimationTimeline() override; @@ -43,6 +47,8 @@ protected: // https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document JS::GCPtr m_associated_document {}; + + HashTable> m_associated_animations {}; }; }