Wren a web browser where WebAssembly runs everything, JavaScript included

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.

memberbit
Capture0Run in the capture phase.
Once1Remove the listener after its first call.
Passive2The listener will not call preventDefault.

flags EventInit : u32

What dispatchEvent creates.

memberbit
Bubbles0
Cancelable1
Composed2The 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.

fieldtype
client_xf64clientX / clientY (CSS px, viewport)
client_yf64
screen_xf64screenX / screenY
screen_yf64
page_xf64pageX / pageY (the document's scroll offsets added)
page_yf64
offset_xf64offsetX / offsetY (from the target's padding edge)
offset_yf64
delta_xf64deltaX / deltaY / deltaZ (WheelEvent)
delta_yf64
delta_zf64
relatedu64relatedTarget (a node), 0 = null
modsu32modifier bits: 1 ctrl, 2 shift, 4 alt, 8 meta
buttoni32MouseEvent.button
buttonsu32MouseEvent.buttons
detaili32UIEvent.detail
key_codeu32KeyboardEvent.keyCode (and which, charCode for keypress)
locationu32KeyboardEvent.location
repeatu32KeyboardEvent.repeat
delta_modeu32WheelEvent.deltaMode
pointer_idi32PointerEvent.pointerId (1 for the mouse)
pointer_typeu32PointerEvent.pointerType: 0 mouse, 1 pen, 2 touch
is_primaryu32PointerEvent.isPrimary
pressuref64PointerEvent.pressure, tangentialPressure
tangential_pressuref64
widthf64PointerEvent.width / height (CSS px)
heightf64
tilt_xf64PointerEvent.tiltX / tiltY / twist (degrees)
tilt_yf64
twistf64

struct TouchPoint

A Touch of a TouchEvent.

fieldtype
identifieri32
targetu64the element the touch started on
client_xf64
client_yf64
screen_xf64
screen_yf64
page_xf64
page_yf64
radius_xf64
radius_yf64
rotation_anglef64
forcef64

enum TouchListKind : i32

The lists of a TouchEvent.

membervalue
Touches0
Target_Touches1
Changed_Touches2

Functions

EventTarget_addEventListener

i32 EventTarget_addEventListener(EventTarget target, string type, EventListener callback, i32 user = 0, ListenerOptions options = none) raises

target.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) raises

target.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) raises

target.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) raises

A 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) raises

Element.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) raises

Element.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) raises

target.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

Edit this page on GitHub