Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions lib/web_ui/lib/src/engine/pointer_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ typedef _PointerDataCallback = void Function(Iterable<ui.PointerData>);
// here, we use an already very large number (30 bits).
const int _kButtonsMask = 0x3FFFFFFF;

// Intentionally set to -1 so it doesn't conflict with other device IDs.
// Intentionally set to -1 or -2 so it doesn't conflict with other device IDs.
const int _mouseDeviceId = -1;
const int _trackpadDeviceId = -2;

const int _kPrimaryMouseButton = 0x1;
const int _kSecondaryMouseButton = 0x2;
Expand Down Expand Up @@ -421,8 +422,10 @@ mixin _WheelEventListenerMixin on _BaseAdapter {
const int domDeltaPage = 0x02;

ui.PointerDeviceKind kind = ui.PointerDeviceKind.mouse;
int deviceId = _mouseDeviceId;
if (_isTrackpadEvent(event)) {
kind = ui.PointerDeviceKind.trackpad;
deviceId = _trackpadDeviceId;
}

// Flutter only supports pixel scroll delta. Convert deltaMode values
Expand Down Expand Up @@ -459,7 +462,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter {
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!),
kind: kind,
signalKind: ui.PointerSignalKind.scroll,
device: _mouseDeviceId,
device: deviceId,
physicalX: offset.dx * ui.window.devicePixelRatio,
physicalY: offset.dy * ui.window.devicePixelRatio,
buttons: event.buttons!.toInt(),
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/test/engine/pointer_binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ void testMain() {
packets[0].data[1].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[0].data[1].kind, equals(ui.PointerDeviceKind.trackpad));
expect(packets[0].data[1].device, equals(-2));
expect(packets[0].data[1].pointerIdentifier, equals(0));
expect(packets[0].data[1].synthesized, isFalse);
expect(packets[0].data[1].physicalX, equals(10.0 * dpi));
Expand All @@ -1281,6 +1282,7 @@ void testMain() {
packets[1].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[1].data[0].kind, equals(ui.PointerDeviceKind.trackpad));
expect(packets[1].data[0].device, equals(-2));
expect(packets[1].data[0].pointerIdentifier, equals(0));
expect(packets[1].data[0].synthesized, isFalse);
expect(packets[1].data[0].physicalX, equals(10.0 * dpi));
Expand All @@ -1297,6 +1299,7 @@ void testMain() {
packets[2].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[2].data[0].kind, equals(ui.PointerDeviceKind.trackpad));
expect(packets[2].data[0].device, equals(-2));
expect(packets[2].data[0].pointerIdentifier, equals(0));
expect(packets[2].data[0].synthesized, isFalse);
expect(packets[2].data[0].physicalX, equals(10.0 * dpi));
Expand All @@ -1313,6 +1316,7 @@ void testMain() {
packets[3].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[3].data[0].kind, equals(ui.PointerDeviceKind.trackpad));
expect(packets[3].data[0].device, equals(-2));
expect(packets[3].data[0].pointerIdentifier, equals(0));
expect(packets[3].data[0].synthesized, isFalse);
expect(packets[3].data[0].physicalX, equals(10.0 * dpi));
Expand All @@ -1330,6 +1334,7 @@ void testMain() {
packets[4].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[4].data[0].kind, equals(ui.PointerDeviceKind.trackpad));
expect(packets[4].data[0].pointerIdentifier, equals(-2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be device?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 🤦‍♀️ - thanks. Still recovering from jet lag.

expect(packets[4].data[0].pointerIdentifier, equals(0));
expect(packets[4].data[0].synthesized, isFalse);
expect(packets[4].data[0].physicalX, equals(10.0 * dpi));
Expand All @@ -1347,6 +1352,7 @@ void testMain() {
packets[5].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[5].data[0].kind, equals(ui.PointerDeviceKind.mouse));
expect(packets[5].data[0].device, equals(-1));
expect(packets[5].data[0].pointerIdentifier, equals(0));
expect(packets[5].data[0].synthesized, isFalse);
expect(packets[5].data[0].physicalX, equals(10.0 * dpi));
Expand All @@ -1364,6 +1370,7 @@ void testMain() {
packets[6].data[0].signalKind, equals(ui.PointerSignalKind.scroll));
expect(
packets[6].data[0].kind, equals(ui.PointerDeviceKind.mouse));
expect(packets[6].data[0].device, equals(-1));
expect(packets[6].data[0].pointerIdentifier, equals(0));
expect(packets[6].data[0].synthesized, isFalse);
expect(packets[6].data[0].physicalX, equals(10.0 * dpi));
Expand Down