From 5b84bd6e4543748e505771b89a5ffa242b9563a2 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sun, 2 Jun 2024 07:26:36 -0700 Subject: [PATCH] LibWeb: Add DocumentOrShadowRoot::get_animations() --- Userland/Libraries/LibWeb/DOM/Document.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ Userland/Libraries/LibWeb/DOM/DocumentOrShadowRoot.idl | 3 +++ Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/DOM/ShadowRoot.h | 2 ++ 5 files changed, 27 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 3a1616ce749..47e60c54529 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -4406,6 +4406,16 @@ void Document::ensure_animation_timer() m_animation_driver_timer->start(); } +Vector> Document::get_animations() +{ + Vector> relevant_animations; + for_each_child_of_type([&](auto& child) { + relevant_animations.extend(child.get_animations({ .subtree = true })); + return IterationDecision::Continue; + }); + return relevant_animations; +} + // https://html.spec.whatwg.org/multipage/dom.html#dom-document-nameditem-filter static bool is_potentially_named_element(DOM::Element const& element) { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index f049f717df6..17e6cf7c49a 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -612,6 +612,8 @@ public: void remove_replaced_animations(); void ensure_animation_timer(); + Vector> get_animations(); + bool ready_to_run_scripts() const { return m_ready_to_run_scripts; } void set_ready_to_run_scripts() { m_ready_to_run_scripts = true; } diff --git a/Userland/Libraries/LibWeb/DOM/DocumentOrShadowRoot.idl b/Userland/Libraries/LibWeb/DOM/DocumentOrShadowRoot.idl index aa08921b0c2..63e8ca0efe8 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentOrShadowRoot.idl +++ b/Userland/Libraries/LibWeb/DOM/DocumentOrShadowRoot.idl @@ -5,4 +5,7 @@ interface mixin DocumentOrShadowRoot { // https://w3c.github.io/csswg-drafts/cssom/#extensions-to-the-document-or-shadow-root-interface [SameObject, ImplementedAs=style_sheets_for_bindings] readonly attribute StyleSheetList styleSheets; attribute any adoptedStyleSheets; + + // https://www.w3.org/TR/web-animations-1/#extensions-to-the-documentorshadowroot-interface-mixin + sequence getAnimations(); }; diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp index f9846aaf510..8fb538280cc 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -130,4 +130,14 @@ void ShadowRoot::for_each_css_style_sheet(Function&& } } +Vector> ShadowRoot::get_animations() +{ + Vector> relevant_animations; + for_each_child_of_type([&](auto& child) { + relevant_animations.extend(child.get_animations({ .subtree = true })); + return IterationDecision::Continue; + }); + return relevant_animations; +} + } diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index 62e70254a5c..b436805db85 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -47,6 +47,8 @@ public: void for_each_css_style_sheet(Function&& callback) const; + Vector> get_animations(); + virtual void finalize() override; protected: