From f5d0f3f9d5bf2b0a3ab9fd3b3264d8b58eb38160 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Sat, 21 Dec 2019 01:10:42 +0100 Subject: [PATCH] Use out of bounds coordinates when dispatching ACTION_HOVER_EXIT (#2510) --- .../vrbrowser/input/MotionEventGenerator.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/input/MotionEventGenerator.java b/app/src/common/shared/org/mozilla/vrbrowser/input/MotionEventGenerator.java index b8f2554fe..a3f000ece 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/input/MotionEventGenerator.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/input/MotionEventGenerator.java @@ -14,6 +14,9 @@ import org.mozilla.vrbrowser.ui.widgets.Widget; import org.mozilla.vrbrowser.utils.SystemUtils; +import java.util.Arrays; +import java.util.List; + public class MotionEventGenerator { static final String LOGTAG = SystemUtils.createLogtag(MotionEventGenerator.class); static class Device { @@ -24,6 +27,7 @@ static class Device { long mDownTime; MotionEvent.PointerProperties mProperties[]; MotionEvent.PointerCoords mCoords[]; + MotionEvent.PointerCoords mMouseOutCoords[]; Device(final int aDevice) { mDevice = aDevice; @@ -33,10 +37,16 @@ static class Device { mProperties[0].toolType = MotionEvent.TOOL_TYPE_FINGER; mCoords = new MotionEvent.PointerCoords[1]; mCoords[0] = new MotionEvent.PointerCoords(); - mCoords[0].toolMajor = 2; - mCoords[0].toolMinor = 2; - mCoords[0].touchMajor = 2; - mCoords[0].touchMinor = 2; + mMouseOutCoords = new MotionEvent.PointerCoords[1]; + for (MotionEvent.PointerCoords[] coords : Arrays.asList(mCoords, mMouseOutCoords)) { + coords[0] = new MotionEvent.PointerCoords(); + coords[0].toolMajor = 2; + coords[0].toolMinor = 2; + coords[0].touchMajor = 2; + coords[0].touchMinor = 2; + } + mMouseOutCoords[0].x = -10; + mMouseOutCoords[0].y = -10; } } @@ -44,13 +54,17 @@ static class Device { private static void generateEvent(Widget aWidget, Device aDevice, int aAction, boolean aGeneric) { + generateEvent(aWidget, aDevice, aAction, aGeneric, aDevice.mCoords); + } + + private static void generateEvent(Widget aWidget, Device aDevice, int aAction, boolean aGeneric, MotionEvent.PointerCoords[] aCoords) { MotionEvent event = MotionEvent.obtain( /*mDownTime*/ aDevice.mDownTime, /*eventTime*/ SystemClock.uptimeMillis(), /*action*/ aAction, /*pointerCount*/ 1, /*pointerProperties*/ aDevice.mProperties, - /*pointerCoords*/ aDevice.mCoords, + /*pointerCoords*/ aCoords, /*metaState*/ 0, /*buttonState*/ 0, /*xPrecision*/ 0, @@ -88,7 +102,7 @@ public static void dispatch(Widget aWidget, int aDevice, boolean aPressed, float generateEvent(device.mPreviousWidget, device, MotionEvent.ACTION_CANCEL, false); device.mWasPressed = false; } - generateEvent(device.mPreviousWidget, device, MotionEvent.ACTION_HOVER_EXIT, true); + generateEvent(device.mPreviousWidget, device, MotionEvent.ACTION_HOVER_EXIT, true, device.mMouseOutCoords); device.mPreviousWidget = null; } if (aWidget == null) {