public class

Event

extends NativeEvent
java.lang.Object
   ↳ com.google.gwt.core.client.JavaScriptObject
     ↳ com.google.gwt.dom.client.NativeEvent
       ↳ com.google.gwt.user.client.Event

Class Overview

An opaque handle to a native DOM Event. An Event cannot be created directly. Instead, use the Event type when returning a native DOM event from JSNI methods. An Event passed back into JSNI becomes the original DOM event the Event was created from, and can be accessed in JavaScript code as expected. This is typically done by calling methods in the DOM class.

Summary

Nested Classes
class Event.NativePreviewEvent Represents a preview of a native Event
interface Event.NativePreviewHandler Handler interface for Event.NativePreviewEvent events. 
Constants
int FOCUSEVENTS A bit-mask covering both focus events (focus and blur).
int GESTUREEVENTS A bit-mask covering all gesture events (start, change, end).
int KEYEVENTS A bit-mask covering all keyboard events (down, up, and press).
int MOUSEEVENTS A bit-mask covering all mouse events (down, up, move, over, and out), but not click, dblclick, or wheel events.
int ONBLUR Fired when an element loses keyboard focus.
int ONCHANGE Fired when the value of an input element changes.
int ONCLICK Fired when the user clicks on an element.
int ONCONTEXTMENU Fired when the user requests an element's context menu (usually by right-clicking).
int ONDBLCLICK Fired when the user double-clicks on an element.
int ONERROR Fired when an image encounters an error.
int ONFOCUS Fired when an element receives keyboard focus.
int ONGESTURECHANGE Fired when the user gesture changes.
int ONGESTUREEND Fired when the user gesture ends.
int ONGESTURESTART Fired when the user gesture starts.
int ONKEYDOWN Fired when the user depresses a key.
int ONKEYPRESS Fired when the a character is generated from a keypress (either directly or through auto-repeat).
int ONKEYUP Fired when the user releases a key.
int ONLOAD Fired when an element (normally an IMG) finishes loading.
int ONLOSECAPTURE Fired when an element that has mouse capture loses it.
int ONMOUSEDOWN Fired when the user depresses a mouse button over an element.
int ONMOUSEMOVE Fired when the mouse is moved within an element's area.
int ONMOUSEOUT Fired when the mouse is moved out of an element's area.
int ONMOUSEOVER Fired when the mouse is moved into an element's area.
int ONMOUSEUP Fired when the user releases a mouse button over an element.
int ONMOUSEWHEEL Fired when the user scrolls the mouse wheel over an element.
int ONPASTE Fired when the user pastes text into an input element.
int ONSCROLL Fired when a scrollable element's scroll offset changes.
int ONTOUCHCANCEL Fired when the user cancels touching an element.
int ONTOUCHEND Fired when the user ends touching an element.
int ONTOUCHMOVE Fired when the user moves while touching an element.
int ONTOUCHSTART Fired when the user starts touching an element.
int TOUCHEVENTS A bit-mask covering all touch events (start, move, end, cancel).
int UNDEFINED Value returned by accessors when the actual integer value is undefined.
[Expand]
Inherited Constants
From class com.google.gwt.dom.client.NativeEvent
Protected Constructors
Event()
Not directly instantiable.
Public Methods
static void addEventPreview(EventPreview preview)
This method is deprecated. replaced by addNativePreviewHandler(NativePreviewHandler)
static HandlerRegistration addNativePreviewHandler(Event.NativePreviewHandler handler)

Adds a Event.NativePreviewHandler that will receive all events before they are fired to their handlers.

static Event as(NativeEvent event)
Converts the NativeEvent to Event.
final void cancelBubble(boolean cancel)
This method is deprecated. use stopPropagation() instead
static boolean fireNativePreviewEvent(NativeEvent nativeEvent)
Fire a Event.NativePreviewEvent for the native event.
static Event getCurrentEvent()
Gets the current event that is being fired.
final Element getCurrentTarget()
This method is deprecated. use getCurrentEventTarget() instead
static EventListener getEventListener(Element elem)
Gets the EventListener that will receive events for the given element.
static int getEventsSunk(Element elem)
Gets the current set of events sunk by a given element.
final Element getFromElement()
This method is deprecated. use getRelatedEventTarget() instead
final Element getRelatedTarget()
This method is deprecated. use getRelatedEventTarget() instead
final boolean getRepeat()
This method is deprecated. not supported on all browsers
final Element getTarget()
This method is deprecated. use getEventTarget() instead
final Element getToElement()
This method is deprecated. use getRelatedEventTarget() instead
static int getTypeInt(String typeName)
Gets the enumerated type of this event given a valid event type name.
final int getTypeInt()
Gets the enumerated type of this event, as defined by ONCLICK, ONMOUSEDOWN, and so forth.
static void releaseCapture(Element elem)
Releases mouse capture on the given element.
static void removeEventPreview(EventPreview preview)
This method is deprecated. use HandlerRegistration returned from addNativePreviewHandler(NativePreviewHandler)
static void setCapture(Element elem)
Sets mouse-capture on the given element.
static void setEventListener(Element elem, EventListener listener)
Sets the EventListener to receive events for the given element.
static void sinkEvents(Element elem, int eventBits)
Sets the current set of events sunk by a given element.
[Expand]
Inherited Methods
From class com.google.gwt.dom.client.NativeEvent
From class com.google.gwt.core.client.JavaScriptObject
From class java.lang.Object

