Revert "MouseRegion enter/exit event can be triggered with button pressed (#81148)" (#81557)

This reverts commit ace61f01efe3d4e53db1845627028d901e7af3e9.
This commit is contained in:
Tong Mu 2021-04-30 12:35:21 -07:00 committed by GitHub
parent ce9aee6606
commit d97f41caed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 43 deletions

View File

@ -282,13 +282,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
event is PointerAddedEvent || event is PointerAddedEvent ||
event is PointerRemovedEvent) { event is PointerRemovedEvent) {
assert(event.position != null); assert(event.position != null);
_mouseTracker!.updateWithEvent( _mouseTracker!.updateWithEvent(event, () => hitTestResult ?? renderView.hitTestMouseTrackers(event.position));
event,
// Mouse events(enter and exit) can be triggered with or without buttons pressed.
// If the button is pressed, we need to re-execute the hit test instead of
// reusing the cached results to trigger possible events.
() => (hitTestResult == null || event.down) ? renderView.hitTestMouseTrackers(event.position) : hitTestResult,
);
} }
super.dispatchEvent(event, hitTestResult); super.dispatchEvent(event, hitTestResult);
} }

View File

@ -76,42 +76,6 @@ class _HoverFeedbackState extends State<HoverFeedback> {
} }
void main() { void main() {
testWidgets('onEnter and onExit can be triggered with mouse buttons pressed', (WidgetTester tester) async {
PointerEnterEvent? enter;
PointerExitEvent? exit;
await tester.pumpWidget(Center(
child: MouseRegion(
child: Container(
color: const Color.fromARGB(0xff, 0xff, 0x00, 0x00),
width: 100.0,
height: 100.0,
),
onEnter: (PointerEnterEvent details) => enter = details,
onExit: (PointerExitEvent details) => exit = details,
),
));
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, buttons: kPrimaryMouseButton);
await gesture.addPointer(location: Offset.zero);
await gesture.down(Offset.zero); // Press the mouse button.
addTearDown(gesture.removePointer);
await tester.pump();
enter = null;
exit = null;
// Trigger the enter event.
await gesture.moveTo(const Offset(400.0, 300.0));
expect(enter, isNotNull);
expect(enter!.position, equals(const Offset(400.0, 300.0)));
expect(enter!.localPosition, equals(const Offset(50.0, 50.0)));
expect(exit, isNull);
// Trigger the exit event.
await gesture.moveTo(const Offset(1.0, 1.0));
expect(exit, isNotNull);
expect(exit!.position, equals(const Offset(1.0, 1.0)));
expect(exit!.localPosition, equals(const Offset(-349.0, -249.0)));
});
testWidgets('detects pointer enter', (WidgetTester tester) async { testWidgets('detects pointer enter', (WidgetTester tester) async {
PointerEnterEvent? enter; PointerEnterEvent? enter;
PointerHoverEvent? move; PointerHoverEvent? move;