简体   繁体   中英

Cefsharp with Winform: OnFocusedNodeChanged never called when the user changes the focus to another node

i'm trying to use OnFocusedNodeChanged to open the virtual keyboard when is needed with Cefsharp and Winform, but this method is never called. I'm using it wrong?

the code is:

class CMSRenderBrowser : IRenderProcessMessageHandler
{
    public void OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
    {
        var message = node == null ? "lost focus" : node.ToString();
        Console.WriteLine("OnFocusedNodeChanged() - " + message);
    }

    public void OnContextCreated(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
    {
    }

    public void OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
    {
    }


    public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
    {
    }
}

and this is the main form .cs:

public Form1()
    {
        InitializeComponent();
        ChromiumWebBrowser browser = new ChromiumWebBrowser("www.google.com");
        browser.RenderProcessMessageHandler = new CMSRenderBrowser();

        this.Controls.Add(browser);
        
    }

Because it involves sending messages from the render process to the browser process it's not enabled by default. You must enabled it by setting CefSharpSettings.FocusedNodeChangedEnabled to true before you call Cef.Initialize (If you don't call Cef.Initialize yourself then before you create the first ChromiumWebBrowser instance).

//This must be set before Cef.Initialized is called
CefSharpSettings.FocusedNodeChangedEnabled = true;

The documentation should be updated to reflect this requirement (Feel free to submit a PR to https://github.com/cefsharp/CefSharp if you have time).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM