Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.app.Activity; | 9 import android.app.Activity; |
| 10 import android.app.SearchManager; | 10 import android.app.SearchManager; |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1012 public boolean isGamepadAPIActive() { | 1012 public boolean isGamepadAPIActive() { |
| 1013 return GamepadList.isGamepadAPIActive(); | 1013 return GamepadList.isGamepadAPIActive(); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 // End FrameLayout overrides. | 1016 // End FrameLayout overrides. |
| 1017 | 1017 |
| 1018 /** | 1018 /** |
| 1019 * @see View#onTouchEvent(MotionEvent) | 1019 * @see View#onTouchEvent(MotionEvent) |
| 1020 */ | 1020 */ |
| 1021 public boolean onTouchEvent(MotionEvent event) { | 1021 public boolean onTouchEvent(MotionEvent event) { |
| 1022 // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here? | |
| 1023 // crbug.com/592082 | |
| 1024 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { | |
| 1025 // Pre-Andorid-L mouse button info is incomplete | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
"Mouse button info is incomplete on L and below"
mustaq
2016/11/09 17:04:33
Done.
| |
| 1026 int apiVersion = Build.VERSION.SDK_INT; | |
| 1027 if (apiVersion >= android.os.Build.VERSION_CODES.M) { | |
| 1028 return sendMouseEvent(event); | |
| 1029 } | |
| 1030 } | |
| 1031 | |
| 1022 final boolean isTouchHandleEvent = false; | 1032 final boolean isTouchHandleEvent = false; |
| 1023 return onTouchEventImpl(event, isTouchHandleEvent); | 1033 return sendTouchEvent(event, isTouchHandleEvent); |
| 1034 } | |
| 1035 | |
| 1036 @SuppressLint("NewApi") | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
I think it would work to do @TargetApi(Build.VERSI
mustaq
2016/11/09 17:04:33
Done, thanks.
| |
| 1037 private boolean sendMouseEvent(MotionEvent event) { | |
| 1038 TraceEvent.begin("sendMouseEvent"); | |
| 1039 | |
| 1040 MotionEvent offsetEvent = createOffsetMotionEvent(event); | |
| 1041 try { | |
| 1042 mContainerView.removeCallbacks(mFakeMouseMoveRunnable); | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
That reminds me that this thing exists... could yo
mustaq
2016/11/09 17:04:32
Commented the main usage instead. Does it look eno
| |
| 1043 if (mNativeContentViewCore != 0) { | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
Please do "if (mNativeContentViewCore == 0) return
mustaq
2016/11/09 17:04:32
Done.
mustaq
2016/11/09 17:04:32
Done.
| |
| 1044 int eventAction = event.getActionMasked(); | |
| 1045 | |
| 1046 // For mousedown and mouseup events, we use ACTION_BUTTON_PRESS | |
| 1047 // and ACTION_BUTTON_RELEASE respectively because they provide | |
| 1048 // info about the changed-button. | |
| 1049 if (eventAction == MotionEvent.ACTION_DOWN | |
| 1050 || eventAction == MotionEvent.ACTION_UP) { | |
| 1051 return false; | |
| 1052 } | |
| 1053 | |
| 1054 // The method getActionButton() is defined only for | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
What happens if you call getActionButton() on one
mustaq
2016/11/09 17:04:32
Assuming it neither throws nor emits any logs, eve
aelias_OOO_until_Jul13
2016/11/09 18:57:03
That seems excessively paranoid. Almost no Androi
mustaq
2016/11/09 19:55:59
Just tested on an N7/M, even with chorded button p
| |
| 1055 // ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE | |
| 1056 int changedButton = 0; | |
| 1057 if (eventAction == MotionEvent.ACTION_BUTTON_PRESS | |
| 1058 || eventAction == MotionEvent.ACTION_BUTTON_RELEASE) { | |
| 1059 changedButton = event.getActionButton(); | |
| 1060 } | |
| 1061 | |
| 1062 nativeSendMouseEvent(mNativeContentViewCore, event.getEventTime( ), eventAction, | |
| 1063 offsetEvent.getX(), offsetEvent.getY(), event.getPointer Id(0), | |
| 1064 event.getPressure(0), event.getOrientation(0), | |
| 1065 event.getAxisValue(MotionEvent.AXIS_TILT, 0), changedBut ton, | |
| 1066 event.getButtonState(), event.getMetaState(), event.getT oolType(0)); | |
| 1067 } | |
| 1068 return true; | |
| 1069 } finally { | |
| 1070 offsetEvent.recycle(); | |
| 1071 TraceEvent.end("sendMouseEvent"); | |
| 1072 } | |
| 1024 } | 1073 } |
| 1025 | 1074 |
| 1026 /** | 1075 /** |
| 1027 * Called by PopupWindow-based touch handles. | 1076 * Called by PopupWindow-based touch handles. |
| 1028 * @param event the MotionEvent targeting the handle. | 1077 * @param event the MotionEvent targeting the handle. |
| 1029 */ | 1078 */ |
| 1030 public boolean onTouchHandleEvent(MotionEvent event) { | 1079 public boolean onTouchHandleEvent(MotionEvent event) { |
| 1031 final boolean isTouchHandleEvent = true; | 1080 final boolean isTouchHandleEvent = true; |
| 1032 return onTouchEventImpl(event, isTouchHandleEvent); | 1081 return sendTouchEvent(event, isTouchHandleEvent); |
| 1033 } | 1082 } |
| 1034 | 1083 |
| 1035 private boolean onTouchEventImpl(MotionEvent event, boolean isTouchHandleEve nt) { | 1084 private boolean sendTouchEvent(MotionEvent event, boolean isTouchHandleEvent ) { |
| 1036 TraceEvent.begin("onTouchEvent"); | 1085 TraceEvent.begin("sendTouchEvent"); |
| 1037 try { | 1086 try { |
| 1038 int eventAction = event.getActionMasked(); | 1087 int eventAction = event.getActionMasked(); |
| 1039 | 1088 |
| 1040 if (eventAction == MotionEvent.ACTION_DOWN) { | 1089 if (eventAction == MotionEvent.ACTION_DOWN) { |
| 1041 cancelRequestToScrollFocusedEditableNodeIntoView(); | 1090 cancelRequestToScrollFocusedEditableNodeIntoView(); |
| 1042 } | 1091 } |
| 1043 | 1092 |
| 1044 if (SPenSupport.isSPenSupported(mContext)) { | 1093 if (SPenSupport.isSPenSupported(mContext)) { |
| 1045 eventAction = SPenSupport.convertSPenEventAction(eventAction); | 1094 eventAction = SPenSupport.convertSPenEventAction(eventAction); |
| 1046 } | 1095 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1085 event.getRawX(), event.getRawY(), | 1134 event.getRawX(), event.getRawY(), |
| 1086 event.getToolType(0), | 1135 event.getToolType(0), |
| 1087 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN, | 1136 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN, |
| 1088 event.getButtonState(), | 1137 event.getButtonState(), |
| 1089 event.getMetaState(), | 1138 event.getMetaState(), |
| 1090 isTouchHandleEvent); | 1139 isTouchHandleEvent); |
| 1091 | 1140 |
| 1092 if (offset != null) offset.recycle(); | 1141 if (offset != null) offset.recycle(); |
| 1093 return consumed; | 1142 return consumed; |
| 1094 } finally { | 1143 } finally { |
| 1095 TraceEvent.end("onTouchEvent"); | 1144 TraceEvent.end("sendTouchEvent"); |
| 1096 } | 1145 } |
| 1097 } | 1146 } |
| 1098 | 1147 |
| 1099 @CalledByNative | 1148 @CalledByNative |
| 1100 private void requestDisallowInterceptTouchEvent() { | 1149 private void requestDisallowInterceptTouchEvent() { |
| 1101 mContainerView.requestDisallowInterceptTouchEvent(true); | 1150 mContainerView.requestDisallowInterceptTouchEvent(true); |
| 1102 } | 1151 } |
| 1103 | 1152 |
| 1104 private static boolean isValidTouchEventActionForNative(int eventAction) { | 1153 private static boolean isValidTouchEventActionForNative(int eventAction) { |
| 1105 // Only these actions have any effect on gesture detection. Other | 1154 // Only these actions have any effect on gesture detection. Other |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 | 1615 |
| 1567 /** | 1616 /** |
| 1568 * @see View#onHoverEvent(MotionEvent) | 1617 * @see View#onHoverEvent(MotionEvent) |
| 1569 * Mouse move events are sent on hover enter, hover move and hover exit. | 1618 * Mouse move events are sent on hover enter, hover move and hover exit. |
| 1570 * They are sent on hover exit because sometimes it acts as both a hover | 1619 * They are sent on hover exit because sometimes it acts as both a hover |
| 1571 * move and hover exit. | 1620 * move and hover exit. |
| 1572 */ | 1621 */ |
| 1573 public boolean onHoverEvent(MotionEvent event) { | 1622 public boolean onHoverEvent(MotionEvent event) { |
| 1574 TraceEvent.begin("onHoverEvent"); | 1623 TraceEvent.begin("onHoverEvent"); |
| 1575 | 1624 |
| 1625 int eventAction = event.getActionMasked(); | |
| 1626 | |
| 1627 // Work around Android bug where the x, y coordinates of a hover exit | |
|
aelias_OOO_until_Jul13
2016/11/09 02:43:14
This if statement is now no-op given your other ea
aelias_OOO_until_Jul13
2016/11/09 20:08:51
Looks like you missed my previous comment. Please
mustaq
2016/11/09 20:22:58
Oops, done.
| |
| 1628 // event are incorrect when touch exploration is on. | |
| 1629 if (mTouchExplorationEnabled && eventAction == MotionEvent.ACTION_HOVER_ EXIT) { | |
| 1630 return true; | |
| 1631 } | |
| 1632 | |
| 1633 // Ignore ACTION_HOVER_ENTER & ACTION_HOVER_EXIT: every mouse-down on | |
| 1634 // Android follows a hover-exit and is followed by a hover-enter. The | |
| 1635 // MotionEvent spec seems to support this behavior indirectly. | |
| 1636 if (eventAction == MotionEvent.ACTION_HOVER_ENTER | |
| 1637 || eventAction == MotionEvent.ACTION_HOVER_EXIT) { | |
| 1638 return false; | |
| 1639 } | |
| 1640 | |
| 1576 MotionEvent offset = createOffsetMotionEvent(event); | 1641 MotionEvent offset = createOffsetMotionEvent(event); |
| 1577 try { | 1642 try { |
| 1578 if (mBrowserAccessibilityManager != null && !mIsObscuredByAnotherVie w) { | 1643 if (mBrowserAccessibilityManager != null && !mIsObscuredByAnotherVie w) { |
| 1579 return mBrowserAccessibilityManager.onHoverEvent(offset); | 1644 return mBrowserAccessibilityManager.onHoverEvent(offset); |
| 1580 } | 1645 } |
| 1581 | 1646 |
| 1582 // Work around Android bug where the x, y coordinates of a hover exi t | |
| 1583 // event are incorrect when touch exploration is on. | |
| 1584 if (mTouchExplorationEnabled && offset.getAction() == MotionEvent.AC TION_HOVER_EXIT) { | |
| 1585 return true; | |
| 1586 } | |
| 1587 | |
| 1588 // TODO(lanwei): Remove this switch once experimentation is complete - | 1647 // TODO(lanwei): Remove this switch once experimentation is complete - |
| 1589 // crbug.com/418188 | 1648 // crbug.com/418188 |
| 1590 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER) { | 1649 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER) { |
| 1591 if (mEnableTouchHover == null) { | 1650 if (mEnableTouchHover == null) { |
| 1592 mEnableTouchHover = | 1651 mEnableTouchHover = |
| 1593 CommandLine.getInstance().hasSwitch(ContentSwitches. ENABLE_TOUCH_HOVER); | 1652 CommandLine.getInstance().hasSwitch(ContentSwitches. ENABLE_TOUCH_HOVER); |
| 1594 } | 1653 } |
| 1595 if (!mEnableTouchHover.booleanValue()) return false; | 1654 if (!mEnableTouchHover.booleanValue()) return false; |
| 1596 } | 1655 } |
| 1597 | 1656 |
| 1598 mContainerView.removeCallbacks(mFakeMouseMoveRunnable); | 1657 mContainerView.removeCallbacks(mFakeMouseMoveRunnable); |
| 1599 if (mNativeContentViewCore != 0) { | 1658 if (mNativeContentViewCore != 0) { |
| 1600 nativeSendMouseMoveEvent(mNativeContentViewCore, offset.getEvent Time(), | 1659 nativeSendMouseEvent(mNativeContentViewCore, event.getEventTime( ), eventAction, |
| 1601 offset.getX(), offset.getY(), event.getToolType(0)); | 1660 offset.getX(), offset.getY(), event.getPointerId(0), eve nt.getPressure(0), |
| 1661 event.getOrientation(0), event.getAxisValue(MotionEvent. AXIS_TILT, 0), | |
| 1662 0 /* changedButton */, event.getButtonState(), event.get MetaState(), | |
| 1663 event.getToolType(0)); | |
| 1602 } | 1664 } |
| 1603 return true; | 1665 return true; |
| 1604 } finally { | 1666 } finally { |
| 1605 offset.recycle(); | 1667 offset.recycle(); |
| 1606 TraceEvent.end("onHoverEvent"); | 1668 TraceEvent.end("onHoverEvent"); |
| 1607 } | 1669 } |
| 1608 } | 1670 } |
| 1609 | 1671 |
| 1610 /** | 1672 /** |
| 1611 * @see View#onGenericMotionEvent(MotionEvent) | 1673 * @see View#onGenericMotionEvent(MotionEvent) |
| 1612 */ | 1674 */ |
| 1613 public boolean onGenericMotionEvent(MotionEvent event) { | 1675 public boolean onGenericMotionEvent(MotionEvent event) { |
| 1614 if (GamepadList.onGenericMotionEvent(event)) return true; | 1676 if (GamepadList.onGenericMotionEvent(event)) return true; |
| 1615 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { | 1677 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 1616 mLastFocalEventX = event.getX(); | 1678 mLastFocalEventX = event.getX(); |
| 1617 mLastFocalEventY = event.getY(); | 1679 mLastFocalEventY = event.getY(); |
| 1618 switch (event.getAction()) { | 1680 switch (event.getActionMasked()) { |
| 1619 case MotionEvent.ACTION_SCROLL: | 1681 case MotionEvent.ACTION_SCROLL: |
| 1620 if (mNativeContentViewCore == 0) return false; | 1682 if (mNativeContentViewCore == 0) return false; |
| 1621 | 1683 |
| 1622 nativeSendMouseWheelEvent(mNativeContentViewCore, event.getE ventTime(), | 1684 nativeSendMouseWheelEvent(mNativeContentViewCore, event.getE ventTime(), |
| 1623 event.getX(), event.getY(), | 1685 event.getX(), event.getY(), |
| 1624 event.getAxisValue(MotionEvent.AXIS_HSCROLL), | 1686 event.getAxisValue(MotionEvent.AXIS_HSCROLL), |
| 1625 event.getAxisValue(MotionEvent.AXIS_VSCROLL), | 1687 event.getAxisValue(MotionEvent.AXIS_VSCROLL), |
| 1626 mRenderCoordinates.getWheelScrollFactor()); | 1688 mRenderCoordinates.getWheelScrollFactor()); |
| 1627 | 1689 |
| 1628 mContainerView.removeCallbacks(mFakeMouseMoveRunnable); | 1690 mContainerView.removeCallbacks(mFakeMouseMoveRunnable); |
| 1629 // Send a delayed onMouseMove event so that we end | 1691 // Send a delayed onMouseMove event so that we end |
| 1630 // up hovering over the right position after the scroll. | 1692 // up hovering over the right position after the scroll. |
| 1631 final MotionEvent eventFakeMouseMove = MotionEvent.obtain(ev ent); | 1693 final MotionEvent eventFakeMouseMove = MotionEvent.obtain(ev ent); |
| 1632 mFakeMouseMoveRunnable = new Runnable() { | 1694 mFakeMouseMoveRunnable = new Runnable() { |
| 1633 @Override | 1695 @Override |
| 1634 public void run() { | 1696 public void run() { |
| 1635 onHoverEvent(eventFakeMouseMove); | 1697 onHoverEvent(eventFakeMouseMove); |
| 1636 eventFakeMouseMove.recycle(); | 1698 eventFakeMouseMove.recycle(); |
| 1637 } | 1699 } |
| 1638 }; | 1700 }; |
| 1639 mContainerView.postDelayed(mFakeMouseMoveRunnable, 250); | 1701 mContainerView.postDelayed(mFakeMouseMoveRunnable, 250); |
| 1640 return true; | 1702 return true; |
| 1703 case MotionEvent.ACTION_BUTTON_PRESS: | |
| 1704 case MotionEvent.ACTION_BUTTON_RELEASE: | |
| 1705 // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STY LUS here? | |
| 1706 // crbug.com/592082 | |
| 1707 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { | |
| 1708 return sendMouseEvent(event); | |
| 1709 } | |
| 1641 } | 1710 } |
| 1642 } else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { | 1711 } else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
| 1643 if (mJoystickScrollProvider.onMotion(event)) return true; | 1712 if (mJoystickScrollProvider.onMotion(event)) return true; |
| 1644 if (mJoystickZoomProvider == null) { | 1713 if (mJoystickZoomProvider == null) { |
| 1645 mJoystickZoomProvider = | 1714 mJoystickZoomProvider = |
| 1646 new JoystickZoomProvider(this, new SystemAnimationInterv alProvider()); | 1715 new JoystickZoomProvider(this, new SystemAnimationInterv alProvider()); |
| 1647 } | 1716 } |
| 1648 if (mJoystickZoomProvider.onMotion(event)) return true; | 1717 if (mJoystickZoomProvider.onMotion(event)) return true; |
| 1649 } | 1718 } |
| 1650 return mContainerViewInternals.super_onGenericMotionEvent(event); | 1719 return mContainerViewInternals.super_onGenericMotionEvent(event); |
| (...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3342 int pointerId0, int pointerId1, | 3411 int pointerId0, int pointerId1, |
| 3343 float touchMajor0, float touchMajor1, | 3412 float touchMajor0, float touchMajor1, |
| 3344 float touchMinor0, float touchMinor1, | 3413 float touchMinor0, float touchMinor1, |
| 3345 float orientation0, float orientation1, | 3414 float orientation0, float orientation1, |
| 3346 float tilt0, float tilt1, | 3415 float tilt0, float tilt1, |
| 3347 float rawX, float rawY, | 3416 float rawX, float rawY, |
| 3348 int androidToolType0, int androidToolType1, | 3417 int androidToolType0, int androidToolType1, |
| 3349 int androidButtonState, int androidMetaState, | 3418 int androidButtonState, int androidMetaState, |
| 3350 boolean isTouchHandleEvent); | 3419 boolean isTouchHandleEvent); |
| 3351 | 3420 |
| 3352 private native int nativeSendMouseMoveEvent( | 3421 private native int nativeSendMouseEvent(long nativeContentViewCoreImpl, long timeMs, int action, |
| 3353 long nativeContentViewCoreImpl, long timeMs, float x, float y, int t oolType); | 3422 float x, float y, int pointerId, float pressure, float orientaton, f loat tilt, |
| 3423 int changedButton, int buttonState, int metaState, int toolType); | |
| 3354 | 3424 |
| 3355 private native int nativeSendMouseWheelEvent(long nativeContentViewCoreImpl, long timeMs, | 3425 private native int nativeSendMouseWheelEvent(long nativeContentViewCoreImpl, long timeMs, |
| 3356 float x, float y, float ticksX, float ticksY, float pixelsPerTick); | 3426 float x, float y, float ticksX, float ticksY, float pixelsPerTick); |
| 3357 | 3427 |
| 3358 private native void nativeScrollBegin(long nativeContentViewCoreImpl, long t imeMs, float x, | 3428 private native void nativeScrollBegin(long nativeContentViewCoreImpl, long t imeMs, float x, |
| 3359 float y, float hintX, float hintY, boolean targetViewport); | 3429 float y, float hintX, float hintY, boolean targetViewport); |
| 3360 | 3430 |
| 3361 private native void nativeScrollEnd(long nativeContentViewCoreImpl, long tim eMs); | 3431 private native void nativeScrollEnd(long nativeContentViewCoreImpl, long tim eMs); |
| 3362 | 3432 |
| 3363 private native void nativeScrollBy( | 3433 private native void nativeScrollBy( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3426 String textTrackTextShadow, String textTrackTextSize); | 3496 String textTrackTextShadow, String textTrackTextSize); |
| 3427 | 3497 |
| 3428 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l, | 3498 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l, |
| 3429 int x, int y, int w, int h); | 3499 int x, int y, int w, int h); |
| 3430 | 3500 |
| 3431 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); | 3501 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); |
| 3432 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); | 3502 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); |
| 3433 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, | 3503 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, |
| 3434 int screenX, int screenY, String[] mimeTypes, String content); | 3504 int screenX, int screenY, String[] mimeTypes, String content); |
| 3435 } | 3505 } |
| OLD | NEW |