AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Event.hpp
1/*
2Copyright (C) 2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_DOM_EVENT_H
17#define AEONGUI_DOM_EVENT_H
18#include <cstdint>
19#include <optional>
20#include <vector>
21#include <chrono>
22#include "aeongui/Platform.hpp"
23#include "DOMString.hpp"
24#include "EventTarget.hpp"
25
26namespace AeonGUI
27{
28 namespace DOM
29 {
31 using DOMHighResTimeStamp = std::chrono::time_point<std::chrono::high_resolution_clock>;
33 struct EventInit
34 {
35 bool bubbles{false};
36 bool cancelable{false};
37 bool composed{false};
38 };
39
46 class Event
47 {
48 public:
53 Event ( const DOMString& type, const std::optional<EventInit>& eventInitDict = {} );
56 std::vector<EventTarget> composedPath() const;
58 void stopPropagation();
62 void preventDefault();
63
64 const uint16_t NONE{0};
65 const uint16_t CAPTURING_PHASE{1};
66 const uint16_t AT_TARGET{2};
67 const uint16_t BUBBLING_PHASE{3};
68
71 constexpr const DOMString& type() const
72 {
73 return m_type;
74 }
75
77 constexpr const EventTarget* const target() const
78 {
79 return m_target;
80 }
81
83 constexpr const EventTarget* const currentTarget() const
84 {
85 return m_currentTarget;
86 }
87
89 constexpr uint16_t eventPhase() const
90 {
91 return m_eventPhase;
92 }
93
95 constexpr bool bubbles() const
96 {
97 return m_bubbles;
98 }
99
101 constexpr bool cancelable() const
102 {
103 return m_cancelable;
104 }
105
107 constexpr bool defaultPrevented() const
108 {
109 return m_defaultPrevented;
110 }
111
113 constexpr bool composed() const
114 {
115 return m_composed;
116 }
117
119 constexpr bool isTrusted() const
120 {
121 return m_isTrusted;
122 }
123
125 constexpr const DOMHighResTimeStamp& timeStamp() const
126 {
127 return m_timeStamp;
128 }
129
130 private:
131 DOMString m_type;
132 EventTarget* m_target{};
133 EventTarget* m_currentTarget{};
134 uint16_t m_eventPhase{NONE};
135 bool m_bubbles{};
136 bool m_cancelable{};
137 bool m_defaultPrevented{};
138 bool m_composed{};
139 bool m_isTrusted{};
140 DOMHighResTimeStamp m_timeStamp{};
141 };
142 }
143}
144#endif
Platform-specific DLL import/export macros and compiler helpers.
constexpr bool composed() const
Check whether the event is composed.
Definition Event.hpp:113
const uint16_t AT_TARGET
At-target phase.
Definition Event.hpp:66
const uint16_t CAPTURING_PHASE
Capture phase.
Definition Event.hpp:65
constexpr uint16_t eventPhase() const
Get the current event phase.
Definition Event.hpp:89
constexpr bool bubbles() const
Check whether the event bubbles.
Definition Event.hpp:95
constexpr const EventTarget *const currentTarget() const
Get the current target during dispatch.
Definition Event.hpp:83
void stopPropagation()
Stop the event from propagating further.
Definition Event.cpp:33
constexpr bool isTrusted() const
Check whether the event was generated by the user agent.
Definition Event.hpp:119
std::vector< EventTarget > composedPath() const
Build the composed path for this event.
Definition Event.cpp:29
constexpr const DOMString & type() const
Get the event type.
Definition Event.hpp:71
const uint16_t NONE
No phase.
Definition Event.hpp:64
const uint16_t BUBBLING_PHASE
Bubble phase.
Definition Event.hpp:67
constexpr const EventTarget *const target() const
Get the target of the event.
Definition Event.hpp:77
void stopImmediatePropagation()
Stop the event from propagating and prevent other listeners on the same target.
Definition Event.cpp:37
constexpr const DOMHighResTimeStamp & timeStamp() const
Get the event's creation timestamp.
Definition Event.hpp:125
constexpr bool defaultPrevented() const
Check whether the default action was prevented.
Definition Event.hpp:107
void preventDefault()
Cancel the event's default action, if cancelable.
Definition Event.cpp:41
constexpr bool cancelable() const
Check whether the event is cancelable.
Definition Event.hpp:101
Event(const DOMString &type, const std::optional< EventInit > &eventInitDict={})
Construct an event of the given type.
Definition Event.cpp:21
Base class for objects that can receive DOM events.
Definition EventTarget.hpp:58
Initialization dictionary for Event construction.
Definition Event.hpp:34
bool cancelable
Whether the event can be cancelled.
Definition Event.hpp:36
bool bubbles
Whether the event bubbles up the DOM tree.
Definition Event.hpp:35
bool composed
Whether the event crosses shadow DOM boundaries.
Definition Event.hpp:37