From 13ae2a4dab18044bcee122bcf2ab4eb4f10eab79 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 4 Nov 2023 08:43:10 -0700 Subject: [PATCH] LibWeb: Store all timelines associated with a document on the document This will be required for propagating the current animation time to all relevant timelines, which each propagate that time to all of their relevant animations. --- .../LibWeb/Animations/AnimationTimeline.cpp | 10 ++++++++++ .../Libraries/LibWeb/Animations/AnimationTimeline.h | 1 + .../Libraries/LibWeb/Animations/DocumentTimeline.h | 1 + Userland/Libraries/LibWeb/DOM/Document.cpp | 13 +++++++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 6 ++++++ 5 files changed, 31 insertions(+) diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp index 3f5b2586b56..1b7096307bd 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp @@ -26,6 +26,10 @@ WebIDL::ExceptionOr AnimationTimeline::set_current_time(Optional v void AnimationTimeline::set_associated_document(JS::GCPtr document) { + if (document) + document->associate_with_timeline(*this); + if (m_associated_document) + m_associated_document->disassociate_with_timeline(*this); m_associated_document = document; } @@ -41,6 +45,12 @@ AnimationTimeline::AnimationTimeline(JS::Realm& realm) { } +AnimationTimeline::~AnimationTimeline() +{ + if (m_associated_document) + m_associated_document->disassociate_with_timeline(*this); +} + void AnimationTimeline::initialize(JS::Realm& realm) { Base::initialize(realm); diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h index 5d7a3d7bc40..8f8c0c9eb09 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h @@ -30,6 +30,7 @@ public: protected: AnimationTimeline(JS::Realm&); + virtual ~AnimationTimeline() override; virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/Animations/DocumentTimeline.h b/Userland/Libraries/LibWeb/Animations/DocumentTimeline.h index 6d24b797438..617ac6efb78 100644 --- a/Userland/Libraries/LibWeb/Animations/DocumentTimeline.h +++ b/Userland/Libraries/LibWeb/Animations/DocumentTimeline.h @@ -33,6 +33,7 @@ public: private: DocumentTimeline(JS::Realm&, DOM::Document&, HighResolutionTime::DOMHighResTimeStamp origin_time); + virtual ~DocumentTimeline() override = default; virtual void initialize(JS::Realm&) override; diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 68d49fe1341..86a092a9753 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -404,6 +404,9 @@ void Document::visit_edges(Cell::Visitor& visitor) for (auto& observer : m_intersection_observers) visitor.visit(observer); + + for (auto& timeline : m_associated_animation_timelines) + visitor.visit(timeline); } // https://w3c.github.io/selection-api/#dom-document-getselection @@ -3572,4 +3575,14 @@ JS::NonnullGCPtr Document::timeline() return *m_default_timeline; } +void Document::associate_with_timeline(JS::NonnullGCPtr timeline) +{ + m_associated_animation_timelines.set(timeline); +} + +void Document::disassociate_with_timeline(JS::NonnullGCPtr timeline) +{ + m_associated_animation_timelines.remove(timeline); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index f04482aa5e6..d0c4603ce2f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -536,6 +536,9 @@ public: JS::NonnullGCPtr timeline(); + void associate_with_timeline(JS::NonnullGCPtr); + void disassociate_with_timeline(JS::NonnullGCPtr); + protected: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; @@ -743,6 +746,9 @@ private: HashMap m_shared_image_requests; + // https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document + HashTable> m_associated_animation_timelines; + // https://www.w3.org/TR/web-animations-1/#document-default-document-timeline JS::GCPtr m_default_timeline; };