Event class
This chapter describes the DOM Event Model. The Event interface itself is described, as well as the interfaces for event registration on nodes in the DOM, and event listeners, and several longer examples that show how the various event interfaces relate to one another.
There is an excellent diagram that clearly explains the three phases of event flow through the DOM in the DOM Level 3 Events draft.
@DomName('Event')
class Event native "Event" {
// In JS, canBubble and cancelable are technically required parameters to
// init*Event. In practice, though, if they aren't provided they simply
// default to false (since that's Boolean(undefined)).
//
// Contrary to JS, we default canBubble and cancelable to true, since that's
// what people want most of the time anyway.
factory Event(String type,
{bool canBubble: true, bool cancelable: true}) {
return new Event.eventType('Event', type, canBubble: canBubble,
cancelable: cancelable);
}
/**
* Creates a new Event object of the specified type.
*
* This is analogous to document.createEvent.
* Normally events should be created via their constructors, if available.
*
* var e = new Event.type('MouseEvent', 'mousedown', true, true);
*/
factory Event.eventType(String type, String name, {bool canBubble: true,
bool cancelable: true}) {
final Event e = document.$dom_createEvent(type);
e.$dom_initEvent(name, canBubble, cancelable);
return e;
}
@DomName('Event.AT_TARGET')
@DocsEditable
static const int AT_TARGET = 2;
@DomName('Event.BLUR')
@DocsEditable
static const int BLUR = 8192;
@DomName('Event.BUBBLING_PHASE')
@DocsEditable
static const int BUBBLING_PHASE = 3;
@DomName('Event.CAPTURING_PHASE')
@DocsEditable
static const int CAPTURING_PHASE = 1;
@DomName('Event.CHANGE')
@DocsEditable
static const int CHANGE = 32768;
@DomName('Event.CLICK')
@DocsEditable
static const int CLICK = 64;
@DomName('Event.DBLCLICK')
@DocsEditable
static const int DBLCLICK = 128;
@DomName('Event.DRAGDROP')
@DocsEditable
static const int DRAGDROP = 2048;
@DomName('Event.FOCUS')
@DocsEditable
static const int FOCUS = 4096;
@DomName('Event.KEYDOWN')
@DocsEditable
static const int KEYDOWN = 256;
@DomName('Event.KEYPRESS')
@DocsEditable
static const int KEYPRESS = 1024;
@DomName('Event.KEYUP')
@DocsEditable
static const int KEYUP = 512;
@DomName('Event.MOUSEDOWN')
@DocsEditable
static const int MOUSEDOWN = 1;
@DomName('Event.MOUSEDRAG')
@DocsEditable
static const int MOUSEDRAG = 32;
@DomName('Event.MOUSEMOVE')
@DocsEditable
static const int MOUSEMOVE = 16;
@DomName('Event.MOUSEOUT')
@DocsEditable
static const int MOUSEOUT = 8;
@DomName('Event.MOUSEOVER')
@DocsEditable
static const int MOUSEOVER = 4;
@DomName('Event.MOUSEUP')
@DocsEditable
static const int MOUSEUP = 2;
@DomName('Event.NONE')
@DocsEditable
static const int NONE = 0;
@DomName('Event.SELECT')
@DocsEditable
static const int SELECT = 16384;
@DomName('Event.bubbles')
@DocsEditable
final bool bubbles;
@DomName('Event.cancelBubble')
@DocsEditable
bool cancelBubble;
@DomName('Event.cancelable')
@DocsEditable
final bool cancelable;
@DomName('Event.clipboardData')
@DocsEditable
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@Experimental
final DataTransfer clipboardData;
EventTarget get currentTarget => _convertNativeToDart_EventTarget(this._get_currentTarget);
@JSName('currentTarget')
@DomName('Event.currentTarget')
@DocsEditable
@Creates('Null')
@Returns('EventTarget|=Object')
final dynamic _get_currentTarget;
@DomName('Event.defaultPrevented')
@DocsEditable
final bool defaultPrevented;
@DomName('Event.eventPhase')
@DocsEditable
final int eventPhase;
EventTarget get target => _convertNativeToDart_EventTarget(this._get_target);
@JSName('target')
@DomName('Event.target')
@DocsEditable
@Creates('Node')
@Returns('EventTarget|=Object')
final dynamic _get_target;
@DomName('Event.timeStamp')
@DocsEditable
final int timeStamp;
@DomName('Event.type')
@DocsEditable
final String type;
@JSName('initEvent')
@DomName('Event.initEvent')
@DocsEditable
void $dom_initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) native;
@DomName('Event.preventDefault')
@DocsEditable
void preventDefault() native;
@DomName('Event.stopImmediatePropagation')
@DocsEditable
void stopImmediatePropagation() native;
@DomName('Event.stopPropagation')
@DocsEditable
void stopPropagation() native;
}
Extends
Interceptor > Event
Subclasses
AnimationEvent, AudioProcessingEvent, AutocompleteErrorEvent, BeforeLoadEvent, BeforeUnloadEvent, CloseEvent, ContextEvent, CssFontFaceLoadEvent, CustomEvent, DeviceMotionEvent, DeviceOrientationEvent, ErrorEvent, HashChangeEvent, MediaKeyEvent, MediaStreamEvent, MediaStreamTrackEvent, MessageEvent, MidiConnectionEvent, MidiMessageEvent, MutationEvent, OfflineAudioCompletionEvent, OverflowEvent, PageTransitionEvent, PopStateEvent, ProgressEvent, RtcDataChannelEvent, RtcDtmfToneChangeEvent, RtcIceCandidateEvent, SecurityPolicyViolationEvent, SpeechInputEvent, SpeechRecognitionError, SpeechRecognitionEvent, SpeechSynthesisEvent, StorageEvent, TrackEvent, TransitionEvent, UIEvent, VersionChangeEvent
Static Properties
Constructors
factory Event(String type, {bool canBubble: true, bool cancelable: true}) #
factory Event(String type,
{bool canBubble: true, bool cancelable: true}) {
return new Event.eventType('Event', type, canBubble: canBubble,
cancelable: cancelable);
}
factory Event.eventType(String type, String name, {bool canBubble: true, bool cancelable: true}) #
Creates a new Event object of the specified type.
This is analogous to document.createEvent. Normally events should be created via their constructors, if available.
var e = new Event.type('MouseEvent', 'mousedown', true, true);
factory Event.eventType(String type, String name, {bool canBubble: true,
bool cancelable: true}) {
final Event e = document.$dom_createEvent(type);
e.$dom_initEvent(name, canBubble, cancelable);
return e;
}
Properties
final bool bubbles #
final bool bubbles
bool cancelBubble #
bool cancelBubble
final DataTransfer clipboardData #
final DataTransfer clipboardData
final EventTarget currentTarget #
EventTarget get currentTarget => _convertNativeToDart_EventTarget(this._get_currentTarget);
final bool defaultPrevented #
event.preventDefault()
has been called on the event.
final bool defaultPrevented
final int eventPhase #
final int eventPhase
final int hashCode #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode it should override the
equality operator as well to maintain consistency.
int get hashCode => Primitives.objectHashCode(this);
final Type runtimeType #
A representation of the runtime type of the object.
Type get runtimeType => getRuntimeType(this);
final EventTarget target #
EventTarget get target => _convertNativeToDart_EventTarget(this._get_target);
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Objects is to return true if and
only if this and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
dynamic noSuchMethod(Invocation invocation) #
noSuchMethod is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod in an Invocation.
If noSuchMethod returns a value, that value becomes the result of
the original invocation.
The default behavior of noSuchMethod is to throw a
noSuchMethodError.
dynamic noSuchMethod(Invocation invocation) {
throw new NoSuchMethodError(
this,
_symbolToString(invocation.memberName),
invocation.positionalArguments,
_symbolMapToStringMap(invocation.namedArguments));
}
void preventDefault() #
@DomName('Event.preventDefault')
@DocsEditable
void preventDefault() native;
void stopImmediatePropagation() #
@DomName('Event.stopImmediatePropagation')
@DocsEditable
void stopImmediatePropagation() native;
void stopPropagation() #
@DomName('Event.stopPropagation')
@DocsEditable
void stopPropagation() native;
String toString() #
Returns a string representation of this object.
String toString() => Primitives.objectToString(this);
void $dom_initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) #
DocumentEvent interface.
@JSName('initEvent')
@DomName('Event.initEvent')
@DocsEditable
void $dom_initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) native;
This page includes content from the
Mozilla Foundation that is graciously
licensed under a
Creative Commons: Attribution-Sharealike license.
Mozilla has no other association with Dart or dartlang.org. We
encourage you to improve the web by
contributing to
The Mozilla Developer Network.