Move drag event to InputDispatcher (2/n)

This CL adds the ability to receive a DRAG event through the
InputChannel, and adds the appropriate processing logic to
InputEventReceiver.

Bug: 158242495
Test: atest libinput_tests
Change-Id: I94d5fa545d920be52e03702d0d24712fd11c497c
This commit is contained in:
arthurhung
2020-12-30 17:26:31 +08:00
parent 242cc497ab
commit cfde236281
2 changed files with 25 additions and 0 deletions

View File

@@ -158,6 +158,16 @@ public abstract class InputEventReceiver {
public void onPointerCaptureEvent(boolean pointerCaptureEnabled) {
}
/**
* Called when a drag event is received, from native code.
*
* @param isExiting if false, the window associated with this input channel has just received
* drag
* if true, the window associated with this input channel has just lost drag
*/
public void onDragEvent(boolean isExiting, float x, float y) {
}
/**
* Called when a batched input event is pending.
*

View File

@@ -57,6 +57,7 @@ static struct {
jmethodID dispatchInputEvent;
jmethodID onFocusEvent;
jmethodID onPointerCaptureEvent;
jmethodID onDragEvent;
jmethodID onBatchedInputEventPending;
} gInputEventReceiverClassInfo;
@@ -400,6 +401,18 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
finishInputEvent(seq, true /* handled */);
continue;
}
case AINPUT_EVENT_TYPE_DRAG: {
const DragEvent* dragEvent = static_cast<DragEvent*>(inputEvent);
if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received drag event: isExiting=%s",
getInputChannelName().c_str(), toString(dragEvent->isExiting()));
}
env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.onDragEvent,
jboolean(dragEvent->isExiting()), dragEvent->getX(),
dragEvent->getY());
finishInputEvent(seq, true /* handled */);
continue;
}
default:
assert(false); // InputConsumer should prevent this from ever happening
@@ -547,6 +560,8 @@ int register_android_view_InputEventReceiver(JNIEnv* env) {
gInputEventReceiverClassInfo.onPointerCaptureEvent =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onPointerCaptureEvent",
"(Z)V");
gInputEventReceiverClassInfo.onDragEvent =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onDragEvent", "(ZFF)V");
gInputEventReceiverClassInfo.onBatchedInputEventPending =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onBatchedInputEventPending",
"(I)V");