-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add pointer data santizing in flutter web engine #14082
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
// 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; | ||
|
@@ -31,7 +24,6 @@ class PointerBinding { | |
assert(() { | ||
registerHotRestartListener(() { | ||
_adapter?.clearListeners(); | ||
_activePointerIds.clear(); | ||
}); | ||
return true; | ||
}()); | ||
|
@@ -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(); | ||
|
@@ -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); | ||
|
@@ -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. | ||
|
@@ -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); | ||
}); | ||
|
||
|
@@ -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') { | ||
chunhtai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_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, | ||
) | ||
]; | ||
} | ||
} | ||
|
||
|
@@ -490,34 +468,6 @@ Duration _eventTimeStampToDuration(num milliseconds) { | |
return Duration(milliseconds: ms, microseconds: micro); | ||
} | ||
|
||
void _ensureMouseDeviceAdded(List<ui.PointerData> data, double clientX, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved all these helper function to baseadapter abstract class |
||
) { | ||
|
@@ -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, | ||
chunhtai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.