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
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ part 'engine/picture.dart';
part 'engine/platform_views.dart';
part 'engine/plugins.dart';
part 'engine/pointer_binding.dart';
part 'engine/pointer_converter.dart';
part 'engine/recording_canvas.dart';
part 'engine/render_vertices.dart';
part 'engine/rrect_renderer.dart';
Expand Down
126 changes: 37 additions & 89 deletions lib/web_ui/lib/src/engine/pointer_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ class PointerBinding {
static PointerBinding get instance => _instance;
static PointerBinding _instance;

// Set of pointerIds that are added before routing hover and mouse wheel
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we no longer need to guess whether the framework will synthesize an add or not, because it won't.

// events.
//
// The device needs to send a one time PointerChange.add before hover and
// wheel events.
Set<int> _activePointerIds = <int>{};

PointerBinding(this.domRenderer) {
if (_instance == null) {
_instance = this;
Expand All @@ -31,7 +24,6 @@ class PointerBinding {
assert(() {
registerHotRestartListener(() {
_adapter?.clearListeners();
_activePointerIds.clear();
});
return true;
}());
Expand Down Expand Up @@ -62,7 +54,6 @@ class PointerBinding {
newDetector ??= const PointerSupportDetector();
// When changing the detector, we need to swap the adapter.
if (newDetector != _detector) {
_activePointerIds.clear();
_detector = newDetector;
_adapter?.clearListeners();
_adapter = _createAdapter();
Expand All @@ -83,7 +74,11 @@ class PointerBinding {
}

void _onPointerData(List<ui.PointerData> data) {
final ui.PointerDataPacket packet = ui.PointerDataPacket(data: data);
final List<ui.PointerData> converted = List<ui.PointerData>.from(
PointerDataConverter.convert(data),
);
print('from data ${data} to converted ${converted}');
final ui.PointerDataPacket packet = ui.PointerDataPacket(data: converted);
final ui.PointerDataPacketCallback callback = ui.window.onPointerDataPacket;
if (callback != null) {
callback(packet);
Expand Down Expand Up @@ -215,8 +210,6 @@ class PointerAdapter extends BaseAdapter {
_addEventListener('pointerdown', (html.Event event) {
final int pointerButton = _pointerButtonFromHtmlEvent(event);
final int device = _deviceFromHtmlEvent(event);
// The pointerdown event will cause an 'add' event on the framework side.
PointerBinding._instance._activePointerIds.add(device);
if (_isButtonDown(device, pointerButton)) {
// TODO(flutter_web): Remove this temporary fix for right click
// on web platform once context guesture is implemented.
Expand All @@ -239,13 +232,6 @@ class PointerAdapter extends BaseAdapter {
? ui.PointerChange.move
: ui.PointerChange.hover,
pointerEvent);
_ensureMouseDeviceAdded(
data,
pointerEvent.client.x,
pointerEvent.client.y,
pointerEvent.buttons,
pointerEvent.timeStamp,
pointerEvent.pointerId);
_callback(data);
});

Expand Down Expand Up @@ -455,29 +441,21 @@ class MouseAdapter extends BaseAdapter {
ui.PointerChange change,
html.MouseEvent event,
) {
final List<ui.PointerData> data = <ui.PointerData>[];
// The mousedown event will cause an 'add' event on the framework side.
if (event.type == 'mousedown') {
PointerBinding._instance._activePointerIds.add(_mouseDeviceId);
}
if (event.type == 'mousemove') {
_ensureMouseDeviceAdded(data, event.client.x, event.client.y,
event.buttons, event.timeStamp, _mouseDeviceId);
}
data.add(ui.PointerData(
change: change,
timeStamp: _eventTimeStampToDuration(event.timeStamp),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.none,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio,
physicalY: event.client.y * ui.window.devicePixelRatio,
buttons: event.buttons,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
));
return data;
return <ui.PointerData>[
ui.PointerData(
change: change,
timeStamp: _eventTimeStampToDuration(event.timeStamp),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.none,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio,
physicalY: event.client.y * ui.window.devicePixelRatio,
buttons: event.buttons,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
)
];
}
}

Expand All @@ -490,34 +468,6 @@ Duration _eventTimeStampToDuration(num milliseconds) {
return Duration(milliseconds: ms, microseconds: micro);
}

void _ensureMouseDeviceAdded(List<ui.PointerData> data, double clientX,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

synthesizing logic is moved to pointer_converter.dart

double clientY, int buttons, double timeStamp, int deviceId) {
if (PointerBinding.instance._activePointerIds.contains(deviceId)) {
return;
}
PointerBinding.instance._activePointerIds.add(deviceId);
// Only send [PointerChange.add] the first time.
data.insert(
0,
ui.PointerData(
change: ui.PointerChange.add,
timeStamp: _eventTimeStampToDuration(timeStamp),
kind: ui.PointerDeviceKind.mouse,
// In order for Flutter to actually add this pointer, we need to set the
// signal to none.
signalKind: ui.PointerSignalKind.none,
device: deviceId,
physicalX: clientX * ui.window.devicePixelRatio,
physicalY: clientY * ui.window.devicePixelRatio,
buttons: buttons,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
scrollDeltaX: 0,
scrollDeltaY: 0,
));
}

List<ui.PointerData> _convertWheelEventToPointerData(
html.WheelEvent event,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved all these helper function to baseadapter abstract class

) {
Expand All @@ -543,25 +493,23 @@ List<ui.PointerData> _convertWheelEventToPointerData(
break;
}

final List<ui.PointerData> data = <ui.PointerData>[];
_ensureMouseDeviceAdded(data, event.client.x, event.client.y, event.buttons,
event.timeStamp, _mouseDeviceId);
data.add(ui.PointerData(
change: ui.PointerChange.hover,
timeStamp: _eventTimeStampToDuration(event.timeStamp),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.scroll,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio,
physicalY: event.client.y * ui.window.devicePixelRatio,
buttons: event.buttons,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
scrollDeltaX: deltaX,
scrollDeltaY: deltaY,
));
return data;
return <ui.PointerData>[
ui.PointerData(
change: ui.PointerChange.hover,
timeStamp: _eventTimeStampToDuration(event.timeStamp),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.scroll,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio,
physicalY: event.client.y * ui.window.devicePixelRatio,
buttons: event.buttons,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
scrollDeltaX: deltaX,
scrollDeltaY: deltaY,
)
];
}

void _addWheelEventListener(void listener(html.WheelEvent e)) {
Expand Down
Loading