forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor synthetic move event sending
1. Create SyntheticEventSender, purpose of which to generate synthetic events based on the previous one. Extract necessary functionality from PointerPositionUpdater. 2. PointerPositionUpdater main purpose is update cursor position for the scene via reusing SyntheticEventSender 3. Remove deprecated functions It is needed for my next PR with multitouch implementation where we need to send synthetic presses/releases API Changes: 1. Removed deprecated SkiaRootForTest.processPointerInput
- Loading branch information
Showing
11 changed files
with
300 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/SyntheticEventSenderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.ui | ||
|
||
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Enter | ||
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Exit | ||
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Move | ||
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Press | ||
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Release | ||
import androidx.compose.ui.input.pointer.PointerInputEvent | ||
import kotlin.test.Test | ||
|
||
class SyntheticEventSenderTest { | ||
@Test | ||
fun `mouse, shouldn't generate new events if order is correct`() { | ||
syntheticEvents( | ||
mouseEvent(Enter, 10f, 20f, pressed = false), | ||
mouseEvent(Press, 10f, 20f, pressed = true), | ||
mouseEvent(Move, 10f, 30f, pressed = true), | ||
mouseEvent(Release, 10f, 30f, pressed = false), | ||
mouseEvent(Move, 10f, 40f, pressed = false), | ||
mouseEvent(Press, 10f, 40f, pressed = true), | ||
mouseEvent(Release, 10f, 40f, pressed = false), | ||
mouseEvent(Exit, -1f, -1f, pressed = false), | ||
) shouldEqual listOf( | ||
mouseEvent(Enter, 10f, 20f, pressed = false), | ||
mouseEvent(Press, 10f, 20f, pressed = true), | ||
mouseEvent(Move, 10f, 30f, pressed = true), | ||
mouseEvent(Release, 10f, 30f, pressed = false), | ||
mouseEvent(Move, 10f, 40f, pressed = false), | ||
mouseEvent(Press, 10f, 40f, pressed = true), | ||
mouseEvent(Release, 10f, 40f, pressed = false), | ||
mouseEvent(Exit, -1f, -1f, pressed = false), | ||
) | ||
} | ||
|
||
@Test | ||
fun `mouse, should generate new move before non-move if position isn't the same`() { | ||
syntheticEvents( | ||
mouseEvent(Enter, 10f, 20f, pressed = false), | ||
mouseEvent(Press, 10f, 25f, pressed = true), | ||
mouseEvent(Move, 10f, 30f, pressed = true), | ||
mouseEvent(Release, 10f, 35f, pressed = false), | ||
mouseEvent(Move, 10f, 40f, pressed = false), | ||
mouseEvent(Press, 10f, 45f, pressed = true), | ||
mouseEvent(Release, 10f, 50f, pressed = false), | ||
mouseEvent(Exit, -1f, -1f, pressed = false), | ||
) shouldEqual listOf( | ||
mouseEvent(Enter, 10f, 20f, pressed = false), | ||
mouseEvent(Move, 10f, 25f, pressed = false), | ||
mouseEvent(Press, 10f, 25f, pressed = true), | ||
mouseEvent(Move, 10f, 30f, pressed = true), | ||
mouseEvent(Move, 10f, 35f, pressed = true), | ||
mouseEvent(Release, 10f, 35f, pressed = false), | ||
mouseEvent(Move, 10f, 40f, pressed = false), | ||
mouseEvent(Move, 10f, 45f, pressed = false), | ||
mouseEvent(Press, 10f, 45f, pressed = true), | ||
mouseEvent(Move, 10f, 50f, pressed = true), | ||
mouseEvent(Release, 10f, 50f, pressed = false), | ||
mouseEvent(Exit, -1f, -1f, pressed = false), | ||
) | ||
} | ||
|
||
private fun syntheticEvents( | ||
vararg inputEvents: PointerInputEvent | ||
): List<PointerInputEvent> { | ||
val received = mutableListOf<PointerInputEvent>() | ||
val sender = SyntheticEventSender(received::add) | ||
for (inputEvent in inputEvents) { | ||
sender.send(inputEvent) | ||
} | ||
return received | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.