-
Notifications
You must be signed in to change notification settings - Fork 709
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
WebView2 control loses pointer capture when when moving mouse outside of the control #8677
Comments
Workaround is possible for this issue (although hacky):
private void PART_WebView_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (PART_WebView == null)
return;
var point = e.GetCurrentPoint(PART_WebView);
if (point.Properties.IsLeftButtonPressed)
{
var position = point.Position;
var message = new EditorControlMessage(EditorControlMessageKind.MouseMove, null, null, (int)position.X, (int)position.Y);
var messageJson = JsonSerializer.Serialize(message, options_);
PART_WebView.CoreWebView2.PostWebMessageAsJson(messageJson);
}
}
var lastFocus;
window.addEventListener("gotpointercapture", event => {
lastFocus = event.target;
});
window.chrome.webview.addEventListener('message', event => {
if (event.data.messageKind === 'mouseMove') {
if (lastFocus !== undefined) {
var evt = new PointerEvent("pointermove", {
clientX: event.data.x,
clientY: event.data.y,
buttons: 1,
bubbles: true,
cancelable: true
});
lastFocus.dispatchEvent(evt);
}
} Note that this hack is monaco editor specific (different components could require different js events/parameters to work), which is enough for me. |
Just to anyone curious, 1.5.4 changes:
Do not fix this issue. Mouse capture is still lost when you drag outside the WebView2 control no matter what. |
Hi everyone, Is it possible that this could get attention as it really makes scrolling a Maui Blazor website very hard for the user - especially with larger vertical content? We had a look at implementing the above workaround, but the WebView2 PointerMoved event is not called - the same goes for PointerGestureRecognizer PointerMoved. A solution would be very greatly appreciated for Maui Blazor! |
Would be a wonderful Christmas present to have this fixed 🥺🎄 I love .NET Blazor Hybrid, apart from the lack of cursor graphic support and the pointer capture issues 🥲 |
Hi @codendone - that is truly awesome - thank you!! 😁 |
Describe the bug
I'm hosting a monaco editor in WebView2 control, and I have focus issue that I think is a bug.
I've added following javascript at the startup to illustrate the issue:
As you can see in the gif, lostpointercapture event fires straight away when you move the mouse outside of WebView2.
This makes small input controls hosted using WebView practically unusable, as both scrolling and text selection break once you move at least 1 pixel outside of webview.
Steps to reproduce the bug
Expected behavior
Focus does not get lost and hosted window gets onmousemove messages correctly until user releases mouse button.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.3.2: 1.3.230602002
Windows version
Windows 11 (22H2): Build 22621
Additional context
This issue does not occur in WPF implementation of WebView2 control, so this is WinUI3 specific.
I've seen some code in backported WinUI2 code here that claims to work around this specific issue:
https://github.com/microsoft/microsoft-ui-xaml/blob/3b77866fbdb2f2eda3fc24a6c92568439b700540/dev/WebView2/WebView2.cpp#L186-L198C21
I don't think this works in WinUI3.
I would be very grateful to at least get a workaround for this issue.
The text was updated successfully, but these errors were encountered: