2022-09-07 20:30:31 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-07 20:30:31 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/RefCounted.h>
|
2024-10-30 21:37:08 +13:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
|
|
|
|
|
namespace Web::Platform {
|
|
|
|
|
|
2024-10-30 21:37:08 +13:00
|
|
|
class Timer : public JS::Cell {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(Timer, JS::Cell);
|
2024-10-30 21:37:08 +13:00
|
|
|
|
2022-09-07 20:30:31 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<Timer> create(GC::Heap&);
|
|
|
|
|
static GC::Ref<Timer> create_repeating(GC::Heap&, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler);
|
|
|
|
|
static GC::Ref<Timer> create_single_shot(GC::Heap&, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler);
|
2022-09-07 20:30:31 +02:00
|
|
|
|
|
|
|
|
virtual ~Timer();
|
|
|
|
|
|
|
|
|
|
virtual void start() = 0;
|
|
|
|
|
virtual void start(int interval_ms) = 0;
|
|
|
|
|
virtual void restart() = 0;
|
|
|
|
|
virtual void restart(int interval_ms) = 0;
|
|
|
|
|
virtual void stop() = 0;
|
|
|
|
|
|
|
|
|
|
virtual void set_active(bool) = 0;
|
|
|
|
|
|
|
|
|
|
virtual bool is_active() const = 0;
|
|
|
|
|
virtual int interval() const = 0;
|
|
|
|
|
virtual void set_interval(int interval_ms) = 0;
|
|
|
|
|
|
|
|
|
|
virtual bool is_single_shot() const = 0;
|
|
|
|
|
virtual void set_single_shot(bool) = 0;
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<GC::Function<void()>> on_timeout;
|
2024-10-30 21:42:05 +13:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
2022-09-07 20:30:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|