This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Web trackpad pan #36346
Merged
Merged
Web trackpad pan #36346
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f04c00
Guess at trackpad pans on web
moffatman ad18dee
Add test
moffatman 77c8347
Update comment
moffatman 34f091b
Handle macOS accelerated scroll wheel
moffatman 41a7f2e
Fix test after last commit
moffatman c5b987e
Disable on firefox
moffatman 50c21a0
Pull out _isTrackpadEvent and add doc links
moffatman 0f2400e
Fix issue with floating point / integer conversion error.
moffatman 31d04af
Workaround for magic mouse events which happen to be divisible by 120.
moffatman 85a0a58
Refactor to handle bad luck in accelerated mouse deltas.
moffatman 426cac0
Use 120 wheelDelta to identify mouse-accelerated events instead of 240
moffatman a07c922
Handle multiple bad-luck events in a row.
moffatman 48b93bd
Cleanup parameters
moffatman 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 hidden or 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 |
|---|---|---|
|
|
@@ -264,6 +264,7 @@ abstract class _BaseAdapter { | |
| final PointerDataConverter _pointerDataConverter; | ||
| final KeyboardConverter _keyboardConverter; | ||
| DomWheelEvent? _lastWheelEvent; | ||
| bool? _lastWheelEventWasTrackpad; | ||
|
|
||
| /// Each subclass is expected to override this method to attach its own event | ||
| /// listeners and convert events into pointer events. | ||
|
|
@@ -349,7 +350,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter { | |
| return (wheelDelta - (-3 * delta)).abs() > 1; | ||
| } | ||
|
|
||
| bool _isTrackpadEvent(DomWheelEvent event, DomWheelEvent? lastEvent) { | ||
| bool _isTrackpadEvent(DomWheelEvent event, DomWheelEvent? lastEvent, bool? lastEventWasTrackpad) { | ||
|
||
| // This function relies on deprecated and non-standard implementation | ||
| // details. Useful reference material can be found below. | ||
| // | ||
|
|
@@ -389,7 +390,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter { | |
| // it was preceded within 50 milliseconds by a trackpad event. This | ||
| // handles unlucky 120-delta trackpad events during rapid movement. | ||
| final num diffMs = event.timeStamp! - lastEvent!.timeStamp!; | ||
| if (diffMs < 50 && _isTrackpadEvent(lastEvent, null)) { | ||
| if (diffMs < 50 && (lastEventWasTrackpad ?? false)) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
@@ -407,7 +408,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter { | |
| const int domDeltaPage = 0x02; | ||
|
|
||
| ui.PointerDeviceKind kind = ui.PointerDeviceKind.mouse; | ||
| if (_isTrackpadEvent(event, _lastWheelEvent)) { | ||
| if (_isTrackpadEvent(event, _lastWheelEvent, _lastWheelEventWasTrackpad)) { | ||
| kind = ui.PointerDeviceKind.trackpad; | ||
| } | ||
|
|
||
|
|
@@ -454,6 +455,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter { | |
| scrollDeltaY: deltaY, | ||
| ); | ||
| _lastWheelEvent = event; | ||
| _lastWheelEventWasTrackpad = kind == ui.PointerDeviceKind.trackpad; | ||
| return data; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
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.
Nit: What do you think about making this non-nullable and initializing it to false? Currently it probably represents reality more accurately as-is, because a value of
nullmeans that there was no last wheel event. However, that null state is not used anywhere.Up to you what you think is better.
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 have it this way as in some previous iterations the null state did matter.