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:
java.io.Serializable
,java.lang.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
public class MouseEvent extends UIEvent
JavaScript object representing a Mouse Event. For general information on which properties and functions should be supported, see DOM Level 2 Events.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private int
button_
The button code according to W3C (0: left button, 1: middle button, 2: right button).static int
BUTTON_LEFT
The code for left mouse button.static int
BUTTON_MIDDLE
The code for middle mouse button.static int
BUTTON_RIGHT
The code for right mouse button.private int
buttons_
The buttons being depressed (if any) when the mouse event was fired.private java.lang.Integer
clientX_
The event's client coordinates; initiallynull
and lazily initialized for performance reasons.private java.lang.Integer
clientY_
private boolean
metaKey_
Whether or not the "meta" key was pressed during the firing of the event.static int
MOZ_SOURCE_CURSOR
Constant forMOZ_SOURCE_CURSOR
.static int
MOZ_SOURCE_ERASER
Constant forMOZ_SOURCE_ERASER
.static int
MOZ_SOURCE_KEYBOARD
Constant forMOZ_SOURCE_KEYBOARD
.static int
MOZ_SOURCE_MOUSE
Constant forMOZ_SOURCE_MOUSE
.static int
MOZ_SOURCE_PEN
Constant forMOZ_SOURCE_PEN
.static int
MOZ_SOURCE_TOUCH
Constant forMOZ_SOURCE_TOUCH
.static int
MOZ_SOURCE_UNKNOWN
Constant forMOZ_SOURCE_UNKNOWN
.private boolean
processLabelAfterBubbling_
Switch to disable label handling if we already processing the event triggered from label processingprivate java.lang.Integer
screenX_
The event's screen coordinates; initiallynull
and lazily initialized for performance reasons.private java.lang.Integer
screenY_
static java.lang.String
TYPE_CLICK
The click event type, triggered byonclick
event handlers.static java.lang.String
TYPE_CONTEXT_MENU
The context menu event type, triggered byoncontextmenu
event handlers.static java.lang.String
TYPE_DBL_CLICK
The dblclick event type, triggered byondblclick
event handlers.static java.lang.String
TYPE_MOUSE_DOWN
The mouse down event type, triggered byonmousedown
event handlers.static java.lang.String
TYPE_MOUSE_MOVE
The mouse move event type, triggered byonmousemove
event handlers.static java.lang.String
TYPE_MOUSE_OUT
The mouse out event type, triggered byonmouseout
event handlers.static java.lang.String
TYPE_MOUSE_OVER
The mouse over event type, triggered byonmouseover
event handlers.static java.lang.String
TYPE_MOUSE_UP
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
-
-
Constructor Summary
Constructors Constructor Description MouseEvent()
Used to build the prototype.MouseEvent(DomNode domNode, java.lang.String type, boolean shiftKey, boolean ctrlKey, boolean altKey, int button, int detail)
Creates a new event instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disableProcessLabelAfterBubbling()
Disable the lable processing if we are already processing one.int
getButton()
Gets the button code.int
getButtons()
Gets the button code.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.static MouseEvent
getCurrentMouseEvent()
Returns the mouse event currently firing, ornull
if no mouse event is being processed.boolean
getMetaKey()
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
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.int
getWhich()
Special for FF (old stuff from Netscape time).void
initMouseEvent(java.lang.String type, boolean bubbles, boolean cancelable, java.lang.Object view, int detail, int screenX, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int button, java.lang.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
isCtrlKey()
Returns whetherCTRL
has been pressed during this event or not.static boolean
isMouseEvent(java.lang.String type)
Returnstrue
if the specified event type should be managed as a mouse event.boolean
isShiftKey()
Returns whetherSHIFT
has been pressed during this event or not.void
jsConstructor(java.lang.String type, org.htmlunit.corejs.javascript.ScriptableObject details)
JavaScript constructor.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.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 Detail
-
MOZ_SOURCE_UNKNOWN
public static final int MOZ_SOURCE_UNKNOWN
Constant forMOZ_SOURCE_UNKNOWN
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_MOUSE
public static final int MOZ_SOURCE_MOUSE
Constant forMOZ_SOURCE_MOUSE
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_PEN
public static final int MOZ_SOURCE_PEN
Constant forMOZ_SOURCE_PEN
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_ERASER
public static final int MOZ_SOURCE_ERASER
Constant forMOZ_SOURCE_ERASER
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_CURSOR
public static final int MOZ_SOURCE_CURSOR
Constant forMOZ_SOURCE_CURSOR
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_TOUCH
public static final int MOZ_SOURCE_TOUCH
Constant forMOZ_SOURCE_TOUCH
.- See Also:
- Constant Field Values
-
MOZ_SOURCE_KEYBOARD
public static final int MOZ_SOURCE_KEYBOARD
Constant forMOZ_SOURCE_KEYBOARD
.- See Also:
- Constant Field Values
-
TYPE_CLICK
public static final java.lang.String TYPE_CLICK
The click event type, triggered byonclick
event handlers.- See Also:
- Constant Field Values
-
TYPE_DBL_CLICK
public static final java.lang.String TYPE_DBL_CLICK
The dblclick event type, triggered byondblclick
event handlers.- See Also:
- Constant Field Values
-
TYPE_MOUSE_OVER
public static final java.lang.String TYPE_MOUSE_OVER
The mouse over event type, triggered byonmouseover
event handlers.- See Also:
- Constant Field Values
-
TYPE_MOUSE_MOVE
public static final java.lang.String TYPE_MOUSE_MOVE
The mouse move event type, triggered byonmousemove
event handlers.- See Also:
- Constant Field Values
-
TYPE_MOUSE_OUT
public static final java.lang.String TYPE_MOUSE_OUT
The mouse out event type, triggered byonmouseout
event handlers.- See Also:
- Constant Field Values
-
TYPE_MOUSE_DOWN
public static final java.lang.String TYPE_MOUSE_DOWN
The mouse down event type, triggered byonmousedown
event handlers.- See Also:
- Constant Field Values
-
TYPE_MOUSE_UP
public static final java.lang.String TYPE_MOUSE_UP
The mouse up event type, triggered byonmouseup
event handlers.- See Also:
- Constant Field Values
-
TYPE_CONTEXT_MENU
public static final java.lang.String TYPE_CONTEXT_MENU
The context menu event type, triggered byoncontextmenu
event handlers.- See Also:
- Constant Field Values
-
BUTTON_LEFT
public static final int BUTTON_LEFT
The code for left mouse button.- See Also:
- Constant Field Values
-
BUTTON_MIDDLE
public static final int BUTTON_MIDDLE
The code for middle mouse button.- See Also:
- Constant Field Values
-
BUTTON_RIGHT
public static final int BUTTON_RIGHT
The code for right mouse button.- See Also:
- Constant Field Values
-
screenX_
private java.lang.Integer screenX_
The event's screen coordinates; initiallynull
and lazily initialized for performance reasons.
-
screenY_
private java.lang.Integer screenY_
-
clientX_
private java.lang.Integer clientX_
The event's client coordinates; initiallynull
and lazily initialized for performance reasons.
-
clientY_
private java.lang.Integer 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 Detail
-
MouseEvent
public MouseEvent()
Used to build the prototype.
-
MouseEvent
public MouseEvent(DomNode domNode, java.lang.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 Detail
-
jsConstructor
public void jsConstructor(java.lang.String type, org.htmlunit.corejs.javascript.ScriptableObject details)
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:
- Mozilla doc
-
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:
- Mozilla doc
-
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).- Overrides:
getWhich
in classUIEvent
- Returns:
- the button code
- See Also:
- Javascript Madness: Mouse Events
-
initMouseEvent
public void initMouseEvent(java.lang.String type, boolean bubbles, boolean cancelable, java.lang.Object view, int detail, int screenX, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int button, java.lang.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
public static MouseEvent getCurrentMouseEvent()
Returns the mouse event currently firing, ornull
if no mouse event is being processed.- Returns:
- the mouse event currently firing
-
isMouseEvent
public static boolean isMouseEvent(java.lang.String type)
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
-
-