Class 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:

    • uses GWT event mechanism.
    • uses modern CSS trick during scrolling for smoother experience: translate3d and transitions

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

      • enableTouchScrolling

        public static TouchScrollDelegate.TouchScrollHandler enableTouchScrolling​(com.google.gwt.user.client.ui.Widget widget,
                                                                                  com.google.gwt.dom.client.Element... scrollables)
        Makes the given elements scrollable, either natively or by using a TouchScrollDelegate, depending on platform capabilities.
        Parameters:
        widget - The widget that contains scrollable elements
        scrollables - The elements inside the widget that should be scrollable
        Returns:
        A scroll handler for the given widget.
      • setScrollHandler

        public void setScrollHandler​(com.google.gwt.event.dom.client.ScrollHandler scrollHandler)
      • 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)
      • getElements

        public static ArrayList<com.google.gwt.dom.client.Element> getElements​(com.google.gwt.dom.client.Element scrolledElement2)
      • 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.dom.client.Element[] elements)
      • getTimeStamp

        public static double getTimeStamp()
        long calcucation are not very efficient in GWT, so this helper method returns timestamp in double.
        Returns: