Skip to content

Commit

Permalink
PointerEvents: Use MotionEvent flags to indicate hoverability
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] Allow for MotionEvents to indicate whether they are dispatched from an input device that supports hoverability

Reviewed By: javache

Differential Revision: D37543296

fbshipit-source-id: 4f70d2bf69ff1c563d8e4a6b5eb6b13b53996b9a
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Jul 6, 2022
1 parent 8be49e8 commit 303aaf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public void onChildEndedNativeGesture() {
}

public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDispatcher) {
boolean supportsHover =
PointerEventHelper.supportsHover(motionEvent.getToolType(motionEvent.getActionIndex()));
boolean supportsHover = PointerEventHelper.supportsHover(motionEvent);

int surfaceId = UIManagerHelper.getSurfaceId(mRootViewGroup);
int action = motionEvent.getActionMasked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class PointerEventHelper {
public static final String POINTER_TYPE_MOUSE = "mouse";
public static final String POINTER_TYPE_UNKNOWN = "";

private static final int X_FLAG_SUPPORTS_HOVER = 0x01000000;

public static enum EVENT {
CANCEL,
CANCEL_CAPTURE,
Expand Down Expand Up @@ -144,7 +146,17 @@ public static int getEventCategory(String pointerEventType) {
return EventCategoryDef.UNSPECIFIED;
}

public static boolean supportsHover(final int toolType) {
public static boolean supportsHover(MotionEvent motionEvent) {
// A flag has been set on the MotionEvent to indicate it supports hover
// See D36958947 on justifications for this.
// TODO(luwe): Leverage previous events to determine if MotionEvent
// is from an input device that supports hover
boolean supportsHoverFlag = (motionEvent.getFlags() & X_FLAG_SUPPORTS_HOVER) != 0;
if (supportsHoverFlag) {
return true;
}

int toolType = motionEvent.getToolType(motionEvent.getActionIndex());
String pointerType = getW3CPointerType(toolType);

if (pointerType.equals(POINTER_TYPE_MOUSE)) {
Expand Down

0 comments on commit 303aaf8

Please sign in to comment.