com.gargoylesoftware.htmlunit.javascript.host
Class Event

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.Event
All Implemented Interfaces:
Serializable, Cloneable, Map, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable
Direct Known Subclasses:
MutationEvent, UIEvent

public class Event
extends SimpleScriptable

JavaScript object representing an event that is passed into event handlers when they are invoked. For general information on which properties and functions should be supported, see the mozilla docs, the W3C DOM Level 2 Event Documentation or IE's IHTMLEventObj interface.

Version:
$Revision: 5864 $
Author:
Chris Eldredge, Mike Bowler, Chris Erskine, Marc Guillemot, Daniel Gredler, Brad Murray, Ahmed Ashour, Rob Di Marco
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static int ABORT
          Constant.
static int ALT_MASK
          Constant.
static short AT_TARGET
          The second event phase: at the event target.
static int BACK
          Constant.
static int BLUR
          Constant.
static short BUBBLING_PHASE
          The third (and final) event phase: the bubbling phase.
static short CAPTURING_PHASE
          The first event phase: the capturing phase.
static int CHANGE
          Constant.
static int CLICK
          Constant.
static int CONTROL_MASK
          Constant.
static int DBLCLICK
          Constant.
static int DRAGDROP
          Constant.
static int ERROR
          Constant.
static int FOCUS
          Constant.
static int FORWARD
          Constant.
static int HELP
          Constant.
static int KEYDOWN
          Constant.
static int KEYPRESS
          Constant.
static int KEYUP
          Constant.
static int LOAD
          Constant.
static int LOCATE
          Constant.
static int META_MASK
          Constant.
static int MOUSEDOWN
          Constant.
static int MOUSEDRAG
          Constant.
static int MOUSEMOVE
          Constant.
static int MOUSEOUT
          Constant.
static int MOUSEOVER
          Constant.
static int MOUSEUP
          Constant.
static int MOVE
          Constant.
static int RESET
          Constant.
static int RESIZE
          Constant.
static int SCROLL
          Constant.
static int SELECT
          Constant.
static int SHIFT_MASK
          Constant.
static int SUBMIT
          Constant.
static int TEXT
          Constant.
static String TYPE_BEFORE_UNLOAD
          The beforeunload event type, triggered by "onbeforeunload" event handlers.
static String TYPE_BLUR
          The blur event type, triggered by "onblur" event handlers.
static String TYPE_CHANGE
          The change event type, triggered by "onchange" event handlers.
static String TYPE_DOM_DOCUMENT_LOADED
          Triggered after the DOM has loaded but before images etc.
static String TYPE_ERROR
          The event type triggered by "onerror" event handlers.
static String TYPE_FOCUS
          The focus event type, triggered by "onfocus" event handlers.
static String TYPE_FOCUS_IN
          The focus in event type, triggered by "onfocusin" event handlers.
static String TYPE_FOCUS_OUT
          The focus out event type, triggered by "onfocusout" event handlers.
static String TYPE_INPUT
          The input event type, triggered by "oninput" event handlers.
static String TYPE_KEY_DOWN
          The key down event type, triggered by "onkeydown" event handlers.
static String TYPE_KEY_PRESS
          The key down event type, triggered by "onkeypress" event handlers.
static String TYPE_KEY_UP
          The key down event type, triggered by "onkeyup" event handlers.
static String TYPE_LOAD
          The load event type, triggered by "onload" event handlers.
static String TYPE_PROPERTY_CHANGE
          The event type triggered by "onpropertychange" event handlers.
static String TYPE_READY_STATE_CHANGE
          The event type triggered by "onreadystatechange" event handlers.
static String TYPE_RESET
          The submit event type, triggered by "onreset" event handlers.
static String TYPE_SUBMIT
          The submit event type, triggered by "onsubmit" event handlers.
static String TYPE_UNLOAD
          The unload event type, triggered by "onunload" event handlers.
static int UNLOAD
          Constant.
static int XFER_DONE
          Constant.
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
Event()
          Used to build the prototype.
Event(DomNode domNode, String type)
          Creates a new event instance.
 
Method Summary
 boolean applies(DomNode node)
          Indicates if the current event can be applied to the provided node.
