LibWeb: Add DocumentOrShadowRoot::get_animations()

This commit is contained in:
Matthew Olsson 2024-06-02 07:26:36 -07:00 committed by Andreas Kling
parent 37322baf54
commit 5b84bd6e45
Notes: sideshowbarker 2024-07-17 07:48:42 +09:00
5 changed files with 27 additions and 0 deletions

View File

@ -4406,6 +4406,16 @@ void Document::ensure_animation_timer()
m_animation_driver_timer->start();
}
Vector<JS::NonnullGCPtr<Animations::Animation>> Document::get_animations()
{
Vector<JS::NonnullGCPtr<Animations::Animation>> relevant_animations;
for_each_child_of_type<Element>([&](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)
{

View File

@ -612,6 +612,8 @@ public:
void remove_replaced_animations();
void ensure_animation_timer();
Vector<JS::NonnullGCPtr<Animations::Animation>> 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; }

View File

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

View File

@ -130,4 +130,14 @@ void ShadowRoot::for_each_css_style_sheet(Function<void(CSS::CSSStyleSheet&)>&&
}
}
Vector<JS::NonnullGCPtr<Animations::Animation>> ShadowRoot::get_animations()
{
Vector<JS::NonnullGCPtr<Animations::Animation>> relevant_animations;
for_each_child_of_type<Element>([&](auto& child) {
relevant_animations.extend(child.get_animations({ .subtree = true }));
return IterationDecision::Continue;
});
return relevant_animations;
}
}

View File

@ -47,6 +47,8 @@ public:
void for_each_css_style_sheet(Function<void(CSS::CSSStyleSheet&)>&& callback) const;
Vector<JS::NonnullGCPtr<Animations::Animation>> get_animations();
virtual void finalize() override;
protected: