TouchEvent abstract class
Abstract class representing touch events.
See {@link <a href="http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html">Safari Touch Event Documentation</a>} @param <H> handler type
abstract class TouchEvent extends DomEvent {
/**
* The implementation singleton.
*/
static TouchSupportDetector _impl;
/**
* Runtime check for whether touch scrolling is supported in this browser. Returns true if touch
* events are supported but touch based scrolling is not natively supported.
*
* @return true if touch events are supported, false if not
*/
static bool isSupported() {
if (_impl == null) {
_impl = new TouchSupportDetector();
}
return _impl.isSupported();
}
/**
* Cast native event to [TouchEvent].
*/
dart_html.TouchEvent getTouchEvent() {
if (getNativeEvent() is dart_html.TouchEvent) {
return getNativeEvent() as dart_html.TouchEvent;
}
throw new Exception("Native event is not subtype of TouchEvent");
}
/**
* Get an array of {@link Touch touches} which have changed since the last
* touch event fired. Note, that for {@link TouchEndEvent touch end events},
* the touch which has just ended will not be present in the array. Moreover,
* if the touch which just ended was the last remaining touch, then a zero
* length array will be returned.
*
* @return an array of touches
*/
List<dart_html.Touch> getChangedTouches() {
return getTouchEvent().changedTouches;
}
/**
* Get an array of {@link Touch touches} all touch which originated at the
* same target as the current touch event. Note, that for {@link TouchEndEvent
* touch end events}, the touch which has just ended will not be present in
* the array. Moreover, if the touch which just ended was the last remaining
* touch, then a zero length array will be returned.
*
* @return an array of touches
*/
List<dart_html.Touch> getTargetTouches() {
return getTouchEvent().targetTouches;
}
/**
* Get an array of all current {@link Touch touches}. Note, that for
* {@link TouchEndEvent touch end events}, the touch which has just ended will
* not be present in the array. Moreover, if the touch which just ended was
* the last remaining touch, then a zero length array will be returned.
*
* @return an array of touches
*/
List<dart_html.Touch> getTouches() {
return getTouchEvent().touches;
}
}
Extends
IEvent<H> > DwtEvent > DomEvent > TouchEvent
Subclasses
TouchCancelEvent, TouchEndEvent, TouchMoveEvent, TouchStartEvent
Static Methods
bool isSupported() #
Runtime check for whether touch scrolling is supported in this browser. Returns true if touch events are supported but touch based scrolling is not natively supported.
@return true if touch events are supported, false if not
static bool isSupported() {
if (_impl == null) {
_impl = new TouchSupportDetector();
}
return _impl.isSupported();
}
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";
}
abstract void dispatch(H 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)
EventType<EventHandler> getAssociatedType() #
List<Touch> getChangedTouches() #
Get an array of {@link Touch touches} which have changed since the last touch event fired. Note, that for {@link TouchEndEvent touch end events}, the touch which has just ended will not be present in the array. Moreover, if the touch which just ended was the last remaining touch, then a zero length array will be returned.
@return an array of touches
List<dart_html.Touch> getChangedTouches() {
return getTouchEvent().changedTouches;
}
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;
}
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();
}
List<Touch> getTargetTouches() #
Get an array of {@link Touch touches} all touch which originated at the same target as the current touch event. Note, that for {@link TouchEndEvent touch end events}, the touch which has just ended will not be present in the array. Moreover, if the touch which just ended was the last remaining touch, then a zero length array will be returned.
@return an array of touches
List<dart_html.Touch> getTargetTouches() {
return getTouchEvent().targetTouches;
}
List<Touch> getTouches() #
Get an array of all current {@link Touch touches}. Note, that for {@link TouchEndEvent touch end events}, the touch which has just ended will not be present in the array. Moreover, if the touch which just ended was the last remaining touch, then a zero length array will be returned.
@return an array of touches
List<dart_html.Touch> getTouches() {
return getTouchEvent().touches;
}
TouchEvent getTouchEvent() #
Cast native event to TouchEvent.
dart_html.TouchEvent getTouchEvent() {
if (getNativeEvent() is dart_html.TouchEvent) {
return getNativeEvent() as dart_html.TouchEvent;
}
throw new Exception("Native event is not subtype of TouchEvent");
}
bool isLive() #
Is the event current live?
@return whether the event is live
bool isLive() {
return !_dead;
}
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;
}