Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Use out of bounds coordinates when dispatching ACTION_HOVER_EXIT (#2510)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Dec 21, 2019
1 parent 99abd68 commit 9bd7b5e
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,6 +27,7 @@ static class Device {
long mDownTime;
MotionEvent.PointerProperties mProperties[];
MotionEvent.PointerCoords mCoords[];
MotionEvent.PointerCoords mMouseOutCoords[];

Device(final int aDevice) {
mDevice = aDevice;
Expand All @@ -33,24 +37,34 @@ 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;
}
}

private static SparseArray<Device> devices = new SparseArray<>();


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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9bd7b5e

Please sign in to comment.