Event (GWT Javadoc)

Overview | Package | Class | Use | Deprecated | Help
| GWT 2.7.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client
Class Event

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

    public class Event

extends NativeEvent

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.

Nested Class Summary
`static class` | `Event.NativePreviewEvent` Represents a preview of a native `Event`.
`static interface` | `Event.NativePreviewHandler` Handler interface for `Event.NativePreviewEvent` events.

Field Summary
`static int` | `FOCUSEVENTS` A bit-mask covering both focus events (focus and blur).
`static int` | `GESTUREEVENTS` A bit-mask covering all gesture events (start, change, end).
`(package private) static HandlerManager` | `handlers` The list of `Event.NativePreviewHandler`.
`static int` | `KEYEVENTS` A bit-mask covering all keyboard events (down, up, and press).
`static int` | `MOUSEEVENTS` A bit-mask covering all mouse events (down, up, move, over, and out), but not click, dblclick, or wheel events.
`static int` | `ONBLUR` Fired when an element loses keyboard focus.
`static int` | `ONCHANGE` Fired when the value of an input element changes.
`static int` | `ONCLICK` Fired when the user clicks on an element.
`static int` | `ONCONTEXTMENU` Fired when the user requests an element's context menu (usually by right-clicking).
`static int` | `ONDBLCLICK` Fired when the user double-clicks on an element.
`static int` | `ONERROR` Fired when an image encounters an error.
`static int` | `ONFOCUS` Fired when an element receives keyboard focus.
`static int` | `ONGESTURECHANGE` Fired when the user gesture changes.
`static int` | `ONGESTUREEND` Fired when the user gesture ends.
`static int` | `ONGESTURESTART` Fired when the user gesture starts.
`static int` | `ONKEYDOWN` Fired when the user depresses a key.
`static int` | `ONKEYPRESS` Fired when the a character is generated from a keypress (either directly or through auto-repeat).
`static int` | `ONKEYUP` Fired when the user releases a key.
`static int` | `ONLOAD` Fired when an element (normally an IMG) finishes loading.
`static int` | `ONLOSECAPTURE` Fired when an element that has mouse capture loses it.
`static int` | `ONMOUSEDOWN` Fired when the user depresses a mouse button over an element.
`static int` | `ONMOUSEMOVE` Fired when the mouse is moved within an element's area.
`static int` | `ONMOUSEOUT` Fired when the mouse is moved out of an element's area.
`static int` | `ONMOUSEOVER` Fired when the mouse is moved into an element's area.
`static int` | `ONMOUSEUP` Fired when the user releases a mouse button over an element.
`static int` | `ONMOUSEWHEEL` Fired when the user scrolls the mouse wheel over an element.
`static int` | `ONPASTE` Fired when the user pastes text into an input element.
`static int` | `ONSCROLL` Fired when a scrollable element's scroll offset changes.
`static int` | `ONTOUCHCANCEL` Fired when the user cancels touching an element.
`static int` | `ONTOUCHEND` Fired when the user ends touching an element.
`static int` | `ONTOUCHMOVE` Fired when the user moves while touching an element.
`static int` | `ONTOUCHSTART` Fired when the user starts touching an element.
`static int` | `TOUCHEVENTS` A bit-mask covering all touch events (start, move, end, cancel).
`static int` | `UNDEFINED` Deprecated.

Fields inherited from class com.google.gwt.dom.client.NativeEvent
`BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT`

Constructor Summary
`protected` | `Event()` Not directly instantiable.

Method Summary
`static void` | `addEventPreview(EventPreview preview)` 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.
`void` | `cancelBubble(boolean cancel)` Deprecated. use `NativeEvent.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.
`Element` | `getCurrentTarget()` Deprecated. use `NativeEvent.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.
`Element` | `getFromElement()` Deprecated. use `NativeEvent.getRelatedEventTarget()` instead
`Element` | `getRelatedTarget()` Deprecated. use `NativeEvent.getRelatedEventTarget()` instead
`boolean` | `getRepeat()` Deprecated. not supported on all browsers
`Element` | `getTarget()` Deprecated. use `NativeEvent.getEventTarget()` instead
`Element` | `getToElement()` Deprecated. use `NativeEvent.getRelatedEventTarget()` instead
`int` | `getTypeInt()` Gets the enumerated type of this event, as defined by `ONCLICK`, `ONMOUSEDOWN`, and so forth.
`static int` | `getTypeInt(java.lang.String typeName)` Gets the enumerated type of this event given a valid event type name.
`static void` | `releaseCapture(Element elem)` Releases mouse capture on the given element.
`static void` | `removeEventPreview(EventPreview preview)` 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.

Methods inherited from class com.google.gwt.dom.client.NativeEvent
`getAltKey, getButton, getChangedTouches, getCharCode, getClientX, getClientY, getCtrlKey, getCurrentEventTarget, getDataTransfer, getEventTarget, getKeyCode, getMetaKey, getMouseWheelVelocityY, getRelatedEventTarget, getRotation, getScale, getScreenX, getScreenY, getShiftKey, getString, getTargetTouches, getTouches, getType, preventDefault, stopPropagation`

