Skip to content
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

Send PointerSignalKind.scale events from web #36348

Merged
merged 3 commits into from Mar 20, 2023

Conversation

moffatman
Copy link
Contributor

Send PointerSignalKind.scale instead of PointerSignalKind.scroll if ctrl key is pressed on wheel event.

Part of flutter/flutter#112103

Sequence

  1. ui.PointerSignalKind forwards compatibility for scale flutter#112170
  2. Add discrete scale pointer signal #36342
  3. Add PointerScaleEvent and use in InteractiveViewer flutter#112172
  4. This PR

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

I want to make sure this is customizable at the app-level if possible, otherwise looks fine to me.

CC @mdebbar Another one that could use a backup review from a web person, thank you!

scrollDeltaX: deltaX,
scrollDeltaY: deltaY,
);
if (event.ctrlKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens on Mac with ctrl and cmd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ctrlKey is just how the browser sends scroll events, for legacy reasons. It's still called ctrlKey on the mac. In my mac Chrome, neither seem to cause a zoom if i hold them and scroll.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wheel events with ctrlKey on Mac do not zoom/scale. Instead they just scroll. But with this PR, the scrolling will stop, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that ctrl (not cmd) and scroll will continue to do the same thing (scroll) after this PR, is that right @moffatman?

scrollDeltaY: deltaY,
);
if (event.ctrlKey) {
_pointerDataConverter.convert(
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could decide what combination of key + scroll does what at the framework level, in case some developers have different opinions about that. Is that something that we could make possible? I get that we need to prevent the browser from zooming in at the engine level though.

Comment on lines 362 to 370
}
else {
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 } else {.

@moffatman
Copy link
Contributor Author

To clarify, right now we are ignoring these ctrl-zoom events altogether. So this isn't causing things that would scroll before to now cause zooms.

@mdebbar
Copy link
Contributor

mdebbar commented Sep 27, 2022

@moffatman you are right that we ignore ctrl-zoom now, but that's not the case on Mac/iOS.

@moffatman
Copy link
Contributor Author

@mdebbar So on macOS, when using ctrl-scroll wheel, what's the expected behavior?

@mdebbar
Copy link
Contributor

mdebbar commented Oct 6, 2022

@moffatman I believe on macOS, it should just scroll even if ctrl is pressed.

@moffatman
Copy link
Contributor Author

@mdebbar I noticed sites which offer trackpad gestures (Ex: Figma) do not handle that properly, they will zoom-in if holding ctrl and scrolling. I guess the only option is to watch document onkey events and have a parallel tracking of the real ctrlKey. Do you think that's worth doing?

@mdebbar
Copy link
Contributor

mdebbar commented Oct 6, 2022

@moffatman I think, by default, we should do what the platform does (in this case, browsers on macOS scroll even if ctrl is pressed).

Apps can customize this behavior if they want to. I'm not sure if they can do such customization today with Flutter or not. Thoughts @justinmc ?

@justinmc
Copy link
Contributor

justinmc commented Oct 6, 2022

Right now I don't believe there's a straightforward way to override a keyboard shortcut and a mouse gesture combined.

@Renzo-Olivares would that be possible with your upcoming gesture shortcuts work?

@skia-gold
Copy link

Gold has detected about 8 new digest(s) on patchset 3.
View them at https://flutter-engine-gold.skia.org/cl/github/36348

@Piinks
Copy link
Contributor

Piinks commented Nov 22, 2022

Right now I don't believe there's a straightforward way to override a keyboard shortcut and a mouse gesture combined.

I asked @gspencergoog about this recently, I was looking into shift+scroll to flip the scroll direction. He recommended not tying it into shortcuts, but just checking the keyboard when a scroll event comes in. So I have a proposal out that would add that key modifier on the inherited ScrollBehavior. Maybe something similar would suit here for ctrl?
flutter/flutter#115610

@goderbauer
Copy link
Member

@moffatman @justinmc @mdebbar @Piinks Are there still plans for this PR? It is getting a little stale...

@moffatman
Copy link
Contributor Author

Remaining issues

  • Is there something that should be done here for future compatibility with framework-defined modifier keys
    • I'm not so sure here, it doesn't make sense as the events are different types
  • Using the mouse wheel while holding ctrl is not supposed to zoom on macOS, just scroll.
    • macOS scroll+zooms and trackpad pinches will both have event.ctrlKey, so we can't tell them apart from the event alone. Will need to add some sort of tracking of key-presses in order to tell if it's a true ctrlKey or not.

To start with, I will fix the merge conflicts at least..

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I'm on board with moving forward with this PR as-is. It seems to me like we're matching browser behavior as close as practical right now. If we do decide that we want to support scaling with other keys, we'll have to rethink our event signalKinds and maybe come up with some combined event that includes both scrolling and scaling. That's probably beyond the scope of this PR.

scrollDeltaX: deltaX,
scrollDeltaY: deltaY,
);
if (event.ctrlKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that ctrl (not cmd) and scroll will continue to do the same thing (scroll) after this PR, is that right @moffatman?

@moffatman
Copy link
Contributor Author

moffatman commented Mar 16, 2023

I still need to add some sort of tracking for the ctrl key press. Since right now it will zoom instead of scroll on macOS safari.

@moffatman
Copy link
Contributor Author

Would appreciate some review from anyone involved in web keyboard handling. I made some very lazy changes to expose what I needed to peek at the data. Maybe there is a better way?

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Other than the kPhysicalControlRight oversight, this PR looks good to me!

lib/web_ui/lib/src/engine/pointer_binding.dart Outdated Show resolved Hide resolved
@Piinks
Copy link
Contributor

Piinks commented Mar 17, 2023

Looks like there are some merge conflicts FYI

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 20, 2023
@auto-submit auto-submit bot merged commit be9b333 into flutter:main Mar 20, 2023
35 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App embedder Related to the embedder API platform-web Code specifically for the web engine
Projects
None yet
7 participants