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.
Modifier and Type | Class and Description |
---|---|
static class |
Event.NativePreviewEvent
Represents a preview of a native
Event . |
static interface |
Event.NativePreviewHandler
Handler interface for
Event.NativePreviewEvent events. |
Modifier and Type | Field and Description |
---|---|
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.
|
BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT
Modifier | Constructor and Description |
---|---|
protected |
Event()
Not directly instantiable.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
public static final int ONBLUR
public static final int ONCHANGE
public static final int ONCLICK
public static final int ONDBLCLICK
public static final int ONERROR
public static final int ONFOCUS
public static final int ONGESTURECHANGE
public static final int ONGESTUREEND
public static final int ONGESTURESTART
public static final int ONKEYDOWN
public static final int ONKEYPRESS
public static final int ONKEYUP
public static final int ONLOAD
public static final int ONLOSECAPTURE
public static final int ONMOUSEDOWN
public static final int ONMOUSEMOVE
public static final int ONMOUSEOUT
public static final int ONMOUSEOVER
public static final int ONMOUSEUP
public static final int ONMOUSEWHEEL
public static final int ONPASTE
public static final int ONSCROLL
public static final int ONTOUCHCANCEL
public static final int ONTOUCHEND
public static final int ONTOUCHMOVE
public static final int ONTOUCHSTART
public static final int ONCONTEXTMENU
public static final int FOCUSEVENTS
public static final int KEYEVENTS
public static final int MOUSEEVENTS
public static final int TOUCHEVENTS
public static final int GESTUREEVENTS
@Deprecated public static final int UNDEFINED
Event
,
Constant Field Valuesstatic HandlerManager handlers
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.protected Event()
@Deprecated public static void addEventPreview(EventPreview preview)
addNativePreviewHandler(NativePreviewHandler)
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.
handler
- the Event.NativePreviewHandler
HandlerRegistration
used to remove this handlerpublic static Event as(NativeEvent event)
NativeEvent
to Event. This is always safe.event
- the event to downcastpublic static boolean fireNativePreviewEvent(NativeEvent nativeEvent)
Event.NativePreviewEvent
for the native event.nativeEvent
- the native eventpublic static Event getCurrentEvent()
public static EventListener getEventListener(Element elem)
EventListener
that will receive events for the given
element. Only one such listener may exist for a single element.elem
- the element whose listener is to be setpublic static int getEventsSunk(Element elem)
elem
- the element whose events are to be retrievedEvent
)public static int getTypeInt(java.lang.String typeName)
typeName
- the typeName to be testedpublic static void releaseCapture(Element elem)
elem
- the element to release capturesetCapture(Element)
@Deprecated public static void removeEventPreview(EventPreview preview)
HandlerRegistration
returned from
addNativePreviewHandler(NativePreviewHandler)
preview
- the event preview to be removed from the stackpublic static void setCapture(Element elem)
releaseCapture(Element)
is called on it.elem
- the element on which to set mouse capturepublic static void setEventListener(Element elem, EventListener listener)
EventListener
to receive events for the given element.
Only one such listener may exist for a single element.elem
- the element whose listener is to be setlistener
- the listener to receive events
public static void sinkEvents(Element elem, int eventBits)
EventListener
specified on any of the
element's parents.elem
- the element whose events are to be retrievedeventBits
- a bitfield describing the events sunk on this element (its
possible values are described in Event
)@Deprecated public final void cancelBubble(boolean cancel)
NativeEvent.stopPropagation()
insteadcancel
- true
to cancel bubbling@Deprecated public final Element getCurrentTarget()
NativeEvent.getCurrentEventTarget()
instead@Deprecated public final Element getFromElement()
NativeEvent.getRelatedEventTarget()
insteadONMOUSEOVER
).@Deprecated public final Element getRelatedTarget()
NativeEvent.getRelatedEventTarget()
instead@Deprecated public final boolean getRepeat()
true
if this key event was an auto-repeat@Deprecated public final Element getTarget()
NativeEvent.getEventTarget()
instead@Deprecated public final Element getToElement()
NativeEvent.getRelatedEventTarget()
insteadONMOUSEOUT
).public final int getTypeInt()
ONCLICK
,
ONMOUSEDOWN
, and so forth.