Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/MotionEventSynthesizer.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/MotionEventSynthesizer.java b/content/public/android/java/src/org/chromium/content/browser/MotionEventSynthesizer.java |
| index 355bd4801677ff7da41ac1095b281464ca787d0c..274ef8b61034e538a9f4e81e6fed4624622d2b85 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/MotionEventSynthesizer.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/MotionEventSynthesizer.java |
| @@ -8,9 +8,11 @@ import android.view.InputDevice; |
| import android.view.MotionEvent; |
| import android.view.MotionEvent.PointerCoords; |
| import android.view.MotionEvent.PointerProperties; |
| +import android.view.View; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.ui.base.WindowAndroid; |
| /** |
| * Provides a Java-side implementation for injecting synthetic touch events. |
| @@ -24,14 +26,19 @@ public class MotionEventSynthesizer { |
| private static final int ACTION_CANCEL = 2; |
| private static final int ACTION_END = 3; |
| private static final int ACTION_SCROLL = 4; |
| + private static final int ACTION_HOVER_ENTER = 5; |
| + private static final int ACTION_HOVER_EXIT = 6; |
| + private static final int ACTION_HOVER_MOVE = 7; |
| - private final ContentViewCore mContentViewCore; |
| + private final View mTarget; |
| + private final WindowAndroid mWindow; |
| private final PointerProperties[] mPointerProperties; |
| private final PointerCoords[] mPointerCoords; |
| private long mDownTimeInMs; |
| - MotionEventSynthesizer(ContentViewCore contentViewCore) { |
| - mContentViewCore = contentViewCore; |
| + public MotionEventSynthesizer(View target, WindowAndroid window) { |
| + mTarget = target; |
| + mWindow = window; |
| mPointerProperties = new PointerProperties[MAX_NUM_POINTERS]; |
| mPointerCoords = new PointerCoords[MAX_NUM_POINTERS]; |
| } |
| @@ -41,7 +48,7 @@ public class MotionEventSynthesizer { |
| assert (0 <= index && index < MAX_NUM_POINTERS); |
| // Convert coordinates from density independent pixels to density dependent pixels. |
| - float scaleFactor = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); |
| + float scaleFactor = mWindow.getDisplay().getDipScale(); |
| PointerCoords coords = new PointerCoords(); |
| coords.x = scaleFactor * x; |
| @@ -58,7 +65,7 @@ public class MotionEventSynthesizer { |
| void setScrollDeltas(int x, int y, int dx, int dy) { |
| setPointer(0, x, y, 0); |
| // Convert coordinates from density independent pixels to density dependent pixels. |
| - float scaleFactor = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); |
| + float scaleFactor = mWindow.getDisplay().getDipScale(); |
| mPointerCoords[0].setAxisValue(MotionEvent.AXIS_HSCROLL, scaleFactor * dx); |
| mPointerCoords[0].setAxisValue(MotionEvent.AXIS_VSCROLL, scaleFactor * dy); |
| } |
| @@ -72,7 +79,7 @@ public class MotionEventSynthesizer { |
| mDownTimeInMs, timeInMs, MotionEvent.ACTION_DOWN, 1, |
| mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| if (pointerCount > 1) { |
| @@ -81,7 +88,7 @@ public class MotionEventSynthesizer { |
| MotionEvent.ACTION_POINTER_DOWN, pointerCount, |
| mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| } |
| break; |
| @@ -91,7 +98,7 @@ public class MotionEventSynthesizer { |
| MotionEvent.ACTION_MOVE, |
| pointerCount, mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| break; |
| } |
| @@ -100,7 +107,7 @@ public class MotionEventSynthesizer { |
| mDownTimeInMs, timeInMs, MotionEvent.ACTION_CANCEL, 1, |
| mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| break; |
| } |
| @@ -110,7 +117,7 @@ public class MotionEventSynthesizer { |
| mDownTimeInMs, timeInMs, MotionEvent.ACTION_POINTER_UP, |
| pointerCount, mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| } |
| @@ -118,7 +125,7 @@ public class MotionEventSynthesizer { |
| mDownTimeInMs, timeInMs, MotionEvent.ACTION_UP, 1, |
| mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, 0, 0); |
| - mContentViewCore.onTouchEvent(event); |
| + mTarget.dispatchTouchEvent(event); |
| event.recycle(); |
| break; |
| } |
| @@ -127,14 +134,32 @@ public class MotionEventSynthesizer { |
| MotionEvent event = MotionEvent.obtain(mDownTimeInMs, timeInMs, |
| MotionEvent.ACTION_SCROLL, pointerCount, mPointerProperties, mPointerCoords, |
| 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_CLASS_POINTER, 0); |
| - mContentViewCore.onGenericMotionEvent(event); |
| + mTarget.dispatchGenericMotionEvent(event); |
| event.recycle(); |
| break; |
| } |
| + case ACTION_HOVER_ENTER: |
| + case ACTION_HOVER_EXIT: |
| + case ACTION_HOVER_MOVE: { |
| + injectHover(action, pointerCount, timeInMs); |
| + break; |
| + } |
| default: { |
| assert false : "Unreached"; |
| break; |
| } |
| } |
| } |
| + |
| + private void injectHover(int action, int pointerCount, long timeInMs) { |
| + assert pointerCount == 1; |
| + int androidAction = MotionEvent.ACTION_HOVER_ENTER; |
| + if (ACTION_HOVER_EXIT == action) androidAction = MotionEvent.ACTION_HOVER_ENTER; |
|
cjgrant
2017/02/16 15:29:34
= MotionEvent.ACTION_HOVER_EXIT, presumably.
mthiesse
2017/02/16 15:53:49
Done. Oops.
|
| + if (ACTION_HOVER_MOVE == action) androidAction = MotionEvent.ACTION_HOVER_MOVE; |
| + MotionEvent event = MotionEvent.obtain(mDownTimeInMs, timeInMs, androidAction, pointerCount, |
| + mPointerProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, |
| + InputDevice.SOURCE_CLASS_POINTER, 0); |
| + mTarget.dispatchGenericMotionEvent(event); |
| + event.recycle(); |
| + } |
| } |