1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibWeb: Define the composite order between two animations

This commit is contained in:
Matthew Olsson 2024-02-19 13:54:30 +00:00 committed by Andreas Kling
parent ceb9d0f8dc
commit 4e6c74dcf6
2 changed files with 33 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <AK/QuickSort.h>
#include <LibJS/Runtime/Iterator.h>
#include <LibWeb/Animations/Animation.h>
#include <LibWeb/Animations/KeyframeEffect.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -582,6 +583,36 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr<KeyFrameSet> keyfr
}
}
// https://www.w3.org/TR/web-animations-1/#animation-composite-order
int KeyframeEffect::composite_order(JS::NonnullGCPtr<KeyframeEffect> a, JS::NonnullGCPtr<KeyframeEffect> 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 Bs 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 Bs 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> KeyframeEffect::create(JS::Realm& realm)
{
return realm.heap().allocate<KeyframeEffect>(realm, realm);

View file

@ -69,6 +69,8 @@ public:
};
static void generate_initial_and_final_frames(RefPtr<KeyFrameSet>, HashTable<CSS::PropertyID> const& animated_properties);
static int composite_order(JS::NonnullGCPtr<KeyframeEffect>, JS::NonnullGCPtr<KeyframeEffect>);
static JS::NonnullGCPtr<KeyframeEffect> create(JS::Realm&);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyframeEffect>> construct_impl(