Dart API Referencedart:htmlMouseEvent

MouseEvent class

The DOM MouseEvent represents events that occur due to the user interacting with a pointing device (such as a mouse). It's represented by the nsINSDOMMouseEvent  interface, which extends the nsIDOMMouseEvent interface.
@DomName('MouseEvent')
class MouseEvent extends UIEvent native "MouseEvent" {
 factory MouseEvent(String type,
     {Window view, int detail: 0, int screenX: 0, int screenY: 0,
     int clientX: 0, int clientY: 0, int button: 0, bool canBubble: true,
     bool cancelable: true, bool ctrlKey: false, bool altKey: false,
     bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) {

   if (view == null) {
     view = window;
   }
   var event = document.$dom_createEvent('MouseEvent');
   event.$dom_initMouseEvent(type, canBubble, cancelable, view, detail,
       screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
       button, relatedTarget);
   return event;
 }

 @DomName('MouseEvent.altKey')
 @DocsEditable
 final bool altKey;

 @DomName('MouseEvent.button')
 @DocsEditable
 final int button;

 @JSName('clientX')
 @DomName('MouseEvent.clientX')
 @DocsEditable
 final int $dom_clientX;

 @JSName('clientY')
 @DomName('MouseEvent.clientY')
 @DocsEditable
 final int $dom_clientY;

 @DomName('MouseEvent.ctrlKey')
 @DocsEditable
 final bool ctrlKey;

 @DomName('MouseEvent.dataTransfer')
 @DocsEditable
 @Unstable
 final DataTransfer dataTransfer;

 @DomName('MouseEvent.fromElement')
 @DocsEditable
 @Experimental // nonstandard
 final Node fromElement;

 @DomName('MouseEvent.metaKey')
 @DocsEditable
 final bool metaKey;

 EventTarget get relatedTarget => _convertNativeToDart_EventTarget(this._get_relatedTarget);
 @JSName('relatedTarget')
 @DomName('MouseEvent.relatedTarget')
 @DocsEditable
 @Creates('Node')
 @Returns('EventTarget|=Object')
 final dynamic _get_relatedTarget;

 @JSName('screenX')
 @DomName('MouseEvent.screenX')
 @DocsEditable
 final int $dom_screenX;

 @JSName('screenY')
 @DomName('MouseEvent.screenY')
 @DocsEditable
 final int $dom_screenY;

 @DomName('MouseEvent.shiftKey')
 @DocsEditable
 final bool shiftKey;

 @DomName('MouseEvent.toElement')
 @DocsEditable
 @Experimental // nonstandard
 final Node toElement;

 @JSName('webkitMovementX')
 @DomName('MouseEvent.webkitMovementX')
 @DocsEditable
 @SupportedBrowser(SupportedBrowser.CHROME)
 @SupportedBrowser(SupportedBrowser.SAFARI)
 @Experimental
 final int $dom_webkitMovementX;

 @JSName('webkitMovementY')
 @DomName('MouseEvent.webkitMovementY')
 @DocsEditable
 @SupportedBrowser(SupportedBrowser.CHROME)
 @SupportedBrowser(SupportedBrowser.SAFARI)
 @Experimental
 final int $dom_webkitMovementY;

 @DomName('MouseEvent.initMouseEvent')
 @DocsEditable
 void $dom_initMouseEvent(String type, bool canBubble, bool cancelable, Window view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, int button, EventTarget relatedTarget) {
   var relatedTarget_1 = _convertDartToNative_EventTarget(relatedTarget);
   _$dom_initMouseEvent_1(type, canBubble, cancelable, view, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget_1);
   return;
 }
 @JSName('initMouseEvent')
 @DomName('MouseEvent.initMouseEvent')
 @DocsEditable
 void _$dom_initMouseEvent_1(type, canBubble, cancelable, Window view, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget) native;


 @deprecated
 int get clientX => client.x;
 @deprecated
 int get clientY => client.y;
 @deprecated
 int get offsetX => offset.x;
 @deprecated
 int get offsetY => offset.y;
 @deprecated
 int get movementX => movement.x;
 @deprecated
 int get movementY => movement.y;
 @deprecated
 int get screenX => screen.x;
 @deprecated
 int get screenY => screen.y;

 @DomName('MouseEvent.clientX')
 @DomName('MouseEvent.clientY')
 Point get client => new Point($dom_clientX, $dom_clientY);

 @DomName('MouseEvent.movementX')
 @DomName('MouseEvent.movementY')
 @SupportedBrowser(SupportedBrowser.CHROME)
 @SupportedBrowser(SupportedBrowser.SAFARI)
 @Experimental
 Point get movement => new Point($dom_webkitMovementX, $dom_webkitMovementY);

 /**
  * The coordinates of the mouse pointer in target node coordinates.
  *
  * This value may vary between platforms if the target node moves
  * after the event has fired or if the element has CSS transforms affecting
  * it.
  */
 Point get offset {
   if (JS('bool', '!!#.offsetX', this)) {
     var x = JS('int', '#.offsetX', this);
     var y = JS('int', '#.offsetY', this);
     return new Point(x, y);
   } else {
     // Firefox does not support offsetX.
     if (!(this.target is Element)) {
       throw new UnsupportedError(
           'offsetX is only supported on elements');
     }
     Element target = this.target;
     return (this.client - target.getBoundingClientRect().topLeft).toInt();
   }
 }

 @DomName('MouseEvent.screenX')
 @DomName('MouseEvent.screenY')
 Point get screen => new Point($dom_screenX, $dom_screenY);
}

Extends

Interceptor > Event > UIEvent > MouseEvent

Subclasses

WheelEvent

Constructors

factory MouseEvent(String type, {Window view, int detail: 0, int screenX: 0, int screenY: 0, int clientX: 0, int clientY: 0, int button: 0, bool canBubble: true, bool cancelable: true, bool ctrlKey: false, bool altKey: false, bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) #

factory MouseEvent(String type,
   {Window view, int detail: 0, int screenX: 0, int screenY: 0,
   int clientX: 0, int clientY: 0, int button: 0, bool canBubble: true,
   bool cancelable: true, bool ctrlKey: false, bool altKey: false,
   bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) {

 if (view == null) {
   view = window;
 }
 var event = document.$dom_createEvent('MouseEvent');
 event.$dom_initMouseEvent(type, canBubble, cancelable, view, detail,
     screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
     button, relatedTarget);
 return event;
}

Properties

final int $dom_charCode #

inherited from UIEvent
final int $dom_charCode

final int $dom_clientX #

The X coordinate of the mouse pointer in local (DOM content) coordinates. Read only.
final int $dom_clientX

final int $dom_clientY #

The Y coordinate of the mouse pointer in local (DOM content) coordinates. Read only.
final int $dom_clientY

final int $dom_keyCode #

inherited from UIEvent
final int $dom_keyCode

final int $dom_layerX #

inherited from UIEvent
final int $dom_layerX

final int $dom_layerY #

inherited from UIEvent
final int $dom_layerY

final int $dom_pageX #

inherited from UIEvent
final int $dom_pageX

final int $dom_pageY #

inherited from UIEvent
final int $dom_pageY

final int $dom_screenX #

The X coordinate of the mouse pointer in global (screen) coordinates. Read only.
final int $dom_screenX

final int $dom_screenY #

The Y coordinate of the mouse pointer in global (screen) coordinates. Read only.
final int $dom_screenY

final int $dom_webkitMovementX #

final int $dom_webkitMovementX

final int $dom_webkitMovementY #

final int $dom_webkitMovementY

final bool altKey #

true if the alt key was down when the mouse event was fired. Read only.
final bool altKey

final bool bubbles #

inherited from Event
A boolean indicating whether the event bubbles up through the DOM or not.
final bool bubbles

final int button #

The button number that was pressed when the mouse event was fired: Left button=0, middle button=1 (if present), right button=2. For mice configured for left handed use in which the button actions are reversed the values are instead read from right to left. Read only.
final int button

final bool cancelable #

inherited from Event
A boolean indicating whether the event is cancelable.
final bool cancelable

bool cancelBubble #

inherited from Event
A boolean indicating whether the bubbling of the event has been canceled or not.
bool cancelBubble

final Point client #

The X coordinate of the mouse pointer in local (DOM content) coordinates. Read only.
@DomName('MouseEvent.clientX')
@DomName('MouseEvent.clientY')
Point get client => new Point($dom_clientX, $dom_clientY);

final int clientX #

@deprecated
int get clientX => client.x;

final int clientY #

@deprecated
int get clientY => client.y;

final DataTransfer clipboardData #

inherited from Event
final DataTransfer clipboardData

final bool ctrlKey #

true if the control key was down when the mouse event was fired. Read only.
final bool ctrlKey

final EventTarget currentTarget #

inherited from Event
EventTarget get currentTarget => _convertNativeToDart_EventTarget(this._get_currentTarget);

final DataTransfer dataTransfer #

final DataTransfer dataTransfer

final bool defaultPrevented #

inherited from Event
Indicates whether or not event.preventDefault() has been called on the event.
final bool defaultPrevented

final int detail #

inherited from UIEvent
Detail about the event, depending on the type of event. Read only.
final int detail

final int eventPhase #

inherited from Event
Indicates which phase of the event flow is being processed.
final int eventPhase

final Node fromElement #

final Node fromElement

final int hashCode #

inherited from Interceptor

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.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final Point layer #

inherited from UIEvent
@DomName('UIEvent.layerX')
@DomName('UIEvent.layerY')
Point get layer => new Point($dom_layerX, $dom_layerY);

final int layerX #

inherited from UIEvent
@deprecated
int get layerX => layer.x;

final int layerY #

inherited from UIEvent
@deprecated
int get layerY => layer.y;

final bool metaKey #

true if the meta key was down when the mouse event was fired. Read only.
final bool metaKey

final Point movement #

@DomName('MouseEvent.movementX')
@DomName('MouseEvent.movementY')
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@Experimental
Point get movement => new Point($dom_webkitMovementX, $dom_webkitMovementY);

final int movementX #

@deprecated
int get movementX => movement.x;

final int movementY #

@deprecated
int get movementY => movement.y;

final Point offset #

The coordinates of the mouse pointer in target node coordinates.

This value may vary between platforms if the target node moves after the event has fired or if the element has CSS transforms affecting it.

Point get offset {
 if (JS('bool', '!!#.offsetX', this)) {
   var x = JS('int', '#.offsetX', this);
   var y = JS('int', '#.offsetY', this);
   return new Point(x, y);
 } else {
   // Firefox does not support offsetX.
   if (!(this.target is Element)) {
     throw new UnsupportedError(
         'offsetX is only supported on elements');
   }
   Element target = this.target;
   return (this.client - target.getBoundingClientRect().topLeft).toInt();
 }
}

final int offsetX #

@deprecated
int get offsetX => offset.x;

final int offsetY #

@deprecated
int get offsetY => offset.y;

final Point page #

inherited from UIEvent
@DomName('UIEvent.pageX')
@DomName('UIEvent.pageY')
Point get page => new Point($dom_pageX, $dom_pageY);

final int pageX #

inherited from UIEvent
@deprecated
int get pageX => page.x;

final int pageY #

inherited from UIEvent
@deprecated
int get pageY => page.y;

final List<Node> path #

inherited from Event
final List<Node> path

final EventTarget relatedTarget #

EventTarget get relatedTarget => _convertNativeToDart_EventTarget(this._get_relatedTarget);

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

final Point screen #

The X coordinate of the mouse pointer in global (screen) coordinates. Read only.
@DomName('MouseEvent.screenX')
@DomName('MouseEvent.screenY')
Point get screen => new Point($dom_screenX, $dom_screenY);

final int screenX #

@deprecated
int get screenX => screen.x;

final int screenY #

@deprecated
int get screenY => screen.y;

final bool shiftKey #

true if the shift key was down when the mouse event was fired. Read only.
final bool shiftKey

final EventTarget target #

inherited from Event
EventTarget get target => _convertNativeToDart_EventTarget(this._get_target);

final int timeStamp #

inherited from Event
The time that the event was created.
final int timeStamp

final Node toElement #

final Node toElement

final String type #

inherited from Event
The name of the event (case-insensitive).
final String type

final WindowBase view #

inherited from UIEvent
WindowBase get view => _convertNativeToDart_Window(this._get_view);

final int which #

inherited from UIEvent
final int which

Operators

bool operator ==(other) #

inherited from Interceptor

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.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

dynamic noSuchMethod(Invocation invocation) #

inherited from Interceptor

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.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     _symbolToString(invocation.memberName),
     invocation.positionalArguments,
     _symbolMapToStringMap(invocation.namedArguments));
}

void preventDefault() #

inherited from Event
Cancels the event (if it is cancelable).
@DomName('Event.preventDefault')
@DocsEditable
void preventDefault() native;

void stopImmediatePropagation() #

inherited from Event
For this particular event, no other listener will be called. Neither those attached on the same element, nor those attached on elements which will be traversed later (in capture phase, for instance)
@DomName('Event.stopImmediatePropagation')
@DocsEditable
void stopImmediatePropagation() native;

void stopPropagation() #

inherited from Event
Stops the propagation of events further along in the DOM.
@DomName('Event.stopPropagation')
@DocsEditable
void stopPropagation() native;

String toString() #

inherited from Interceptor

Returns a string representation of this object.

docs inherited from Object
String toString() => Primitives.objectToString(this);

void $dom_initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) #

inherited from Event
Initializes the value of an Event created through the DocumentEvent interface.
@JSName('initEvent')
@DomName('Event.initEvent')
@DocsEditable
void $dom_initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) native;

void $dom_initMouseEvent(String type, bool canBubble, bool cancelable, Window view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, int button, EventTarget relatedTarget) #

@DomName('MouseEvent.initMouseEvent')
@DocsEditable
void $dom_initMouseEvent(String type, bool canBubble, bool cancelable, Window view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, int button, EventTarget relatedTarget) {
 var relatedTarget_1 = _convertDartToNative_EventTarget(relatedTarget);
 _$dom_initMouseEvent_1(type, canBubble, cancelable, view, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget_1);
 return;
}

void $dom_initUIEvent(String type, bool canBubble, bool cancelable, Window view, int detail) #

inherited from UIEvent

Initializes the UIEvent object.

Parameters
typeArg
The type of UI event.
canBubbleArg
Whether or not the event can bubble.
cancelableArg
Whether or not the event can be canceled.
viewArg
Specifies the view attribute value. This may be null.
detailArg
Specifies the detail attribute value.
@JSName('initUIEvent')
@DomName('UIEvent.initUIEvent')
@DocsEditable
void $dom_initUIEvent(String type, bool canBubble, bool cancelable, Window view, int detail) 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.