LibWeb: Change update_style() to update animated style only if needed

Instead of invalidating animated style properties whenever
`Document::update_style()` is called, now we only do that when
animations might have actually progressed. We still have to ensure
animated properties are up-to-date in `update_style()` to ensure that
JS methods can access updated style properties.
This commit is contained in:
Aliaksandr Kalenik 2024-03-21 10:59:55 +01:00 committed by Andreas Kling
parent 3c8d4c9876
commit b7d28ee57d
2 changed files with 25 additions and 11 deletions

View file

@ -1151,17 +1151,7 @@ void Document::update_style()
if (!browsing_context())
return;
for (auto& timeline : m_associated_animation_timelines) {
for (auto& animation : timeline->associated_animations()) {
if (auto effect = animation->effect(); effect && effect->target())
effect->target()->reset_animated_css_properties();
}
for (auto& animation : timeline->associated_animations()) {
if (auto effect = animation->effect())
effect->update_style_properties();
}
}
update_animated_style_if_needed();
if (!needs_full_style_update() && !needs_style_update() && !child_needs_style_update())
return;
@ -1187,6 +1177,25 @@ void Document::update_style()
m_needs_full_style_update = false;
}
void Document::update_animated_style_if_needed()
{
if (!m_needs_animated_style_update)
return;
for (auto& timeline : m_associated_animation_timelines) {
for (auto& animation : timeline->associated_animations()) {
if (auto effect = animation->effect(); effect && effect->target())
effect->target()->reset_animated_css_properties();
}
for (auto& animation : timeline->associated_animations()) {
if (auto effect = animation->effect())
effect->update_style_properties();
}
}
m_needs_animated_style_update = false;
}
void Document::update_paint_and_hit_testing_properties_if_needed()
{
if (!m_needs_to_resolve_paint_only_properties)
@ -4055,6 +4064,8 @@ void Document::ensure_animation_timer()
for (auto& animation : timeline->associated_animations())
dispatch_events_for_animation_if_necessary(animation);
}
m_needs_animated_style_update = true;
}));
}

View file

@ -211,6 +211,7 @@ public:
void update_style();
void update_layout();
void update_paint_and_hit_testing_properties_if_needed();
void update_animated_style_if_needed();
void set_needs_layout();
@ -736,6 +737,8 @@ private:
bool m_needs_full_style_update { false };
bool m_needs_animated_style_update { false };
HashTable<JS::GCPtr<NodeIterator>> m_node_iterators;
HashTable<JS::NonnullGCPtr<DocumentObserver>> m_document_observers;