|
Ultralight C++ API 2.0.0
|
#include <Ultralight/dom/Event.h>
A page event (such as a click or key press) received by a listener callback.
When an action occurs on a page– like a click or key press– the library delivers an Event to your listener callback. It works like the JavaScript event object.
This listener cancels a form submission to handle it in native code:
An Event is valid only during the callback that received it. Listener callbacks take it by value, and you can't copy, move, or store it.
Pass an Event to helper functions by const reference:
Handles you get from the event (like target() and currentTarget()) are ordinary DOM handles you can keep after the callback returns.
Each typed view provides access to properties specific to that kind of event:
| View | Fields Added |
|---|---|
| AsMouse() | Position, buttons, and modifier keys |
| AsWheel() | Scroll deltas |
| AsKeyboard() | Key, code, and modifier keys |
| AsFocus() | Element gaining or losing focus |
| AsInput() | Edit kind and inserted text |
| AsSubmit() | Button that submitted the form |
| AsCustom() | String payload |
Calling a view method on an event of a different type returns fallback values rather than failing. If a single callback handles multiple event types, check type() before converting the event.
This listener checks the key pressed during a keyboard event:
Public Member Functions | |
| Event (ULDOMEvent borrowed) | |
| Wrap an event handle from the C API. | |
| Event (const Event &)=delete | |
| Event & | operator= (const Event &)=delete |
| std::string | type () const |
| Get the event's type (type). | |
| unsigned | eventPhase () const |
| Get the current dispatch phase (eventPhase). | |
| bool | bubbles () const |
| Whether or not the event bubbles up the tree (bubbles). | |
| bool | cancelable () const |
| Whether or not preventDefault() can cancel the event (cancelable). | |
| bool | isTrusted () const |
| Whether or not the event came from user input or the library (isTrusted). | |
| double | timeStamp () const |
| Get the time the event was created (timeStamp). | |
| bool | defaultPrevented () const |
| Whether or not the event was canceled (defaultPrevented). | |
| void | preventDefault () const |
| Cancel the event's default action (preventDefault). | |
| void | stopPropagation () const |
| Stop the event from reaching other targets (stopPropagation). | |
| void | stopImmediatePropagation () const |
| Stop the event from reaching any other listener (stopImmediatePropagation). | |
| Element | target () const |
| Get the element the event was dispatched to (target). | |
| Node | targetNode () const |
| Get the node the event was dispatched to (target). | |
| Element | currentTarget () const |
| Get the element whose listener is running (currentTarget). | |
| MouseEvent | AsMouse () const |
| View this event as a MouseEvent. | |
| WheelEvent | AsWheel () const |
| View this event as a WheelEvent. | |
| KeyboardEvent | AsKeyboard () const |
| View this event as a KeyboardEvent. | |
| FocusEvent | AsFocus () const |
| View this event as a FocusEvent. | |
| InputEvent | AsInput () const |
| View this event as an InputEvent. | |
| SubmitEvent | AsSubmit () const |
| View this event as a SubmitEvent. | |
| CustomEvent | AsCustom () const |
| View this event as a CustomEvent. | |
| ULDOMEvent | raw () const |
| Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMEvent.h> functions. | |
|
inlineexplicit |
|
delete |
|
inline |
View this event as a CustomEvent.
|
inline |
View this event as a FocusEvent.
|
inline |
View this event as an InputEvent.
|
inline |
View this event as a KeyboardEvent.
|
inline |
View this event as a MouseEvent.
|
inline |
View this event as a SubmitEvent.
|
inline |
View this event as a WheelEvent.
|
inline |
Whether or not the event bubbles up the tree (bubbles).
|
inline |
Whether or not preventDefault() can cancel the event (cancelable).
|
inline |
Get the element whose listener is running (currentTarget).
|
inline |
Whether or not the event was canceled (defaultPrevented).
|
inline |
Get the current dispatch phase (eventPhase).
|
inline |
Whether or not the event came from user input or the library (isTrusted).
Events from user input and the page (eg, load) are trusted. Events dispatched by page script, or with Element::dispatchEvent() or Element::click(), aren't.
|
inline |
Cancel the event's default action (preventDefault).
This stops what the library would do in response to the event (like submitting a form, following a link, or toggling a checkbox).
|
inline |
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMEvent.h> functions.
|
inline |
Stop the event from reaching any other listener (stopImmediatePropagation).
Unlike stopPropagation(), this also skips the remaining listeners on the current target.
|
inline |
Stop the event from reaching other targets (stopPropagation).
The remaining listeners on the current target still run.
|
inline |
Get the element the event was dispatched to (target).
|
inline |
Get the node the event was dispatched to (target).
Use this instead of target() when the target can be a text node or another node that isn't an element.
|
inline |
Get the time the event was created (timeStamp).
|
inline |
Get the event's type (type).