Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[web] Fix event transform between mousedown/up due to mouse move event #22813

Merged
merged 7 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine/pointer_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class _ButtonSanitizer {
}

_pressedButtons = newPressedButtons;

return _SanitizedDetails(
change: _pressedButtons == 0
? ui.PointerChange.hover
Expand Down
14 changes: 13 additions & 1 deletion lib/web_ui/lib/src/engine/pointer_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ class PointerDataConverter {
// Map from browser pointer identifiers to PointerEvent pointer identifiers.
final Map<int, _PointerState> _pointers = <int, _PointerState>{};

/// 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
/// converter after hot reload.
void clearPointerState() {
_pointers.clear();
_PointerState._pointerCount = 0;
_activeButtons = 0;
}

_PointerState _ensureStateForPointer(int device, double x, double y) {
Expand Down Expand Up @@ -328,6 +337,7 @@ class PointerDataConverter {
scrollDeltaY: scrollDeltaY,
)
);
_activeButtons = buttons;
break;
case ui.PointerChange.down:
final bool alreadyAdded = _pointers.containsKey(device);
Expand Down Expand Up @@ -426,6 +436,7 @@ class PointerDataConverter {
scrollDeltaY: scrollDeltaY,
)
);
_activeButtons = buttons;
break;
case ui.PointerChange.move:
assert(_pointers.containsKey(device));
Expand Down Expand Up @@ -459,6 +470,7 @@ class PointerDataConverter {
scrollDeltaY: scrollDeltaY,
)
);
_activeButtons = buttons;
break;
case ui.PointerChange.up:
case ui.PointerChange.cancel:
Expand All @@ -485,7 +497,7 @@ class PointerDataConverter {
device: device,
physicalX: physicalX,
physicalY: physicalY,
buttons: buttons,
buttons: _activeButtons,
obscured: obscured,
pressure: pressure,
pressureMin: pressureMin,
Expand Down