static Event createPropertyChangeEvent(DomNode domNode, String propertyName)
          Creates a new Event with TYPE_PROPERTY_CHANGE type.
 boolean isAborted(ScriptResult result)
          Returns true if this event has been aborted via preventDefault() in standards-compliant browsers, or via the event's returnValue property in IE, or by the event handler returning false.
 boolean isPropagationStopped()
          Indicates if event propagation is stopped.
 void jsxFunction_initEvent(String type, boolean bubbles, boolean cancelable)
          Initializes this event.
 void jsxFunction_preventDefault()
          If, during any stage of event flow, this method is called the event is canceled.
 void jsxFunction_stopPropagation()
          Stops the event from propagating.
 boolean jsxGet_altKey()
           
 boolean jsxGet_bubbles()
           
 boolean jsxGet_cancelable()
           
 boolean jsxGet_cancelBubble()
           
 boolean jsxGet_ctrlKey()
           
 Object jsxGet_currentTarget()
          Returns the event target whose event listeners are currently being processed.
 int jsxGet_eventPhase()
           
 Object jsxGet_keyCode()
          Returns the key code associated with the event.
 String jsxGet_propertyName()
          Returns the property name associated with the event.
 Object jsxGet_returnValue()
          Returns the return value associated with the event.
 boolean jsxGet_shiftKey()
           
 Object jsxGet_srcElement()
          Returns the object that fired the event.
 Object jsxGet_target()
          Returns the event target to which the event was originally dispatched.
 long jsxGet_timeStamp()
          Returns the time at which this event was created.
 String jsxGet_type()
          Returns the event type.
 void jsxSet_cancelBubble(boolean newValue)
           
 void jsxSet_returnValue(Object returnValue)
          Sets the return value associated with the event.
 void jsxSet_srcElement(Object srcElement)
          Sets the object that fired the event.
protected  void setAltKey(boolean altKey)
           
protected  void setCtrlKey(boolean ctrlKey)
           
 void setCurrentTarget(net.sourceforge.htmlunit.corejs.javascript.Scriptable target)
          Sets the current target.
 void setEventPhase(short phase)
          Sets the current event phase.
 void setEventType(String eventType)
          Sets the event type.
protected  void setKeyCode(Object keyCode)
          Sets the key code.
protected  void setShiftKey(boolean shiftKey)
           
 void setTarget(Object target)
          Sets the event target.
 String toString()
          
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, clear, containsKey, containsValue, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, entrySet, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, keySet, preventExtensions, put, put, put, putAll, putConst, putConstProperty, putProperty, putProperty, redefineProperty, remove, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

TYPE_SUBMIT

public static final String TYPE_SUBMIT
The submit event type, triggered by "onsubmit" event handlers.

See Also:
Constant Field Values

TYPE_CHANGE

public static final String TYPE_CHANGE
The change event type, triggered by "onchange" event handlers.

See Also:
Constant Field Values

TYPE_LOAD

public static final String TYPE_LOAD
The load event type, triggered by "onload" event handlers.

See Also:
Constant Field Values

TYPE_UNLOAD

public static final String TYPE_UNLOAD
The unload event type, triggered by "onunload" event handlers.

See Also:
Constant Field Values

TYPE_FOCUS

public static final String TYPE_FOCUS
The focus event type, triggered by "onfocus" event handlers.

See Also:
Constant Field Values

TYPE_FOCUS_IN

public static final String TYPE_FOCUS_IN
The focus in event type, triggered by "onfocusin" event handlers.

See Also:
Constant Field Values

TYPE_FOCUS_OUT

public static final String TYPE_FOCUS_OUT
The focus out event type, triggered by "onfocusout" event handlers.

See Also:
Constant Field Values

TYPE_BLUR

public static final String TYPE_BLUR
The blur event type, triggered by "onblur" event handlers.

See Also:
Constant Field Values

TYPE_KEY_DOWN

public static final String TYPE_KEY_DOWN
The key down event type, triggered by "onkeydown" event handlers.

See Also:
Constant Field Values

TYPE_KEY_PRESS

public static final String TYPE_KEY_PRESS
The key down event type, triggered by "onkeypress" event handlers.

See Also:
Constant Field Values

TYPE_INPUT

public static final String TYPE_INPUT
The input event type, triggered by "oninput" event handlers.

See Also:
Constant Field Values

TYPE_KEY_UP

public static final String TYPE_KEY_UP
The key down event type, triggered by "onkeyup" event handlers.

See Also:
Constant Field Values

TYPE_RESET

public static final String TYPE_RESET
The submit event type, triggered by "onreset" event handlers.

See Also:
Constant Field Values

TYPE_BEFORE_UNLOAD

public static final String TYPE_BEFORE_UNLOAD
The beforeunload event type, triggered by "onbeforeunload" event handlers.

See Also:
Constant Field Values

TYPE_DOM_DOCUMENT_LOADED

public static final String TYPE_DOM_DOCUMENT_LOADED
Triggered after the DOM has loaded but before images etc.

See Also:
Constant Field Values

TYPE_PROPERTY_CHANGE

public static final String TYPE_PROPERTY_CHANGE
The event type triggered by "onpropertychange" event handlers.

