| 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..14c6ace9e215fc6f9683d461a2ef9c4c7b161650 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,12 @@ 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.ContextUtils;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| +import org.chromium.ui.display.DisplayAndroid;
|
|
|
| /**
|
| * Provides a Java-side implementation for injecting synthetic touch events.
|
| @@ -24,24 +27,37 @@ 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 WindowAndroidProvider mWindowProvider;
|
| private final PointerProperties[] mPointerProperties;
|
| private final PointerCoords[] mPointerCoords;
|
| private long mDownTimeInMs;
|
|
|
| - MotionEventSynthesizer(ContentViewCore contentViewCore) {
|
| - mContentViewCore = contentViewCore;
|
| + public MotionEventSynthesizer(View target, WindowAndroidProvider windowProvider) {
|
| + mTarget = target;
|
| + mWindowProvider = windowProvider;
|
| mPointerProperties = new PointerProperties[MAX_NUM_POINTERS];
|
| mPointerCoords = new PointerCoords[MAX_NUM_POINTERS];
|
| }
|
|
|
| + // Guaranteed to return a non-null DisplayAndroid.
|
| + private DisplayAndroid getDisplay() {
|
| + if (mWindowProvider != null && mWindowProvider.getWindowAndroid() != null) {
|
| + return mWindowProvider.getWindowAndroid().getDisplay();
|
| + }
|
| + return DisplayAndroid.getNonMultiDisplay(ContextUtils.getApplicationContext());
|
| + }
|
| +
|
| @CalledByNative
|
| void setPointer(int index, int x, int y, int id) {
|
| assert (0 <= index && index < MAX_NUM_POINTERS);
|
|
|
| // Convert coordinates from density independent pixels to density dependent pixels.
|
| - float scaleFactor = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
|
| + float scaleFactor = getDisplay().getDipScale();
|
|
|
| PointerCoords coords = new PointerCoords();
|
| coords.x = scaleFactor * x;
|
| @@ -58,7 +74,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 = getDisplay().getDipScale();
|
| mPointerCoords[0].setAxisValue(MotionEvent.AXIS_HSCROLL, scaleFactor * dx);
|
| mPointerCoords[0].setAxisValue(MotionEvent.AXIS_VSCROLL, scaleFactor * dy);
|
| }
|
| @@ -72,7 +88,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 +97,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 +107,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 +116,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 +126,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 +134,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 +143,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_EXIT;
|
| + 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();
|
| + }
|
| }
|
|
|