MouseEvent class
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
final DataTransfer dataTransfer;
@DomName('MouseEvent.fromElement')
@DocsEditable
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
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.
var target = this.target;
if (!(target is Element)) {
throw new UnsupportedError(
'offsetX is only supported on elements');
}
return (this.client -
this.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
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_clientX #
final int $dom_clientX
final int $dom_clientY #
final int $dom_clientY
final int $dom_screenX #
final int $dom_screenX
final int $dom_screenY #
final int $dom_screenY
final bool altKey #
true if the alt key was down when the mouse event was fired. Read only.
final bool altKey
final bool bubbles #
final bool bubbles
final int button #
final int button
final bool cancelable #
final bool cancelable
bool cancelBubble #
bool cancelBubble
final Point client #
@DomName('MouseEvent.clientX')
@DomName('MouseEvent.clientY')
Point get client => new Point($dom_clientX, $dom_clientY);
final bool ctrlKey #
true if the control key was down when the mouse event was fired. Read only.
final bool ctrlKey
final EventTarget currentTarget #
EventTarget get currentTarget => _convertNativeToDart_EventTarget(this._get_currentTarget);
final DataTransfer dataTransfer #
final DataTransfer dataTransfer
final bool defaultPrevented #
event.preventDefault()
has been called on the event.
final bool defaultPrevented
final int detail #
final int detail
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 Point layer #
@DomName('UIEvent.layerX')
@DomName('UIEvent.layerY')
Point get layer => new Point($dom_layerX, $dom_layerY);
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 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.
var target = this.target;
if (!(target is Element)) {
throw new UnsupportedError(
'offsetX is only supported on elements');
}
return (this.client -
this.target.getBoundingClientRect().topLeft).toInt();
}
}
final Point page #
@DomName('UIEvent.pageX')
@DomName('UIEvent.pageY')
Point get page => new Point($dom_pageX, $dom_pageY);
final EventTarget relatedTarget #
EventTarget get relatedTarget => _convertNativeToDart_EventTarget(this._get_relatedTarget);
final Type runtimeType #
A representation of the runtime type of the object.
Type get runtimeType => getRuntimeType(this);
final Point screen #
@DomName('MouseEvent.screenX')
@DomName('MouseEvent.screenY')
Point get screen => new Point($dom_screenX, $dom_screenY);
final bool shiftKey #
true if the shift key was down when the mouse event was fired. Read only.
final bool shiftKey
final EventTarget target #
EventTarget get target => _convertNativeToDart_EventTarget(this._get_target);
final String type #
final String type
final WindowBase view #
WindowBase get view => _convertNativeToDart_Window(this._get_view);
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;
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) #
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
viewattribute value. This may benull. 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.