docs
Loading...
Searching...
No Matches
Event.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
6#include <Ultralight/CAPI/CAPI_DOMEvent.h>
7#include <Ultralight/dom/detail/Support.h>
8
9#include <optional>
10#include <string>
11
12namespace ultralight {
13namespace dom {
14
15class Element;
16class Node;
17class MouseEvent;
18class WheelEvent;
19class KeyboardEvent;
20class FocusEvent;
21class InputEvent;
22class SubmitEvent;
23class CustomEvent;
24
25///
26/// Options for an event you dispatch yourself (the web's EventInit).
27///
28/// @see Element::dispatchEvent(), Element::dispatchCustomEvent()
29///
30struct EventInit {
31 bool bubbles = false; ///< Whether or not the event bubbles up the tree.
32 bool cancelable = false; ///< Whether or not Event::preventDefault() can cancel the event.
33 bool composed = false; ///< Whether or not the event crosses shadow-tree boundaries.
34};
35
36/// \cond INTERNAL
37namespace detail {
38
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);
43}
44
45} // namespace detail
46/// \endcond
47
48///
49/// A page event (such as a click or key press) received by a listener callback.
50///
51/// When an action occurs on a page-- like a click or key press-- the library delivers an Event to
52/// your listener callback. It works like the JavaScript event object.
53///
54/// This listener cancels a form submission to handle it in native code:
55///
56/// ```
57/// dom::Element signup = document.getElementById("signup");
58/// signup.addEventListener("submit", [](dom::Event event) {
59/// event.preventDefault(); // handle the submission natively
60/// SaveProfile(event.target()); // a handle you can keep
61/// });
62/// ```
63///
64/// ## Event Lifetime
65///
66/// An Event is valid only during the callback that received it. Listener callbacks take it by
67/// value, and you can't copy, move, or store it.
68///
69/// Pass an Event to helper functions by const reference:
70///
71/// ```
72/// void HandleKey(const dom::Event& event) {
73/// Log(event.AsKeyboard().key());
74/// }
75/// ```
76///
77/// Handles you get from the event (like target() and currentTarget()) are ordinary DOM handles you
78/// can keep after the callback returns.
79///
80/// ## Typed Event Views
81///
82/// Each typed view provides access to properties specific to that kind of event:
83///
84/// | %View | Fields Added |
85/// |--------------|--------------------------------------|
86/// | AsMouse() | Position, buttons, and modifier keys |
87/// | AsWheel() | Scroll deltas |
88/// | AsKeyboard() | Key, code, and modifier keys |
89/// | AsFocus() | Element gaining or losing focus |
90/// | AsInput() | Edit kind and inserted text |
91/// | AsSubmit() | Button that submitted the form |
92/// | AsCustom() | %String payload |
93///
94/// Calling a view method on an event of a different type returns fallback values rather than
95/// failing. If a single callback handles multiple event types, check type() before converting the
96/// event.
97///
98/// This listener checks the key pressed during a keyboard event:
99///
100/// ```
101/// document.addEventListener("keydown", [](dom::Event event) {
102/// if (event.AsKeyboard().key() == "Escape")
103/// CloseMenu();
104/// });
105/// ```
106///
107/// @see dom::EventListener, dom::Element::addEventListener(), dom::Element::dispatchEvent(),
108/// dom::MouseEvent, dom::KeyboardEvent
109///
110class Event {
111 public:
112 ///
113 /// Wrap an event handle from the C API.
114 ///
115 /// Listener callbacks already give you an Event, so you rarely need this.
116 ///
117 /// @param borrowed The event handle passed to a C listener callback. The Event is valid only
118 /// during that callback.
119 ///
120 explicit Event(ULDOMEvent borrowed) : borrowed_(borrowed) {}
121
122 Event(const Event&) = delete;
123 Event& operator=(const Event&) = delete;
124
125 ///
126 /// Get the event's type (type).
127 ///
128 /// @return Returns the type (eg, `click`).
129 ///
130 std::string type() const { return detail::TakeString(ulDOMEventGetType(borrowed_)); }
131
132 ///
133 /// Get the current dispatch phase (eventPhase).
134 ///
135 /// @return Returns 1 while capturing, 2 at the target, or 3 while bubbling.
136 ///
137 unsigned eventPhase() const { return ulDOMEventGetPhase(borrowed_); }
138
139 ///
140 /// Whether or not the event bubbles up the tree (bubbles).
141 ///
142 bool bubbles() const { return ulDOMEventGetBubbles(borrowed_); }
143
144 ///
145 /// Whether or not preventDefault() can cancel the event (cancelable).
146 ///
147 bool cancelable() const { return ulDOMEventGetCancelable(borrowed_); }
148
149 ///
150 /// Whether or not the event came from user input or the library (isTrusted).
151 ///
152 /// Events from user input and the page (eg, `load`) are trusted. Events dispatched by page
153 /// script, or with Element::dispatchEvent() or Element::click(), aren't.
154 ///
155 bool isTrusted() const { return ulDOMEventIsTrusted(borrowed_); }
156
157 ///
158 /// Get the time the event was created (timeStamp).
159 ///
160 /// @return Returns the time in milliseconds, measured from when the page started loading (the
161 /// same clock as the page's `performance.now()`).
162 ///
163 double timeStamp() const { return ulDOMEventGetTimeStamp(borrowed_); }
164
165 ///
166 /// Whether or not the event was canceled (defaultPrevented).
167 ///
168 /// @return Returns true if a call to preventDefault() canceled the event. A call that had no
169 /// effect (see preventDefault()) leaves this false.
170 ///
171 bool defaultPrevented() const { return ulDOMEventGetDefaultPrevented(borrowed_); }
172
173 ///
174 /// Cancel the event's default action (preventDefault).
175 ///
176 /// This stops what the library would do in response to the event (like submitting a form,
177 /// following a link, or toggling a checkbox).
178 ///
179 /// @note This does nothing if the event isn't cancelable or the listener is passive. Wheel
180 /// listeners on the window, the document, `<html>`, and `<body>` are passive unless you
181 /// add them with EventListenerFlags::NotPassive (or AddEventListenerOptions::passive set
182 /// to false).
183 ///
184 void preventDefault() const { ulDOMEventPreventDefault(borrowed_); }
185
186 ///
187 /// Stop the event from reaching other targets (stopPropagation).
188 ///
189 /// The remaining listeners on the current target still run.
190 ///
191 void stopPropagation() const { ulDOMEventStopPropagation(borrowed_); }
192
193 ///
194 /// Stop the event from reaching any other listener (stopImmediatePropagation).
195 ///
196 /// Unlike stopPropagation(), this also skips the remaining listeners on the current target.
197 ///
198 void stopImmediatePropagation() const { ulDOMEventStopImmediatePropagation(borrowed_); }
199
200 ///
201 /// Get the element the event was dispatched to (target).
202 ///
203 /// @return Returns the target (empty if it isn't an element, like the document for page
204 /// `load`). Use targetNode() for a target that may be a text node.
205 ///
206 Element target() const;
207
208 ///
209 /// Get the node the event was dispatched to (target).
210 ///
211 /// Use this instead of target() when the target can be a text node or another node that isn't
212 /// an element.
213 ///
214 /// @return Returns the target (empty if it's the document or the window).
215 ///
216 Node targetNode() const;
217
218 ///
219 /// Get the element whose listener is running (currentTarget).
220 ///
221 /// @return Returns the element (empty for a listener on the document or the window).
222 ///
223 /// @note In a delegated listener (see Element::On()), this is the element you added the
224 /// listener to, not the matched element.
225 ///
226 Element currentTarget() const;
227
228 ///
229 /// View this event as a MouseEvent.
230 ///
231 MouseEvent AsMouse() const;
232
233 ///
234 /// View this event as a WheelEvent.
235 ///
236 WheelEvent AsWheel() const;
237
238 ///
239 /// View this event as a KeyboardEvent.
240 ///
242
243 ///
244 /// View this event as a FocusEvent.
245 ///
246 FocusEvent AsFocus() const;
247
248 ///
249 /// View this event as an InputEvent.
250 ///
251 InputEvent AsInput() const;
252
253 ///
254 /// View this event as a SubmitEvent.
255 ///
256 SubmitEvent AsSubmit() const;
257
258 ///
259 /// View this event as a CustomEvent.
260 ///
261 CustomEvent AsCustom() const;
262
263 ///
264 /// Get the C handle, for passing to the `<Ultralight/CAPI/CAPI_DOMEvent.h>` functions.
265 ///
266 /// @return Returns the handle (valid only during the callback, like this Event).
267 ///
268 ULDOMEvent raw() const { return borrowed_; }
269
270 private:
271 ULDOMEvent borrowed_;
272};
273
274///
275/// A mouse event (MouseEvent).
276///
277/// Get one with Event::AsMouse(). It works for mouse events (eg, `click`), pointer events (eg,
278/// `pointerdown`), and `wheel` (see WheelEvent).
279///
280/// @note In mouse and wheel events from View::FireMouseEvent() and View::FireScrollEvent(), the
281/// modifier keys (ctrlKey() and the rest) are the ones held in the last KeyEvent you
282/// passed to View::FireKeyEvent(), since mouse and scroll events carry no modifier state.
283///
284class MouseEvent : public Event {
285 public:
286 ///
287 /// Wrap an event handle from the C API (Event::AsMouse() is the usual way to get one).
288 ///
289 /// @param borrowed The event handle passed to a C listener callback.
290 ///
291 explicit MouseEvent(ULDOMEvent borrowed) : Event(borrowed) {}
292
293 ///
294 /// Get the click count (detail).
295 ///
296 /// @return Returns 1 for a single click, 2 for a double click, and so on (0 for an event
297 /// without a click count, like `mousemove`).
298 ///
299 int detail() const { return ulDOMEventGetDetail(raw()); }
300
301 ///
302 /// Get the pointer's x-position in the viewport, in CSS pixels (clientX).
303 ///
304 /// @return Returns the position (0 for an event without a pointer position).
305 ///
306 double clientX() const { return ulDOMEventGetClientX(raw()); }
307
308 ///
309 /// Get the pointer's y-position in the viewport, in CSS pixels (clientY).
310 ///
311 /// @return Returns the position (0 for an event without a pointer position).
312 ///
313 double clientY() const { return ulDOMEventGetClientY(raw()); }
314
315 ///
316 /// Get the pointer's x-position in the page, in CSS pixels (pageX).
317 ///
318 /// This is clientX() plus the page's horizontal scroll position.
319 ///
320 /// @return Returns the position (0 for an event without a pointer position).
321 ///
322 double pageX() const { return ulDOMEventGetPageX(raw()); }
323
324 ///
325 /// Get the pointer's y-position in the page, in CSS pixels (pageY).
326 ///
327 /// This is clientY() plus the page's vertical scroll position.
328 ///
329 /// @return Returns the position (0 for an event without a pointer position).
330 ///
331 double pageY() const { return ulDOMEventGetPageY(raw()); }
332
333 ///
334 /// Get the pointer's x-position relative to the View (screenX).
335 ///
336 /// This is the position you passed to View::FireMouseEvent() (in the View's logical pixels),
337 /// not a position on the screen.
338 ///
339 /// @return Returns the position (0 for an event without a pointer position).
340 ///
341 double screenX() const { return ulDOMEventGetScreenX(raw()); }
342
343 ///
344 /// Get the pointer's y-position relative to the View (screenY).
345 ///
346 /// This is the position you passed to View::FireMouseEvent() (in the View's logical pixels),
347 /// not a position on the screen.
348 ///
349 /// @return Returns the position (0 for an event without a pointer position).
350 ///
351 double screenY() const { return ulDOMEventGetScreenY(raw()); }
352
353 ///
354 /// Get the button that caused the event (button).
355 ///
356 /// @return Returns 0 for the left button, 1 for middle, 2 for right, 3 for back, or 4 for
357 /// forward (0 for an event no button caused, like `mousemove` or `wheel`). Returns -1
358 /// for a `pointermove` without a button change, or for an event that isn't a mouse
359 /// event.
360 ///
361 int button() const { return ulDOMEventGetButton(raw()); }
362
363 ///
364 /// Get the buttons held down during the event (buttons).
365 ///
366 /// @return Returns a bitmask of 1 for left, 2 for right, 4 for middle, 8 for back, and 16 for
367 /// forward (always 0 for `wheel`).
368 ///
369 unsigned buttons() const { return ulDOMEventGetButtons(raw()); }
370
371 ///
372 /// Whether or not the Control key was held down (ctrlKey).
373 ///
374 bool ctrlKey() const { return ulDOMEventGetCtrlKey(raw()); }
375
376 ///
377 /// Whether or not the Shift key was held down (shiftKey).
378 ///
379 bool shiftKey() const { return ulDOMEventGetShiftKey(raw()); }
380
381 ///
382 /// Whether or not the Alt key was held down (altKey).
383 ///
384 bool altKey() const { return ulDOMEventGetAltKey(raw()); }
385
386 ///
387 /// Whether or not the Meta key was held down (metaKey).
388 ///
389 bool metaKey() const { return ulDOMEventGetMetaKey(raw()); }
390
391 ///
392 /// Get the other element of a mouse transition (relatedTarget).
393 ///
394 /// On `mouseover` and `mouseenter` this is the element the pointer left. On `mouseout` and
395 /// `mouseleave` it's the element the pointer entered.
396 ///
397 /// @return Returns the element (empty if there's none).
398 ///
399 Element relatedTarget() const;
400};
401
402///
403/// A wheel event (WheelEvent).
404///
405/// Get one with Event::AsWheel(). It adds the scroll amounts to the MouseEvent getters. The
406/// position and modifier keys work as for any mouse event, but button() and buttons() always
407/// read 0.
408///
409class WheelEvent : public MouseEvent {
410 public:
411 ///
412 /// Wrap an event handle from the C API (Event::AsWheel() is the usual way to get one).
413 ///
414 /// @param borrowed The event handle passed to a C listener callback.
415 ///
416 explicit WheelEvent(ULDOMEvent borrowed) : MouseEvent(borrowed) {}
417
418 ///
419 /// Get the horizontal scroll amount (deltaX).
420 ///
421 /// @return Returns the amount, in the unit deltaMode() gives (0 for an event that isn't a
422 /// wheel event).
423 ///
424 double deltaX() const { return ulDOMEventGetDeltaX(raw()); }
425
426 ///
427 /// Get the vertical scroll amount (deltaY).
428 ///
429 /// @return Returns the amount, in the unit deltaMode() gives (0 for an event that isn't a
430 /// wheel event).
431 ///
432 double deltaY() const { return ulDOMEventGetDeltaY(raw()); }
433
434 ///
435 /// Get the unit of the scroll amounts (deltaMode).
436 ///
437 /// @return Returns 0 for pixels, 1 for lines, or 2 for pages. Wheel events from
438 /// View::FireScrollEvent() are in pixels or pages (ScrollEvent::kType_ScrollByPixel
439 /// or ScrollEvent::kType_ScrollByPage).
440 ///
441 unsigned deltaMode() const { return ulDOMEventGetDeltaMode(raw()); }
442};
443
444///
445/// A keyboard event (KeyboardEvent).
446///
447/// Get one with Event::AsKeyboard(). It works for `keydown`, `keyup`, and `keypress`.
448///
449class KeyboardEvent : public Event {
450 public:
451 ///
452 /// Wrap an event handle from the C API (Event::AsKeyboard() is the usual way to get one).
453 ///
454 /// @param borrowed The event handle passed to a C listener callback.
455 ///
456 explicit KeyboardEvent(ULDOMEvent borrowed) : Event(borrowed) {}
457
458 ///
459 /// Get the key's value (key).
460 ///
461 /// @return Returns the value (eg, `a`, `Enter`, or `ArrowLeft`). Returns an empty string for
462 /// an event that isn't a keyboard event.
463 ///
464 std::string key() const { return detail::TakeString(ulDOMEventGetKey(raw())); }
465
466 ///
467 /// Get the physical key (code).
468 ///
469 /// @return Returns the physical key (eg, `KeyA` or `Numpad1`). Returns an empty string if it
470 /// isn't known.
471 ///
472 /// @note The physical key is known only for a KeyEvent you created from a Windows key
473 /// message. For other key events this is empty, so use key() in code that must work on
474 /// every platform.
475 ///
476 std::string code() const { return detail::TakeString(ulDOMEventGetCode(raw())); }
477
478 ///
479 /// Get the key's location on the keyboard (location).
480 ///
481 /// @return Returns 0 for a standard key, 1 for the left key of a pair (eg, left Shift), 2 for
482 /// the right one, or 3 for the numeric keypad.
483 ///
484 unsigned location() const { return ulDOMEventGetKeyLocation(raw()); }
485
486 ///
487 /// Whether or not the key is held down and repeating (repeat).
488 ///
489 bool repeat() const { return ulDOMEventGetRepeat(raw()); }
490
491 ///
492 /// Whether or not the event happened during IME composition (isComposing).
493 ///
494 bool isComposing() const { return ulDOMEventIsComposing(raw()); }
495
496 ///
497 /// Whether or not the Control key was held down (ctrlKey).
498 ///
499 bool ctrlKey() const { return ulDOMEventGetCtrlKey(raw()); }
500
501 ///
502 /// Whether or not the Shift key was held down (shiftKey).
503 ///
504 bool shiftKey() const { return ulDOMEventGetShiftKey(raw()); }
505
506 ///
507 /// Whether or not the Alt key was held down (altKey).
508 ///
509 bool altKey() const { return ulDOMEventGetAltKey(raw()); }
510
511 ///
512 /// Whether or not the Meta key was held down (metaKey).
513 ///
514 bool metaKey() const { return ulDOMEventGetMetaKey(raw()); }
515};
516
517///
518/// A focus event (FocusEvent).
519///
520/// Get one with Event::AsFocus(). It adds the other element of the focus change. It works for
521/// `focus`, `blur`, `focusin`, and `focusout`.
522///
523class FocusEvent : public Event {
524 public:
525 ///
526 /// Wrap an event handle from the C API (Event::AsFocus() is the usual way to get one).
527 ///
528 /// @param borrowed The event handle passed to a C listener callback.
529 ///
530 explicit FocusEvent(ULDOMEvent borrowed) : Event(borrowed) {}
531
532 ///
533 /// Get the other element of the focus change (relatedTarget).
534 ///
535 /// On `focus` and `focusin` this is the element losing focus. On `blur` and `focusout` it's the
536 /// element gaining focus.
537 ///
538 /// @return Returns the element (empty if there's none).
539 ///
540 Element relatedTarget() const;
541};
542
543///
544/// An edit to an editable element (InputEvent).
545///
546/// Get one with Event::AsInput(). It adds the kind of edit and the inserted text. It works for
547/// the `input` events that typing and editing fire.
548///
549/// @note Changing a checkbox, a radio button, or a `<select>` fires a plain `input` event, so
550/// both getters return nullopt for it.
551///
552class InputEvent : public Event {
553 public:
554 ///
555 /// Wrap an event handle from the C API (Event::AsInput() is the usual way to get one).
556 ///
557 /// @param borrowed The event handle passed to a C listener callback.
558 ///
559 explicit InputEvent(ULDOMEvent borrowed) : Event(borrowed) {}
560
561 ///
562 /// Get the kind of edit (inputType).
563 ///
564 /// @return Returns the kind of edit (eg, `insertText` or `deleteContentBackward`). Returns
565 /// nullopt if the event isn't an InputEvent.
566 ///
567 std::optional<std::string> inputType() const {
568 ULString s = ulDOMEventGetInputType(raw());
569 if (!s)
570 return std::nullopt;
571 return detail::TakeString(s);
572 }
573
574 ///
575 /// Get the inserted text (data).
576 ///
577 /// @return Returns the text (nullopt if the edit inserted none, eg, a deletion).
578 ///
579 std::optional<std::string> data() const {
580 ULString s = ulDOMEventGetData(raw());
581 if (!s)
582 return std::nullopt;
583 return detail::TakeString(s);
584 }
585};
586
587///
588/// A form submission event (SubmitEvent).
589///
590/// Get one with Event::AsSubmit() in a `submit` listener. It adds the button that submitted the
591/// form.
592///
593class SubmitEvent : public Event {
594 public:
595 ///
596 /// Wrap an event handle from the C API (Event::AsSubmit() is the usual way to get one).
597 ///
598 /// @param borrowed The event handle passed to a C listener callback.
599 ///
600 explicit SubmitEvent(ULDOMEvent borrowed) : Event(borrowed) {}
601
602 ///
603 /// Get the button that submitted the form (submitter).
604 ///
605 /// @return Returns the button (empty if no button submitted the form, eg,
606 /// HTMLFormElement::requestSubmit() without one).
607 ///
608 Element submitter() const;
609};
610
612 return MouseEvent(borrowed_);
613}
615 return WheelEvent(borrowed_);
616}
618 return KeyboardEvent(borrowed_);
619}
621 return FocusEvent(borrowed_);
622}
624 return InputEvent(borrowed_);
625}
627 return SubmitEvent(borrowed_);
628}
629
630///
631/// An event with a string payload (CustomEvent).
632///
633/// Get one with Event::AsCustom(). Dispatch one from native code with
634/// Element::dispatchCustomEvent().
635///
636class CustomEvent : public Event {
637 public:
638 ///
639 /// Wrap an event handle from the C API (Event::AsCustom() is the usual way to get one).
640 ///
641 /// @param borrowed The event handle passed to a C listener callback.
642 ///
643 explicit CustomEvent(ULDOMEvent borrowed) : Event(borrowed) {}
644
645 ///
646 /// Get the string payload (detail).
647 ///
648 /// @return Returns the payload (nullopt if the event has none or isn't a CustomEvent).
649 ///
650 /// @note Only a payload dispatched from native code is readable here. A `detail` set by page
651 /// script reads as nullopt, so use a js::API function to get data from page script.
652 ///
653 std::optional<std::string> detail() const {
654 ULString payload = ulDOMEventGetCustomDetail(raw());
655 if (!payload)
656 return std::nullopt;
657 return dom::detail::TakeString(payload);
658 }
659};
660
662 return CustomEvent(borrowed_);
663}
664
665/// \cond INTERNAL
666namespace detail {
667
668// Detects a listener callable by calling it with a prvalue Event, the way the listener thunks
669// do. std::is_invocable would pass an xvalue, which needs the move constructor Event lacks.
670template <typename Fn, typename... Rest>
671concept InvocableWithEvent = requires(Fn& fn, ULDOMEvent event, Rest&&... rest) {
672 fn(Event(event), static_cast<Rest&&>(rest)...);
673};
674
675} // namespace detail
676/// \endcond
677
678} // namespace dom
679} // namespace ultralight
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
An edit to an editable element (InputEvent).
Definition Event.h:552
std::optional< std::string > inputType() const
Get the kind of edit (inputType).
Definition Event.h:567
std::optional< std::string > data() const
Get the inserted text (data).
Definition Event.h:579
InputEvent(ULDOMEvent borrowed)
Wrap an event handle from the C API (Event::AsInput() is the usual way to get one).
Definition Event.h:559
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