6#include <Ultralight/CAPI/CAPI_DOMEvent.h>
7#include <Ultralight/dom/detail/Support.h>
39inline unsigned EventInitFlags(
const EventInit& init) {
40 return (init.
bubbles ? kULDOMEventInit_Bubbles : 0u)
41 | (init.
cancelable ? kULDOMEventInit_Cancelable : 0u)
42 | (init.
composed ? kULDOMEventInit_Composed : 0u);
120 explicit Event(ULDOMEvent borrowed) : borrowed_(borrowed) {}
130 std::string
type()
const {
return detail::TakeString(ulDOMEventGetType(borrowed_)); }
137 unsigned eventPhase()
const {
return ulDOMEventGetPhase(borrowed_); }
142 bool bubbles()
const {
return ulDOMEventGetBubbles(borrowed_); }
147 bool cancelable()
const {
return ulDOMEventGetCancelable(borrowed_); }
155 bool isTrusted()
const {
return ulDOMEventIsTrusted(borrowed_); }
163 double timeStamp()
const {
return ulDOMEventGetTimeStamp(borrowed_); }
268 ULDOMEvent
raw()
const {
return borrowed_; }
271 ULDOMEvent borrowed_;
299 int detail()
const {
return ulDOMEventGetDetail(
raw()); }
306 double clientX()
const {
return ulDOMEventGetClientX(
raw()); }
313 double clientY()
const {
return ulDOMEventGetClientY(
raw()); }
322 double pageX()
const {
return ulDOMEventGetPageX(
raw()); }
331 double pageY()
const {
return ulDOMEventGetPageY(
raw()); }
341 double screenX()
const {
return ulDOMEventGetScreenX(
raw()); }
351 double screenY()
const {
return ulDOMEventGetScreenY(
raw()); }
361 int button()
const {
return ulDOMEventGetButton(
raw()); }
369 unsigned buttons()
const {
return ulDOMEventGetButtons(
raw()); }
384 bool altKey()
const {
return ulDOMEventGetAltKey(
raw()); }
424 double deltaX()
const {
return ulDOMEventGetDeltaX(
raw()); }
432 double deltaY()
const {
return ulDOMEventGetDeltaY(
raw()); }
464 std::string
key()
const {
return detail::TakeString(ulDOMEventGetKey(
raw())); }
476 std::string
code()
const {
return detail::TakeString(ulDOMEventGetCode(
raw())); }
484 unsigned location()
const {
return ulDOMEventGetKeyLocation(
raw()); }
489 bool repeat()
const {
return ulDOMEventGetRepeat(
raw()); }
509 bool altKey()
const {
return ulDOMEventGetAltKey(
raw()); }
568 ULString s = ulDOMEventGetInputType(
raw());
571 return detail::TakeString(s);
579 std::optional<std::string>
data()
const {
580 ULString s = ulDOMEventGetData(
raw());
583 return detail::TakeString(s);
653 std::optional<std::string> detail()
const {
654 ULString payload = ulDOMEventGetCustomDetail(
raw());
657 return dom::detail::TakeString(payload);
670template <
typename Fn,
typename... Rest>
671concept InvocableWithEvent =
requires(Fn& fn, ULDOMEvent event, Rest&&... rest) {
672 fn(
Event(event),
static_cast<Rest&&
>(rest)...);
An event with a string payload (CustomEvent).
Definition Event.h:636
CustomEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsCustom() is the usual way to get one).
Definition Event.h:643
A handle to an element on a page.
Definition Element.h:142
A page event (such as a click or key press) received by a listener callback.
Definition Event.h:110
void preventDefault() const
Cancel the event's default action (preventDefault).
Definition Event.h:184
Node targetNode() const
Get the node the event was dispatched to (target).
Definition Element.h:3460
void stopPropagation() const
Stop the event from reaching other targets (stopPropagation).
Definition Event.h:191
void stopImmediatePropagation() const
Stop the event from reaching any other listener (stopImmediatePropagation).
Definition Event.h:198
double timeStamp() const
Get the time the event was created (timeStamp).
Definition Event.h:163
WheelEvent AsWheel() const
View this event as a WheelEvent.
Definition Event.h:614
CustomEvent AsCustom() const
View this event as a CustomEvent.
Definition Event.h:661
bool defaultPrevented() const
Whether or not the event was canceled (defaultPrevented).
Definition Event.h:171
Event(ULDOMEvent borrowed)
Wrap an event handle from the C API.
Definition Event.h:120
bool isTrusted() const
Whether or not the event came from user input or the library (isTrusted).
Definition Event.h:155
Event(const Event &)=delete
FocusEvent AsFocus() const
View this event as a FocusEvent.
Definition Event.h:620
SubmitEvent AsSubmit() const
View this event as a SubmitEvent.
Definition Event.h:626
unsigned eventPhase() const
Get the current dispatch phase (eventPhase).
Definition Event.h:137
Element target() const
Get the element the event was dispatched to (target).
Definition Element.h:3456
MouseEvent AsMouse() const
View this event as a MouseEvent.
Definition Event.h:611
InputEvent AsInput() const
View this event as an InputEvent.
Definition Event.h:623
KeyboardEvent AsKeyboard() const
View this event as a KeyboardEvent.
Definition Event.h:617
Element currentTarget() const
Get the element whose listener is running (currentTarget).
Definition Element.h:3464
bool cancelable() const
Whether or not preventDefault() can cancel the event (cancelable).
Definition Event.h:147
ULDOMEvent raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMEvent.h> functions.
Definition Event.h:268
std::string type() const
Get the event's type (type).
Definition Event.h:130
bool bubbles() const
Whether or not the event bubbles up the tree (bubbles).
Definition Event.h:142
Event & operator=(const Event &)=delete
A focus event (FocusEvent).
Definition Event.h:523
FocusEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsFocus() is the usual way to get one).
Definition Event.h:530
Element relatedTarget() const
Get the other element of the focus change (relatedTarget).
Definition Element.h:3472
A keyboard event (KeyboardEvent).
Definition Event.h:449
bool repeat() const
Whether or not the key is held down and repeating (repeat).
Definition Event.h:489
std::string key() const
Get the key's value (key).
Definition Event.h:464
KeyboardEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsKeyboard() is the usual way to get one).
Definition Event.h:456
std::string code() const
Get the physical key (code).
Definition Event.h:476
bool altKey() const
Whether or not the Alt key was held down (altKey).
Definition Event.h:509
bool shiftKey() const
Whether or not the Shift key was held down (shiftKey).
Definition Event.h:504
bool isComposing() const
Whether or not the event happened during IME composition (isComposing).
Definition Event.h:494
bool metaKey() const
Whether or not the Meta key was held down (metaKey).
Definition Event.h:514
bool ctrlKey() const
Whether or not the Control key was held down (ctrlKey).
Definition Event.h:499
unsigned location() const
Get the key's location on the keyboard (location).
Definition Event.h:484
A mouse event (MouseEvent).
Definition Event.h:284
double pageY() const
Get the pointer's y-position in the page, in CSS pixels (pageY).
Definition Event.h:331
double screenY() const
Get the pointer's y-position relative to the View (screenY).
Definition Event.h:351
double clientY() const
Get the pointer's y-position in the viewport, in CSS pixels (clientY).
Definition Event.h:313
double pageX() const
Get the pointer's x-position in the page, in CSS pixels (pageX).
Definition Event.h:322
double clientX() const
Get the pointer's x-position in the viewport, in CSS pixels (clientX).
Definition Event.h:306
MouseEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsMouse() is the usual way to get one).
Definition Event.h:291
double screenX() const
Get the pointer's x-position relative to the View (screenX).
Definition Event.h:341
Element relatedTarget() const
Get the other element of a mouse transition (relatedTarget).
Definition Element.h:3468
unsigned buttons() const
Get the buttons held down during the event (buttons).
Definition Event.h:369
bool altKey() const
Whether or not the Alt key was held down (altKey).
Definition Event.h:384
bool shiftKey() const
Whether or not the Shift key was held down (shiftKey).
Definition Event.h:379
int button() const
Get the button that caused the event (button).
Definition Event.h:361
bool metaKey() const
Whether or not the Meta key was held down (metaKey).
Definition Event.h:389
bool ctrlKey() const
Whether or not the Control key was held down (ctrlKey).
Definition Event.h:374
A reference to an item in the DOM tree.
Definition Node.h:147
A form submission event (SubmitEvent).
Definition Event.h:593
SubmitEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsSubmit() is the usual way to get one).
Definition Event.h:600
Element submitter() const
Get the button that submitted the form (submitter).
Definition Element.h:3476
A wheel event (WheelEvent).
Definition Event.h:409
unsigned deltaMode() const
Get the unit of the scroll amounts (deltaMode).
Definition Event.h:441
double deltaY() const
Get the vertical scroll amount (deltaY).
Definition Event.h:432
WheelEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsWheel() is the usual way to get one).
Definition Event.h:416
double deltaX() const
Get the horizontal scroll amount (deltaX).
Definition Event.h:424
Direct C++ access to modify page elements and handle events.
Root namespace for every public Ultralight type, function, and enumeration.
Options for an event you dispatch yourself (the web's EventInit).
Definition Event.h:30
bool cancelable
Whether or not Event::preventDefault() can cancel the event.
Definition Event.h:32
bool bubbles
Whether or not the event bubbles up the tree.
Definition Event.h:31
bool composed
Whether or not the event crosses shadow-tree boundaries.
Definition Event.h:33