See Also:
Constant Field Values

TYPE_READY_STATE_CHANGE

public static final String TYPE_READY_STATE_CHANGE
The event type triggered by "onreadystatechange" event handlers.

See Also:
Constant Field Values

TYPE_ERROR

public static final String TYPE_ERROR
The event type triggered by "onerror" event handlers.

See Also:
Constant Field Values

CAPTURING_PHASE

public static final short CAPTURING_PHASE
The first event phase: the capturing phase.

See Also:
Constant Field Values

AT_TARGET

public static final short AT_TARGET
The second event phase: at the event target.

See Also:
Constant Field Values

BUBBLING_PHASE

public static final short BUBBLING_PHASE
The third (and final) event phase: the bubbling phase.

See Also:
Constant Field Values

ABORT

public static final int ABORT
Constant.

See Also:
Constant Field Values

ALT_MASK

public static final int ALT_MASK
Constant.

See Also:
Constant Field Values

BACK

public static final int BACK
Constant.

See Also:
Constant Field Values

BLUR

public static final int BLUR
Constant.

See Also:
Constant Field Values

CHANGE

public static final int CHANGE
Constant.

See Also:
Constant Field Values

CLICK

public static final int CLICK
Constant.

See Also:
Constant Field Values

CONTROL_MASK

public static final int CONTROL_MASK
Constant.

See Also:
Constant Field Values

DBLCLICK

public static final int DBLCLICK
Constant.

See Also:
Constant Field Values

DRAGDROP

public static final int DRAGDROP
Constant.

See Also:
Constant Field Values

ERROR

public static final int ERROR
Constant.

See Also:
Constant Field Values

FOCUS

public static final int FOCUS
Constant.

See Also:
Constant Field Values

FORWARD

public static final int FORWARD
Constant.

See Also:
Constant Field Values

HELP

public static final int HELP
Constant.

See Also:
Constant Field Values

KEYDOWN

public static final int KEYDOWN
Constant.

See Also:
Constant Field Values

KEYPRESS

public static final int KEYPRESS
Constant.

See Also:
Constant Field Values

KEYUP

public static final int KEYUP
Constant.

See Also:
Constant Field Values

LOAD

public static final int LOAD
Constant.

See Also:
Constant Field Values

LOCATE

public static final int LOCATE
Constant.

See Also:
Constant Field Values

META_MASK

public static final int META_MASK
Constant.

See Also:
Constant Field Values

MOUSEDOWN

public static final int MOUSEDOWN
Constant.

See Also:
Constant Field Values

MOUSEDRAG

public static final int MOUSEDRAG
Constant.

See Also:
Constant Field Values

MOUSEMOVE

public static final int MOUSEMOVE
Constant.

See Also:
Constant Field Values

MOUSEOUT

public static final int MOUSEOUT
Constant.

See Also:
Constant Field Values

MOUSEOVER

public static final int MOUSEOVER
Constant.

See Also:
Constant Field Values

MOUSEUP

public static final int MOUSEUP
Constant.

See Also:
Constant Field Values

MOVE

public static final int MOVE
Constant.

See Also:
Constant Field Values

RESET

public static final int RESET
Constant.

See Also:
Constant Field Values

RESIZE

public static final int RESIZE
Constant.

See Also:
Constant Field Values

SCROLL

public static final int SCROLL
Constant.

See Also:
Constant Field Values

SELECT

public static final int SELECT
Constant.

See Also:
Constant Field Values

SHIFT_MASK

public static final int SHIFT_MASK
Constant.

See Also:
Constant Field Values

SUBMIT

public static final int SUBMIT
Constant.

See Also:
Constant Field Values

TEXT

public static final int TEXT
Constant.

See Also:
Constant Field Values

UNLOAD

public static final int UNLOAD
Constant.

See Also:
Constant Field Values

XFER_DONE

public static final int XFER_DONE
Constant.

See Also:
Constant Field Values
Constructor Detail

Event

public Event(DomNode domNode,
             String type)
Creates a new event instance.

Parameters:
domNode - the DOM node that triggered the event
type - the event type

Event

public Event()
Used to build the prototype.

Method Detail

createPropertyChangeEvent

public static Event createPropertyChangeEvent(DomNode domNode,
                                              String propertyName)
Creates a new Event with TYPE_PROPERTY_CHANGE type.

Parameters:
domNode - the DOM node that triggered the event
propertyName - the property name that was changed
Returns:
the new Event object

jsxGet_srcElement

public Object jsxGet_srcElement()
Returns the object that fired the event. This is an IE-only property.

Returns:
the object that fired the event

jsxSet_srcElement

