Page 1 of 1

Strange focus behavior

PostPosted: Sun Dec 15, 2013 9:14 am
by Cromon
Hello all!

In my application ive found a weird behavior with focus handling. If i create a browser and load up my site with just an input element in it i can click it and write into it using my keyboard, tho its shown as not-focused and no text-cursor is drawn. If i switch out of the window to another window and back in everything is fine, cursor shows and the input has the expected highlight. I set focus to my browser in OnAfterCreated and i even tested sendind a chain of messages like when i move to another window (WM_KILLFOCUS, and SendCaptureLost) to the browser but still i have to switch to another window first before there is real focus handling in the browser.

The browser is an off screen browser. I can provide code where neccessary but as there is already quite a lot its probably easier to just print the lines where the problem could be instead of all now.

Thanks in advance
Cromon

Re: Strange focus behavior

PostPosted: Sun Dec 15, 2013 2:38 pm
by magreenblatt
Are you calling CefBrowserHost::SetFocus()?

Re: Strange focus behavior

PostPosted: Sun Dec 15, 2013 4:04 pm
by Cromon
Yes, right now i have this code:
Code: Select all
      void CefAppClient::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
         mBrowser = browser;
         sUIMgr->setActiveBrowser(browser);
         mBrowser->GetHost()->SetFocus(true);
         mBrowser->GetHost()->SendFocusEvent(true);
      }


I tried only one of them without any change, also setting the focus to false first and then to true, sending capture lost first then focus lost, then focus set, focus lost first, capture lost second, focus got third and basically every other combination also using messages (with SendMessage), nothing changes it. The input focus goes to the input element and you can enter text, but its not drawn highlighted and no caret is drawn unless you switch to another window and then back once.

Re: Strange focus behavior

PostPosted: Sun Dec 15, 2013 4:21 pm
by magreenblatt
Cromon wrote:The input focus goes to the input element and you can enter text, but its not drawn highlighted and no caret is drawn unless you switch to another window and then back once.

How does it behave in the cefclient off-screen rendering example?

Re: Strange focus behavior

PostPosted: Sun Dec 15, 2013 4:35 pm
by Cromon
If i run the sample with off screen eanbled it works, but i cant find the difference. What else if not the SetFocus could cause the problem?

Re: Strange focus behavior

PostPosted: Sun Dec 15, 2013 5:20 pm
by magreenblatt
Off-screen rendering has no focus or activation of its own. It must all come from your application. Look closely at how cefclient handles focus/activation in comparison to your own window model.

Re: Strange focus behavior

PostPosted: Tue Jan 07, 2014 9:36 am
by wcoder
Do you solve your problem, i have exactly the same...

WCoder

Re: Strange focus behavior

PostPosted: Thu Sep 21, 2017 2:21 am
by vaibhav
Hello,
I have also same issue. We have an WPF application and in that we are using cefSharp browser(version 57). When we click on text field in browser we can type any with keyboard but text field shown not focused, no text cursor is drown.

If there is any solution for that please let me know.

Re: Strange focus behavior

PostPosted: Sat May 30, 2020 9:33 am
by douglas444
Same problem here. Im using Pandomium. If someone of you guys have found a solution, please, let me know.