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]: have a way to set focus/blur state of the WebView2 without HWND c++ #4944

Open
pichillilorenzo opened this issue Nov 21, 2024 · 0 comments
Labels
feature request feature request

Comments

@pichillilorenzo
Copy link

pichillilorenzo commented Nov 21, 2024

Describe the feature/enhancement you need

Hi, I'm the author of the Flutter plugin flutter_inappwebview and, on Windows, I'm using WebView2 for the implementation.

Currently, the offscreen rendering feature still not supported (#20, #547), so the current implementation to render it inside a Flutter Texture is using the same implementation of webview_windows logic, that is: "currently relies on the Windows.Graphics.Capture API provided by Windows 10." and using the ICoreWebView2CompositionController for dispatching user input events (click, scroll, etc.).

However, as an HWND is currently required to create a WebView, there are unexpected problems about focus of the webview (check microsoft/microsoft-ui-xaml#5615, #4140, microsoft/microsoft-ui-xaml#9288).

So, a "fake" native window is created (using the CreateWindowEx API) to get a valid HWND in order to create a WebView2 instance.
However, this window is never shown, as it is always in background or hidden, so it will never really get focus.
The Flutter texture is used to render the WebView2 content instead.
On the Flutter side, I intercept user click, scroll, etc. events on the Texture and send these events on the native c++ Windows side and dispatch them using the ICoreWebView2CompositionController API, but as soon as an user clicks inside the Flutter Texture rendering the WebView2, the focus will be lost and got again instantly, causing the blur and focus events to be fired every single time, for each click.
Indeed, the blur event is caused by the user clicking on the Flutter Window (the Flutter application) as it "steals" the focus, and then the focus event is fired because the WebView2 take again the focus when using the ICoreWebView2CompositionController -> SendPointerInput/SendMouseInput APIs in order to dispatch the user input actions correctly.

So, is there a way to set a custom "focus" / "blur" state of the WebView2 instance without using the HWND??
I tried many workarounds using the native c++ Windows SetFocus, SetActiveWindows, etc. APIs but it won't really work, as to work correctly, the Flutter window must have the focus, otherwise the flutter app won't work correctly.
Another workaround could be to set the fake window as "invisible" c++ native window over the Flutter texture area but this would block all the user interactions with possible Flutter widgets (views) over the Flutter texture, so it is not a viable option.

Probably, the best would be a real offscreen rendering API, as it will solve this issue (also performance issue because the current implementation impacts user GPU usage).

The scenario/use case where you would use this feature

without this feature, texture implementation is limited and some basic functionalities will not work as expected.

How important is this request to you?

Critical. My app's basic functions wouldn't work without it.

Suggested implementation

No response

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

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

1 participant