@@ -12414,18 +12414,22 @@ class InputDispatcherDragTests : public InputDispatcherTest {
1241412414 0});
1241512415 }
1241612416
12417- void injectDown(int fromSource = AINPUT_SOURCE_TOUCHSCREEN) {
12417+ void injectDown(int fromSource = AINPUT_SOURCE_TOUCHSCREEN,
12418+ ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT) {
1241812419 bool consumeButtonPress = false;
12420+ const PointF location =
12421+ displayId == ui::LogicalDisplayId::DEFAULT ? PointF(50, 50) : PointF(50, 450);
1241912422 switch (fromSource) {
1242012423 case AINPUT_SOURCE_TOUCHSCREEN: {
1242112424 ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
12422- injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN,
12423- ui::LogicalDisplayId::DEFAULT, {50, 50} ))
12425+ injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, displayId,
12426+ location ))
1242412427 << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
1242512428 break;
1242612429 }
1242712430 case AINPUT_SOURCE_STYLUS: {
12428- PointerBuilder pointer = PointerBuilder(0, ToolType::STYLUS).x(50).y(50);
12431+ PointerBuilder pointer =
12432+ PointerBuilder(0, ToolType::STYLUS).x(location.x).y(location.y);
1242912433 ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
1243012434 injectMotionEvent(*mDispatcher,
1243112435 MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN,
@@ -12448,19 +12452,22 @@ class InputDispatcherDragTests : public InputDispatcherTest {
1244812452 break;
1244912453 }
1245012454 case AINPUT_SOURCE_MOUSE: {
12451- PointerBuilder pointer =
12452- PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE).x(50).y(50);
12455+ PointerBuilder pointer = PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE)
12456+ .x(location.x)
12457+ .y(location.y);
1245312458 ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
1245412459 injectMotionEvent(*mDispatcher,
1245512460 MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN,
1245612461 AINPUT_SOURCE_MOUSE)
12462+ .displayId(displayId)
1245712463 .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
1245812464 .pointer(pointer)
1245912465 .build()));
1246012466 ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
1246112467 injectMotionEvent(*mDispatcher,
1246212468 MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS,
1246312469 AINPUT_SOURCE_MOUSE)
12470+ .displayId(displayId)
1246412471 .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
1246512472 .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
1246612473 .pointer(pointer)
@@ -12474,25 +12481,30 @@ class InputDispatcherDragTests : public InputDispatcherTest {
1247412481 }
1247512482
1247612483 // Window should receive motion event.
12477- mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT);
12484+ sp<FakeWindowHandle>& targetWindow =
12485+ displayId == ui::LogicalDisplayId::DEFAULT ? mWindow : mWindowOnSecondDisplay;
12486+ targetWindow->consumeMotionDown(displayId);
1247812487 if (consumeButtonPress) {
12479- mWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
12488+ targetWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
12489+ }
12490+
12491+ // Spy window should also receive motion event if event is on the same display.
12492+ if (displayId == ui::LogicalDisplayId::DEFAULT) {
12493+ mSpyWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT);
1248012494 }
12481- // Spy window should also receive motion event
12482- mSpyWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT);
1248312495 }
1248412496
1248512497 // Start performing drag, we will create a drag window and transfer touch to it.
1248612498 // @param sendDown : if true, send a motion down on first window before perform drag and drop.
1248712499 // Returns true on success.
12488- bool startDrag(bool sendDown = true, int fromSource = AINPUT_SOURCE_TOUCHSCREEN) {
12500+ bool startDrag(bool sendDown = true, int fromSource = AINPUT_SOURCE_TOUCHSCREEN,
12501+ ui::LogicalDisplayId dragStartDisplay = ui::LogicalDisplayId::DEFAULT) {
1248912502 if (sendDown) {
12490- injectDown(fromSource);
12503+ injectDown(fromSource, dragStartDisplay );
1249112504 }
1249212505
1249312506 // The drag window covers the entire display
12494- mDragWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "DragWindow",
12495- ui::LogicalDisplayId::DEFAULT);
12507+ mDragWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "DragWindow", dragStartDisplay);
1249612508 mDragWindow->setTouchableRegion(Region{{0, 0, 0, 0}});
1249712509 mDispatcher->onWindowInfosChanged(
1249812510 {{*mDragWindow->getInfo(), *mSpyWindow->getInfo(), *mWindow->getInfo(),
@@ -12501,14 +12513,17 @@ class InputDispatcherDragTests : public InputDispatcherTest {
1250112513 0,
1250212514 0});
1250312515
12516+ sp<FakeWindowHandle>& targetWindow = dragStartDisplay == ui::LogicalDisplayId::DEFAULT
12517+ ? mWindow
12518+ : mWindowOnSecondDisplay;
12519+
1250412520 // Transfer touch focus to the drag window
1250512521 bool transferred =
12506- mDispatcher->transferTouchGesture(mWindow ->getToken(), mDragWindow->getToken(),
12522+ mDispatcher->transferTouchGesture(targetWindow ->getToken(), mDragWindow->getToken(),
1250712523 /*isDragDrop=*/true);
1250812524 if (transferred) {
12509- mWindow->consumeMotionCancel();
12510- mDragWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT,
12511- AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
12525+ targetWindow->consumeMotionCancel(dragStartDisplay);
12526+ mDragWindow->consumeMotionDown(dragStartDisplay, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
1251212527 }
1251312528 return transferred;
1251412529 }
@@ -15292,10 +15307,10 @@ TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseGesture) {
1529215307 mWindow->consumeMotionUp(SECOND_DISPLAY_ID);
1529315308}
1529415309
15295- TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseDragAndDrop ) {
15310+ TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseDragAndDropFromPrimaryDisplay ) {
1529615311 SCOPED_FLAG_OVERRIDE(connected_displays_cursor, true);
1529715312
15298- startDrag(true, AINPUT_SOURCE_MOUSE);
15313+ EXPECT_TRUE( startDrag(true, AINPUT_SOURCE_MOUSE) );
1529915314 // Move on window.
1530015315 mDispatcher->notifyMotion(
1530115316 MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE)
@@ -15346,4 +15361,46 @@ TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseDragAndDrop) {
1534615361 mWindowOnSecondDisplay->assertNoEvents();
1534715362}
1534815363
15364+ TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseDragAndDropFromNonPrimaryDisplay) {
15365+ SCOPED_FLAG_OVERRIDE(connected_displays_cursor, true);
15366+
15367+ EXPECT_TRUE(startDrag(true, AINPUT_SOURCE_MOUSE, SECOND_DISPLAY_ID));
15368+ // Move on window.
15369+ mDispatcher->notifyMotion(
15370+ MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE)
15371+ .displayId(SECOND_DISPLAY_ID)
15372+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
15373+ .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE).x(50).y(50))
15374+ .build());
15375+ mDragWindow->consumeMotionMove(SECOND_DISPLAY_ID, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
15376+ mWindow->assertNoEvents();
15377+ mSecondWindow->assertNoEvents();
15378+ mWindowOnSecondDisplay->consumeDragEvent(false, 50, 50);
15379+
15380+ // Move to window on the primary display
15381+ mDispatcher->notifyMotion(
15382+ MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE)
15383+ .displayId(DISPLAY_ID)
15384+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
15385+ .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE).x(50).y(50))
15386+ .build());
15387+ mDragWindow->consumeMotionMove(DISPLAY_ID, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
15388+ mWindow->consumeDragEvent(false, 50, 50);
15389+ mSecondWindow->assertNoEvents();
15390+ mWindowOnSecondDisplay->consumeDragEvent(true, 50, 50);
15391+
15392+ // drop on the primary display
15393+ mDispatcher->notifyMotion(
15394+ MotionArgsBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE)
15395+ .displayId(DISPLAY_ID)
15396+ .buttonState(0)
15397+ .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE).x(50).y(50))
15398+ .build());
15399+ mDragWindow->consumeMotionUp(DISPLAY_ID, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
15400+ mFakePolicy->assertDropTargetEquals(*mDispatcher, mWindow->getToken());
15401+ mWindow->assertNoEvents();
15402+ mSecondWindow->assertNoEvents();
15403+ mWindowOnSecondDisplay->assertNoEvents();
15404+ }
15405+
1534915406} // namespace android::inputdispatcher
0 commit comments