cefsharp / CefSharp.Wpf.HwndHost

Designed as a drop in replacement for CefSharp.Wpf for those who want the native Win32 based implementation (For IME support and better performance).
Other
37 stars 11 forks source link

Focus - Notify WPF when Browser has focus #6

Open amaitland opened 4 years ago

amaitland commented 4 years ago

Directly clicking the mouse in the browser and CEF will recieve focus, we need to let WPF know that our HWND host has focus in this scenario.

We need to set the Logical focus, not the actual focus. Something like the following might work.

var focusScope = FocusManager.GetFocusScope(this);
if (FocusManager.GetFocusedElement(focusScope) != this)
{
    FocusManager.SetFocusedElement(focusScope, this);
}

https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/UIElement.cs,2647

When the browser directly gets focus IFocusHandler.OnGotFocus should be called.

Follow up to #5