diff options
author | Markus Koivisto <markus@vaadin.com> | 2015-10-28 19:23:22 +0200 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-11-02 08:20:35 +0000 |
commit | 0e9386aa16ca574043d10fb52d707e4f25aa2614 (patch) | |
tree | af88705ec675c1d74e3561a61d09cfef0c834859 /client | |
parent | 731fec8cc81c4ff6ca53d404b68a2c1538fd3885 (diff) | |
download | vaadin-framework-0e9386aa16ca574043d10fb52d707e4f25aa2614.tar.gz vaadin-framework-0e9386aa16ca574043d10fb52d707e4f25aa2614.zip |
Touch long tap context click emulation improvements (#19222)
Removed Android handling since it already fires a context menu event
when not selecting text. Increased the threshold for iOS move. Prevent
some browser default functionality on TouchEnd after sending context
click event to server.
Change-Id: I9297a5738e593a260b50ba176d483fbdd3293ba3
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/AbstractComponentConnector.java | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 7afefe8061..1b3f5de3b1 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -33,6 +33,7 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Focusable; import com.google.gwt.user.client.ui.HasEnabled; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.HasComponentsConnector; import com.vaadin.client.LayoutManager; @@ -85,10 +86,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector private HandlerRegistration touchEndHandler; private int touchStartX; private int touchStartY; + private boolean preventNextTouchEnd = false; + + protected int SIGNIFICANT_MOVE_THRESHOLD = 20; // pixels // long touch event delay // TODO replace with global constant for accessibility - private static final int TOUCH_CONTEXT_MENU_TIMEOUT = 250; + private static final int TOUCH_CONTEXT_MENU_TIMEOUT = 500; /** * Default constructor @@ -117,7 +121,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector // if the widget has a contextclick listener, add touch support as // well. - registerTouchHandlers(); + if (shouldHandleLongTap()) { + registerTouchHandlers(); + } } else if (contextHandler != null && !hasEventListener(EventId.CONTEXT_CLICK)) { @@ -140,12 +146,18 @@ public abstract class AbstractComponentConnector extends AbstractConnector * @since 7.6 */ protected void unregisterTouchHandlers() { - touchStartHandler.removeHandler(); - touchStartHandler = null; - touchMoveHandler.removeHandler(); - touchMoveHandler = null; - touchEndHandler.removeHandler(); - touchEndHandler = null; + if (touchStartHandler != null) { + touchStartHandler.removeHandler(); + touchStartHandler = null; + } + if (touchMoveHandler != null) { + touchMoveHandler.removeHandler(); + touchMoveHandler = null; + } + if (touchEndHandler != null) { + touchEndHandler.removeHandler(); + touchEndHandler = null; + } } /** @@ -155,6 +167,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector * If you do not want this in your component, override this with a blank * method to get rid of said behaviour. * + * Some Vaadin Components already handle the long tap as a context menu. + * This method is unnecessary for those. + * * @since 7.6 */ protected void registerTouchHandlers() { @@ -162,6 +177,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector @Override public void onTouchStart(final TouchStartEvent event) { + if (longTouchTimer != null && longTouchTimer.isRunning()) { + return; + } /* * we need to build mouseEventDetails eagerly - the event won't @@ -189,7 +207,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector // element of widget. sendContextClickEvent(mouseEventDetails, eventTarget); - + preventNextTouchEnd = true; } }; @@ -232,8 +250,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector // Compare to the square of the significant move threshold to // remove the need for a square root - if (delta > TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD - * TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD) { + if (delta > SIGNIFICANT_MOVE_THRESHOLD + * SIGNIFICANT_MOVE_THRESHOLD) { return true; } return false; @@ -247,10 +265,19 @@ public abstract class AbstractComponentConnector extends AbstractConnector // cancel the timer so the event doesn't fire cancelTouchTimer(); + if (preventNextTouchEnd) { + event.preventDefault(); + preventNextTouchEnd = false; + } } }, TouchEndEvent.getType()); } + protected boolean shouldHandleLongTap() { + final BrowserInfo browserInfo = BrowserInfo.get(); + return browserInfo.isTouchDevice() && !browserInfo.isAndroid(); + } + /** * If a long touch event timer is running, cancel it. * |