2020-06-27 18:30:29 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-27 18:30:29 +02:00
|
|
|
*/
|
|
|
|
|
2022-03-07 23:54:56 +01:00
|
|
|
#include <LibWeb/HTML/Timer.h>
|
2022-03-07 23:08:26 +01:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
#include <LibWeb/Platform/Timer.h>
|
2020-06-27 18:30:29 +02:00
|
|
|
|
2022-03-07 23:54:56 +01:00
|
|
|
namespace Web::HTML {
|
2020-06-27 18:30:29 +02:00
|
|
|
|
2022-09-01 12:21:47 +02:00
|
|
|
JS::NonnullGCPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
2020-06-27 18:30:29 +02:00
|
|
|
{
|
2022-12-14 17:40:33 +00:00
|
|
|
return window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id);
|
2020-06-27 18:30:29 +02:00
|
|
|
}
|
|
|
|
|
2022-03-07 23:54:56 +01:00
|
|
|
Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
2020-06-27 18:30:29 +02:00
|
|
|
: m_window(window)
|
2022-09-01 12:21:47 +02:00
|
|
|
, m_callback(move(callback))
|
2022-03-04 10:41:12 -05:00
|
|
|
, m_id(id)
|
2020-06-27 18:30:29 +02:00
|
|
|
{
|
2022-09-07 20:30:31 +02:00
|
|
|
m_timer = Platform::Timer::create_single_shot(milliseconds, [this] {
|
2022-09-01 12:21:47 +02:00
|
|
|
m_callback();
|
2022-03-04 10:41:12 -05:00
|
|
|
});
|
2020-06-27 18:30:29 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 12:21:47 +02:00
|
|
|
void Timer::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_window.ptr());
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:30:29 +02:00
|
|
|
Timer::~Timer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-04 10:41:12 -05:00
|
|
|
void Timer::start()
|
|
|
|
{
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:30:29 +02:00
|
|
|
}
|