pub trait EventHandler {
fn get_subscription(&mut self) -> Option<EVENT_GROUPS> { ... }
fn attached(&mut self, root: HELEMENT) { ... }
fn detached(&mut self, root: HELEMENT) { ... }
fn document_complete(&mut self, root: HELEMENT, target: HELEMENT) { ... }
fn document_close(&mut self, root: HELEMENT, target: HELEMENT) { ... }
fn on_method_call(
&mut self,
root: HELEMENT,
params: MethodParams<'_>
) -> bool { ... }
fn on_script_call(
&mut self,
root: HELEMENT,
name: &str,
args: &[Value]
) -> Option<Value> { ... }
fn on_event(
&mut self,
root: HELEMENT,
source: HELEMENT,
target: HELEMENT,
code: BEHAVIOR_EVENTS,
phase: PHASE_MASK,
reason: EventReason
) -> bool { ... }
fn on_timer(&mut self, root: HELEMENT, timer_id: u64) -> bool { ... }
fn on_draw(
&mut self,
root: HELEMENT,
gfx: HGFX,
area: &RECT,
layer: DRAW_EVENTS
) -> bool { ... }
fn on_size(&mut self, root: HELEMENT) { ... }
}
Expand description
DOM event handler which can be attached to any DOM element.
In notifications:
root
means the DOM element to which we are attached (<html>
forWindow
event handlers).target
contains a reference to the notification target DOM element.source
element e.g. inSELECTION_CHANGED
it is the new selected<option>
, inMENU_ITEM_CLICK
it is a menu item (<li>
) element.
For example, if we are attached to the <body>
element,
we will receive document_complete
with target
set to <html>
.
Provided methods
fn get_subscription(&mut self) -> Option<EVENT_GROUPS>
fn get_subscription(&mut self) -> Option<EVENT_GROUPS>
Return a list of event groups this event handler is subscribed to.
Default are HANDLE_BEHAVIOR_EVENT | HANDLE_SCRIPTING_METHOD_CALL | HANDLE_METHOD_CALL
.
See also default_events()
.
Called when handler was attached to element or window.
root
is NULL
if attaching to window without loaded document.
Subscription: always.
Called when handler was detached from element or window.
Subscription: always.
fn document_complete(&mut self, root: HELEMENT, target: HELEMENT)
fn document_complete(&mut self, root: HELEMENT, target: HELEMENT)
Notification that document finishes its loading - all requests for external resources are finished.
Subscription: requires HANDLE_BEHAVIOR_EVENT
,
but will be sent only for the root element (<html>
).
fn document_close(&mut self, root: HELEMENT, target: HELEMENT)
fn document_close(&mut self, root: HELEMENT, target: HELEMENT)
The last notification before document removal from the DOM.
Subscription: requires HANDLE_BEHAVIOR_EVENT
,
but will be sent only for the root element (<html>
).
fn on_method_call(&mut self, root: HELEMENT, params: MethodParams<'_>) -> bool
fn on_method_call(&mut self, root: HELEMENT, params: MethodParams<'_>) -> bool
Behavior method calls from script or other behaviors.
Return false
to skip this event.
Subscription: requires HANDLE_METHOD_CALL
.
Script calls from CSSS! script and TIScript.
Return None
to skip this event.
Subscription: requires HANDLE_SCRIPTING_METHOD_CALL
.
fn on_event(
&mut self,
root: HELEMENT,
source: HELEMENT,
target: HELEMENT,
code: BEHAVIOR_EVENTS,
phase: PHASE_MASK,
reason: EventReason
) -> bool
fn on_event(
&mut self,
root: HELEMENT,
source: HELEMENT,
target: HELEMENT,
code: BEHAVIOR_EVENTS,
phase: PHASE_MASK,
reason: EventReason
) -> bool
Notification event from builtin behaviors.
Return false
to skip this event.
Subscription: requires HANDLE_BEHAVIOR_EVENT
.
Timer event from attached element.
Return false
to skip this event.
Subscription: requires HANDLE_TIMER
.
Drawing request event.
It allows to intercept drawing events of an Element
and to manually draw its content, background and foreground layers.
Return false
to skip this event.
Subscription: requires HANDLE_DRAW
.
Size changed event.
Subscription: requires HANDLE_SIZE
.