Prechádzať zdrojové kódy

LibWeb: Keep track of associated Animations in AnimationTimeline

This allows the timeline to propagate changes in time to any relevant
animation objects.
Matthew Olsson 1 rok pred
rodič
commit
4efbb10a36

+ 6 - 0
Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp

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

+ 6 - 0
Userland/Libraries/LibWeb/Animations/AnimationTimeline.h

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