[SOLVED] Prevent activation of CEF child win at creation (26

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

[SOLVED] Prevent activation of CEF child win at creation (26

Postby romariorios » Tue Mar 29, 2016 6:25 pm

Hello.

I'm creating a CEF child window with CefWindowInfo::SetAsChild(), but the parent window keeps getting activated at the moment I create the child. CefFocusHandler::OnSetFocus() already returns false (EDIT: true, sorry), so calls to e.g. LoadURL() do not raise the window, but my problem here seems to be at the moment the window is created, that is, at the CefBrowserHost::CreateBrowser() call.

I tried modifying SetAsChild by adding the WS_EX_NOACTIVATE flag, and it seems that that makes the window not be raised from the background any longer, but then the it stops reacting to user input events (of course) and it still steals the focus.

Any ideas?

(Also, I think this problem didn't exist in CEF 2454. Did anything change?)
Last edited by romariorios on Wed Mar 30, 2016 6:49 am, edited 2 times in total.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: Prevent activation of CEF child win at creation (2623, w

Postby magreenblatt » Wed Mar 30, 2016 3:48 am

magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Prevent activation of CEF child win at creation (2623, w

Postby romariorios » Wed Mar 30, 2016 6:48 am

Indeed, removing the

Code: Select all
  params.activatable = views::Widget::InitParams::ACTIVATABLE_YES;

line solved my problem. I'd make a patch to make this configurable, but I don't have enough knowledge of CEF's internals and I don't know where to start.

Anyway, thanks.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: Prevent activation of CEF child win at creation (2623, w

Postby PetrCBR » Wed Aug 03, 2016 7:30 am

Problem with this workaround is that window can not be activated by clicking inside the window ... must be activated by click on window title.
PetrCBR
Techie
 
Posts: 41
Joined: Thu Mar 13, 2014 12:01 pm

Re: [SOLVED] Prevent activation of CEF child win at creation

Postby romariorios » Wed Jul 26, 2017 8:19 pm



Looking at the issue now, it has been marked as Framework-HasFix since April. Does it mean there's now a proper fix for that without relying on patches? If so, what is it?
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: [SOLVED] Prevent activation of CEF child win at creation

Postby magreenblatt » Wed Jul 26, 2017 8:38 pm

A PR exists for that issue but it has unresolved problems.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: [SOLVED] Prevent activation of CEF child win at creation

Postby romariorios » Sat Aug 26, 2017 12:33 am

So, I have come back to this issue, since I'm trying to remove my reliance on a patched build of CEF.

Setting the WS_EX_NOACTIVATE style works, as mentioned, but with two problems:

  1. Child window takes no input
  2. The window still steals the focus

To solve 1, simply adding an EnableWindow call in OnAfterCreated was enough. It doesn't raise the window, but it allows it to take input.

I'm still struggling to work around 2. I tried ignoring the the WM messages in both the parent and the child window, but I didn't have much luck. So far, I know that ignoring any of the following messages is ineffective:

  • In the parent:
    • WM_ACTIVATE
    • WM_NCACTIVATE
    • WM_SETFOCUS
    • WM_PARENTNOTIFY
    • (maybe others, I don't remember right now)
  • In the child:
    • WM_CHILDACTIVATE
    • WM_ACTIVATE
    • WM_SETFOCUS
    • WM_NOTIFY
    • WM_NCACTIVATE
    • WM_NCCREATE
    • WM_IME_NOTIFY
    • WM_UPDATEUISTATE
    • WM_ENABLE
    • WM_CHANGEUISTATE
    • WM_UPDATEUISTATE
    • WM_MOUSEACTIVATE

Ignoring these messages does all sorts of stuff except preventing the parent window from getting focus. Are there any other messages I should try? Any other strategy to circumvent problem 2?
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: [SOLVED] Prevent activation of CEF child win at creation

Postby ScottKevill » Sat Dec 16, 2017 11:35 am

Recently bumped into this myself, and this simple workaround seemed to do the trick for me. Hopefully it helps someone else.

(And to confirm the second post, it does affect 2526 as well.)

Create the browser wnd as disabled:
Code: Select all
info.SetAsChild(parent_wnd, wnd_rect);
info.style |= WS_DISABLED;
...
CefBrowserHost::CreateBrowser(info, client, start_url, settings, request_context);

Then enable it in CefLifeSpanHandler::OnAfterCreated():
Code: Select all
void CefClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
   CEF_REQUIRE_UI_THREAD();

   base::AutoLock      lock_scope(lock_);

   browser_ = browser;
   browser_id_ = browser->GetIdentifier();
   
   browser_wnd_ = browser->GetHost()->GetWindowHandle();
   ::EnableWindow(browser_wnd_, true);
}

This all happens before the browser does its implicit LoadURL() from CefBrowserHost::CreateBrowser()'s start_url, which calls CefBrowserHost::OnSetFocus(browser, FOCUS_SOURCE_NAVIGATION) and can be filtered as normal.
ScottKevill
Techie
 
Posts: 16
Joined: Sun Oct 14, 2012 10:34 pm

Re: [SOLVED] Prevent activation of CEF child win at creation

Postby Winexcel » Sun Apr 08, 2018 1:19 am

Are there some workarounds to keep the focus in another application? If some application is focused at the moment.
For the new CEF version
Winexcel
Newbie
 
Posts: 3
Joined: Wed Sep 14, 2016 11:39 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 51 guests