From 3ea26327c7bd60bde6f1a63a1dcd7448c702028e Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 3 Feb 2024 12:17:29 -0700 Subject: [PATCH] LibWeb: Implement Animatable::get_animations() --- .../LibWeb/Animations/Animatable.cpp | 27 +++++++++++++++++-- .../Libraries/LibWeb/Animations/Animatable.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.cpp b/Userland/Libraries/LibWeb/Animations/Animatable.cpp index f3df72e156..4b817c51de 100644 --- a/Userland/Libraries/LibWeb/Animations/Animatable.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animatable.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -56,14 +57,36 @@ WebIDL::ExceptionOr> Animatable::animate(Optional> Animatable::get_animations(Web::Animations::GetAnimationsOptions options) { - // FIXME: Implement this + // Returns the set of relevant animations for this object, or, if an options parameter is passed with subtree set to + // true, returns the set of relevant animations for a subtree for this object. + + // The returned list is sorted using the composite order described for the associated animations of effects in + // ยง5.4.2 The effect stack. + if (!m_is_sorted_by_composite_order) { + quick_sort(m_associated_effects, [](JS::NonnullGCPtr& a, JS::NonnullGCPtr& b) { + auto& a_effect = verify_cast(*a); + auto& b_effect = verify_cast(*b); + return KeyframeEffect::composite_order(a_effect, b_effect) < 0; + }); + m_is_sorted_by_composite_order = true; + } + + // FIXME: Support subtree (void)options; - return {}; + + Vector> relevant_animations; + for (auto& effect : m_associated_effects) { + if (auto animation = effect->associated_animation(); animation && animation->is_relevant()) + relevant_animations.append(*animation); + } + + return relevant_animations; } void Animatable::associate_with_effect(JS::NonnullGCPtr effect) { m_associated_effects.append(effect); + m_is_sorted_by_composite_order = false; } void Animatable::disassociate_with_effect(JS::NonnullGCPtr effect) diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.h b/Userland/Libraries/LibWeb/Animations/Animatable.h index cb335e5bce..6b5d5c79a8 100644 --- a/Userland/Libraries/LibWeb/Animations/Animatable.h +++ b/Userland/Libraries/LibWeb/Animations/Animatable.h @@ -35,6 +35,7 @@ public: private: Vector> m_associated_effects; + bool m_is_sorted_by_composite_order { true }; }; }