1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:47:35 +00:00

LibWeb: Move Timer from DOM directory & namespace to HTML

Timers are part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
This commit is contained in:
Linus Groh 2022-03-07 23:54:56 +01:00
parent 1422bd45eb
commit 0706f0d487
6 changed files with 15 additions and 15 deletions

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/Timer.h>
#include <LibWeb/DOM/Timer.h>
#include <LibWeb/HTML/Window.h>
namespace Web::DOM {
NonnullRefPtr<Timer> Timer::create(HTML::Window& window, i32 milliseconds, Function<void()> callback, i32 id)
{
return adopt_ref(*new Timer(window, milliseconds, move(callback), id));
}
Timer::Timer(HTML::Window& window, i32 milliseconds, Function<void()> callback, i32 id)
: m_window(window)
, m_id(id)
{
m_timer = Core::Timer::create_single_shot(milliseconds, [this, callback = move(callback)] {
NonnullRefPtr strong_timer { *this };
callback();
});
}
Timer::~Timer()
{
m_window.deallocate_timer_id({}, m_id);
}
void Timer::start()
{
m_timer->start();
}
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/Function.h>
#include <LibCore/Forward.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
class Timer final : public RefCounted<Timer> {
public:
static NonnullRefPtr<Timer> create(HTML::Window& window, i32 milliseconds, Function<void()> callback, i32 id);
~Timer();
void start();
private:
Timer(HTML::Window& window, i32 milliseconds, Function<void()> callback, i32 id);
RefPtr<Core::Timer> m_timer;
HTML::Window& m_window;
i32 m_id { 0 };
};
}