LibWeb: Apply all animations and transitions before invalidating style

This fixes an issue where only the last KeyframeEffect applied to an
element would actually have an effect on the computed properties.

It was particularly noticeable when animating a shorthand property like
border-width, since only one of the border edges would have its width
actually animate.

By deferring the invalidation until all animations have been processed,
we also reduce the amount of work that gets done on pages with many
animations/transitions per element. Discord is very fond of this for
example.
This commit is contained in:
Andreas Kling 2025-07-18 11:56:00 +02:00 committed by Alexander Kalenik
parent 50422eb563
commit 92221f0c57
Notes: github-actions[bot] 2025-07-19 15:10:06 +00:00
11 changed files with 198 additions and 152 deletions

View file

@ -9,6 +9,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Bitmap.h>
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/GenericLexer.h>
@ -1537,15 +1538,18 @@ void Document::update_animated_style_if_needed()
if (!m_needs_animated_style_update)
return;
Animations::AnimationUpdateContext context;
for (auto& timeline : m_associated_animation_timelines) {
for (auto& animation : timeline->associated_animations()) {
if (animation->is_idle() || animation->is_finished())
continue;
if (auto effect = animation->effect()) {
effect->update_computed_properties();
effect->update_computed_properties(context);
}
}
}
m_needs_animated_style_update = false;
}