Unverified Commit 314eb3ba authored by chunhtai's avatar chunhtai Committed by GitHub

Moving pointer event sanitizing to engine. (#44217)

parent f8cafd9d
...@@ -26,7 +26,6 @@ TestGestureFlutterBinding _binding = TestGestureFlutterBinding(); ...@@ -26,7 +26,6 @@ TestGestureFlutterBinding _binding = TestGestureFlutterBinding();
void ensureTestGestureBinding() { void ensureTestGestureBinding() {
_binding ??= TestGestureFlutterBinding(); _binding ??= TestGestureFlutterBinding();
PointerEventConverter.clearPointers();
assert(GestureBinding.instance != null); assert(GestureBinding.instance != null);
} }
...@@ -72,9 +71,11 @@ void main() { ...@@ -72,9 +71,11 @@ void main() {
test('Pointer hover events', () { test('Pointer hover events', () {
const ui.PointerDataPacket packet = ui.PointerDataPacket( const ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[ data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add),
ui.PointerData(change: ui.PointerChange.hover), ui.PointerData(change: ui.PointerChange.hover),
ui.PointerData(change: ui.PointerChange.hover), ui.PointerData(change: ui.PointerChange.hover),
ui.PointerData(change: ui.PointerChange.remove), ui.PointerData(change: ui.PointerChange.remove),
ui.PointerData(change: ui.PointerChange.add),
ui.PointerData(change: ui.PointerChange.hover), ui.PointerData(change: ui.PointerChange.hover),
], ],
); );
...@@ -97,33 +98,6 @@ void main() { ...@@ -97,33 +98,6 @@ void main() {
expect(pointerRouterEvents[5].runtimeType, equals(PointerHoverEvent)); expect(pointerRouterEvents[5].runtimeType, equals(PointerHoverEvent));
}); });
test('Synthetic move events', () {
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(
change: ui.PointerChange.down,
physicalX: 1.0 * ui.window.devicePixelRatio,
physicalY: 3.0 * ui.window.devicePixelRatio,
),
ui.PointerData(
change: ui.PointerChange.up,
physicalX: 10.0 * ui.window.devicePixelRatio,
physicalY: 15.0 * ui.window.devicePixelRatio,
),
],
);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = events.add;
ui.window.onPointerDataPacket(packet);
expect(events.length, 3);
expect(events[0].runtimeType, equals(PointerDownEvent));
expect(events[1].runtimeType, equals(PointerMoveEvent));
expect(events[1].delta, equals(const Offset(9.0, 12.0)));
expect(events[2].runtimeType, equals(PointerUpEvent));
});
test('Pointer cancel events', () { test('Pointer cancel events', () {
const ui.PointerDataPacket packet = ui.PointerDataPacket( const ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[ data: <ui.PointerData>[
...@@ -168,6 +142,7 @@ void main() { ...@@ -168,6 +142,7 @@ void main() {
ui.PointerData(change: ui.PointerChange.add, device: 24), ui.PointerData(change: ui.PointerChange.add, device: 24),
ui.PointerData(change: ui.PointerChange.hover, device: 24), ui.PointerData(change: ui.PointerChange.hover, device: 24),
ui.PointerData(change: ui.PointerChange.remove, device: 24), ui.PointerData(change: ui.PointerChange.remove, device: 24),
ui.PointerData(change: ui.PointerChange.add, device: 24),
ui.PointerData(change: ui.PointerChange.hover, device: 24), ui.PointerData(change: ui.PointerChange.hover, device: 24),
], ],
); );
...@@ -183,28 +158,6 @@ void main() { ...@@ -183,28 +158,6 @@ void main() {
expect(events[4].runtimeType, equals(PointerHoverEvent)); expect(events[4].runtimeType, equals(PointerHoverEvent));
}); });
test('Synthetic hover and cancel for misplaced down and remove', () {
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, device: 25, physicalX: 10.0 * ui.window.devicePixelRatio, physicalY: 10.0 * ui.window.devicePixelRatio),
ui.PointerData(change: ui.PointerChange.down, device: 25, physicalX: 15.0 * ui.window.devicePixelRatio, physicalY: 17.0 * ui.window.devicePixelRatio),
const ui.PointerData(change: ui.PointerChange.remove, device: 25),
],
);
final List<PointerEvent> events = PointerEventConverter.expand(
packet.data, ui.window.devicePixelRatio).toList();
expect(events.length, 6);
expect(events[0].runtimeType, equals(PointerAddedEvent));
expect(events[1].runtimeType, equals(PointerHoverEvent));
expect(events[1].delta, equals(const Offset(5.0, 7.0)));
expect(events[2].runtimeType, equals(PointerDownEvent));
expect(events[3].runtimeType, equals(PointerCancelEvent));
expect(events[4].runtimeType, equals(PointerHoverEvent));
expect(events[5].runtimeType, equals(PointerRemovedEvent));
});
test('Can expand pointer scroll events', () { test('Can expand pointer scroll events', () {
const ui.PointerDataPacket packet = ui.PointerDataPacket( const ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[ data: <ui.PointerData>[
...@@ -221,36 +174,6 @@ void main() { ...@@ -221,36 +174,6 @@ void main() {
expect(events[1].runtimeType, equals(PointerScrollEvent)); expect(events[1].runtimeType, equals(PointerScrollEvent));
}); });
test('Synthetic hover/move for misplaced scrolls', () {
final Offset lastLocation = const Offset(10.0, 10.0) * ui.window.devicePixelRatio;
const Offset unexpectedOffset = Offset(5.0, 7.0);
final Offset scrollLocation = lastLocation + unexpectedOffset * ui.window.devicePixelRatio;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, physicalX: lastLocation.dx, physicalY: lastLocation.dy),
ui.PointerData(change: ui.PointerChange.hover, physicalX: scrollLocation.dx, physicalY: scrollLocation.dy, signalKind: ui.PointerSignalKind.scroll),
// Move back to starting location, click, and repeat to test mouse-down version.
ui.PointerData(change: ui.PointerChange.hover, physicalX: lastLocation.dx, physicalY: lastLocation.dy),
ui.PointerData(change: ui.PointerChange.down, physicalX: lastLocation.dx, physicalY: lastLocation.dy),
ui.PointerData(change: ui.PointerChange.hover, physicalX: scrollLocation.dx, physicalY: scrollLocation.dy, signalKind: ui.PointerSignalKind.scroll),
],
);
final List<PointerEvent> events = PointerEventConverter.expand(
packet.data, ui.window.devicePixelRatio).toList();
expect(events.length, 7);
expect(events[0].runtimeType, equals(PointerAddedEvent));
expect(events[1].runtimeType, equals(PointerHoverEvent));
expect(events[1].delta, equals(unexpectedOffset));
expect(events[2].runtimeType, equals(PointerScrollEvent));
expect(events[3].runtimeType, equals(PointerHoverEvent));
expect(events[4].runtimeType, equals(PointerDownEvent));
expect(events[5].runtimeType, equals(PointerMoveEvent));
expect(events[5].delta, equals(unexpectedOffset));
expect(events[6].runtimeType, equals(PointerScrollEvent));
});
test('Should synthesize kPrimaryButton for touch', () { test('Should synthesize kPrimaryButton for touch', () {
final Offset location = const Offset(10.0, 10.0) * ui.window.devicePixelRatio; final Offset location = const Offset(10.0, 10.0) * ui.window.devicePixelRatio;
const PointerDeviceKind kind = PointerDeviceKind.touch; const PointerDeviceKind kind = PointerDeviceKind.touch;
...@@ -278,8 +201,6 @@ void main() { ...@@ -278,8 +201,6 @@ void main() {
expect(events[3].buttons, equals(kPrimaryButton)); expect(events[3].buttons, equals(kPrimaryButton));
expect(events[4].runtimeType, equals(PointerUpEvent)); expect(events[4].runtimeType, equals(PointerUpEvent));
expect(events[4].buttons, equals(0)); expect(events[4].buttons, equals(0));
PointerEventConverter.clearPointers();
}); });
test('Should synthesize kPrimaryButton for stylus', () { test('Should synthesize kPrimaryButton for stylus', () {
...@@ -313,8 +234,6 @@ void main() { ...@@ -313,8 +234,6 @@ void main() {
expect(events[3].buttons, equals(kPrimaryButton | kSecondaryStylusButton)); expect(events[3].buttons, equals(kPrimaryButton | kSecondaryStylusButton));
expect(events[4].runtimeType, equals(PointerUpEvent)); expect(events[4].runtimeType, equals(PointerUpEvent));
expect(events[4].buttons, equals(0)); expect(events[4].buttons, equals(0));
PointerEventConverter.clearPointers();
} }
}); });
...@@ -345,8 +264,6 @@ void main() { ...@@ -345,8 +264,6 @@ void main() {
expect(events[3].buttons, equals(kPrimaryButton)); expect(events[3].buttons, equals(kPrimaryButton));
expect(events[4].runtimeType, equals(PointerUpEvent)); expect(events[4].runtimeType, equals(PointerUpEvent));
expect(events[4].buttons, equals(0)); expect(events[4].buttons, equals(0));
PointerEventConverter.clearPointers();
}); });
test('Should not synthesize kPrimaryButton for mouse', () { test('Should not synthesize kPrimaryButton for mouse', () {
...@@ -378,8 +295,6 @@ void main() { ...@@ -378,8 +295,6 @@ void main() {
expect(events[3].buttons, equals(kMiddleMouseButton | kSecondaryMouseButton)); expect(events[3].buttons, equals(kMiddleMouseButton | kSecondaryMouseButton));
expect(events[4].runtimeType, equals(PointerUpEvent)); expect(events[4].runtimeType, equals(PointerUpEvent));
expect(events[4].buttons, equals(0)); expect(events[4].buttons, equals(0));
PointerEventConverter.clearPointers();
} }
}); });
} }
...@@ -77,7 +77,6 @@ void main() { ...@@ -77,7 +77,6 @@ void main() {
setUp(() { setUp(() {
_ensureTestGestureBinding(); _ensureTestGestureBinding();
_binding.postFrameCallbacks.clear(); _binding.postFrameCallbacks.clear();
PointerEventConverter.clearPointers();
}); });
test('MouseTrackerAnnotation has correct toString', () { test('MouseTrackerAnnotation has correct toString', () {
...@@ -134,11 +133,10 @@ void main() { ...@@ -134,11 +133,10 @@ void main() {
// Remove // Remove
ui.window.onPointerDataPacket(ui.PointerDataPacket(data: <ui.PointerData>[ ui.window.onPointerDataPacket(ui.PointerDataPacket(data: <ui.PointerData>[
_pointerData(PointerChange.remove, const Offset(1.0, 201.0)), _pointerData(PointerChange.remove, const Offset(1.0, 101.0)),
])); ]));
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
const PointerHoverEvent(position: Offset(1.0, 201.0)), const PointerExitEvent(position: Offset(1.0, 101.0)),
const PointerExitEvent(position: Offset(1.0, 201.0)),
])); ]));
expect(listenerLogs, <bool>[false]); expect(listenerLogs, <bool>[false]);
events.clear(); events.clear();
...@@ -286,12 +284,12 @@ void main() { ...@@ -286,12 +284,12 @@ void main() {
_setUpWithOneAnnotation(logEvents: events); _setUpWithOneAnnotation(logEvents: events);
ui.window.onPointerDataPacket(ui.PointerDataPacket(data: <ui.PointerData>[ ui.window.onPointerDataPacket(ui.PointerDataPacket(data: <ui.PointerData>[
_pointerData(PointerChange.add, const Offset(0.0, 101.0)),
_pointerData(PointerChange.down, const Offset(0.0, 101.0)), _pointerData(PointerChange.down, const Offset(0.0, 101.0)),
])); ]));
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
// This Enter event is triggered by the [PointerAddedEvent] that was // This Enter event is triggered by the [PointerAddedEvent] The
// synthesized during the event normalization of pointer event converter. // [PointerDownEvent] is ignored by [MouseTracker].
// The [PointerDownEvent] is ignored by [MouseTracker].
const PointerEnterEvent(position: Offset(0.0, 101.0)), const PointerEnterEvent(position: Offset(0.0, 101.0)),
])); ]));
events.clear(); events.clear();
......
...@@ -808,8 +808,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -808,8 +808,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
'active mouse gesture to remove the mouse pointer.'); 'active mouse gesture to remove the mouse pointer.');
// ignore: invalid_use_of_visible_for_testing_member // ignore: invalid_use_of_visible_for_testing_member
RendererBinding.instance.initMouseTracker(); RendererBinding.instance.initMouseTracker();
// ignore: invalid_use_of_visible_for_testing_member
PointerEventConverter.clearPointers();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment