LibWeb: Ensure all DocumentTimeline objects have the same time value

The DocumentTimeline constructor used the current millisecond time to
initialize its currentTime, but that means that a newly created timeline
would always have a different time value than other timelines that have
been through the update_animations_and_send_events function.
This commit is contained in:
Matthew Olsson 2024-06-02 06:48:36 -07:00 committed by Andreas Kling
commit 37322baf54
Notes: sideshowbarker 2024-07-17 05:02:35 +09:00
5 changed files with 32 additions and 3 deletions

View file

@ -20,9 +20,14 @@ JS_DEFINE_ALLOCATOR(DocumentTimeline);
JS::NonnullGCPtr<DocumentTimeline> DocumentTimeline::create(JS::Realm& realm, DOM::Document& document, HighResolutionTime::DOMHighResTimeStamp origin_time)
{
auto timeline = realm.heap().allocate<DocumentTimeline>(realm, realm, document, origin_time);
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
VERIFY(window_or_worker);
timeline->set_current_time(window_or_worker->performance()->now());
auto current_time = document.last_animation_frame_timestamp();
if (!current_time.has_value()) {
// The document hasn't processed an animation frame yet, so just use the exact current time
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
VERIFY(window_or_worker);
current_time = window_or_worker->performance()->now();
}
timeline->set_current_time(current_time);
return timeline;
}