From bdb72fb7995c4681aeaf0da0cfec7c16e9eac75b Mon Sep 17 00:00:00 2001 From: ferhatb Date: Tue, 1 Dec 2020 16:35:46 -0800 Subject: [PATCH 1/6] Fix event transform between mousedown/up due to mouse move event --- lib/web_ui/lib/src/engine/pointer_binding.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 7a28ad5588467..1a1d9eb661d6b 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -387,6 +387,8 @@ class _ButtonSanitizer { ); } + static const int kRightMouseButton = 1; + _SanitizedDetails sanitizeMoveEvent({required int buttons}) { final int newPressedButtons = _htmlButtonsToFlutterButtons(buttons); // This could happen when the context menu is active and the user clicks @@ -411,7 +413,10 @@ class _ButtonSanitizer { ); } - _pressedButtons = newPressedButtons; + if (_pressedButtons == kRightMouseButton) { + _pressedButtons = newPressedButtons; + } + return _SanitizedDetails( change: _pressedButtons == 0 ? ui.PointerChange.hover From d210eda1c372f7fc2c7fe69bb421576fbecc98e2 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 2 Dec 2020 09:31:02 -0800 Subject: [PATCH 2/6] Update test cases to ignore buttons update on move unless user clicks RMB --- lib/web_ui/lib/src/engine/pointer_binding.dart | 4 ++-- lib/web_ui/test/engine/pointer_binding_test.dart | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 1a1d9eb661d6b..69d9ee353b31e 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -387,7 +387,7 @@ class _ButtonSanitizer { ); } - static const int kRightMouseButton = 1; + static const int kRightMouseButton = 2; _SanitizedDetails sanitizeMoveEvent({required int buttons}) { final int newPressedButtons = _htmlButtonsToFlutterButtons(buttons); @@ -413,7 +413,7 @@ class _ButtonSanitizer { ); } - if (_pressedButtons == kRightMouseButton) { + if ((_pressedButtons & kRightMouseButton) != 0) { _pressedButtons = newPressedButtons; } diff --git a/lib/web_ui/test/engine/pointer_binding_test.dart b/lib/web_ui/test/engine/pointer_binding_test.dart index 4c100b91e112d..aa6e7e29d2ac4 100644 --- a/lib/web_ui/test/engine/pointer_binding_test.dart +++ b/lib/web_ui/test/engine/pointer_binding_test.dart @@ -1040,7 +1040,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(5)); + expect(packets[0].data[0].buttons, equals(1)); packets.clear(); // Release LMB. @@ -1052,7 +1052,8 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(4)); + // Left button should stay in buttons until mouse up is received. + expect(packets[0].data[0].buttons, equals(1)); packets.clear(); // Release MMB. From 56fa4f04e72a63a9ddf8e60b8380c05086793287 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 2 Dec 2020 17:04:17 -0800 Subject: [PATCH 3/6] Fix buttons used to synthesize move event --- lib/web_ui/lib/src/engine/pointer_converter.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/pointer_converter.dart b/lib/web_ui/lib/src/engine/pointer_converter.dart index f7870823b97fb..c76e1a8e51716 100644 --- a/lib/web_ui/lib/src/engine/pointer_converter.dart +++ b/lib/web_ui/lib/src/engine/pointer_converter.dart @@ -48,6 +48,14 @@ class PointerDataConverter { // Map from browser pointer identifiers to PointerEvent pointer identifiers. final Map _pointers = {}; + /// This field is used to keep track of button state. + /// + /// To normalize pointer events, when we receive pointer down followed by + /// pointer up, we synthesize a move event. To make sure that button state + /// is correct for move regardless of button state at the time of up event + /// we store it on down,hover and move events. + int _activeButtons = 0; + /// Clears the existing pointer states. /// /// This method is invoked during hot reload to make sure we have a clean @@ -55,6 +63,7 @@ class PointerDataConverter { void clearPointerState() { _pointers.clear(); _PointerState._pointerCount = 0; + _activeButtons = 0; } _PointerState _ensureStateForPointer(int device, double x, double y) { @@ -328,6 +337,7 @@ class PointerDataConverter { scrollDeltaY: scrollDeltaY, ) ); + _activeButtons = buttons; break; case ui.PointerChange.down: final bool alreadyAdded = _pointers.containsKey(device); @@ -426,6 +436,7 @@ class PointerDataConverter { scrollDeltaY: scrollDeltaY, ) ); + _activeButtons = buttons; break; case ui.PointerChange.move: assert(_pointers.containsKey(device)); @@ -459,6 +470,7 @@ class PointerDataConverter { scrollDeltaY: scrollDeltaY, ) ); + _activeButtons = buttons; break; case ui.PointerChange.up: case ui.PointerChange.cancel: @@ -485,7 +497,7 @@ class PointerDataConverter { device: device, physicalX: physicalX, physicalY: physicalY, - buttons: buttons, + buttons: _activeButtons, obscured: obscured, pressure: pressure, pressureMin: pressureMin, From 354687370db0f466e43a15519eb4f5aed97220a8 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 2 Dec 2020 17:35:02 -0800 Subject: [PATCH 4/6] Fix synthesized move event in PointerConverter --- lib/web_ui/lib/src/engine/pointer_binding.dart | 6 ------ lib/web_ui/test/engine/pointer_binding_test.dart | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 69d9ee353b31e..8b523842c5366 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -387,8 +387,6 @@ class _ButtonSanitizer { ); } - static const int kRightMouseButton = 2; - _SanitizedDetails sanitizeMoveEvent({required int buttons}) { final int newPressedButtons = _htmlButtonsToFlutterButtons(buttons); // This could happen when the context menu is active and the user clicks @@ -413,10 +411,6 @@ class _ButtonSanitizer { ); } - if ((_pressedButtons & kRightMouseButton) != 0) { - _pressedButtons = newPressedButtons; - } - return _SanitizedDetails( change: _pressedButtons == 0 ? ui.PointerChange.hover diff --git a/lib/web_ui/test/engine/pointer_binding_test.dart b/lib/web_ui/test/engine/pointer_binding_test.dart index aa6e7e29d2ac4..eeebeb203fe22 100644 --- a/lib/web_ui/test/engine/pointer_binding_test.dart +++ b/lib/web_ui/test/engine/pointer_binding_test.dart @@ -1197,7 +1197,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(3)); + expect(packets[0].data[0].buttons, equals(2)); packets.clear(); // Release LMB. @@ -1364,7 +1364,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(3)); + expect(packets[0].data[0].buttons, equals(2)); packets.clear(); // Release LMB. From c3201d87092626fbdc4bcd8c3d74adc4e159a801 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 2 Dec 2020 17:38:24 -0800 Subject: [PATCH 5/6] Revert pointer_binding.dart changes --- lib/web_ui/lib/src/engine/pointer_binding.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 8b523842c5366..74f21a5b65fe0 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -411,6 +411,8 @@ class _ButtonSanitizer { ); } + _pressedButtons = newPressedButtons; + return _SanitizedDetails( change: _pressedButtons == 0 ? ui.PointerChange.hover From b154ef3c22a2623c3cb91027379b256fda11acde Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 2 Dec 2020 17:40:48 -0800 Subject: [PATCH 6/6] Revert pointer_binding_test.dart changes --- lib/web_ui/test/engine/pointer_binding_test.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/web_ui/test/engine/pointer_binding_test.dart b/lib/web_ui/test/engine/pointer_binding_test.dart index eeebeb203fe22..4c100b91e112d 100644 --- a/lib/web_ui/test/engine/pointer_binding_test.dart +++ b/lib/web_ui/test/engine/pointer_binding_test.dart @@ -1040,7 +1040,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(1)); + expect(packets[0].data[0].buttons, equals(5)); packets.clear(); // Release LMB. @@ -1052,8 +1052,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - // Left button should stay in buttons until mouse up is received. - expect(packets[0].data[0].buttons, equals(1)); + expect(packets[0].data[0].buttons, equals(4)); packets.clear(); // Release MMB. @@ -1197,7 +1196,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(2)); + expect(packets[0].data[0].buttons, equals(3)); packets.clear(); // Release LMB. @@ -1364,7 +1363,7 @@ void testMain() { expect(packets[0].data, hasLength(1)); expect(packets[0].data[0].change, equals(ui.PointerChange.move)); expect(packets[0].data[0].synthesized, equals(false)); - expect(packets[0].data[0].buttons, equals(2)); + expect(packets[0].data[0].buttons, equals(3)); packets.clear(); // Release LMB.