DomEvent abstract class
abstract class DomEvent extends DwtEvent implements HasNativeEvent { dart_html.Event _nativeEvent; dart_html.Element _relativeElem; static Map<String, DomEventType> _registered; static Map<String, DomEventType> getRegistered() { if (_registered == null) { _registered = new Map<String, DomEventType>(); } return _registered; } /** * The event type. */ static EventType<EventHandler> TYPE = new EventType<EventHandler>(); EventType<EventHandler> getAssociatedType() { return TYPE; } DomEvent(); /** * Fires the given native event on the specified handlers. * * @param _nativeEvent the native event * @param handlerSource the source of the handlers to fire * @param _relativeElem the element relative to which event coordinates will be * measured */ static void fireNativeEvent(dart_html.Event nativeEvent, HasHandlers handlerSource, [dart_html.Element relativeElem = null]) { assert (nativeEvent != null); // : "_nativeEvent must not be null"; if (_registered != null) { DomEventType typeKey = _registered[nativeEvent.type]; if (typeKey != null) { // Store and restore native event just in case we are in recursive // loop. dart_html.Event currentNative = typeKey.flyweight._nativeEvent; dart_html.Element currentRelativeElem = typeKey.flyweight._relativeElem; typeKey.flyweight._nativeEvent = nativeEvent; typeKey.flyweight._relativeElem = relativeElem; handlerSource.fireEvent(typeKey.flyweight); typeKey.flyweight._nativeEvent = currentNative; typeKey.flyweight._relativeElem = currentRelativeElem; } } } /** * Prevents the wrapped native event's default action. */ void preventDefault() { assertLive(); _nativeEvent.preventDefault(); } /** * Stops the propagation of the underlying native event. */ void stopPropagation() { assertLive(); _nativeEvent.stopPropagation(); } dart_html.Event getNativeEvent() { assertLive(); return _nativeEvent; } /** * Gets the element relative to which event coordinates will be measured. * If this element is <code>null</code>, event coordinates will be measured * relative to the window's client area. * * @return the event's relative element */ dart_html.Element getRelativeElement() { assertLive(); return _relativeElem; } }
Extends
IEvent<H> > DwtEvent > DomEvent
Subclasses
BlurEvent, ChangeEvent, ErrorEvent, FocusEvent, GestureChangeEvent, GestureEndEvent, GestureStartEvent, HumanInputEvent, KeyEvent, LoadEvent, MouseEvent, ScrollEvent, TouchEvent
Implements
Static Properties
EventType<EventHandler> TYPE #
The event type.
static EventType<EventHandler> TYPE = new EventType<EventHandler>()
Static Methods
Map<String, DomEventType> getRegistered() #
static Map<String, DomEventType> getRegistered() { if (_registered == null) { _registered = new Map<String, DomEventType>(); } return _registered; }
void fireNativeEvent(Event nativeEvent, HasHandlers handlerSource, [Element relativeElem = null]) #
Fires the given native event on the specified handlers.
@param nativeEvent the native event @param handlerSource the source of the handlers to fire @param relativeElem the element relative to which event coordinates will be
measured
static void fireNativeEvent(dart_html.Event nativeEvent, HasHandlers handlerSource, [dart_html.Element relativeElem = null]) { assert (nativeEvent != null); // : "_nativeEvent must not be null"; if (_registered != null) { DomEventType typeKey = _registered[nativeEvent.type]; if (typeKey != null) { // Store and restore native event just in case we are in recursive // loop. dart_html.Event currentNative = typeKey.flyweight._nativeEvent; dart_html.Element currentRelativeElem = typeKey.flyweight._relativeElem; typeKey.flyweight._nativeEvent = nativeEvent; typeKey.flyweight._relativeElem = relativeElem; handlerSource.fireEvent(typeKey.flyweight); typeKey.flyweight._nativeEvent = currentNative; typeKey.flyweight._relativeElem = currentRelativeElem; } } }
Methods
void assertLive() #
Asserts that the event still should be accessed. All events are considered to be "dead" after their original handler manager finishes firing them. An event can be revived by calling {@link GwtEvent#revive()}.
void assertLive() { assert (!_dead) ; //: "This event has already finished being processed by its original handler manager, so you can no longer access it"; }
abstract void dispatch(H handler) #
Implemented by subclasses to invoke their handlers in a type safe
manner. Intended to be called by EventBus#fireEvent(Event)
or
EventBus#fireEventFromSource(Event, Object)
.
@param handler handler @see EventBus#dispatchEvent(Event, Object)
EventType<EventHandler> getAssociatedType() #
Event getNativeEvent() #
dart_html.Event getNativeEvent() { assertLive(); return _nativeEvent; }
Element getRelativeElement() #
Gets the element relative to which event coordinates will be measured. If this element is <code>null</code>, event coordinates will be measured relative to the window's client area.
@return the event's relative element
dart_html.Element getRelativeElement() { assertLive(); return _relativeElem; }
Object getSource() #
Returns the source for this event. The type and meaning of the source is
arbitrary, and is most useful as a secondary key for handler registration.
(See EventBus#addHandlerToSource
, which allows a handler to
register for events of a particular type, tied to a particular source.)
Note that the source is actually set at dispatch time, e.g. via
EventBus#fireEventFromSource(Event, Object)
.
@return object representing the source of this event
Object getSource() { assertLive(); return super.getSource(); }
bool isLive() #
Is the event current live?
@return whether the event is live
bool isLive() { return !_dead; }
void kill() #
Kill the event. After the event has been killed, users cannot really on its values or functions being available.
void kill() { _dead = true; setSource(null); }
void overrideSource(Object source) #
void overrideSource(Object source) { super.setSource(source); }
void preventDefault() #
Prevents the wrapped native event's default action.
void preventDefault() { assertLive(); _nativeEvent.preventDefault(); }
void revive() #
Revives the event. Used when recycling event instances.
void revive() { _dead = false; setSource(null); }
void setSource(source) #
Set the source that triggered this event. Intended to be called by the EventBus during dispatch.
@param source the source of this event. @see EventBus#fireEventFromSource(Event, Object) @see EventBus#setSourceOfEvent(Event, Object)
void setSource(dynamic source) { this._source = source; }
void stopPropagation() #
Stops the propagation of the underlying native event.
void stopPropagation() { assertLive(); _nativeEvent.stopPropagation(); }