Chromium Code Reviews| 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 1bef1209ac767f7ac0a4eaa44cb90335cd4fa37f..272f1b1c29c6cd3727fc4b41cf22972d9c645253 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.EventHandler; |
| 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. |
|
David Trainor- moved to gerrit
2017/02/28 01:31:23
Nice :). Should we add you specifically to the OW
Jinsuk Kim
2017/02/28 06:56:05
That would be great if that's the way to get notif
|
| + * See https://crbug.com/598880. |
| */ |
| @JNINamespace("content") |
| public class ContentViewCore implements AccessibilityStateChangeListener, DisplayAndroidObserver, |
| @@ -331,10 +335,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| // WebView. |
| private boolean mShouldSetAccessibilityFocusOnPageLoad; |
| - // Temporary notification to tell onSizeChanged to focus a form element, |
| - // because the OSK was just brought up. |
| - private final Rect mFocusPreOSKViewportRect = new Rect(); |
| - |
| // Whether a touch scroll sequence is active, used to hide text selection |
| // handles. Note that a scroll sequence will *always* bound a pinch |
| // sequence, so this will also be true for the duration of a pinch gesture. |
| @@ -618,6 +618,10 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| } |
| } |
| + private EventHandler getEventHandler() { |
| + return getWebContents().getEventHandler(); |
| + } |
| + |
| /** |
| * Set {@link ActionMode.Callback} used by {@link SelectionPopupController}. |
| * @param callback ActionMode.Callback instance. |
| @@ -937,127 +941,9 @@ 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"); |
| - } |
| + return getEventHandler().onMouseEvent(event); |
| } |
| @CalledByNative |
| @@ -1065,18 +951,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| 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. |
| */ |
| @@ -1434,24 +1308,23 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| // Execute a delayed form focus operation because the OSK was brought |
| // up earlier. |
| - if (!mFocusPreOSKViewportRect.isEmpty()) { |
| + Rect focusPreOSKViewport = getFocusPreOSKViewportRect(); |
| + if (!focusPreOSKViewport.isEmpty()) { |
| Rect rect = new Rect(); |
| getContainerView().getWindowVisibleDisplayFrame(rect); |
| - if (!rect.equals(mFocusPreOSKViewportRect)) { |
| + if (!rect.equals(focusPreOSKViewport)) { |
| // Only assume the OSK triggered the onSizeChanged if width was preserved. |
| - if (rect.width() == mFocusPreOSKViewportRect.width()) { |
| + if (rect.width() == focusPreOSKViewport.width()) { |
| assert mWebContents != null; |
| mWebContents.scrollFocusedEditableNodeIntoView(); |
| } |
| - cancelRequestToScrollFocusedEditableNodeIntoView(); |
| + getEventHandler().cancelRequestToScrollFocusedEditableNodeIntoView(); |
| } |
| } |
| } |
| - private void cancelRequestToScrollFocusedEditableNodeIntoView() { |
| - // Zero-ing the rect will prevent |updateAfterSizeChanged()| from |
| - // issuing the delayed form focus event. |
| - mFocusPreOSKViewportRect.setEmpty(); |
| + private Rect getFocusPreOSKViewportRect() { |
| + return getEventHandler().getFocusPreOSKViewportRect(); |
| } |
| /** |
| @@ -1477,7 +1350,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| if (gainFocus) { |
| restoreSelectionPopupsIfNecessary(); |
| } else { |
| - cancelRequestToScrollFocusedEditableNodeIntoView(); |
| + getEventHandler().cancelRequestToScrollFocusedEditableNodeIntoView(); |
| if (mPreserveSelectionOnNextLossOfFocus) { |
| mPreserveSelectionOnNextLossOfFocus = false; |
| hidePopupsAndPreserveSelection(); |
| @@ -1542,14 +1415,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)); |
| - } |
| - return true; |
| + return getEventHandler().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)); |
| } finally { |
| offset.recycle(); |
| TraceEvent.end("onHoverEvent"); |
| @@ -1601,6 +1471,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| public void setCurrentTouchEventOffsets(float dx, float dy) { |
| mCurrentTouchOffsetX = dx; |
| mCurrentTouchOffsetY = dy; |
| + getEventHandler().setCurrentTouchEventOffsets(dx, dy); |
| } |
| private MotionEvent createOffsetMotionEvent(MotionEvent src) { |
| @@ -2697,8 +2568,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(getFocusPreOSKViewportRect()); |
| } else if (hasFocus() && resultCode == InputMethodManager.RESULT_UNCHANGED_SHOWN) { |
| // If the OSK was already there, focus the form immediately. |
| if (mWebContents != null) { |
| @@ -2734,21 +2604,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); |