-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
WPF - Capture/Release mouse to allow scrolling outside bounds of browser control #2871
Conversation
…he right of a scroll bar #2060
✅ Build CefSharp 76.1.90-CI3247 completed (commit 6f68267aa2 by @mol) |
I'll admit a capture is likely the only way to get the usability that everyone expects. Adding a link to #1723 for future reference, if this does crash then the stack trace should be compared.
I was trying to avoid performing a capture on every down/up combination. As part of #2258 my initial attempt was c843317 That was a long time ago, the only major problem I rememeber it had was leaving would always perform a capture even if a parent control had a capture at the time, an additional not null check on Mouse.Captured should probably be enough to resolve that. The change was released as part version
With a capture in place the code should be removed.
The mouse capture was removed and replaced with directly forwarding the events from the
Sounds good to me, let me know how it goes 👍 |
Took me a while to remember the reason I actually abandoned the initial set of changes in #2258 (c843317). So this will actually reintroduce #2060 when the mouse exits the Slightly more detailed steps to reproduce than in #2060 would be:
|
You just added this for reference right? I followed the steps and it didn't reproduce the issue for me. Everything looks to be working fine. I also checked that drag/drop to and from works (in Mailbird). |
✅ Build CefSharp 76.1.90-CI3249 completed (commit 09b358d5d0 by @mol) |
Unfortunately no. I just did a clean checkout of 3566995 and can reliably reproduce the issue. |
Screen capture that demos the problem, you should be able to visually see when I have the mouse pressed, as it has a circle. After I've released the mouse the browser still thinks the mouse down as it didn't get the correct message, moving the mouse anywhere on the scroll bar triggers a scroll when no mouse is actually pressed. I tried upgrading |
What version of Windows are you running? I'm on Windows 10 (1903). |
I cannot really tell from the screen capture when you released the mouse, so it's really hard to say if you are doing anything different.
No, I did a clean checkout to confirm that it is still a problem. It's the exact reason that I reverted the previous mouse capture code last year.
I recently upgraded to I'll test again on a different machine when I can, probably in a week or so. |
I'm releasing it outside the window so definitely the same as you. Well we've released it to all of our users and so far no issues. I have a task for myself to update this pull request in a couple of weeks (earlier if I hear of any issues) so we'll see how it goes :) |
I just had Dimas from the team test it and he can reproduce it. He's using a button on a track pad, not a mouse - so if you're doing the same then I think that's why it happens to him and you and not me. |
Turns out this is related to this issue dotnet/wpf#1323 Adding the workaround mentioned in dotnet/wpf#1323 (comment) to the WPF example fixes the issue. It disables tablet support though and might not be something you want to do in CefSharp. We're already doing it in Mailbird only for the two affected versions. |
I am using a Mouse, though this machine does have a touch screen.
The stated versions of
Just as an
I don't think it's the place of a third party framework like |
I fixed this issue with capturing half year ago for my project like you (but more custom code existed). |
Thanks. What exactly did you add for the LostMouseCapture event? Do you have some code to share? How does it differ from 3566995? Also, have you tested this on a laptop with a touch screen? The issue with the mouse button not being released is only an issue on laptops with a touch screen as far as I know, and as far as I know is due to the referenced bug in WPF. |
So. Firstly, cefsharp had bug with content jumping while resizing. And i fixed it by replacing canvas to grid. I extend grid with my custom Grid class.
Now, in subclass to ChromiumWebBrowser i do following:
Tested on tablet with touch. All works fine everywhere. SendMouseClickEvent i added because i had same issue that mouse not relased. |
Thanks a lot @timaiv I'll take a look at that when I have some time. About the "jumping" issue - I think I've had users experience that. Can you tell me how to reproduce it? |
There was an issue resolved in version 75 (#2844) @timaiv If you can still reproduce this issue you were seeing then please open a new issue (it's unrelated to mouse capture).
@mol This is something we should handle, store a local variable and only release the mouse capture if it was successfully obtained. |
//We won't get here if e.g. the right mouse button is pressed and released | ||
//while the left is still held, but in that case the left mouse capture seems | ||
//to be released implicitly (even without the left mouse SendMouseClickEvent in leave below) | ||
Mouse.Capture(null); |
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.
If we switch to UIElement.ReleaseMouseCapture();
it has an additional Mouse.Captured == this
check.
https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/UIElement.cs,2514
May as well switch to UIElementCaptureMouse()
as well for consistency.
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.
You already made these changes right? It's a little unclear from the commit with the ChromiumWebBrowserWithMouseCapture but it looks like it.
How are you envisioning this drag fix will make it into the next release now that it's experimental? Should I do something? :)
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.
You already made these changes right? It's a little unclear from the commit with the ChromiumWebBrowserWithMouseCapture but it looks like it.
I did. Those changes are only in the cefsharp/75
branch at the moment. ChromiumWebBrowserWithMouseCapture
is already marked as Obsolete
.
How are you envisioning this drag fix will make it into the next release now that it's experimental?
I'm reluctant to assign a milestone
until I get a better understanding of which versions of Windows 10
the fix will be applied to. Leave this for now, will revisit once there's some clarity. Thanks 👍
Based on #2871 Use CaptureMouse/ReleaseMouseCapture instead as there's an additional check in ReleaseMouseCapture https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/UIElement.cs,d6873c5315db5dbb,references Issue #2258
Also, you need really subscribe LostMouseCapture event (and do SendMouseClickEvent in it), because you can lose capture when your button is pressed to notify browser. From my experience, wpf automatically forces to lose capture in some cases if you didnt subscribe any special capture event, i got it. But, now i cant reproduce it on win7, maybe it lie. I wrote that cefsharp had jumping issue. I wrote reason why i used grid. |
Finally! |
@timaiv You are welcome to submit a |
I added next:
and saw that some bug still exists with alt+tab (my custom scrollbar stopped jumping after mouse returning on host, that is normal, but style was like pressed). I checked that chrome, firefox scrollbars have same behavior (but it also continue jumps on hovers), other apps like VS don't do it. SendMouseClickEvent also in this case doesn't help. |
Manually merged with additional lost capture call in commit 21c89b1 |
Fixes #2870 and #2060
Summary:
I re-added and improved the previously suggested fix to the no scrolling outside browser issue, which it turns out also fixes the selection issue when dragging past the viewable area.
I know you're not super keen on Mouse.Capture, which I totally understand, but I think it's the only way to accomplish it after having read up on how it works and its implementation in the reference source.
PreviewMouseDownOutsideCapturedElement
I don't believe would accomplish anything related to this.Changes:
I re-added the
Mouse.Capture(this)
andMouse.Capture(null)
calls inOnMouseDown
andOnMouseUp
respectively, but in a way so the mouse is only captured on left mouse down (I can't think of a reason to capture the other buttons).I also removed the code in
OnMouseLeave
that was sending a mouse up event when the left mouse is pressed, as it didn't have any effect when testing with these other changes (so I assume is no longer required). But yeah it doesn't seem to do anything at all in relation with the changes though so it could also be kept.How Has This Been Tested?
Tested in Windows 10 x64. I believe I've looked through all of the issues, commits and pull requests in relation to these issues and I've tested that combo boxes still work and doesn't cause any crashes, as well as every imaginable scenario of button presses to make sure nothing has been broken as a result. I'm happy to run this out to our users and report back in a while if you'd prefer to err on the side of caution though.
Screenshots (if appropriate):
Types of changes
Checklist: