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

LibWeb: Let HTML::EventLoop drive animation frame callbacks

This commit is contained in:
Andreas Kling 2021-10-03 16:28:14 +02:00
parent ae71e5f99b
commit 81ef2b646e
3 changed files with 36 additions and 6 deletions

View file

@ -47,11 +47,7 @@ struct RequestAnimationFrameDriver {
RequestAnimationFrameDriver()
{
m_timer = Core::Timer::create_single_shot(16, [this] {
auto taken_callbacks = move(m_callbacks);
for (auto& it : taken_callbacks) {
if (!it.value->is_cancelled())
it.value->invoke();
}
HTML::main_thread_event_loop().schedule();
});
}
@ -75,6 +71,15 @@ struct RequestAnimationFrameDriver {
return true;
}
void run()
{
auto taken_callbacks = move(m_callbacks);
for (auto& it : taken_callbacks) {
if (!it.value->is_cancelled())
it.value->invoke();
}
}
private:
HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_callbacks;
IDAllocator m_id_allocator;
@ -87,6 +92,13 @@ static RequestAnimationFrameDriver& request_animation_frame_driver()
return driver;
}
// https://html.spec.whatwg.org/#run-the-animation-frame-callbacks
void run_animation_frame_callbacks(DOM::Document&, double)
{
// FIXME: Bring this closer to the spec.
request_animation_frame_driver().run();
}
NonnullRefPtr<Window> Window::create_with_document(Document& document)
{
return adopt_ref(*new Window(document));