From 9b17bc12f8116e33468e81d3b397ca81d8fea530 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Thu, 3 May 2012 15:02:57 +0000 Subject: [PATCH] New helper class handling touch scrolling either natively or with TouchScrollDelegate, depending on platform capabilities svn changeset:23671/svn branch:6.8 --- .../gwt/client/ui/TouchScrollDelegate.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java index 8b2248aff6..a2a94489e4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java @@ -15,10 +15,12 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Touch; import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.dom.client.TouchStartEvent; +import com.google.gwt.event.dom.client.TouchStartHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; +import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.VConsole; @@ -86,6 +88,49 @@ public class TouchScrollDelegate implements NativePreviewHandler { private static final boolean androidWithBrokenScrollTop = BrowserInfo.get() .isAndroidWithBrokenScrollTop(); + public static class TouchScrollHandler implements TouchStartHandler { + + private final TouchScrollDelegate delegate; + private final boolean requiresDelegate = BrowserInfo.get() + .requiresTouchScrollDelegate(); + + public TouchScrollHandler(Widget widget, Element... scrollables) { + if (requiresDelegate) { + delegate = new TouchScrollDelegate(); + widget.addDomHandler(this, TouchStartEvent.getType()); + } else { + delegate = null; + widget.addDomHandler(new TouchStartHandler() { + + public void onTouchStart(TouchStartEvent event) { + // TODO Auto-generated method stub + + } + }, TouchStartEvent.getType()); + } + setElements(scrollables); + } + + public void onTouchStart(TouchStartEvent event) { + VConsole.log("TouchScrollHandler onTouchStart"); + assert delegate != null; + delegate.onTouchStart(event); + } + + public void setElements(Element... scrollables) { + if (requiresDelegate) { + delegate.setElements(scrollables); + } else if (BrowserInfo.get().isTouchDevice()) { + for (Element e : scrollables) { + e.getStyle().setProperty("overflow", "auto"); + e.getStyle().setProperty("-webkit-overflow-scrolling", + "touch"); + e.getStyle().setProperty("-webkit-user-select", "none"); + } + } + } + } + public TouchScrollDelegate(Element... elements) { scrollableElements = elements; } @@ -535,7 +580,7 @@ public class TouchScrollDelegate implements NativePreviewHandler { } } - public void setElements(com.google.gwt.user.client.Element[] elements) { + public void setElements(Element[] elements) { scrollableElements = elements; } -- 2.39.5