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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: EventForwarder... Created 3 years, 9 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 60547aeb8ff4864843b12b98d370da43e52e5298..a024d0fa1eb78f1b5bc35c2ecc5b744daffe3fb6 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
@@ -69,6 +69,7 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.device.gamepad.GamepadList;
import org.chromium.ui.base.DeviceFormFactor;
+import org.chromium.ui.base.EventForwarder;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.base.ime.TextInputType;
@@ -87,6 +88,9 @@ import java.util.Map;
* Provides a Java-side 'wrapper' around a WebContent (native) instance.
* Contains all the major functionality necessary to manage the lifecycle of a ContentView without
* being tied to the view system.
+ *
+ * WARNING: ContentViewCore is in the process of being broken up. Please do not add new stuff.
+ * See https://crbug.com/598880.
*/
@JNINamespace("content")
public class ContentViewCore implements AccessibilityStateChangeListener, DisplayAndroidObserver,
@@ -618,6 +622,10 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
}
}
+ private EventForwarder getEventForwarder() {
+ return getWebContents().getEventForwarder();
+ }
+
/**
* Set {@link ActionMode.Callback} used by {@link SelectionPopupController}.
* @param callback ActionMode.Callback instance.
@@ -937,146 +945,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
return GamepadList.isGamepadAPIActive();
}
- /**
- * @see View#onTouchEvent(MotionEvent)
- */
- public boolean onTouchEvent(MotionEvent event) {
- // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
- // crbug.com/592082
- if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
- // Mouse button info is incomplete on L and below
- int apiVersion = Build.VERSION.SDK_INT;
- if (apiVersion >= android.os.Build.VERSION_CODES.M) {
- return sendMouseEvent(event);
- }
- }
-
- final boolean isTouchHandleEvent = false;
- return sendTouchEvent(event, isTouchHandleEvent);
- }
-
- @TargetApi(Build.VERSION_CODES.M)
- private boolean sendMouseEvent(MotionEvent event) {
- TraceEvent.begin("sendMouseEvent");
-
- MotionEvent offsetEvent = createOffsetMotionEvent(event);
- try {
- if (mNativeContentViewCore == 0) return false;
-
- int eventAction = event.getActionMasked();
-
- // For mousedown and mouseup events, we use ACTION_BUTTON_PRESS
- // and ACTION_BUTTON_RELEASE respectively because they provide
- // info about the changed-button.
- if (eventAction == MotionEvent.ACTION_DOWN || eventAction == MotionEvent.ACTION_UP) {
- return false;
- }
-
- nativeSendMouseEvent(mNativeContentViewCore, event.getEventTime(), eventAction,
- offsetEvent.getX(), offsetEvent.getY(), event.getPointerId(0),
- event.getPressure(0), event.getOrientation(0),
- event.getAxisValue(MotionEvent.AXIS_TILT, 0), event.getActionButton(),
- event.getButtonState(), event.getMetaState(), event.getToolType(0));
- return true;
- } finally {
- offsetEvent.recycle();
- TraceEvent.end("sendMouseEvent");
- }
- }
-
- /**
- * Called by PopupWindow-based touch handles.
- * @param event the MotionEvent targeting the handle.
- */
- public boolean onTouchHandleEvent(MotionEvent event) {
- final boolean isTouchHandleEvent = true;
- return sendTouchEvent(event, isTouchHandleEvent);
- }
-
- private boolean sendTouchEvent(MotionEvent event, boolean isTouchHandleEvent) {
- TraceEvent.begin("sendTouchEvent");
- try {
- int eventAction = event.getActionMasked();
-
- if (eventAction == MotionEvent.ACTION_DOWN) {
- if (mShouldRequestUnbufferedDispatch) {
- requestUnbufferedDispatch(event);
- }
- cancelRequestToScrollFocusedEditableNodeIntoView();
- }
-
- if (SPenSupport.isSPenSupported(mContext)) {
- eventAction = SPenSupport.convertSPenEventAction(eventAction);
- }
- if (!isValidTouchEventActionForNative(eventAction)) return false;
-
- if (mNativeContentViewCore == 0) return false;
-
- // A zero offset is quite common, in which case the unnecessary copy should be avoided.
- MotionEvent offset = null;
- if (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0) {
- offset = createOffsetMotionEvent(event);
- event = offset;
- }
-
- final int pointerCount = event.getPointerCount();
-
- float[] touchMajor = {event.getTouchMajor(),
- pointerCount > 1 ? event.getTouchMajor(1) : 0};
- float[] touchMinor = {event.getTouchMinor(),
- pointerCount > 1 ? event.getTouchMinor(1) : 0};
-
- for (int i = 0; i < 2; i++) {
- if (touchMajor[i] < touchMinor[i]) {
- float tmp = touchMajor[i];
- touchMajor[i] = touchMinor[i];
- touchMinor[i] = tmp;
- }
- }
-
- final boolean consumed = nativeOnTouchEvent(mNativeContentViewCore, event,
- event.getEventTime(), eventAction,
- pointerCount, event.getHistorySize(), event.getActionIndex(),
- event.getX(), event.getY(),
- pointerCount > 1 ? event.getX(1) : 0,
- pointerCount > 1 ? event.getY(1) : 0,
- event.getPointerId(0), pointerCount > 1 ? event.getPointerId(1) : -1,
- touchMajor[0], touchMajor[1],
- touchMinor[0], touchMinor[1],
- event.getOrientation(), pointerCount > 1 ? event.getOrientation(1) : 0,
- event.getAxisValue(MotionEvent.AXIS_TILT),
- pointerCount > 1 ? event.getAxisValue(MotionEvent.AXIS_TILT, 1) : 0,
- event.getRawX(), event.getRawY(),
- event.getToolType(0),
- pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_TYPE_UNKNOWN,
- event.getButtonState(),
- event.getMetaState(),
- isTouchHandleEvent);
-
- if (offset != null) offset.recycle();
- return consumed;
- } finally {
- TraceEvent.end("sendTouchEvent");
- }
- }
-
@CalledByNative
private void requestDisallowInterceptTouchEvent() {
mContainerView.requestDisallowInterceptTouchEvent(true);
}
- private static boolean isValidTouchEventActionForNative(int eventAction) {
- // 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.
- return 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 Whether a scroll targeting web content is in progress.
*/
@@ -1429,6 +1302,12 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
}
}
+ @CalledByNative
+ private void onTouchDown(MotionEvent event) {
+ if (mShouldRequestUnbufferedDispatch) requestUnbufferedDispatch(event);
+ cancelRequestToScrollFocusedEditableNodeIntoView();
+ }
+
private void updateAfterSizeChanged() {
mPopupZoomer.hide(false);
@@ -1542,13 +1421,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
return mBrowserAccessibilityManager.onHoverEvent(offset);
}
- if (mNativeContentViewCore != 0) {
- nativeSendMouseEvent(mNativeContentViewCore, event.getEventTime(), eventAction,
- offset.getX(), offset.getY(), event.getPointerId(0), event.getPressure(0),
- event.getOrientation(0), event.getAxisValue(MotionEvent.AXIS_TILT, 0),
- 0 /* changedButton */, event.getButtonState(), event.getMetaState(),
- event.getToolType(0));
- }
+ getEventForwarder().sendMouseEvent(event.getEventTime(), eventAction, offset.getX(),
+ offset.getY(), event.getPointerId(0), event.getPressure(0),
+ event.getOrientation(0), event.getAxisValue(MotionEvent.AXIS_TILT, 0),
+ 0 /* changedButton */, event.getButtonState(), event.getMetaState(),
+ event.getToolType(0));
return true;
} finally {
offset.recycle();
@@ -1577,7 +1454,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
// TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
// crbug.com/592082
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
- return sendMouseEvent(event);
+ return getEventForwarder().onMouseEvent(event);
}
}
} else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
@@ -1601,6 +1478,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
public void setCurrentTouchEventOffsets(float dx, float dy) {
mCurrentTouchOffsetX = dx;
mCurrentTouchOffsetY = dy;
+ getEventForwarder().setCurrentTouchEventOffsets(dx, dy);
}
private MotionEvent createOffsetMotionEvent(MotionEvent src) {
@@ -2695,8 +2573,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
// new size).
// TODO(jdduke): We should not assume that onSizeChanged will
// always be called, crbug.com/294908.
- getContainerView().getWindowVisibleDisplayFrame(
- mFocusPreOSKViewportRect);
+ getContainerView().getWindowVisibleDisplayFrame(mFocusPreOSKViewportRect);
} else if (hasFocus() && resultCode == InputMethodManager.RESULT_UNCHANGED_SHOWN) {
// If the OSK was already there, focus the form immediately.
if (mWebContents != null) {
@@ -2732,25 +2609,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
private native void nativeSendOrientationChangeEvent(
long nativeContentViewCoreImpl, int orientation);
- // All touch events (including flings, scrolls etc) accept coordinates in physical pixels.
- private native boolean nativeOnTouchEvent(
- long nativeContentViewCoreImpl, MotionEvent event,
- long timeMs, int action, int pointerCount, int historySize, int actionIndex,
- float x0, float y0, float x1, float y1,
- int pointerId0, int pointerId1,
- float touchMajor0, float touchMajor1,
- float touchMinor0, float touchMinor1,
- float orientation0, float orientation1,
- float tilt0, float tilt1,
- float rawX, float rawY,
- int androidToolType0, int androidToolType1,
- int androidButtonState, int androidMetaState,
- boolean isTouchHandleEvent);
-
- private native int nativeSendMouseEvent(long nativeContentViewCoreImpl, long timeMs, int action,
- float x, float y, int pointerId, float pressure, float orientaton, float tilt,
- int actionButton, int buttonState, int metaState, int toolType);
-
private native int nativeSendMouseWheelEvent(long nativeContentViewCoreImpl, long timeMs,
float x, float y, float ticksX, float ticksY, float pixelsPerTick);

Powered by Google App Engine
This is Rietveld 408576698