ladybird/Userland/Libraries/LibWeb/DOM/Timer.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

40 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/Timer.h>
#include <LibJS/Runtime/Function.h>
#include <LibWeb/DOM/Timer.h>
#include <LibWeb/DOM/Window.h>
namespace Web::DOM {
NonnullRefPtr<Timer> Timer::create_interval(Window& window, int milliseconds, JS::Function& callback)
{
return adopt(*new Timer(window, Type::Interval, milliseconds, callback));
}
NonnullRefPtr<Timer> Timer::create_timeout(Window& window, int milliseconds, JS::Function& callback)
{
return adopt(*new Timer(window, Type::Timeout, milliseconds, callback));
}
Timer::Timer(Window& window, Type type, int milliseconds, JS::Function& callback)
: m_window(window)
, m_type(type)
, m_callback(JS::make_handle(&callback))
{
m_id = window.allocate_timer_id({});
m_timer = Core::Timer::construct(milliseconds, [this] { m_window.timer_did_fire({}, *this); });
if (m_type == Type::Timeout)
m_timer->set_single_shot(true);
}
Timer::~Timer()
{
m_window.deallocate_timer_id({}, m_id);
}
}