Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 9dea1cf20d90e39fef4c10dde07a10e3e14892b0..b3c0b27b53ef89afe50dcbeefec9f85faf7b6f92 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -22,7 +22,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
-import android.os.SystemClock;
import android.provider.Browser;
import android.provider.Settings;
import android.text.Editable;
@@ -59,7 +58,6 @@ import org.chromium.base.ObserverList.RewindableIterator;
import org.chromium.base.TraceEvent;
import org.chromium.base.WeakContext;
import org.chromium.content.R;
-import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegate;
import org.chromium.content.browser.accessibility.AccessibilityInjector;
import org.chromium.content.browser.accessibility.BrowserAccessibilityManager;
import org.chromium.content.browser.input.AdapterInputConnection;
@@ -93,8 +91,7 @@ import java.util.Map;
* being tied to the view system.
*/
@JNINamespace("content")
-public class ContentViewCore
- implements MotionEventDelegate, NavigationClient, AccessibilityStateChangeListener {
+public class ContentViewCore implements NavigationClient, AccessibilityStateChangeListener {
private static final String TAG = "ContentViewCore";
@@ -320,7 +317,6 @@ public class ContentViewCore
private boolean mInForeground = false;
- private ContentViewGestureHandler mContentViewGestureHandler;
private final ObserverList<GestureStateListener> mGestureStateListeners;
private final RewindableIterator<GestureStateListener> mGestureStateListenersIterator;
private ZoomControlsDelegate mZoomControlsDelegate;
@@ -410,39 +406,17 @@ public class ContentViewCore
// vsync.
private boolean mRequestedVSyncForInput = false;
- // Used for tracking UMA ActionAfterDoubleTap to tell user's immediate
- // action after a double tap.
- private long mLastDoubleTapTimeMs;
-
// On single tap this will store the x, y coordinates of the touch.
private int mSingleTapX;
private int mSingleTapY;
+ private boolean scrollInProgress = false;
+ private boolean pinchInProgress = false;
+
private ViewAndroid mViewAndroid;
private SmartClipDataListener mSmartClipDataListener = null;
- /** ActionAfterDoubleTap defined in tools/metrics/histograms/histograms.xml. */
- private static class UMAActionAfterDoubleTap {
- public static final int NAVIGATE_BACK = 0;
- public static final int NAVIGATE_STOP = 1;
- public static final int NO_ACTION = 2;
- public static final int COUNT = 3;
- }
-
- /** TapDelayType defined in tools/metrics/histograms/histograms.xml. */
- private static class UMASingleTapType {
- public static final int DELAYED_TAP = 0;
- public static final int UNDELAYED_TAP = 1;
- public static final int COUNT = 2;
- }
-
- /**
- * Used by UMA stat for tracking accidental double tap navigations. Specifies the amount of
- * time after a double tap within which actions will be recorded to the UMA stat.
- */
- private static final long ACTION_AFTER_DOUBLE_TAP_WINDOW_MS = 5000;
-
/**
* Constructs a new ContentViewCore. Embedders must call initialize() after constructing
* a ContentViewCore and before using it.
@@ -688,9 +662,6 @@ public class ContentViewCore
viewAndroidNativePointer = mViewAndroid.getNativePointer();
}
- // Note ContentViewGestureHandler initialization must occur before nativeInit
- // because nativeInit may callback into hasTouchEventHandlers.
- mContentViewGestureHandler = new ContentViewGestureHandler(mContext, this);
mZoomControlsDelegate = new ZoomControlsDelegate() {
@Override
public void invokeZoomPicker() {}
@@ -926,7 +897,6 @@ public class ContentViewCore
* Stops loading the current web contents.
*/
public void stopLoading() {
- reportActionAfterDoubleTapUMA(UMAActionAfterDoubleTap.NAVIGATE_STOP);
if (mNativeContentViewCore != 0) nativeStopLoading(mNativeContentViewCore);
}
@@ -1226,12 +1196,27 @@ public class ContentViewCore
mRequestedVSyncForInput = true;
addVSyncSubscriber();
}
- return mContentViewGestureHandler.onTouchEvent(event);
+
+ final int eventAction = event.getActionMasked();
+ // Only these actions have any effect on gesture detection. Other
+ // actions have no corresponding WebTouchEvent type and may confuse the
+ // touch pipline, so we ignore them entirely.
+ if (eventAction != MotionEvent.ACTION_DOWN
+ && eventAction != MotionEvent.ACTION_UP
+ && eventAction != MotionEvent.ACTION_CANCEL
+ && eventAction != MotionEvent.ACTION_MOVE
+ && eventAction != MotionEvent.ACTION_POINTER_DOWN
+ && eventAction != MotionEvent.ACTION_POINTER_UP) {
+ return false;
+ }
+
+ if (mNativeContentViewCore == 0) return false;
+ return nativeOnTouchEvent(mNativeContentViewCore, event);
}
- /** @see ContentViewGestureHandler#setIgnoreRemainingTouchEvents */
public void setIgnoreRemainingTouchEvents() {
- mContentViewGestureHandler.setIgnoreRemainingTouchEvents();
+ if (mNativeContentViewCore == 0) return;
+ nativeIgnoreRemainingTouchEvents(mNativeContentViewCore);
}
@SuppressWarnings("unused")
@@ -1263,6 +1248,7 @@ public class ContentViewCore
@SuppressWarnings("unused")
@CalledByNative
private void onScrollBeginEventAck() {
+ scrollInProgress = true;
temporarilyHideTextHandles();
mZoomControlsDelegate.invokeZoomPicker();
updateGestureStateListener(GestureEventType.SCROLL_START);
@@ -1281,12 +1267,14 @@ public class ContentViewCore
@SuppressWarnings("unused")
@CalledByNative
private void onScrollEndEventAck() {
+ scrollInProgress = false;
updateGestureStateListener(GestureEventType.SCROLL_END);
}
@SuppressWarnings("unused")
@CalledByNative
private void onPinchBeginEventAck() {
+ pinchInProgress = true;
temporarilyHideTextHandles();
updateGestureStateListener(GestureEventType.PINCH_BEGIN);
}
@@ -1294,6 +1282,7 @@ public class ContentViewCore
@SuppressWarnings("unused")
@CalledByNative
private void onPinchEndEventAck() {
+ pinchInProgress = false;
updateGestureStateListener(GestureEventType.PINCH_END);
}
@@ -1313,99 +1302,9 @@ public class ContentViewCore
return true;
}
updateForTapOrPress(type, x, y);
- updateForDoubleTapUMA(type);
return false;
}
- @Override
- public void onTouchEventHandlingBegin(MotionEvent event) {
- if (mNativeContentViewCore == 0) return;
- nativeOnTouchEventHandlingBegin(mNativeContentViewCore,event);
- }
-
- @Override
- public void onTouchEventHandlingEnd() {
- if (mNativeContentViewCore == 0) return;
- nativeOnTouchEventHandlingEnd(mNativeContentViewCore);
- }
-
- /**
- * Note: These events may or may not actually be forwarded to the renderer,
- * depending on ack disposition of the underlying touch events. All listening
- * for sent gestures should take place in {@link #filterGestureEvent(int, int, int)}.
- */
- @Override
- public boolean onGestureEventCreated(int type, long timeMs, int x, int y, Bundle b) {
- if (mNativeContentViewCore == 0) return false;
- switch (type) {
- case GestureEventType.SHOW_PRESS:
- nativeShowPress(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.TAP_CANCEL:
- nativeTapCancel(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.TAP_DOWN:
- nativeTapDown(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.DOUBLE_TAP:
- nativeDoubleTap(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.SINGLE_TAP_UP:
- nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false);
- return true;
- case GestureEventType.SINGLE_TAP_CONFIRMED:
- if (!b.getBoolean(ContentViewGestureHandler.SHOW_PRESS, false)) {
- nativeShowPress(mNativeContentViewCore, timeMs, x, y);
- }
- nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false);
- return true;
- case GestureEventType.SINGLE_TAP_UNCONFIRMED:
- nativeSingleTapUnconfirmed(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.LONG_PRESS:
- nativeLongPress(mNativeContentViewCore, timeMs, x, y, false);
- return true;
- case GestureEventType.LONG_TAP:
- nativeLongTap(mNativeContentViewCore, timeMs, x, y, false);
- return true;
- case GestureEventType.SCROLL_START: {
- int dx = b.getInt(ContentViewGestureHandler.DELTA_HINT_X);
- int dy = b.getInt(ContentViewGestureHandler.DELTA_HINT_Y);
- nativeScrollBegin(mNativeContentViewCore, timeMs, x, y, dx, dy);
- return true;
- }
- case GestureEventType.SCROLL_BY: {
- int dx = b.getInt(ContentViewGestureHandler.DISTANCE_X);
- int dy = b.getInt(ContentViewGestureHandler.DISTANCE_Y);
- nativeScrollBy(mNativeContentViewCore, timeMs, x, y, dx, dy);
- return true;
- }
- case GestureEventType.SCROLL_END:
- nativeScrollEnd(mNativeContentViewCore, timeMs);
- return true;
- case GestureEventType.FLING_START:
- nativeFlingStart(mNativeContentViewCore, timeMs, x, y,
- b.getInt(ContentViewGestureHandler.VELOCITY_X, 0),
- b.getInt(ContentViewGestureHandler.VELOCITY_Y, 0));
- return true;
- case GestureEventType.FLING_CANCEL:
- nativeFlingCancel(mNativeContentViewCore, timeMs);
- return true;
- case GestureEventType.PINCH_BEGIN:
- nativePinchBegin(mNativeContentViewCore, timeMs, x, y);
- return true;
- case GestureEventType.PINCH_BY:
- nativePinchBy(mNativeContentViewCore, timeMs, x, y,
- b.getFloat(ContentViewGestureHandler.DELTA, 0));
- return true;
- case GestureEventType.PINCH_END:
- nativePinchEnd(mNativeContentViewCore, timeMs);
- return true;
- default:
- return false;
- }
- }
-
@VisibleForTesting
public void sendDoubleTapForTest(long timeMs, int x, int y) {
if (mNativeContentViewCore == 0) return;
@@ -1543,15 +1442,15 @@ public class ContentViewCore
}
private void onRenderCoordinatesUpdated() {
- if (mContentViewGestureHandler == null) return;
+ if (mNativeContentViewCore == 0) return;
// We disable double tap zoom for pages that have a width=device-width
// or narrower viewport (indicating that this is a mobile-optimized or
// responsive web design, so text will be legible without zooming).
// We also disable it for pages that disallow the user from zooming in
// or out (even if they don't have a device-width or narrower viewport).
- mContentViewGestureHandler.updateShouldDisableDoubleTap(
- mRenderCoordinates.hasMobileViewport() || mRenderCoordinates.hasFixedPageScale());
+ nativeUpdateDoubleTapSupportForPage(mNativeContentViewCore,
+ !mRenderCoordinates.hasMobileViewport() && !mRenderCoordinates.hasFixedPageScale());
}
private void hidePopupDialog() {
@@ -1572,7 +1471,8 @@ public class ContentViewCore
}
private void resetGestureDetectors() {
- mContentViewGestureHandler.resetGestureHandlers();
+ if (mNativeContentViewCore == 0) return;
+ nativeResetGestureDetectors(mNativeContentViewCore);
}
/**
@@ -1785,7 +1685,8 @@ public class ContentViewCore
*/
public void onWindowFocusChanged(boolean hasWindowFocus) {
if (!hasWindowFocus) {
- mContentViewGestureHandler.onWindowFocusLost();
+ if (mNativeContentViewCore == 0) return;
+ nativeOnWindowFocusLost(mNativeContentViewCore);
}
}
@@ -2048,76 +1949,18 @@ public class ContentViewCore
return mSingleTapY;
}
- // Watch for the UMA "action after double tap" timer expiring and reset
- // the timer if necessary.
- private void updateDoubleTapUmaTimer() {
- if (mLastDoubleTapTimeMs == 0) return;
-
- long nowMs = SystemClock.uptimeMillis();
- if ((nowMs - mLastDoubleTapTimeMs) >= ACTION_AFTER_DOUBLE_TAP_WINDOW_MS) {
- // Time expired, user took no action (that we care about).
- sendActionAfterDoubleTapUMA(UMAActionAfterDoubleTap.NO_ACTION);
- mLastDoubleTapTimeMs = 0;
- }
- }
-
- private void updateForDoubleTapUMA(int type) {
- updateDoubleTapUmaTimer();
-
- if (type == GestureEventType.SINGLE_TAP_UP
- || type == GestureEventType.SINGLE_TAP_CONFIRMED) {
- sendSingleTapUMA(mContentViewGestureHandler.isDoubleTapDisabled() ?
- UMASingleTapType.UNDELAYED_TAP : UMASingleTapType.DELAYED_TAP);
- } else if (type == GestureEventType.DOUBLE_TAP) {
- // Make sure repeated double taps don't get silently dropped from
- // the statistics.
- if (mLastDoubleTapTimeMs > 0) {
- sendActionAfterDoubleTapUMA(UMAActionAfterDoubleTap.NO_ACTION);
- }
-
- mLastDoubleTapTimeMs = SystemClock.uptimeMillis();
- }
- }
-
- private void reportActionAfterDoubleTapUMA(int type) {
- updateDoubleTapUmaTimer();
-
- if (mLastDoubleTapTimeMs == 0) return;
-
- long nowMs = SystemClock.uptimeMillis();
- if ((nowMs - mLastDoubleTapTimeMs) < ACTION_AFTER_DOUBLE_TAP_WINDOW_MS) {
- sendActionAfterDoubleTapUMA(type);
- mLastDoubleTapTimeMs = 0;
- }
- }
-
- private void sendSingleTapUMA(int type) {
- if (mNativeContentViewCore == 0) return;
- nativeSendSingleTapUma(
- mNativeContentViewCore,
- type,
- UMASingleTapType.COUNT);
- }
-
- private void sendActionAfterDoubleTapUMA(int type) {
- if (mNativeContentViewCore == 0) return;
- nativeSendActionAfterDoubleTapUma(
- mNativeContentViewCore,
- type,
- !mContentViewGestureHandler.isClickDelayDisabled(),
- UMAActionAfterDoubleTap.COUNT);
- }
-
public void setZoomControlsDelegate(ZoomControlsDelegate zoomControlsDelegate) {
mZoomControlsDelegate = zoomControlsDelegate;
}
public void updateMultiTouchZoomSupport(boolean supportsMultiTouchZoom) {
- mContentViewGestureHandler.updateMultiTouchSupport(supportsMultiTouchZoom);
+ if (mNativeContentViewCore == 0) return;
+ nativeUpdateMultiTouchZoomSupport(mNativeContentViewCore, supportsMultiTouchZoom);
}
public void updateDoubleTapSupport(boolean supportsDoubleTap) {
- mContentViewGestureHandler.updateDoubleTapSupport(supportsDoubleTap);
+ if (mNativeContentViewCore == 0) return;
+ nativeUpdateDoubleTapSupport(mNativeContentViewCore, supportsDoubleTap);
}
public void selectPopupMenuItems(int[] indices) {
@@ -2429,10 +2272,7 @@ public class ContentViewCore
}
private boolean allowTextHandleFadeIn() {
- if (mContentViewGestureHandler.isNativeScrolling() ||
- mContentViewGestureHandler.isNativePinching()) {
- return false;
- }
+ if (scrollInProgress || pinchInProgress) return false;
if (mPopupZoomer.isShowing()) return false;
@@ -3332,10 +3172,7 @@ public class ContentViewCore
long nativeContentViewCoreImpl, int orientation);
// All touch events (including flings, scrolls etc) accept coordinates in physical pixels.
- private native void nativeOnTouchEventHandlingBegin(
- long nativeContentViewCoreImpl, MotionEvent event);
-
- private native void nativeOnTouchEventHandlingEnd(long nativeContentViewCoreImpl);
+ private native boolean nativeOnTouchEvent(long nativeContentViewCoreImpl, MotionEvent event);
private native int nativeSendMouseMoveEvent(
long nativeContentViewCoreImpl, long timeMs, float x, float y);
@@ -3361,27 +3198,12 @@ public class ContentViewCore
private native void nativeSingleTap(
long nativeContentViewCoreImpl, long timeMs, float x, float y, boolean linkPreviewTap);
- private native void nativeSingleTapUnconfirmed(
- long nativeContentViewCoreImpl, long timeMs, float x, float y);
-
- private native void nativeShowPress(
- long nativeContentViewCoreImpl, long timeMs, float x, float y);
-
- private native void nativeTapCancel(
- long nativeContentViewCoreImpl, long timeMs, float x, float y);
-
- private native void nativeTapDown(
- long nativeContentViewCoreImpl, long timeMs, float x, float y);
-
private native void nativeDoubleTap(
long nativeContentViewCoreImpl, long timeMs, float x, float y);
private native void nativeLongPress(
long nativeContentViewCoreImpl, long timeMs, float x, float y, boolean linkPreviewTap);
- private native void nativeLongTap(
- long nativeContentViewCoreImpl, long timeMs, float x, float y, boolean linkPreviewTap);
-
private native void nativePinchBegin(
long nativeContentViewCoreImpl, long timeMs, float x, float y);
@@ -3395,6 +3217,16 @@ public class ContentViewCore
private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y);
+ private native void nativeResetGestureDetectors(long nativeContentViewCoreImpl);
+ private native void nativeIgnoreRemainingTouchEvents(long nativeContentViewCoreImpl);
+ private native void nativeOnWindowFocusLost(long nativeContentViewCoreImpl);
+ private native void nativeUpdateDoubleTapSupportForPage(
+ long nativeContentViewCoreImpl, boolean supportsDoubleTap);
+ private native void nativeUpdateDoubleTapSupport(
+ long nativeContentViewCoreImpl, boolean supportsDoubleTap);
+ private native void nativeUpdateMultiTouchZoomSupport(
+ long nativeContentViewCoreImpl, boolean supportsMultiTouchZoom);
+
private native void nativeLoadIfNecessary(long nativeContentViewCoreImpl);
private native void nativeRequestRestoreLoad(long nativeContentViewCoreImpl);
@@ -3474,12 +3306,6 @@ public class ContentViewCore
private native void nativeSetAccessibilityEnabled(
long nativeContentViewCoreImpl, boolean enabled);
- private native void nativeSendSingleTapUma(long nativeContentViewCoreImpl,
- int type, int count);
-
- private native void nativeSendActionAfterDoubleTapUma(long nativeContentViewCoreImpl,
- int type, boolean hasDelay, int count);
-
private native void nativeExtractSmartClipData(long nativeContentViewCoreImpl,
int x, int y, int w, int h);
}

Powered by Google App Engine
This is Rietveld 408576698