Commit c0d46895 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Ensure AreaGestureEventFilter has a valid down event

Because of the way touch events are routed in the layout system, it
is possible for the gesture detectors to occacionally miss events.
This patch checks that events captured by the AreaGestureEventFilter
have a valid down event prior to processing.

Bug: 1026139
Change-Id: I37c26dcc49c36c61290aba7586bdc962238a06eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490321
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819908}
parent 9f1b0c8a
......@@ -15,6 +15,9 @@ import android.view.MotionEvent;
public class AreaGestureEventFilter extends GestureEventFilter {
private final RectF mTriggerRect = new RectF();
/** Whether a down event has occurred inside of the specified area. */
private boolean mHasDownEventInArea;
/**
* Creates a {@link AreaGestureEventFilter}.
* @param context The context to build the gesture handler under.
......@@ -66,9 +69,29 @@ public class AreaGestureEventFilter extends GestureEventFilter {
}
}
@Override
public boolean onTouchEventInternal(MotionEvent e) {
// If the action is up or down, consider it to be a new gesture.
if (e.getActionMasked() == MotionEvent.ACTION_UP
|| e.getActionMasked() == MotionEvent.ACTION_DOWN) {
mHasDownEventInArea = false;
}
return super.onTouchEventInternal(e);
}
@Override
public boolean onInterceptTouchEventInternal(MotionEvent e, boolean isKeyboardShowing) {
// If the action is up or down, consider it to be a new gesture.
if (e.getActionMasked() == MotionEvent.ACTION_UP
|| e.getActionMasked() == MotionEvent.ACTION_DOWN) {
mHasDownEventInArea = false;
}
if (mTriggerRect.contains(e.getX() * mPxToDp, e.getY() * mPxToDp)) {
if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
mHasDownEventInArea = true;
} else if (!mHasDownEventInArea) {
return false;
}
return super.onInterceptTouchEventInternal(e, isKeyboardShowing);
}
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment