-
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
[Web] Fix pointer binding #14378
[Web] Fix pointer binding #14378
Conversation
|
||
void handleDown({@required _PointerStateDataCallback dataCallback, @required int buttons}) { | ||
// TODO(flutter_web): Remove this temporary fix for right click | ||
// on web platform once context guesture is implemented. |
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.
typo: s/guesture/gesture
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.
Fixed. Also I didn't add this TODO, but only moved it (since there was a corresponding test), and I have no idea why it was there.
_pressedButtons = 0; | ||
dataCallback(change: ui.PointerChange.up, buttons: _pressedButtons); |
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.
Same comment as above: did you mean to reverse the order of these two statements?
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.
Why do we want to reverse these two statements? We indeed want to dispatch an up event with "buttons: 0". Events should contain the current state of buttons of this pointer.
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.
Maybe I'm misunderstading something here. I thought we tell Flutter which button
are being released with this pointerup
event. Is that not true?
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.
Flutter's PointerEvent
class doesn't have a "button" property, but only a "buttons" property. https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/events.dart#L211
The "button" property (as only seen in HTML PointerEvent
class) tells which button is changed, while the "buttons" property (as defined in HTML and Flutter) is a bitfield of which buttons are pressed after the event.
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.
Yeah, I meant buttons
(and used "are" after it) but I misspelled it 😛
That's good to know, TIL. Is it documented anywhere that buttons
specifies the buttons that are pressed after the event?
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.
Not really, and I'll add it when I got the opportunity.
) : super(callback, domRenderer, _pointerDataConverter); | ||
) : super(callback, glassPaneElement, _pointerDataConverter); | ||
|
||
final Map<int, _PointerStateManager> _pointerStates = <int, _PointerStateManager>{}; |
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.
Concern: this map will keep growing indefinitely since on touch devices, the browser gives us a new pointer id on every interaction.
return buttons & _kButtonsMask; | ||
} | ||
|
||
void handleDown({@required _PointerStateDataCallback dataCallback, @required int buttons}) { |
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.
I wish Dart had support for tuples. We would have avoided the dataCallback
and just returned a Tuple<ui.PointerChange, int>
.
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 can always create a class for that, but I think it's not as flexible as callbacks, since some handlers are stateful, and returning the list would be a little more complicated.
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.
On a second thought, I'll make it a list to address the issue mentioned in #14378 (comment)
final int len = touches.length; | ||
for (int i = 0; i < len; i++) { | ||
final html.Touch touch = touches[i]; | ||
for (html.Touch touch in event.changedTouches) { |
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.
The reason we avoided for in
here was to avoid the creation of unnecessary iterators.
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.
Are you worrying about performance? I think it's a premature optimization unless it's backed by a benchmark. In my opinion, loops in this file is of the same impact as loops in app files, so if app files do not care about the overhead of for in
, so shouldn't we.
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.
I agree it's premature optimization and it's not backed by a benchmark. This specific code path though, could be a gazillion times when the user is moving their fingers. And we know for sure that Dart generates sub-optimal JS code in some cases for for in
. That's why we avoided it here.
You can keep the for in
if you want. We are gonna have to tackle performance at some point anyway. Then, we would more concrete data to optimize against.
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.
Ok, I'll leave it to you. Thanks for explaining.
* 988b8f1 Fix FontLoader does not remove the cache in web engine (flutter/engine#14536) * 0aacac7 Roll src/third_party/skia 21df075cab00..e6a2ad81ab40 (1 commits) (flutter/engine#14552) * 417dd7e Roll fuchsia/sdk/core/mac-amd64 from esDH2... to NHgyx... (flutter/engine#14554) * f2e841d [Web] Fix pointer binding (flutter/engine#14378) * 105eb66 Roll src/third_party/skia e6a2ad81ab40..8fec4140f614 (17 commits) (flutter/engine#14557) * 1ecfdcb [web] Calculate align offset for each paragraph line (LineMetrics.left) (flutter/engine#14537) * dda3619 Roll src/third_party/dart 270966b16044..171059d27689 (19 commits) (flutter/engine#14558) * 9c1bd8a Fixes Objective-C objects memory leaks (flutter/engine#14326) * f2dbeb8 Reland Wire up Opacity on Fuchsia (flutter/engine#14559) * 2f536e5 Roll fuchsia/sdk/core/linux-amd64 from jsuQq... to VdBKA... (flutter/engine#14560) * 4312d37 Revert "[fuchsia] Add diagnostics directory to the set of remote dirs (#14470)" (flutter/engine#14566) * 5c77ea1 Roll src/third_party/skia 8fec4140f614..9e0afb791ac2 (4 commits) (flutter/engine#14563) * a09ff7c Roll src/third_party/dart 171059d27689..aa6709974dea (11 commits) (flutter/engine#14567) * 0f90e65 Revert "[web] Calculate align offset for each paragraph line (LineMetrics.left) (#14537)" (flutter/engine#14569)
Refactors pointer_binding, fixes a few issues related to the pointer data converter in Web, and adds a number of tests for all three adapters.
Overview
This PR refactors pointer_binding, fixes a few issues, and adds a number of tests for all three adapters.
Details
Rewrite adapters
A number of issues are fixed and tested in this PR, namely:
TouchAdapter
does not work with multiple pointers.TouchAdapter
norPointerAdapter
generatesremove
event for touch end, leading to memory leak.Some of the issues emerged after #14082, while some have existed since the first write.
This PR introduces the following non-trivial changes:
pointermove
, as it's only available during this event according to specs.buttons
bitfield is limited to the right-most 30 bits (_kButtonsMask
).This PR introduces the following minor improvements:
PointerAdapter
andMouseAdapter
.domRenderer
is read during its constructor.Improve tests
This PR also creates a test environment to test the 3 adapters, and added a number of tests. With the help of "test contexts", we can test all applicable adapters without duplicate code.