LibWeb: Keep track of associated Animations in AnimationTimeline

This allows the timeline to propagate changes in time to any relevant
animation objects.
This commit is contained in:
Matthew Olsson 2023-11-04 11:58:09 -07:00 committed by Andreas Kling
parent 0d3c8a1cd9
commit 4efbb10a36
Notes: sideshowbarker 2024-07-17 02:05:41 +09:00
2 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Animations/Animation.h>
#include <LibWeb/Animations/AnimationTimeline.h>
#include <LibWeb/DOM/Document.h>
@ -21,6 +22,9 @@ WebIDL::ExceptionOr<void> AnimationTimeline::set_current_time(Optional<double> 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);
}
}

View File

@ -28,6 +28,10 @@ public:
virtual Optional<double> convert_a_timeline_time_to_an_original_relative_time(Optional<double>) { VERIFY_NOT_REACHED(); }
virtual bool can_convert_a_timeline_time_to_an_original_relative_time() const { return false; }
void associate_with_animation(JS::NonnullGCPtr<Animation> value) { m_associated_animations.set(value); }
void disassociate_with_animation(JS::NonnullGCPtr<Animation> value) { m_associated_animations.remove(value); }
HashTable<JS::NonnullGCPtr<Animation>> 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<DOM::Document> m_associated_document {};
HashTable<JS::NonnullGCPtr<Animation>> m_associated_animations {};
};
}