Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W3CPointerEvents: properly update hit path during native gestures #37638

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public void onChildStartedNativeGesture(

dispatchCancelEventForTarget(childView, motionInRoot, eventDispatcher);
mChildHandlingNativeGesture = childView.getId();

// clear "previous" state since interaction was canceled
resetPreviousStateForMotionEvent(motionEvent);
}

private MotionEvent convertMotionToRootFrame(View childView, MotionEvent childMotion) {
Expand All @@ -84,6 +87,28 @@ private MotionEvent convertMotionToRootFrame(View childView, MotionEvent childMo
return motionInRoot;
}

private void updatePreviousStateFromEvent(MotionEvent event, PointerEventState eventState) {
// Caching the event state so we have a new "last"
mLastHitPathByPointerId = eventState.getHitPathByPointerId();
mLastEventCoordinatesByPointerId = eventState.getEventCoordinatesByPointerId();
mLastButtonState = event.getButtonState();

// Clean up any stale pointerIds
Set<Integer> allPointerIds = mLastEventCoordinatesByPointerId.keySet();
mHoveringPointerIds.retainAll(allPointerIds);
}

private void resetPreviousStateForMotionEvent(MotionEvent event) {
int activePointerId = event.getPointerId(event.getActionIndex());
if (mLastHitPathByPointerId != null) {
mLastHitPathByPointerId.remove(activePointerId);
}
if (mLastEventCoordinatesByPointerId != null) {
mLastEventCoordinatesByPointerId.remove(activePointerId);
}
mLastButtonState = 0;
}

public void onChildEndedNativeGesture() {
// There should be only one child gesture at any given time. We can safely turn off the flag.
mChildHandlingNativeGesture = -1;
Expand Down Expand Up @@ -368,14 +393,7 @@ public void handleMotionEvent(
return;
}

// Caching the event state so we have a new "last"
mLastHitPathByPointerId = eventState.getHitPathByPointerId();
mLastEventCoordinatesByPointerId = eventState.getEventCoordinatesByPointerId();
mLastButtonState = motionEvent.getButtonState();

// Clean up any stale pointerIds
Set<Integer> allPointerIds = mLastEventCoordinatesByPointerId.keySet();
mHoveringPointerIds.retainAll(allPointerIds);
updatePreviousStateFromEvent(motionEvent, eventState);
}

private static boolean isAnyoneListeningForBubblingEvent(
Expand Down