-
-
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
Enhancement - FocusHandler Take4 #774
Conversation
…h possible this time
I think it's worth going forward with this for starters. User can implement |
@jankurianski Will these changes impact your current |
|
||
public static void Activate(this Control control) | ||
{ | ||
//Notify WinForms world that inner browser window got focus. This will trigger Leave event to previous focused control |
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.
//Notify -> // Notify
@amaitland I think this is a good change. It's got the good default WinForms focus behaviour that @sylvain-hamel was looking for in #702. But this also retains My scenario is wanting to prevent the Chromium control from taking focus upon navigation or click. So I checked out this PR, and was able to set my own I also tried the test cases in #702 with the Not sure where the conflict is in this PR, as I was able to build OK. I think you should go ahead with the merge so we can get this good focus behaviour in |
@jankurianski Greatly appreciated! I'll merge in |
Enhancement - FocusHandler Take4
Hi @amaitland, thanks for your work on that. I'll give it a go and I let you know if I find anything.
Will you log a separate issue for this specific bug? Do you know the cause of the bug? |
Hi @amaitland, The bug does not only affect minimize/maximize. It affects any form of deactivation/activation of the application, which is very important:
The reason is that you took out the part where we used The code in
But as discovered earlier while investigating all this, Can you bring this code back? Recall that after you had discovered the name of that window, I suggested that the code could be like this: // The window that gets the focus is a child window of the browser and is called
// Chrome_RenderWidgetHostHWND, see See https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hmBh5YHjOFY
var cefWindowHandle = SomeHelper.GetSubWindowsByName(
webBrowser.Handle, "Chrome_RenderWidgetHostHWND"); instead of User32.GetSubWindows(webBrowser.Handle, childWindows);
var cefWindowHandle = childWindows.Last(); See discussion in #710 for more detail. |
@sylvain-hamel As it stands I'm not prepared to spend any more time on this. Your welcome to provide another PR with a |
It's also worth noting that I created |
So, I've done some looking into this. It seems our troubles stem from:
That is from: http://cboard.cprogramming.com/windows-programming/141510-wm_activate-woes.html
Since we seem to need the Does that about sum it up? If so, then the core problem seems to be Chromium ought to expose the current focus HWND out to CEF, for CEF to expose to us. That way regardless of whether it's the legacy That way, we might be able to sanely construct a subclassed WndProc for the owning (If we couldn't, it wouldn't be CEF's fault, it might be due to difficulty in working well within the constraints of how WinForms code is structured in this area.) Regarding, cefclient: cefclient doesn't have this problem because it doesn't implement @sylvain-hamel, @amaitland , does this make sense based on your own investigation? If it does, we should ask for my suggestion from upstream. Thoughts? |
@rassilon I think you have indeed identified the root cause. As for what the right fix is, I'm not certain. I read @amaitland 's comment in #672 ...
... and I tend to agree. If we send the request for change upsteam and if they fix it rapidly, then I'd be ok to keep this bug in CefSharp until it's fixed. But if it's going to take a while, then I'd rather have a temporary solution that is based on a undocumented thing then a bug. How long do you think it will take to get the fix? And do you feel like they are going to fix v39? Thoughts? |
After some surface examination of the underlying Chromium code, it appears that asking for a way to forward activation messages into Chromium through Cef might be the approach since hwnds are so Windows specific. I'll write up an email for Cef and Chromium development and see what they think. If upstream is willing to provide a way to do this in the future, I would tend to be less concerned about the window class name fragility. There might be a way without using the window class name with some fancy wm_syscommand sc_minimize/wm_activate juggling. I'm just not convinced that's a stable long term solution either even if it appeared to work in tabulation demo. Bill |
@rassilon Thanks! |
Okay actually there is one issue with the commit. public void SetFocus(bool isFocused)
{
if (IsBrowserInitialized && managedCefBrowserAdapter != null)
{
managedCefBrowserAdapter.SetFocus(isFocused);
}
} For some reason on some machines, this gets called during Cef.Shutdown and causes a NullReferenceException, but adding the null check fixes the issue. |
@RadicalLinux Submit a PR 👍 |
Another attempt at getting focus to work correctly - Simplest approach possible this time
Only feature that's not currently working when compared to #702 is when you minimize then maximize the window when the browser had focus, it's lost. It should be fairly noninvasive.
InvokeOnUiThreadIfRequired
intoWinForms
project