16#ifndef AEONGUI_DOM_EVENTTARGET_H
17#define AEONGUI_DOM_EVENTTARGET_H
23#include <unordered_map>
26#include "DOMString.hpp"
27#include "EventListener.hpp"
37 using EventHandler = std::function<void (
Event& ) >;
67 void addEventListener (
const DOMString& type,
EventListener* callback,
const std::variant<std::monostate, AddEventListenerOptions, bool>& options = {} );
80 std::unordered_map<DOMString, std::vector<EventListener* >> mEventListeners{};
96 static AbortSignal
abort (
const std::optional<AnyType>&
reason = std::nullopt );
101 static AbortSignal
timeout ( uint64_t milliseconds );
106 static AbortSignal
any ( std::vector<AbortSignal> signals );
121 AbortSignal() =
default;
Signal that can abort an asynchronous operation.
Definition EventTarget.hpp:90
const AnyType & reason() const
Get the reason for the abort.
static AbortSignal abort(const std::optional< AnyType > &reason=std::nullopt)
Create an already-aborted signal.
bool aborted() const
Check whether the signal has been aborted.
void throwIfAborted()
Throw if the signal has been aborted.
virtual ~AbortSignal()=default
Destructor.
static AbortSignal any(std::vector< AbortSignal > signals)
Create a signal that aborts when any of the given signals abort.
EventHandler onabort
Handler invoked when the signal is aborted.
Definition EventTarget.hpp:117
static AbortSignal timeout(uint64_t milliseconds)
Create a signal that will abort after a timeout.
Represents a DOM event.
Definition Event.hpp:47
Interface for objects that handle DOM events.
Definition EventListener.hpp:32
Base class for objects that can receive DOM events.
Definition EventTarget.hpp:58
virtual ~EventTarget()=0
Virtual destructor.
void removeEventListener(const DOMString &type, EventListener *callback, const std::variant< std::monostate, EventListenerOptions, bool > &options={})
Unregister an event listener.
Definition EventTarget.cpp:31
virtual bool dispatchEvent(Event &event)
Dispatch an event to this target.
Definition EventTarget.cpp:44
void addEventListener(const DOMString &type, EventListener *callback, const std::variant< std::monostate, AddEventListenerOptions, bool > &options={})
Register an event listener.
Definition EventTarget.cpp:23
Extended options for addEventListener.
Definition EventTarget.hpp:46
bool passive
If true, the listener will not call preventDefault.
Definition EventTarget.hpp:47
AbortSignal * signal
An AbortSignal that can remove the listener.
Definition EventTarget.hpp:49
bool once
If true, the listener is automatically removed after firing.
Definition EventTarget.hpp:48
Options for addEventListener / removeEventListener.
Definition EventTarget.hpp:40
bool capture
If true, listen during the capture phase.
Definition EventTarget.hpp:41