I am using CEF with c++ visual studio 2013. I have hooked up CEF with my application successfully and can use it to load a HTML5 game that I created. It handles mouse clicks fine. I have added a key hook to my application so when I press a key it will show the dev tools dialogue on the screen for me to debug the game. It loads and shows the dev tools fine but does not accept any mouse clicks for me to navigate with. Mouse clicking works in the rest of game using SendMouseClickEvent on the browser host.
When I create and initialise CEF I store the browserSettings and WindowSettings so I can reuse them as the parameters to ShowDevTools.
To initialise cef and to show in my game window I simply do: (this is a cut down version, I've stripped out everything that is irrelevant. Please note my game has multiple screens, hence the map)
- Code: Select all
struct WindowData
{
CefRefPtr<CefBrowser> m_browser;
CefRefPtr<BrowserEventHandler> m_browserClient;
CefWindowInfo m_window_info;
CefBrowserSettings m_browserSettings;
CefRefPtr<ClientApp> m_clientApp;
};
std::map<std::string, WindowData> m_windowData;
WindowData wd ;
CefMainArgs args;
wd.m_clientApp = CefRefPtr<ClientApp>(new ClientApp);
CefExecuteProcess(args, wd.m_clientApp.get(), nullptr);
CefSettings settings;
settings.single_process = true;
CefInitialize(args, settings, wd.m_clientApp.get(), nullptr);
wd.m_browserSettings.javascript = STATE_ENABLED;
wd.m_browserSettings.caret_browsing = STATE_ENABLED;
wd.m_browserSettings.tab_to_links = STATE_ENABLED;
wd.m_browserSettings.web_security = STATE_DISABLED;
wd.m_browserSettings.universal_access_from_file_urls = STATE_ENABLED;
wd.m_browserSettings.file_access_from_file_urls = STATE_ENABLED;
std::size_t windowHandle = getWindowHandle("Screen1");
wd.m_window_info.SetAsWindowless((HWND)windowHandle, false);
wd.m_browserClient = new BrowserEventHandler();
std::string url = "http://www.google.com";
wd.m_clientApp->m_browser = CefBrowserHost::CreateBrowserSync(wd.m_window_info, wd.m_browserClient.get(), url.c_str(), wd.m_browserSettings, nullptr);
wd.m_clientApp->m_browser->GetHost()->SendFocusEvent(true);
m_windData["Screen1"] = wd;
Then inside my keyevent callback I simply do:
- Code: Select all
//show dev tools
if (keyPressed == 'a') // show dev tools
{
WindowData wd = m_windowData["Screen1"];
m_browser->GetHost()->ShowDevTools(wd.m_window_info, wd.m_browserClient.get(), wd.m_browserSettings, CefPoint());
}
This successfully shows the devtools page over the google page but it doesn't respond to mouse clicks when google did.
Just for completeness my mouse click handler looks like so:
- Code: Select all
void RenderHandler::OnClick(int x, int y, bool up)
{
CefMouseEvent me;
me.x = x;
me.y = y;
m_browser->GetHost()->SendMouseClickEvent(me, MBT_LEFT, up, 1);
}
Thanks for any help
Edit: please note, that I am rendering this inside a game engine by rendering to texture. The idea was to use the same browser object to show the dev tools inside the game window rather than having a separate pop-up to show the dev tools like cef-project. Not sure if this is what's causing it. Perhaps the mouse clicks are not getting sent to the dev tools browser like I thought due to this.