Module events
Events (DOM Standard: EventTarget, Event; UI Events: MouseEvent, KeyboardEvent). Any node and any host object (a promise, a socket, a worker, an abort signal...) is an EventTarget. An Event handle is valid while its listeners run.
Exposed to: Window, Worker. Source: api/events.widl.
Odin: import "wren:core".
Types
handle EventTarget
A node or a host object: whatever can have listeners. Checked by the functions that take it.
handle Event
The event being dispatched.
Checked by the browser on every call (lookup_Event).
flags ListenerOptions : u32
addEventListener options.
| member | bit | |
|---|---|---|
Capture | 0 | Run in the capture phase. |
Once | 1 | Remove the listener after its first call. |
Passive | 2 | The listener will not call preventDefault. |
flags EventInit : u32
What dispatchEvent creates.
| member | bit | |
|---|---|---|
Bubbles | 0 | |
Cancelable | 1 | |
Composed | 2 | The event crosses shadow roots: its path goes on to the hosts (targets retargeted). |
callback EventListener
void EventListener(i32 user, Event event)A listener: user is the value given to addEventListener.
struct UiEventData
The numeric details of a UI event.
| field | type | |
|---|---|---|
client_x | f64 | clientX / clientY (CSS px, viewport) |
client_y | f64 | |
screen_x | f64 | screenX / screenY |
screen_y | f64 | |
page_x | f64 | pageX / pageY (the document's scroll offsets added) |
page_y | f64 | |
offset_x | f64 | offsetX / offsetY (from the target's padding edge) |
offset_y | f64 | |
delta_x | f64 | deltaX / deltaY / deltaZ (WheelEvent) |
delta_y | f64 | |
delta_z | f64 | |
related | u64 | relatedTarget (a node), 0 = null |
mods | u32 | modifier bits: 1 ctrl, 2 shift, 4 alt, 8 meta |
button | i32 | MouseEvent.button |
buttons | u32 | MouseEvent.buttons |
detail | i32 | UIEvent.detail |
key_code | u32 | KeyboardEvent.keyCode (and which, charCode for keypress) |
location | u32 | KeyboardEvent.location |
repeat | u32 | KeyboardEvent.repeat |
delta_mode | u32 | WheelEvent.deltaMode |
pointer_id | i32 | PointerEvent.pointerId (1 for the mouse) |
pointer_type | u32 | PointerEvent.pointerType: 0 mouse, 1 pen, 2 touch |
is_primary | u32 | PointerEvent.isPrimary |
pressure | f64 | PointerEvent.pressure, tangentialPressure |
tangential_pressure | f64 | |
width | f64 | PointerEvent.width / height (CSS px) |
height | f64 | |
tilt_x | f64 | PointerEvent.tiltX / tiltY / twist (degrees) |
tilt_y | f64 | |
twist | f64 |
struct TouchPoint
A Touch of a TouchEvent.
| field | type | |
|---|---|---|
identifier | i32 | |
target | u64 | the element the touch started on |
client_x | f64 | |
client_y | f64 | |
screen_x | f64 | |
screen_y | f64 | |
page_x | f64 | |
page_y | f64 | |
radius_x | f64 | |
radius_y | f64 | |
rotation_angle | f64 | |
force | f64 |
enum TouchListKind : i32
The lists of a TouchEvent.
| member | value | |
|---|---|---|
Touches | 0 | |
Target_Touches | 1 | |
Changed_Touches | 2 |
Functions
EventTarget_addEventListener
i32 EventTarget_addEventListener(EventTarget target, string type, EventListener callback, i32 user = 0, ListenerOptions options = none) raisestarget.addEventListener(type, listener, options). Returns the listener's id (for removeEventListener); adding the same (type, callback, user) again returns the existing id.
Raises: returns an Error (see web).
Host: EventTarget_addEventListener :: proc(c: ^Call, target: u64, type: string, callback: u32, user: i32, options: Api_ListenerOptions) -> (i32, Api_Error)
EventTarget_removeEventListener
void EventTarget_removeEventListener(EventTarget target, i32 id) raisestarget.removeEventListener(id). Not_Found when there is no such listener.
Raises: returns an Error (see web).
Host: EventTarget_removeEventListener :: proc(c: ^Call, target: u64, id: i32) -> Api_Error
EventTarget_dispatchEvent
bool EventTarget_dispatchEvent(EventTarget target, string type, EventInit init = none) raisestarget.dispatchEvent(new Event(type, init)): false when a listener cancelled it.
Raises: returns an Error (see web).
Host: EventTarget_dispatchEvent :: proc(c: ^Call, target: u64, type: string, init: Api_EventInit) -> (bool, Api_Error)
Event_preventDefault
void Event_preventDefault(Event event)event.preventDefault() (ignored when the event is not cancelable).
Host: Event_preventDefault :: proc(c: ^Call, event: Api_Event)
Event_stopPropagation
void Event_stopPropagation(Event event)event.stopPropagation()
Host: Event_stopPropagation :: proc(c: ^Call, event: Api_Event)
Event_stopImmediatePropagation
void Event_stopImmediatePropagation(Event event)event.stopImmediatePropagation()
Host: Event_stopImmediatePropagation :: proc(c: ^Call, event: Api_Event)
Event_target
EventTarget Event_target(Event event)event.target
Host: Event_target :: proc(c: ^Call, event: Api_Event) -> u64
Event_currentTarget
EventTarget Event_currentTarget(Event event)event.currentTarget
Host: Event_currentTarget :: proc(c: ^Call, event: Api_Event) -> u64
Event_type
string Event_type(Event event)event.type
Host: Event_type :: proc(c: ^Call, event: Api_Event) -> string
Event_defaultPrevented
bool Event_defaultPrevented(Event event)event.defaultPrevented
Host: Event_defaultPrevented :: proc(c: ^Call, event: Api_Event) -> bool
Event_data
string Event_data(Event event)The main string payload of a non-UI event: MessageEvent.data, InputEvent.data, ErrorEvent.message...
Host: Event_data :: proc(c: ^Call, event: Api_Event) -> string
Event_text
string Event_text(Event event)The second string payload: CloseEvent.reason, InputEvent.inputType, MessageEvent.lastEventId, the reason of an abort...
Host: Event_text :: proc(c: ^Call, event: Api_Event) -> string
Event_code
i64 Event_code(Event event)The numeric payload: CloseEvent.code, an abort reason's code, the number of buffers of a message...
Host: Event_code :: proc(c: ^Call, event: Api_Event) -> i64
Event_object
EventTarget Event_object(Event event)The object payload: a buffer, SubmitEvent.submitter, FocusEvent.relatedTarget, FormDataEvent.formData...
Host: Event_object :: proc(c: ^Call, event: Api_Event) -> u64
MouseEvent_clientX
f64 MouseEvent_clientX(Event event)MouseEvent.clientX
Host: MouseEvent_clientX :: proc(c: ^Call, event: Api_Event) -> f64
MouseEvent_clientY
f64 MouseEvent_clientY(Event event)MouseEvent.clientY
Host: MouseEvent_clientY :: proc(c: ^Call, event: Api_Event) -> f64
MouseEvent_button
i32 MouseEvent_button(Event event)MouseEvent.button
Host: MouseEvent_button :: proc(c: ^Call, event: Api_Event) -> i32
KeyboardEvent_keyCode
i32 KeyboardEvent_keyCode(Event event)KeyboardEvent.keyCode
Host: KeyboardEvent_keyCode :: proc(c: ^Call, event: Api_Event) -> i32
TouchEvent_count
i32 TouchEvent_count(Event event, TouchListKind list)The number of touches in a list of a TouchEvent the browser dispatches (0 for another event).
Host: TouchEvent_count :: proc(c: ^Call, event: Api_Event, list: Api_TouchListKind) -> i32
TouchEvent_touch
TouchPoint TouchEvent_touch(Event event, TouchListKind list, i32 index) raisesA touch of that list (Invalid_Argument past its end).
Raises: returns an Error (see web).
Host: TouchEvent_touch :: proc(c: ^Call, event: Api_Event, list: Api_TouchListKind, index: i32) -> (Api_TouchPoint, Api_Error)
PointerCapture_set
void PointerCapture_set(Element element, i32 pointer_id) raisesElement.setPointerCapture(pointerId): Not_Found for a pointer that is not active, Invalid_State for an element that is not connected. The capture takes effect at the pointer's next event (gotpointercapture).
Raises: returns an Error (see web).
Host: PointerCapture_set :: proc(c: ^Call, element: Api_Element, pointer_id: i32) -> Api_Error
PointerCapture_release
void PointerCapture_release(Element element, i32 pointer_id) raisesElement.releasePointerCapture(pointerId): Not_Found for a pointer that is not active.
Raises: returns an Error (see web).
Host: PointerCapture_release :: proc(c: ^Call, element: Api_Element, pointer_id: i32) -> Api_Error
PointerCapture_has
bool PointerCapture_has(Element element, i32 pointer_id)Element.hasPointerCapture(pointerId)
Host: PointerCapture_has :: proc(c: ^Call, element: Api_Element, pointer_id: i32) -> bool
Event_uiData
UiEventData Event_uiData(Event event)The details of a UI event being dispatched.
Host: Event_uiData :: proc(c: ^Call, event: Api_Event) -> Api_UiEventData
UiEvent_key
string UiEvent_key(Event event)KeyboardEvent.key ("Enter", "a"...): "Unidentified" when unknown.
Host: UiEvent_key :: proc(c: ^Call, event: Api_Event) -> string
UiEvent_code
string UiEvent_code(Event event)KeyboardEvent.code ("KeyA", "Enter"...): "" when unknown.
Host: UiEvent_code :: proc(c: ^Call, event: Api_Event) -> string
EventTarget_dispatchEngineEvent
bool EventTarget_dispatchEngineEvent(EventTarget target, string type, EventInit init, i64 engine_id, f64 time_stamp) raisestarget.dispatchEvent(event) for an Event the engine owns: like EventTarget_dispatchEvent, with the engine's identifier of the object (Event_engineId gives it back to the listeners) and its timeStamp. Returns false when a listener cancelled it. The event is not trusted (isTrusted is false).
Raises: returns an Error (see web).
Host: EventTarget_dispatchEngineEvent :: proc(c: ^Call, target: u64, type: string, init: Api_EventInit, engine_id: i64, time_stamp: f64) -> (bool, Api_Error)
Event_engineId
i64 Event_engineId(Event event)The engine's identifier given to EventTarget_dispatchEngineEvent (0 for an event the browser made).
Host: Event_engineId :: proc(c: ^Call, event: Api_Event) -> i64
Event_interface
u32 Event_interface(Event event)The interface of the wrapper of an event the browser made (MouseEvent, KeyboardEvent...): an index into the engine's interface table.
Host: Event_interface :: proc(c: ^Call, event: Api_Event) -> u32
Event_isLive
bool Event_isLive(u64 event)Whether the event is still being dispatched (its handle is live).
Host: Event_isLive :: proc(c: ^Call, event: u64) -> bool
Event_bubbles
bool Event_bubbles(Event event)event.bubbles
Host: Event_bubbles :: proc(c: ^Call, event: Api_Event) -> bool
Event_cancelable
bool Event_cancelable(Event event)event.cancelable
Host: Event_cancelable :: proc(c: ^Call, event: Api_Event) -> bool
Event_composed
bool Event_composed(Event event)event.composed: whether the event crosses shadow boundaries (the browser's UI events, fullscreenchange...).
Host: Event_composed :: proc(c: ^Call, event: Api_Event) -> bool
Event_eventPhase
i32 Event_eventPhase(Event event)event.eventPhase: 0 none, 1 capturing, 2 at target, 3 bubbling.
Host: Event_eventPhase :: proc(c: ^Call, event: Api_Event) -> i32
Event_timeStamp
f64 Event_timeStamp(Event event)event.timeStamp, on the performance.now() timeline of the page.
Host: Event_timeStamp :: proc(c: ^Call, event: Api_Event) -> f64
Event_isTrusted
bool Event_isTrusted(Event event)event.isTrusted
Host: Event_isTrusted :: proc(c: ^Call, event: Api_Event) -> bool
Event_propagationStopped
bool Event_propagationStopped(Event event)Whether stopPropagation was called.
Host: Event_propagationStopped :: proc(c: ^Call, event: Api_Event) -> bool
EventTarget_create
Object EventTarget_create()new EventTarget(): a host object with nothing but listeners.
Host: EventTarget_create :: proc(c: ^Call) -> u64
Event_composedPathPacked
bytes Event_composedPathPacked(Event event)event.composedPath() of the event being dispatched: what a listener at the current target may see (closed shadow trees it is not in are hidden); 8 bytes per handle, the Window's handle for the Window.
Host: Event_composedPathPacked :: proc(c: ^Call, event: Api_Event) -> []u8
EventTarget_lastTarget
u64 EventTarget_lastTarget()The target of the last event dispatched by EventTarget_dispatchEngineEvent once its dispatch ended (0: null, it was in a shadow tree).
Host: EventTarget_lastTarget :: proc(c: ^Call) -> u64
EventTarget_lastRelated
u64 EventTarget_lastRelated()... and its relatedTarget (0: null or cleared).
Host: EventTarget_lastRelated :: proc(c: ^Call) -> u64
Event_setNextRelated
void Event_setNextRelated(u64 related)The relatedTarget (a node) of the next EventTarget_dispatchEngineEvent: retargeted along its path.
Host: Event_setNextRelated :: proc(c: ^Call, related: u64)
Event_relatedNow
u64 Event_relatedNow(Event event)The relatedTarget of the event being dispatched as the current listener sees it (retargeted; 0: null).
Host: Event_relatedNow :: proc(c: ^Call, event: Api_Event) -> u64
Event_inShadowTreeNow
bool Event_inShadowTreeNow(u64 event)Whether the current listener's node was in a shadow tree when the event's path was built (window.event is then left as it was).
Host: Event_inShadowTreeNow :: proc(c: ^Call, event: u64) -> bool