Constants

public static final int FOCUSEVENTS

A bit-mask covering both focus events (focus and blur).

Constant Value: 6144 (0x00001800)

public static final int GESTUREEVENTS

A bit-mask covering all gesture events (start, change, end).

Constant Value: 117440512 (0x07000000)

public static final int KEYEVENTS

A bit-mask covering all keyboard events (down, up, and press).

Constant Value: 896 (0x00000380)

public static final int MOUSEEVENTS

A bit-mask covering all mouse events (down, up, move, over, and out), but not click, dblclick, or wheel events.

Constant Value: 124 (0x0000007c)

public static final int ONBLUR

Fired when an element loses keyboard focus.

Constant Value: 4096 (0x00001000)

public static final int ONCHANGE

Fired when the value of an input element changes.

Constant Value: 1024 (0x00000400)

public static final int ONCLICK

Fired when the user clicks on an element.

Constant Value: 1 (0x00000001)

public static final int ONCONTEXTMENU

Fired when the user requests an element's context menu (usually by right-clicking). Note that not all browsers will fire this event (notably Opera, as of 9.5).

Constant Value: 262144 (0x00040000)

public static final int ONDBLCLICK

Fired when the user double-clicks on an element.

Constant Value: 2 (0x00000002)

public static final int ONERROR

Fired when an image encounters an error.

Constant Value: 65536 (0x00010000)

public static final int ONFOCUS

Fired when an element receives keyboard focus.

Constant Value: 2048 (0x00000800)

public static final int ONGESTURECHANGE

Fired when the user gesture changes.

Constant Value: 33554432 (0x02000000)

public static final int ONGESTUREEND

Fired when the user gesture ends.

Constant Value: 67108864 (0x04000000)

public static final int ONGESTURESTART

Fired when the user gesture starts.

Constant Value: 16777216 (0x01000000)

public static final int ONKEYDOWN

Fired when the user depresses a key.

Constant Value: 128 (0x00000080)

public static final int ONKEYPRESS

Fired when the a character is generated from a keypress (either directly or through auto-repeat).

Constant Value: 256 (0x00000100)

public static final int ONKEYUP

Fired when the user releases a key.

Constant Value: 512 (0x00000200)

public static final int ONLOAD

Fired when an element (normally an IMG) finishes loading.

Constant Value: 32768 (0x00008000)

public static final int ONLOSECAPTURE

Fired when an element that has mouse capture loses it.

Constant Value: 8192 (0x00002000)

public static final int ONMOUSEDOWN

Fired when the user depresses a mouse button over an element.

Constant Value: 4 (0x00000004)

public static final int ONMOUSEMOVE

Fired when the mouse is moved within an element's area.

Constant Value: 64 (0x00000040)

public static final int ONMOUSEOUT

Fired when the mouse is moved out of an element's area.

Constant Value: 32 (0x00000020)

public static final int ONMOUSEOVER

Fired when the mouse is moved into an element's area.

Constant Value: 16 (0x00000010)

public static final int ONMOUSEUP

Fired when the user releases a mouse button over an element.

Constant Value: 8 (0x00000008)

public static final int ONMOUSEWHEEL

Fired when the user scrolls the mouse wheel over an element.

Constant Value: 131072 (0x00020000)

public static final int ONPASTE

Fired when the user pastes text into an input element.

Note: This event is not supported on Firefox 2 and earlier, or Opera 10 and earlier. Be aware that it will not fire on these browser versions.

Constant Value: 524288 (0x00080000)

public static final int ONSCROLL

Fired when a scrollable element's scroll offset changes.

Constant Value: 16384 (0x00004000)

public static final int ONTOUCHCANCEL

Fired when the user cancels touching an element.

Constant Value: 8388608 (0x00800000)

public static final int ONTOUCHEND

Fired when the user ends touching an element.

Constant Value: 4194304 (0x00400000)

public static final int ONTOUCHMOVE

Fired when the user moves while touching an element.

Constant Value: 2097152 (0x00200000)

public static final int ONTOUCHSTART

Fired when the user starts touching an element.

Constant Value: 1048576 (0x00100000)

public static final int TOUCHEVENTS

A bit-mask covering all touch events (start, move, end, cancel).

Constant Value: 15728640 (0x00f00000)

public static final int UNDEFINED

Value returned by accessors when the actual integer value is undefined. In Development Mode, most accessors assert that the requested attribute is reliable across all supported browsers.

Constant Value: 0 (0x00000000)

Protected Constructors

protected Event ()

Not directly instantiable. Subclasses should also define a protected no-arg constructor to prevent client code from directly instantiating the class.

Public Methods

public static void addEventPreview (EventPreview preview)

This method is deprecated.
replaced by addNativePreviewHandler(NativePreviewHandler)

Adds an event preview to the preview stack. As long as this preview remains on the top of the stack, it will receive all events before they are fired to their listeners. Note that the event preview will receive all events, including those received due to bubbling, whereas normal event handlers only receive explicitly sunk events.

Parameters
preview the event preview to be added to the stack.

public static HandlerRegistration addNativePreviewHandler (Event.NativePreviewHandler handler)

Adds a Event.NativePreviewHandler that will receive all events before they are fired to their handlers. Note that the handler will receive all native events, including those received due to bubbling, whereas normal event handlers only receive explicitly sunk events.

Unlike other event handlers, Event.NativePreviewHandler are fired in the reverse order that they are added, such that the last Event.NativePreviewEvent that was added is the first to be fired.

Please note that nondeterministic behavior will result if more than one GWT application registers preview handlers. See issue 3892 for details.

Parameters
handler the Event.NativePreviewHandler
Returns

public static Event as (NativeEvent event)

Converts the NativeEvent to Event. This is always safe.

Parameters
event the event to downcast

public final void cancelBubble (boolean cancel)

This method is deprecated.
use stopPropagation() instead

Cancels bubbling for the given event. This will stop the event from being propagated to parent elements.

Parameters
cancel true to cancel bubbling

public static boolean fireNativePreviewEvent (NativeEvent nativeEvent)

Fire a Event.NativePreviewEvent for the native event.

Parameters
nativeEvent the native event
Returns
  • true to fire the event normally, false to cancel the event

public static Event getCurrentEvent ()

Gets the current event that is being fired. The current event is only available within the lifetime of the onBrowserEvent function. Once the onBrowserEvent method returns, the current event is reset to null.

Returns
  • the current event

public final Element getCurrentTarget ()

This method is deprecated.
use getCurrentEventTarget() instead

Gets the current target element of this event. This is the element whose listener fired last, not the element which fired the event initially.

Returns
  • the event's current target element

public static EventListener getEventListener (Element elem)

Gets the EventListener that will receive events for the given element. Only one such listener may exist for a single element.

Parameters
elem the element whose listener is to be set
Returns
  • the element's event listener

public static int getEventsSunk (Element elem)

Gets the current set of events sunk by a given element.

Parameters
elem the element whose events are to be retrieved
Returns

public final Element getFromElement ()

This method is deprecated.
use getRelatedEventTarget() instead

Gets the element from which the mouse pointer was moved (only valid for ONMOUSEOVER).

Returns
  • the element from which the mouse pointer was moved

public final Element getRelatedTarget ()

This method is deprecated.
use getRelatedEventTarget() instead

Gets the related target for this event.

Returns
  • the related target

public final boolean getRepeat ()

This method is deprecated.
not supported on all browsers

Gets the key-repeat state of this event.

Returns
  • true if this key event was an auto-repeat

public final Element getTarget ()

This method is deprecated.
use getEventTarget() instead

Returns the element that was the actual target of the given event.

Returns
  • the target element

public final Element getToElement ()

This method is deprecated.
use getRelatedEventTarget() instead

Gets the element to which the mouse pointer was moved (only valid for ONMOUSEOUT).

Returns
  • the element to which the mouse pointer was moved

public static int getTypeInt (String typeName)

Gets the enumerated type of this event given a valid event type name.

Parameters
typeName the typeName to be tested
Returns
  • the event's enumerated type, or -1 if not defined

public final int getTypeInt ()

Gets the enumerated type of this event, as defined by ONCLICK, ONMOUSEDOWN, and so forth.

Returns
  • the event's enumerated type

public static void releaseCapture (Element elem)

Releases mouse capture on the given element. Calling this method has no effect if the element does not currently have mouse capture.

Parameters
elem the element to release capture

public static void removeEventPreview (EventPreview preview)

This method is deprecated.
use HandlerRegistration returned from addNativePreviewHandler(NativePreviewHandler)

Removes an element from the preview stack. This element will no longer capture events, though any preview underneath it will begin to do so.

Parameters
preview the event preview to be removed from the stack

public static void setCapture (Element elem)

Sets mouse-capture on the given element. This element will directly receive all mouse events until releaseCapture(Element) is called on it.

Parameters
elem the element on which to set mouse capture

public static void setEventListener (Element elem, EventListener listener)

Sets the EventListener to receive events for the given element. Only one such listener may exist for a single element.

Parameters
elem the element whose listener is to be set
listener the listener to receive events

public static void sinkEvents (Element elem, int eventBits)

Sets the current set of events sunk by a given element. These events will be fired to the nearest EventListener specified on any of the element's parents.

Parameters
elem the element whose events are to be retrieved
eventBits a bitfield describing the events sunk on this element (its possible values are described in Event.NativePreviewEvent)