public void jsxSet_srcElement(Object srcElement)
Sets the object that fired the event. This is an IE-only property.

Parameters:
srcElement - the object that fired the event

jsxGet_target

public Object jsxGet_target()
Returns the event target to which the event was originally dispatched.

Returns:
the event target to which the event was originally dispatched

setTarget

public void setTarget(Object target)
Sets the event target.

Parameters:
target - the event target

jsxGet_currentTarget

public Object jsxGet_currentTarget()
Returns the event target whose event listeners are currently being processed. This is useful during event capturing and event bubbling.

Returns:
the current event target

setCurrentTarget

public void setCurrentTarget(net.sourceforge.htmlunit.corejs.javascript.Scriptable target)
Sets the current target.

Parameters:
target - the new value

jsxGet_type

public String jsxGet_type()
Returns the event type.

Returns:
the event type

setEventType

public void setEventType(String eventType)
Sets the event type.

Parameters:
eventType - the event type

jsxGet_timeStamp

public long jsxGet_timeStamp()
Returns the time at which this event was created.

Returns:
the time at which this event was created

setKeyCode

protected void setKeyCode(Object keyCode)
Sets the key code.

Parameters:
keyCode - the virtual key code value of the key which was depressed, otherwise zero

jsxGet_keyCode

public Object jsxGet_keyCode()
Returns the key code associated with the event.

Returns:
the key code associated with the event

jsxGet_shiftKey

public boolean jsxGet_shiftKey()
Returns:
whether SHIFT has been pressed during this event or not

setShiftKey

protected void setShiftKey(boolean shiftKey)
Parameters:
shiftKey - whether SHIFT has been pressed during this event or not

jsxGet_ctrlKey

public boolean jsxGet_ctrlKey()
Returns:
whether CTRL has been pressed during this event or not

setCtrlKey

protected void setCtrlKey(boolean ctrlKey)
Parameters:
ctrlKey - whether CTRL has been pressed during this event or not

jsxGet_altKey

public boolean jsxGet_altKey()
Returns:
whether ALT has been pressed during this event or not

setAltKey

protected void setAltKey(boolean altKey)
Parameters:
altKey - whether ALT has been pressed during this event or not

jsxGet_eventPhase

public int jsxGet_eventPhase()
Returns:
the current event phase for the event

setEventPhase

public void setEventPhase(short phase)
Sets the current event phase. Must be one of CAPTURING_PHASE, AT_TARGET or BUBBLING_PHASE.

Parameters:
phase - the phase the event is in

jsxGet_bubbles

public boolean jsxGet_bubbles()
Returns:
whether or not this event bubbles

jsxGet_cancelable

public boolean jsxGet_cancelable()
Returns:
whether or not this event can be canceled

jsxGet_cancelBubble

public boolean jsxGet_cancelBubble()
Returns:
indicates if event propagation is stopped

jsxSet_cancelBubble

public void jsxSet_cancelBubble(boolean newValue)
Parameters:
newValue - indicates if event propagation is stopped

jsxFunction_stopPropagation

public void jsxFunction_stopPropagation()
Stops the event from propagating.


isPropagationStopped

public boolean isPropagationStopped()
Indicates if event propagation is stopped.

Returns:
the status

jsxGet_returnValue

public Object jsxGet_returnValue()
Returns the return value associated with the event.

Returns:
the return value associated with the event

jsxGet_propertyName

public String jsxGet_propertyName()
Returns the property name associated with the event.

Returns:
the property name associated with the event

jsxSet_returnValue

public void jsxSet_returnValue(Object returnValue)
Sets the return value associated with the event.

Parameters:
returnValue - the return value associated with the event

jsxFunction_initEvent

public void jsxFunction_initEvent(String type,
                                  boolean bubbles,
                                  boolean cancelable)
Initializes this event.

Parameters:
type - the event type
bubbles - whether or not the event should bubble
cancelable - whether or not the event the event should be cancelable

jsxFunction_preventDefault

public void jsxFunction_preventDefault()
If, during any stage of event flow, this method is called the event is canceled. Any default action associated with the event will not occur. Calling this method for a non-cancelable event has no effect.


isAborted

public boolean isAborted(ScriptResult result)
Returns true if this event has been aborted via preventDefault() in standards-compliant browsers, or via the event's returnValue property in IE, or by the event handler returning false.

Parameters:
result - the event handler result (if false, the event is considered aborted)
Returns:
true if this event has been aborted

toString

public String toString()

Overrides:
toString in class Object

applies

public boolean applies(DomNode node)
Indicates if the current event can be applied to the provided node. TODO: investigate systematically ALL nodes and ALL events!

Parameters:
node - the node to test
Returns:
false if the event can't be applied


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.