From 899f45bb45d61b9c1738dbdf9a530aa6a2c9ee12 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 15 Dec 2015 13:39:12 +0200 Subject: Fix text selection and context click events for Android devices (#19367) Text and element selection needs to be disabled on touch start for Android as well. Other touch event handling used by iOS devices is not used on Android. Change-Id: I7f17af437ddf4f7b747232fbd19b2cd5c825c0e2 --- .../vaadin/client/ui/AbstractComponentConnector.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 9a1c21d556..c312cf5325 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -181,6 +181,15 @@ public abstract class AbstractComponentConnector extends AbstractConnector return; } + // Prevent selection for the element while pending long tap. + WidgetUtil.setTextSelectionEnabled(getWidget().getElement(), + false); + + if (BrowserInfo.get().isAndroid()) { + // Android fires ContextMenu events automatically. + return; + } + /* * we need to build mouseEventDetails eagerly - the event won't * be guaranteed to be around when the timer executes. At least @@ -190,10 +199,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector final MouseEventDetails mouseEventDetails = MouseEventDetailsBuilder.buildMouseEventDetails( event.getNativeEvent(), getWidget().getElement()); - // Prevent selection for the element while pending long tap. - WidgetUtil.setTextSelectionEnabled(getWidget().getElement(), - false); - final EventTarget eventTarget = event.getNativeEvent() .getEventTarget(); @@ -278,8 +283,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector } protected boolean shouldHandleLongTap() { - final BrowserInfo browserInfo = BrowserInfo.get(); - return browserInfo.isTouchDevice() && !browserInfo.isAndroid(); + return BrowserInfo.get().isTouchDevice(); } /** @@ -288,9 +292,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector * @since 7.6 */ private void cancelTouchTimer() { + WidgetUtil.setTextSelectionEnabled(getWidget().getElement(), true); if (longTouchTimer != null) { // Re-enable text selection - WidgetUtil.setTextSelectionEnabled(getWidget().getElement(), true); longTouchTimer.cancel(); } } -- cgit v1.2.3