com.vaadin.terminal.gwt.client.ui
Class TouchScrollDelegate

java.lang.Object
  extended by com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate
All Implemented Interfaces:
com.google.gwt.event.shared.EventHandler, com.google.gwt.user.client.Event.NativePreviewHandler

public class TouchScrollDelegate
extends Object
implements com.google.gwt.user.client.Event.NativePreviewHandler

Provides one finger touch scrolling for elements with once scrollable elements inside. One widget can have several of these scrollable elements. Scrollable elements are provided in the constructor. Users must pass touchStart events to this delegate, from there on the delegate takes over with an event preview. Other touch events needs to be sunken though.

This is bit similar as Scroller class in GWT expenses example, but ideas drawn from iscroll.js project:

Scroll event should only happen when the "touch scrolling actually ends". Later we might also tune this so that a scroll event happens if user stalls her finger long enought. TODO static getter for active touch scroll delegate. Components might need to prevent scrolling in some cases. Consider Table with drag and drop, or drag and drop in scrollable area. Optimal implementation might be to start the drag and drop only if user keeps finger down for a moment, otherwise do the scroll. In this case, the draggable component would need to cancel scrolling in a timer after touchstart event and take over from there. TODO support scrolling horizontally TODO cancel if user add second finger to the screen (user expects a gesture). TODO "scrollbars", see e.g. iscroll.js TODO write an email to sjobs √§t apple dot com and beg for this feature to be built into webkit. Seriously, we should try to lobbying this to webkit folks. This sure ain't our business to implement this with javascript. TODO collect all general touch related constant to better place.

Author:
Matti Tahvonen, Vaadin Ltd

Field Summary
static int SIGNIFICANT_MOVE_THRESHOLD
           
 
Constructor Summary
TouchScrollDelegate(com.google.gwt.dom.client.Element... elements)
           
 
Method Summary
static TouchScrollDelegate getActiveScrollDelegate()
           
 boolean isMoved()
          Has user moved the touch.
 void onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent event)
           
 void onTouchStart(com.google.gwt.event.dom.client.TouchStartEvent event)
           
 void setElements(com.google.gwt.user.client.Element[] elements)
           
 void stopScrolling()
          Forces the scroll delegate to cancels scrolling process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIGNIFICANT_MOVE_THRESHOLD

public static final int SIGNIFICANT_MOVE_THRESHOLD
See Also:
Constant Field Values
Constructor Detail

TouchScrollDelegate

public TouchScrollDelegate(com.google.gwt.dom.client.Element... elements)
Method Detail

getActiveScrollDelegate

public static TouchScrollDelegate getActiveScrollDelegate()

isMoved

public boolean isMoved()
Has user moved the touch.

Returns:

stopScrolling

public void stopScrolling()
Forces the scroll delegate to cancels scrolling process. Can be called by users if they e.g. decide to handle touch event by themselves after all (e.g. a pause after touch start before moving touch -> interpreted as long touch/click or drag start).


onTouchStart

public void onTouchStart(com.google.gwt.event.dom.client.TouchStartEvent event)

onPreviewNativeEvent

public void onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent event)
Specified by:
onPreviewNativeEvent in interface com.google.gwt.user.client.Event.NativePreviewHandler

setElements

public void setElements(com.google.gwt.user.client.Element[] elements)


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.