MouseWheelEvent class
Represents a native mouse wheel event.
class MouseWheelEvent extends MouseEvent { /** * The event type. */ static DomEventType<MouseWheelHandler> TYPE = new DomEventType<MouseWheelHandler>(BrowserEvents.MOUSEWHEEL, new MouseWheelEvent()); DomEventType<MouseWheelHandler> getAssociatedType() { return TYPE; } MouseWheelEvent(); void dispatch(MouseWheelHandler handler) { handler.onMouseWheel(this); } /** * Cast native event to [WheelEvent]. */ dart_html.WheelEvent getWheelEvent() { if (getNativeEvent() is dart_html.WheelEvent) { return getNativeEvent() as dart_html.WheelEvent; } throw new Exception("Native event is not subtype of WheelEvent"); } /** * Get the change in the mouse wheel position along the Y-axis; positive if * the mouse wheel is moving north (toward the top of the screen) or negative * if the mouse wheel is moving south (toward the bottom of the screen). * * Note that delta values are not normalized across browsers or OSes. * * @return the delta of the mouse wheel along the y axis */ int getDeltaY() { return getWheelEvent().deltaY; } /** * Convenience method that returns <code>true</code> if {@link #getDeltaY()} * is a negative value (ie, the velocity is directed toward the top of the * screen). * * @return true if the velocity is directed toward the top of the screen */ bool isNorth() { return getDeltaY() < 0; } /** * Convenience method that returns <code>true</code> if {@link #getDeltaY()} * is a positive value (ie, the velocity is directed toward the bottom of the * screen). * * @return true if the velocity is directed toward the bottom of the screen */ bool isSouth() { return getDeltaY() > 0; } }
Extends
IEvent<H> > DwtEvent > DomEvent > MouseEvent > MouseWheelEvent
Static Properties
DomEventType<MouseWheelHandler> TYPE #
The event type.
static DomEventType<MouseWheelHandler> TYPE = new DomEventType<MouseWheelHandler>(BrowserEvents.MOUSEWHEEL, new MouseWheelEvent())
Methods
void assertLive() #
Asserts that the event still should be accessed. All events are considered to be "dead" after their original handler manager finishes firing them. An event can be revived by calling {@link GwtEvent#revive()}.
void assertLive() { assert (!_dead) ; //: "This event has already finished being processed by its original handler manager, so you can no longer access it"; }
void dispatch(MouseWheelHandler handler) #
Implemented by subclasses to invoke their handlers in a type safe
manner. Intended to be called by EventBus#fireEvent(Event)
or
EventBus#fireEventFromSource(Event, Object)
.
@param handler handler @see EventBus#dispatchEvent(Event, Object)
void dispatch(MouseWheelHandler handler) { handler.onMouseWheel(this); }
DomEventType<MouseWheelHandler> getAssociatedType() #
int getClientX() #
Gets the mouse x-position within the browser window's client area.
@return the mouse x-position
int getClientX() { return getMouseEvent().client.x; }
int getClientY() #
Gets the mouse y-position within the browser window's client area.
@return the mouse y-position
int getClientY() { return getMouseEvent().client.y; }
int getDeltaY() #
Get the change in the mouse wheel position along the Y-axis; positive if the mouse wheel is moving north (toward the top of the screen) or negative if the mouse wheel is moving south (toward the bottom of the screen).
Note that delta values are not normalized across browsers or OSes.
@return the delta of the mouse wheel along the y axis
int getDeltaY() { return getWheelEvent().deltaY; }
MouseEvent getMouseEvent() #
Cast native event to MouseEvent.
dart_html.MouseEvent getMouseEvent() { if (getNativeEvent() is dart_html.MouseEvent) { return getNativeEvent() as dart_html.MouseEvent; } throw new Exception("Native event is not subtype of MouseEvent"); }
int getNativeButton() #
Gets the button value. Compare it to {@link com.google.gwt.dom.client.NativeEvent#BUTTONLEFT}, {@link com.google.gwt.dom.client.NativeEvent#BUTTONRIGHT}, {@link com.google.gwt.dom.client.NativeEvent#BUTTON_MIDDLE}
@return the button value
int getNativeButton() { return getMouseEvent().button; }
Event getNativeEvent() #
dart_html.Event getNativeEvent() { assertLive(); return _nativeEvent; }
Element getRelativeElement() #
Gets the element relative to which event coordinates will be measured. If this element is <code>null</code>, event coordinates will be measured relative to the window's client area.
@return the event's relative element
dart_html.Element getRelativeElement() { assertLive(); return _relativeElem; }
int getRelativeX(Element target) #
Gets the mouse x-position relative to a given element.
@param target the element whose coordinate system is to be used @return the relative x-position
int getRelativeX(dart_html.Element target) { return getMouseEvent().client.x - Dom.getAbsoluteLeft(target) + target.scrollLeft + target.document.documentElement.scrollLeft; }
int getRelativeY(Element target) #
Gets the mouse y-position relative to a given element.
@param target the element whose coordinate system is to be used @return the relative y-position
int getRelativeY(dart_html.Element target) { return getMouseEvent().client.y - Dom.getAbsoluteTop(target) + target.scrollTop + target.document.documentElement.scrollTop; }
int getScreenX() #
Gets the mouse x-position on the user's display.
@return the mouse x-position
int getScreenX() { return getMouseEvent().screen.x; }
int getScreenY() #
Gets the mouse y-position on the user's display.
@return the mouse y-position
int getScreenY() { return getMouseEvent().screen.y; }
Object getSource() #
Returns the source for this event. The type and meaning of the source is
arbitrary, and is most useful as a secondary key for handler registration.
(See EventBus#addHandlerToSource
, which allows a handler to
register for events of a particular type, tied to a particular source.)
Note that the source is actually set at dispatch time, e.g. via
EventBus#fireEventFromSource(Event, Object)
.
@return object representing the source of this event
Object getSource() { assertLive(); return super.getSource(); }
WheelEvent getWheelEvent() #
Cast native event to WheelEvent
.
dart_html.WheelEvent getWheelEvent() { if (getNativeEvent() is dart_html.WheelEvent) { return getNativeEvent() as dart_html.WheelEvent; } throw new Exception("Native event is not subtype of WheelEvent"); }
int getX() #
Gets the mouse x-position relative to the event's current target element.
@return the relative x-position
int getX() { dart_html.Element relativeElem = getRelativeElement(); if (relativeElem != null) { return getRelativeX(relativeElem); } return getClientX(); }
int getY() #
Gets the mouse y-position relative to the event's current target element.
@return the relative y-position
int getY() { dart_html.Element relativeElem = getRelativeElement(); if (relativeElem != null) { return getRelativeY(relativeElem); } return getClientY(); }
bool isAltKeyDown() #
Is <code>alt</code> key down.
@return whether the alt key is down
bool isAltKeyDown() { return getMouseEvent().altKey; }
bool isControlKeyDown() #
Is <code>control</code> key down.
@return whether the control key is down
bool isControlKeyDown() { return getMouseEvent().ctrlKey; }
bool isLive() #
Is the event current live?
@return whether the event is live
bool isLive() { return !_dead; }
bool isMetaKeyDown() #
Is <code>meta</code> key down.
@return whether the meta key is down
bool isMetaKeyDown() { return getMouseEvent().metaKey; }
bool isNorth() #
Convenience method that returns <code>true</code> if {@link #getDeltaY()} is a negative value (ie, the velocity is directed toward the top of the screen).
@return true if the velocity is directed toward the top of the screen
bool isNorth() { return getDeltaY() < 0; }
bool isShiftKeyDown() #
Is <code>shift</code> key down.
@return whether the shift key is down
bool isShiftKeyDown() { return getMouseEvent().shiftKey; }
bool isSouth() #
Convenience method that returns <code>true</code> if {@link #getDeltaY()} is a positive value (ie, the velocity is directed toward the bottom of the screen).
@return true if the velocity is directed toward the bottom of the screen
bool isSouth() { return getDeltaY() > 0; }
void kill() #
Kill the event. After the event has been killed, users cannot really on its values or functions being available.
void kill() { _dead = true; setSource(null); }
void overrideSource(Object source) #
void overrideSource(Object source) { super.setSource(source); }
void preventDefault() #
Prevents the wrapped native event's default action.
void preventDefault() { assertLive(); _nativeEvent.preventDefault(); }
void revive() #
Revives the event. Used when recycling event instances.
void revive() { _dead = false; setSource(null); }
void setSource(source) #
Set the source that triggered this event. Intended to be called by the EventBus during dispatch.
@param source the source of this event. @see EventBus#fireEventFromSource(Event, Object) @see EventBus#setSourceOfEvent(Event, Object)
void setSource(dynamic source) { this._source = source; }