Methods inherited from class com.google.gwt.core.client.JavaScriptObject
`cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### ONBLUR

    public static final int ONBLUR

  Fired when an element loses keyboard focus.

  See Also:
    Constant Field Values

### ONCHANGE

    public static final int ONCHANGE

  Fired when the value of an input element changes.

  See Also:
    Constant Field Values

### ONCLICK

    public static final int ONCLICK

  Fired when the user clicks on an element.

  See Also:
    Constant Field Values

### ONDBLCLICK

    public static final int ONDBLCLICK

  Fired when the user double-clicks on an element.

  See Also:
    Constant Field Values

### ONERROR

    public static final int ONERROR

  Fired when an image encounters an error.

  See Also:
    Constant Field Values

### ONFOCUS

    public static final int ONFOCUS

  Fired when an element receives keyboard focus.

  See Also:
    Constant Field Values

### ONGESTURECHANGE

    public static final int ONGESTURECHANGE

  Fired when the user gesture changes.

  See Also:
    Constant Field Values

### ONGESTUREEND

    public static final int ONGESTUREEND

  Fired when the user gesture ends.

  See Also:
    Constant Field Values

### ONGESTURESTART

    public static final int ONGESTURESTART

  Fired when the user gesture starts.

  See Also:
    Constant Field Values

### ONKEYDOWN

    public static final int ONKEYDOWN

  Fired when the user depresses a key.

  See Also:
    Constant Field Values

### ONKEYPRESS

    public static final int ONKEYPRESS

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

  See Also:
    Constant Field Values

### ONKEYUP

    public static final int ONKEYUP

  Fired when the user releases a key.

  See Also:
    Constant Field Values

### ONLOAD

    public static final int ONLOAD

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

  See Also:
    Constant Field Values

### ONLOSECAPTURE

    public static final int ONLOSECAPTURE

  Fired when an element that has mouse capture loses it.

  See Also:
    Constant Field Values

### ONMOUSEDOWN

    public static final int ONMOUSEDOWN

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

  See Also:
    Constant Field Values

### ONMOUSEMOVE

    public static final int ONMOUSEMOVE

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

  See Also:
    Constant Field Values

### ONMOUSEOUT

    public static final int ONMOUSEOUT

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

  See Also:
    Constant Field Values

### ONMOUSEOVER

    public static final int ONMOUSEOVER

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

  See Also:
    Constant Field Values

### ONMOUSEUP

    public static final int ONMOUSEUP

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

  See Also:
    Constant Field Values

### ONMOUSEWHEEL

    public static final int ONMOUSEWHEEL

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

  See Also:
    Constant Field Values

### ONPASTE

    public static final int ONPASTE

  Fired when the user pastes text into an input element.

  See Also:
    Constant Field Values

### ONSCROLL

    public static final int ONSCROLL

  Fired when a scrollable element's scroll offset changes.

  See Also:
    Constant Field Values

### ONTOUCHCANCEL

    public static final int ONTOUCHCANCEL

  Fired when the user cancels touching an element.

  See Also:
    Constant Field Values

### ONTOUCHEND

    public static final int ONTOUCHEND

  Fired when the user ends touching an element.

  See Also:
    Constant Field Values

### ONTOUCHMOVE

    public static final int ONTOUCHMOVE

  Fired when the user moves while touching an element.

  See Also:
    Constant Field Values

### ONTOUCHSTART

    public static final int ONTOUCHSTART

  Fired when the user starts touching an element.

  See Also:
    Constant Field Values

### ONCONTEXTMENU

    public static final int ONCONTEXTMENU

  Fired when the user requests an element's context menu (usually by right-clicking).

  See Also:
    Constant Field Values

### FOCUSEVENTS

    public static final int FOCUSEVENTS

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

  See Also:
    Constant Field Values

### KEYEVENTS

    public static final int KEYEVENTS

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

  See Also:
    Constant Field Values

### MOUSEEVENTS

    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.

  See Also:
    Constant Field Values

### TOUCHEVENTS

    public static final int TOUCHEVENTS

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

  See Also:
    Constant Field Values

### GESTUREEVENTS

    public static final int GESTUREEVENTS

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

  See Also:
    Constant Field Values

### UNDEFINED

    @Deprecated
    public static final int UNDEFINED

  Deprecated.
  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.

  See Also:
    `Event.NativePreviewEvent`, Constant Field Values

### handlers

    static HandlerManager handlers

  The list of `Event.NativePreviewHandler`. We use a list instead of a handler manager for efficiency and because we want to fire the handlers in reverse order. When the last handler is removed, handlers is reset to null.

Constructor Detail

### Event

    protected Event()

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

Method Detail

### addEventPreview

    @Deprecated
    public static void addEventPreview(EventPreview preview)

  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.

### addNativePreviewHandler

    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:
    `HandlerRegistration` used to remove this handler

### as

    public static Event as(NativeEvent event)

  Converts the `NativeEvent` to Event. This is always safe.

  Parameters:
    `event` - the event to downcast

### fireNativePreviewEvent

    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

### getCurrentEvent

    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

### getEventListener

    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

### getEventsSunk

    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:
    a bitfield describing the events sunk on this element (its possible values are described in `Event.NativePreviewEvent`)

### getTypeInt

    public static int getTypeInt(java.lang.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

### releaseCapture

    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
  See Also:
    `setCapture(Element)`

### removeEventPreview

    @Deprecated
    public static void removeEventPreview(EventPreview preview)

  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

### setCapture

    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

### setEventListener

    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`

### sinkEvents

    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`)

### cancelBubble

    @Deprecated
    public final void cancelBubble(boolean cancel)

  Deprecated. use `NativeEvent.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

### getCurrentTarget

    @Deprecated
    public final Element getCurrentTarget()

  Deprecated. use `NativeEvent.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

### getFromElement

    @Deprecated
    public final Element getFromElement()

  Deprecated. use `NativeEvent.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

### getRelatedTarget

    @Deprecated
    public final Element getRelatedTarget()

  Deprecated. use `NativeEvent.getRelatedEventTarget()` instead

  Gets the related target for this event.

  Returns:
    the related target

### getRepeat

    @Deprecated
    public final boolean getRepeat()

  Deprecated. not supported on all browsers

  Gets the key-repeat state of this event.

  Returns:
    `true` if this key event was an auto-repeat

### getTarget

    @Deprecated
    public final Element getTarget()

  Deprecated. use `NativeEvent.getEventTarget()` instead

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

  Returns:
    the target element

### getToElement

    @Deprecated
    public final Element getToElement()

  Deprecated. use `NativeEvent.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

### getTypeInt

    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

Overview | Package | Class | Use | Deprecated | Help
| GWT 2.7.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD