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.
This commit is contained in:
Matthew Olsson 2023-11-04 08:43:10 -07:00 committed by Andreas Kling
parent 2fbb9649e3
commit 13ae2a4dab
Notes: sideshowbarker 2024-07-17 07:16:27 +09:00
5 changed files with 31 additions and 0 deletions

View file

@ -26,6 +26,10 @@ WebIDL::ExceptionOr<void> AnimationTimeline::set_current_time(Optional<double> v
void AnimationTimeline::set_associated_document(JS::GCPtr<DOM::Document> 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);

View file

@ -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;

View file

@ -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;

View file

@ -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<Animations::DocumentTimeline> Document::timeline()
return *m_default_timeline;
}
void Document::associate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline> timeline)
{
m_associated_animation_timelines.set(timeline);
}
void Document::disassociate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline> timeline)
{
m_associated_animation_timelines.remove(timeline);
}
}

View file

@ -536,6 +536,9 @@ public:
JS::NonnullGCPtr<Animations::DocumentTimeline> timeline();
void associate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline>);
void disassociate_with_timeline(JS::NonnullGCPtr<Animations::AnimationTimeline>);
protected:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
@ -743,6 +746,9 @@ private:
HashMap<AK::URL, HTML::SharedImageRequest*> m_shared_image_requests;
// https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document
HashTable<JS::NonnullGCPtr<Animations::AnimationTimeline>> m_associated_animation_timelines;
// https://www.w3.org/TR/web-animations-1/#document-default-document-timeline
JS::GCPtr<Animations::DocumentTimeline> m_default_timeline;
};