2020-06-27 18:30:29 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-06-27 18:30:29 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-27 18:30:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
2022-03-04 10:41:12 -05:00
|
|
|
#include <AK/Function.h>
|
2022-09-01 12:21:47 +02:00
|
|
|
#include <AK/WeakPtr.h>
|
2020-06-27 18:30:29 +02:00
|
|
|
#include <LibCore/Forward.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Function.h>
|
|
|
|
#include <LibGC/Ptr.h>
|
2022-09-01 12:21:47 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2020-06-27 18:30:29 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
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
|
|
|
class Timer final : public JS::Cell {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(Timer, JS::Cell);
|
|
|
|
GC_DECLARE_ALLOCATOR(Timer);
|
2022-09-01 12:21:47 +02:00
|
|
|
|
2020-06-27 18:30:29 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<Timer> create(JS::Object&, i32 milliseconds, Function<void()> callback, i32 id);
|
2022-09-01 12:21:47 +02:00
|
|
|
virtual ~Timer() override;
|
2020-06-27 18:30:29 +02:00
|
|
|
|
2022-03-04 10:41:12 -05:00
|
|
|
void start();
|
2023-09-26 11:44:56 +02:00
|
|
|
void stop();
|
2020-06-27 18:30:29 +02:00
|
|
|
|
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
Timer(JS::Object& window, i32 milliseconds, GC::Ref<GC::Function<void()>> callback, i32 id);
|
2020-06-27 18:30:29 +02:00
|
|
|
|
2022-09-01 12:21:47 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2023-09-26 11:53:37 +02:00
|
|
|
RefPtr<Core::Timer> m_timer;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<JS::Object> m_window_or_worker_global_scope;
|
|
|
|
GC::Ref<GC::Function<void()>> m_callback;
|
2022-03-04 10:41:12 -05:00
|
|
|
i32 m_id { 0 };
|
2020-06-27 18:30:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|