Class MouseEvent
java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.event.Event
org.htmlunit.javascript.host.event.UIEvent
org.htmlunit.javascript.host.event.MouseEvent
- All Implemented Interfaces:
Serializable
,Cloneable
,org.htmlunit.corejs.javascript.ConstProperties
,org.htmlunit.corejs.javascript.debug.DebuggableObject
,org.htmlunit.corejs.javascript.Scriptable
,org.htmlunit.corejs.javascript.SymbolScriptable
- Direct Known Subclasses:
DragEvent
,MouseScrollEvent
,PointerEvent
,WheelEvent
JavaScript object representing a Mouse Event.
For general information on which properties and functions should be supported, see
DOM Level 2 Events.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The button code according to W3C (0: left button, 1: middle button, 2: right button).static final int
The code for left mouse button.static final int
The code for middle mouse button.static final int
The code for right mouse button.private int
The buttons being depressed (if any) when the mouse event was fired.private Integer
The event's client coordinates; initiallynull
and lazily initialized for performance reasons.private Integer
private boolean
Whether or not the "meta" key was pressed during the firing of the event.static final int
Constant forMOZ_SOURCE_CURSOR
.static final int
Constant forMOZ_SOURCE_ERASER
.static final int
Constant forMOZ_SOURCE_KEYBOARD
.static final int
Constant forMOZ_SOURCE_MOUSE
.static final int
Constant forMOZ_SOURCE_PEN
.static final int
Constant forMOZ_SOURCE_TOUCH
.static final int
Constant forMOZ_SOURCE_UNKNOWN
.private boolean
Switch to disable label handling if we already processing the event triggered from label processingprivate Integer
The event's screen coordinates; initiallynull
and lazily initialized for performance reasons.private Integer
static final String
The click event type, triggered byonclick
event handlers.static final String
The context menu event type, triggered byoncontextmenu
event handlers.static final String
The dblclick event type, triggered byondblclick
event handlers.static final String
The mouse down event type, triggered byonmousedown
event handlers.static final String
The mouse move event type, triggered byonmousemove
event handlers.static final String
The mouse out event type, triggered byonmouseout
event handlers.static final String
The mouse over event type, triggered byonmouseover
event handlers.static final String
The mouse up event type, triggered byonmouseup
event handlers.Fields inherited from class org.htmlunit.javascript.host.event.UIEvent
SCROLL_PAGE_DOWN, SCROLL_PAGE_UP
Fields inherited from class org.htmlunit.javascript.host.event.Event
ALT_MASK, AT_TARGET, BUBBLING_PHASE, CAPTURING_PHASE, CONTROL_MASK, KEY_CURRENT_EVENT, META_MASK, NONE, SHIFT_MASK, TYPE_ABORT, TYPE_AFTERPRINT, TYPE_AFTERSCRIPTEXECUTE, TYPE_ANIMATIONCANCEL, TYPE_ANIMATIONEND, TYPE_ANIMATIONITERATION, TYPE_ANIMATIONSTART, TYPE_AUXCLICK, TYPE_BEFORE_UNLOAD, TYPE_BEFORECOPY, TYPE_BEFORECUT, TYPE_BEFOREPASTE, TYPE_BEFOREPRINT, TYPE_BEFORESCRIPTEXECUTE, TYPE_BLUR, TYPE_CANCEL, TYPE_CANPLAY, TYPE_CANPLAYTHROUGH, TYPE_CHANGE, TYPE_CLOSE, TYPE_COPY, TYPE_CUECHANGE, TYPE_CUT, TYPE_DEVICEMOTION, TYPE_DEVICEORIENTATION, TYPE_DEVICEORIENTATIONABSOLUTE, TYPE_DOM_DOCUMENT_LOADED, TYPE_DRAG, TYPE_DRAGEND, TYPE_DRAGENTER, TYPE_DRAGLEAVE, TYPE_DRAGOVER, TYPE_DRAGSTART, TYPE_DROP, TYPE_DURATIONCHANGE, TYPE_EMPTIED, TYPE_ENDED, TYPE_ERROR, TYPE_FOCUS, TYPE_FOCUS_IN, TYPE_FOCUS_OUT, TYPE_GAMEPAD_CONNECTED, TYPE_GAMEPAD_DISCONNECTED, TYPE_GOTPOINTERCAPTURE, TYPE_HASH_CHANGE, TYPE_INPUT, TYPE_INVALID, TYPE_KEY_DOWN, TYPE_KEY_PRESS, TYPE_KEY_UP, TYPE_LANGUAGECHANGE, TYPE_LOAD, TYPE_LOAD_END, TYPE_LOAD_START, TYPE_LOADEDDATA, TYPE_LOADEDMETADATA, TYPE_LOSTPOINTERCAPTURE, TYPE_MESSAGE, TYPE_MOUDEENTER, TYPE_MOUSELEAVE, TYPE_MOUSEWHEEL, TYPE_MOZFULLSCREENCHANGE, TYPE_MOZFULLSCREENERROR, TYPE_MSSITEMODEJUMPLISTITEMREMOVED, TYPE_OFFLINE, TYPE_ONLINE, TYPE_ONMESSAGEERROR, TYPE_ONTRANSITIONCANCEL, TYPE_ONTRANSITIONEND, TYPE_ONTRANSITIONRUN, TYPE_ONTRANSITIONSTART, TYPE_OPEN, TYPE_PAGEHIDE, TYPE_PAGESHOW, TYPE_PASTE, TYPE_PAUSE, TYPE_PLAY, TYPE_PLAYING, TYPE_POINTERCANCEL, TYPE_POINTERDOWN, TYPE_POINTERENTER, TYPE_POINTERLEAVE, TYPE_POINTERLOCKCHANGE, TYPE_POINTERLOCKERROR, TYPE_POINTERMOVE, TYPE_POINTEROUT, TYPE_POINTEROVER, TYPE_POINTERUP, TYPE_POPSTATE, TYPE_PROGRESS, TYPE_PROPERTY_CHANGE, TYPE_RATECHANGE, TYPE_READY_STATE_CHANGE, TYPE_REJECTIONHANDLED, TYPE_RESET, TYPE_RESIZE, TYPE_SCROLL, TYPE_SCROLLEND, TYPE_SEARCH, TYPE_SEEKED, TYPE_SEEKING, TYPE_SELECT, TYPE_SELECTIONCHANGE, TYPE_SELECTSTART, TYPE_STALLED, TYPE_STORAGE, TYPE_SUBMIT, TYPE_SUSPEND, TYPE_TIMEOUT, TYPE_TIMEUPDATE, TYPE_TOGGLE, TYPE_TRANSITIONEND, TYPE_UNHANDLEDREJECTION, TYPE_UNLOAD, TYPE_VOLUMECHANGE, TYPE_WAITING, TYPE_WEBANIMATIONSTART, TYPE_WEBKITANIMATIONEND, TYPE_WEBKITANIMATIONITERATION, TYPE_WEBKITFULLSCREENCHANGE, TYPE_WEBKITFULLSCREENERROR, TYPE_WEBKITTRANSITIONEND, TYPE_WHEEL
Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
ConstructorsConstructorDescriptionUsed to build the prototype.MouseEvent
(DomNode domNode, String type, boolean shiftKey, boolean ctrlKey, boolean altKey, int button, int detail) Creates a new event instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Disable the lable processing if we are already processing one.int
Gets the button code.int
Gets the button code.int
The horizontal coordinate at which the event occurred relative to the DOM implementation's client area.int
The vertical coordinate at which the event occurred relative to the DOM implementation's client area.static MouseEvent
Returns the mouse event currently firing, ornull
if no mouse event is being processed.boolean
Returns whether or not the "meta" key was pressed during the event firing.int
getPageX()
Returns the horizontal coordinate of the event relative to whole document..int
getPageY()
Returns the vertical coordinate of the event relative to the whole document.int
The horizontal coordinate at which the event occurred relative to the origin of the screen coordinate system.int
The vertical coordinate at which the event occurred relative to the origin of the screen coordinate system.int
getWhich()
Special for FF (old stuff from Netscape time).void
initMouseEvent
(String type, boolean bubbles, boolean cancelable, Object view, int detail, int screenX, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int button, Object relatedTarget) Implementation of the DOM Level 2 Event method for initializing the mouse event.boolean
isAltKey()
Returns whetherALT
has been pressed during this event or not.boolean
Returns whetherCTRL
has been pressed during this event or not.static boolean
isMouseEvent
(String type) Returnstrue
if the specified event type should be managed as a mouse event.boolean
Returns whetherSHIFT
has been pressed during this event or not.void
jsConstructor
(String type, org.htmlunit.corejs.javascript.ScriptableObject details) JavaScript constructor.boolean
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
If we click on a label, we have to simulate a click on the element referenced by the 'for' attribute also.void
setButton
(int value) Sets the button code.void
setButtons
(int value) Sets the button code.void
setClientX
(int value) Sets the clientX value.void
setClientY
(int value) Sets the clientY value.protected void
setMetaKey
(boolean metaKey) Methods inherited from class org.htmlunit.javascript.host.event.UIEvent
getDetail, getView, initUIEvent, setDetail
Methods inherited from class org.htmlunit.javascript.host.event.Event
createPropertyChangeEvent, endFire, eventCreated, getComposed, getCurrentTarget, getEventPhase, getKeyCode, getPropertyName, getReturnValue, getSrcElement, getTarget, getTimeStamp, getType, handlePropertyHandlerReturnValue, initEvent, isAborted, isBubbles, isCancelable, isCancelBubble, isDefaultPrevented, isImmediatePropagationStopped, isMissingOrUndefined, isPropagationStopped, preventDefault, setAltKey, setBubbles, setCancelable, setCancelBubble, setCtrlKey, setCurrentTarget, setEventPhase, setEventType, setKeyCode, setReturnValue, setShiftKey, setSrcElement, setTarget, setType, startFire, stopImmediatePropagation, stopPropagation, toString
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
Field Details
-
MOZ_SOURCE_UNKNOWN
public static final int MOZ_SOURCE_UNKNOWNConstant forMOZ_SOURCE_UNKNOWN
.- See Also:
-
MOZ_SOURCE_MOUSE
public static final int MOZ_SOURCE_MOUSEConstant forMOZ_SOURCE_MOUSE
.- See Also:
-
MOZ_SOURCE_PEN
public static final int MOZ_SOURCE_PENConstant forMOZ_SOURCE_PEN
.- See Also:
-
MOZ_SOURCE_ERASER
public static final int MOZ_SOURCE_ERASERConstant forMOZ_SOURCE_ERASER
.- See Also:
-
MOZ_SOURCE_CURSOR
public static final int MOZ_SOURCE_CURSORConstant forMOZ_SOURCE_CURSOR
.- See Also:
-
MOZ_SOURCE_TOUCH
public static final int MOZ_SOURCE_TOUCHConstant forMOZ_SOURCE_TOUCH
.- See Also:
-
MOZ_SOURCE_KEYBOARD
public static final int MOZ_SOURCE_KEYBOARDConstant forMOZ_SOURCE_KEYBOARD
.- See Also:
-
TYPE_CLICK
The click event type, triggered byonclick
event handlers.- See Also:
-
TYPE_DBL_CLICK
The dblclick event type, triggered byondblclick
event handlers.- See Also:
-
TYPE_MOUSE_OVER
The mouse over event type, triggered byonmouseover
event handlers.- See Also:
-
TYPE_MOUSE_MOVE
The mouse move event type, triggered byonmousemove
event handlers.- See Also:
-
TYPE_MOUSE_OUT
The mouse out event type, triggered byonmouseout
event handlers.- See Also:
-
TYPE_MOUSE_DOWN
The mouse down event type, triggered byonmousedown
event handlers.- See Also:
-
TYPE_MOUSE_UP
The mouse up event type, triggered byonmouseup
event handlers.- See Also:
-
TYPE_CONTEXT_MENU
The context menu event type, triggered byoncontextmenu
event handlers.- See Also:
-
BUTTON_LEFT
public static final int BUTTON_LEFTThe code for left mouse button.- See Also:
-
BUTTON_MIDDLE
public static final int BUTTON_MIDDLEThe code for middle mouse button.- See Also:
-
BUTTON_RIGHT
public static final int BUTTON_RIGHTThe code for right mouse button.- See Also:
-
screenX_
The event's screen coordinates; initiallynull
and lazily initialized for performance reasons. -
screenY_
-
clientX_
The event's client coordinates; initiallynull
and lazily initialized for performance reasons. -
clientY_
-
button_
private int button_The button code according to W3C (0: left button, 1: middle button, 2: right button). -
buttons_
private int buttons_The buttons being depressed (if any) when the mouse event was fired. -
processLabelAfterBubbling_
private boolean processLabelAfterBubbling_Switch to disable label handling if we already processing the event triggered from label processing -
metaKey_
private boolean metaKey_Whether or not the "meta" key was pressed during the firing of the event.
-
-
Constructor Details
-
MouseEvent
public MouseEvent()Used to build the prototype. -
MouseEvent
public MouseEvent(DomNode domNode, String type, boolean shiftKey, boolean ctrlKey, boolean altKey, int button, int detail) Creates a new event instance.- Parameters:
domNode
- the DOM node that triggered the eventtype
- the event typeshiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must beBUTTON_LEFT
,BUTTON_MIDDLE
orBUTTON_RIGHT
detail
- the detail value
-
-
Method Details
-
jsConstructor
JavaScript constructor.- Overrides:
jsConstructor
in classUIEvent
- Parameters:
type
- the event typedetails
- the event details (optional)
-
getClientX
public int getClientX()The horizontal coordinate at which the event occurred relative to the DOM implementation's client area.- Returns:
- the horizontal coordinate
-
setClientX
public void setClientX(int value) Sets the clientX value.- Parameters:
value
- the clientX value
-
getScreenX
public int getScreenX()The horizontal coordinate at which the event occurred relative to the origin of the screen coordinate system. The value of this attribute is initialized lazily, in order to optimize performance (it requires CSS parsing).- Returns:
- the horizontal coordinate
-
getPageX
public int getPageX()Returns the horizontal coordinate of the event relative to whole document..- Returns:
- the horizontal coordinate (currently the same as
getScreenX()
) - See Also:
-
getClientY
public int getClientY()The vertical coordinate at which the event occurred relative to the DOM implementation's client area.- Returns:
- the horizontal coordinate
-
setClientY
public void setClientY(int value) Sets the clientY value.- Parameters:
value
- the clientY value
-
getScreenY
public int getScreenY()The vertical coordinate at which the event occurred relative to the origin of the screen coordinate system. The value of this attribute is initialized lazily, in order to optimize performance (it requires CSS parsing).- Returns:
- the vertical coordinate
-
getPageY
public int getPageY()Returns the vertical coordinate of the event relative to the whole document.- Returns:
- the horizontal coordinate (currently the same as
getScreenY()
) - See Also:
-
getButton
public int getButton()Gets the button code.- Returns:
- the button code
-
setButton
public void setButton(int value) Sets the button code.- Parameters:
value
- the button code
-
getButtons
public int getButtons()Gets the button code.- Returns:
- the button code
-
setButtons
public void setButtons(int value) Sets the button code.- Parameters:
value
- the button code
-
getWhich
public int getWhich()Special for FF (old stuff from Netscape time). -
initMouseEvent
public void initMouseEvent(String type, boolean bubbles, boolean cancelable, Object view, int detail, int screenX, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int button, Object relatedTarget) Implementation of the DOM Level 2 Event method for initializing the mouse event.- Parameters:
type
- the event typebubbles
- can the event bubblecancelable
- can the event be canceledview
- the view to use for this eventdetail
- the detail to set for the eventscreenX
- the initial value of screenXscreenY
- the initial value of screenYclientX
- the initial value of clientXclientY
- the initial value of clientYctrlKey
- is the control key pressedaltKey
- is the alt key pressedshiftKey
- is the shift key pressedmetaKey
- is the meta key pressedbutton
- what mouse button is pressedrelatedTarget
- is there a related target for the event
-
getCurrentMouseEvent
Returns the mouse event currently firing, ornull
if no mouse event is being processed.- Returns:
- the mouse event currently firing
-
isMouseEvent
Returnstrue
if the specified event type should be managed as a mouse event.- Parameters:
type
- the type of event to check- Returns:
true
if the specified event type should be managed as a mouse event
-
isAltKey
public boolean isAltKey()Returns whetherALT
has been pressed during this event or not. Overridden to modify browser configurations. -
isCtrlKey
public boolean isCtrlKey()Returns whetherCTRL
has been pressed during this event or not. Overridden to modify browser configurations. -
isShiftKey
public boolean isShiftKey()Returns whetherSHIFT
has been pressed during this event or not. Overridden to modify browser configurations.- Overrides:
isShiftKey
in classEvent
- Returns:
- whether
SHIFT
has been pressed during this event or not
-
processLabelAfterBubbling
public boolean processLabelAfterBubbling()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
If we click on a label, we have to simulate a click on the element referenced by the 'for' attribute also. To support this for special events we have this method here. Overridden take care of click events.- Overrides:
processLabelAfterBubbling
in classEvent
- Returns:
- false in this default impl
-
disableProcessLabelAfterBubbling
public void disableProcessLabelAfterBubbling()Disable the lable processing if we are already processing one. -
getMetaKey
public boolean getMetaKey()Returns whether or not the "meta" key was pressed during the event firing.- Returns:
- whether or not the "meta" key was pressed during the event firing
-
setMetaKey
protected void setMetaKey(boolean metaKey) - Parameters:
metaKey
- whether Meta has been pressed during this event or not
-