1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

LibWeb: Store Animations in Animatable instead of AnimationEffects

This is closer to what the spec instructs us to do, and matches how
associations are maintained in the timelines. Also note that the removed
destructor logic is not necessary since we visit the associated
animations anyways.
This commit is contained in:
Matthew Olsson 2024-03-07 11:11:27 -07:00 committed by Alexander Kalenik
parent f386c01ae1
commit 90290eb985
5 changed files with 22 additions and 26 deletions

View file

@ -63,9 +63,9 @@ Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::
// 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<AnimationEffect>& a, JS::NonnullGCPtr<AnimationEffect>& b) {
auto& a_effect = verify_cast<KeyframeEffect>(*a);
auto& b_effect = verify_cast<KeyframeEffect>(*b);
quick_sort(m_associated_animations, [](JS::NonnullGCPtr<Animation>& a, JS::NonnullGCPtr<Animation>& b) {
auto& a_effect = verify_cast<KeyframeEffect>(*a->effect());
auto& b_effect = verify_cast<KeyframeEffect>(*b->effect());
return KeyframeEffect::composite_order(a_effect, b_effect) < 0;
});
m_is_sorted_by_composite_order = true;
@ -75,29 +75,29 @@ Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::
(void)options;
Vector<JS::NonnullGCPtr<Animation>> relevant_animations;
for (auto& effect : m_associated_effects) {
if (auto animation = effect->associated_animation(); animation && animation->is_relevant())
for (auto const& animation : m_associated_animations) {
if (animation->is_relevant())
relevant_animations.append(*animation);
}
return relevant_animations;
}
void Animatable::associate_with_effect(JS::NonnullGCPtr<AnimationEffect> effect)
void Animatable::associate_with_animation(JS::NonnullGCPtr<Animation> animation)
{
m_associated_effects.append(effect);
m_associated_animations.append(animation);
m_is_sorted_by_composite_order = false;
}
void Animatable::disassociate_with_effect(JS::NonnullGCPtr<AnimationEffect> effect)
void Animatable::disassociate_with_animation(JS::NonnullGCPtr<Animation> animation)
{
m_associated_effects.remove_first_matching([&](auto element) { return effect == element; });
m_associated_animations.remove_first_matching([&](auto element) { return animation == element; });
}
void Animatable::visit_edges(JS::Cell::Visitor& visitor)
{
for (auto const& effect : m_associated_effects)
visitor.visit(effect);
for (auto const& animation : m_associated_animations)
visitor.visit(animation);
visitor.visit(m_cached_animation_name_source);
visitor.visit(m_cached_animation_name_animation);
}