Interface MouseEvent
-
- All Known Implementing Classes:
DOMMouseEvent
public interface MouseEvent extends UIEvent
TheMouseEvent
interface provides specific contextual information associated with Mouse events.In the case of nested elements mouse events are always targeted at the most deeply nested element. Ancestors of the targeted element may use bubbling to obtain notification of mouse events which occur within theirs descendent elements.
To create an instance of the
MouseEvent
interface, use theDocumentEvent.createEvent("MouseEvent")
method call.Note: When initializing
MouseEvent
objects usinginitMouseEvent
orinitMouseEventNS
, implementations should use the client coordinatesclientX
andclientY
for calculation of other coordinates (such as target coordinates exposed by DOM Level 0 implementations).See also the Document Object Model (DOM) Level 3 Events Specification .
- Since:
- DOM Level 2
-
-
Field Summary
-
Fields inherited from interface org.w3c.dom.events.Event
AT_TARGET, BUBBLING_PHASE, CAPTURING_PHASE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
getAltKey()
true
if the alt (alternative) key modifier is activated.short
getButton()
During mouse events caused by the depression or release of a mouse button,button
is used to indicate which mouse button changed state.int
getClientX()
The horizontal coordinate at which the event occurred relative to the DOM implementation's client area.int
getClientY()
The vertical coordinate at which the event occurred relative to the DOM implementation's client area.boolean
getCtrlKey()
true
if the control (Ctrl) key modifier is activated.boolean
getMetaKey()
true
if the meta (Meta) key modifier is activated.boolean
getModifierState(java.lang.String keyIdentifierArg)
This methods queries the state of a modifier using a key identifier.EventTarget
getRelatedTarget()
Used to identify a secondaryEventTarget
related to a UI event, depending on the type of event.int
getScreenX()
The horizontal coordinate at which the event occurred relative to the origin of the screen coordinate system.int
getScreenY()
The vertical coordinate at which the event occurred relative to the origin of the screen coordinate system.boolean
getShiftKey()
true
if the shift (Shift) key modifier is activated.void
initMouseEvent(java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, org.w3c.dom.views.AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, boolean ctrlKeyArg, boolean altKeyArg, boolean shiftKeyArg, boolean metaKeyArg, short buttonArg, EventTarget relatedTargetArg)
TheinitMouseEvent
method is used to initialize the value of aMouseEvent
object and has the same behavior asUIEvent.initUIEvent()
.void
initMouseEventNS(java.lang.String namespaceURI, java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, org.w3c.dom.views.AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, short buttonArg, EventTarget relatedTargetArg, java.lang.String modifiersList)
TheinitMouseEventNS
method is used to initialize the value of aMouseEvent
object and has the same behavior asUIEvent.initUIEventNS()
.-
Methods inherited from interface org.w3c.dom.events.Event
getBubbles, getCancelable, getCurrentTarget, getDefaultPrevented, getEventPhase, getNamespaceURI, getTarget, getTimeStamp, getType, initEvent, initEventNS, preventDefault, stopImmediatePropagation, stopPropagation
-
Methods inherited from interface org.w3c.dom.events.UIEvent
getDetail, getView, initUIEvent, initUIEventNS
-
-
-
-
Method Detail
-
getScreenX
int getScreenX()
The horizontal coordinate at which the event occurred relative to the origin of the screen coordinate system.
-
getScreenY
int getScreenY()
The vertical coordinate at which the event occurred relative to the origin of the screen coordinate system.
-
getClientX
int getClientX()
The horizontal coordinate at which the event occurred relative to the DOM implementation's client area.
-
getClientY
int getClientY()
The vertical coordinate at which the event occurred relative to the DOM implementation's client area.
-
getCtrlKey
boolean getCtrlKey()
true
if the control (Ctrl) key modifier is activated.
-
getShiftKey
boolean getShiftKey()
true
if the shift (Shift) key modifier is activated.
-
getAltKey
boolean getAltKey()
true
if the alt (alternative) key modifier is activated.Note: The Option key modifier on Macintosh systems must be represented using this key modifier.
-
getMetaKey
boolean getMetaKey()
true
if the meta (Meta) key modifier is activated.Note: The Command key modifier on Macintosh system must be represented using this meta key.
-
getButton
short getButton()
During mouse events caused by the depression or release of a mouse button,button
is used to indicate which mouse button changed state.0
indicates the normal button of the mouse (in general on the left or the one button on Macintosh mice, used to activate a button or select text).2
indicates the contextual property (in general on the right, used to display a context menu) button of the mouse if present.1
indicates the extra (in general in the middle and often combined with the mouse wheel) button. Some mice may provide or simulate more buttons, and values higher than2
can be used to represent such buttons.
-
getRelatedTarget
EventTarget getRelatedTarget()
Used to identify a secondaryEventTarget
related to a UI event, depending on the type of event.
-
initMouseEvent
void initMouseEvent(java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, org.w3c.dom.views.AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, boolean ctrlKeyArg, boolean altKeyArg, boolean shiftKeyArg, boolean metaKeyArg, short buttonArg, EventTarget relatedTargetArg)
TheinitMouseEvent
method is used to initialize the value of aMouseEvent
object and has the same behavior asUIEvent.initUIEvent()
.- Parameters:
typeArg
- Refer to theUIEvent.initUIEvent()
method for a description of this parameter.canBubbleArg
- Refer to theUIEvent.initUIEvent()
method for a description of this parameter.cancelableArg
- Refer to theUIEvent.initUIEvent()
method for a description of this parameter.viewArg
- Refer to theUIEvent.initUIEvent()
method for a description of this parameter.detailArg
- Refer to theUIEvent.initUIEvent()
method for a description of this parameter.screenXArg
- SpecifiesMouseEvent.screenX
.screenYArg
- SpecifiesMouseEvent.screenY
.clientXArg
- SpecifiesMouseEvent.clientX
.clientYArg
- SpecifiesMouseEvent.clientY
.ctrlKeyArg
- SpecifiesMouseEvent.ctrlKey
.altKeyArg
- SpecifiesMouseEvent.altKey
.shiftKeyArg
- SpecifiesMouseEvent.shiftKey
.metaKeyArg
- SpecifiesMouseEvent.metaKey
.buttonArg
- SpecifiesMouseEvent.button
.relatedTargetArg
- SpecifiesMouseEvent.relatedTarget
. This value may benull
.
-
getModifierState
boolean getModifierState(java.lang.String keyIdentifierArg)
This methods queries the state of a modifier using a key identifier. See also .- Parameters:
keyIdentifierArg
- A modifier key identifier, as defined by theKeyboardEvent.keyIdentifier
attribute. Common modifier keys are"Alt"
,"AltGraph"
,"CapsLock"
,"Control"
,"Meta"
,"NumLock"
,"Scroll"
, or"Shift"
.Note: If an application wishes to distinguish between right and left modifiers, this information could be deduced using keyboard events and
KeyboardEvent.keyLocation
.- Returns:
true
if it is modifier key and the modifier is activated,false
otherwise.- Since:
- DOM Level 3
-
initMouseEventNS
void initMouseEventNS(java.lang.String namespaceURI, java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, org.w3c.dom.views.AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, short buttonArg, EventTarget relatedTargetArg, java.lang.String modifiersList)
TheinitMouseEventNS
method is used to initialize the value of aMouseEvent
object and has the same behavior asUIEvent.initUIEventNS()
.- Parameters:
namespaceURI
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.typeArg
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.canBubbleArg
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.cancelableArg
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.viewArg
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.detailArg
- Refer to theUIEvent.initUIEventNS()
method for a description of this parameter.screenXArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.screenYArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.clientXArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.clientYArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.buttonArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.relatedTargetArg
- Refer to theMouseEvent.initMouseEvent()
method for a description of this parameter.modifiersList
- A white space separated list of modifier key identifiers to be activated on this object. As an example,"Control Alt"
will activated the control and alt modifiers.- Since:
- DOM Level 3
-
-