From 4e6c74dcf6e97028dda49ac017c7835b9a9e6991 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Mon, 19 Feb 2024 13:54:30 +0000 Subject: [PATCH] LibWeb: Define the composite order between two animations --- .../LibWeb/Animations/KeyframeEffect.cpp | 31 +++++++++++++++++++ .../LibWeb/Animations/KeyframeEffect.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 9639cf8f1f..68440ee629 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -582,6 +583,36 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr keyfr } } +// https://www.w3.org/TR/web-animations-1/#animation-composite-order +int KeyframeEffect::composite_order(JS::NonnullGCPtr a, JS::NonnullGCPtr b) +{ + // 1. Let the associated animation of an animation effect be the animation associated with the animation effect. + auto a_animation = a->associated_animation(); + auto b_animation = b->associated_animation(); + + // 2. Sort A and B by applying the following conditions in turn until the order is resolved, + + // 1. If A and B’s associated animations differ by class, sort by any inter-class composite order defined for + // the corresponding classes. + auto a_class = a_animation->animation_class(); + auto b_class = b_animation->animation_class(); + + // From https://www.w3.org/TR/css-animations-2/#animation-composite-order: + // "CSS Animations with an owning element have a later composite order than CSS Transitions but an earlier + // composite order than animations without a specific animation class." + if (a_class != b_class) + return to_underlying(a_class) - to_underlying(b_class); + + // 2. If A and B are still not sorted, sort by any class-specific composite order defined by the common class of + // A and B’s associated animations. + if (auto order = a_animation->class_specific_composite_order(*b_animation); order.has_value()) + return order.value(); + + // 3. If A and B are still not sorted, sort by the position of their associated animations in the global + // animation list. + return a_animation->global_animation_list_order() - b_animation->global_animation_list_order(); +} + JS::NonnullGCPtr KeyframeEffect::create(JS::Realm& realm) { return realm.heap().allocate(realm, realm); diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.h b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.h index 038a9194dd..1c35c1f6e9 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.h +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.h @@ -69,6 +69,8 @@ public: }; static void generate_initial_and_final_frames(RefPtr, HashTable const& animated_properties); + static int composite_order(JS::NonnullGCPtr, JS::NonnullGCPtr); + static JS::NonnullGCPtr create(JS::Realm&); static WebIDL::ExceptionOr> construct_impl(