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

[Feature]: Add WillZoomFactorChange event #4522

Open
pushkin- opened this issue May 2, 2024 · 4 comments
Open

[Feature]: Add WillZoomFactorChange event #4522

pushkin- opened this issue May 2, 2024 · 4 comments
Assignees
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@pushkin-
Copy link

pushkin- commented May 2, 2024

Describe the feature/enhancement you need

Currently, there's an ZoomFactorChanged event that fires after the zoom factor has changed.

My app wants to prevent zooming all the way in. If the window is small, we might want to stop you half way, say.

To achieve this, I was playing around with hooking into the ZoomFactorChanged event and detecting if we zoomed to far, but the problem is at that point we already finished zooming, so I need to undo the zoom which looks choppy. (in Electron, they had zoom-changed event which fires without any actual zooming happening since Electron disables zoom by default and we have to intercept and handle it programmatically)

So instead I set IsZoomControlEnabled to false and tried listening for the WebView control's MouseWheel event, but that doesn't fire due to #1040

So I'm having to use the workaround mentioned and execute JS on every navigation to intercept the wheel event and post back the response.

It would be nicer if there were an event I could hook into before the zoom actually happened where I could also cancel the zoom.

The scenario/use case where you would use this feature

see above (detect zoom but cancel it and do custom handling)

How important is this request to you?

Nice to have. There are other ways to tackle this, but having official API support would be beneficial.
Actually, very important now.

Suggested implementation

a WillZoomFactorChange type of event where I can cancel the zoom before it happens

What does your app do? Is there a pending deadline for this request?

No response

AB#54703408

@pushkin- pushkin- added the feature request feature request label May 2, 2024
@pushkin-
Copy link
Author

pushkin- commented May 3, 2024

Actually, this is more important to have than I initially thought.

In Electron, I would intercept the zoom-changed event and handle the zoom manually.

Here, if zoom is enabled for the control, the zoom happens automatically and I can't cancel it. My app puts a limit on how far you can zoom in. So if zoom happens automatically, I can't enforce the limit (or I can zoom you out after, but that looks very choppy)

So I tried intercepting the WebView2's WheelDown event but that's apparently not supported according to another issue (and I verified that the handler never fires)

So I tried injecting JS into every frame on navigationcompleted to listen JS's wheel event and post message (window.chrome.webview.postMessage) when it occurs

This sometimes works, but not for all iframes (all same origin).

No idea why. I can see that the postmessage function is defined, but after it gets called, my handler (webMessageReceived) never gets hit. No errors. No exceptions in devtools.

Same issue when using host objects via AddHostObject APIs. Sometimes it works, sometimes it doesn't.

haven't been able to repro in a minimal example though.

@victorhuangwq
Copy link
Collaborator

victorhuangwq commented May 6, 2024

Hey @pushkin- is this similar to the request that you previously asked for here? #4511

@pushkin-
Copy link
Author

@victorhuangwq they're separate issues. That one is about the existing ZoomFactorChanged event. Though I really would like zoom direction exposed in this new event as well.

@pushkin-
Copy link
Author

@victorhuangwq And one nuance in Electron is that if a page intercepts the wheel event and handles it themselves (and possibly calls e.preventDefault()), the event won't fire.

@bradp0721 bradp0721 added the tracked We are tracking this work internally. label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants