From bfb2efaa567e06cea5f0dec6ecae2687eb29d978 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 22 Aug 2013 17:11:50 +0000 Subject: [PATCH] Merge revision 1384 changes: - Add CefSetOSModalLoop function (issue #194). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1547@1385 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/capi/cef_app_capi.h | 6 ++++++ include/cef_app.h | 7 +++++++ libcef/browser/context.cc | 15 +++++++++++++++ libcef_dll/libcef_dll.cc | 8 ++++++++ libcef_dll/wrapper/libcef_dll_wrapper.cc | 8 ++++++++ tests/cefclient/cefclient_win.cpp | 14 ++++++++++++++ 6 files changed, 58 insertions(+) diff --git a/include/capi/cef_app_capi.h b/include/capi/cef_app_capi.h index 77b641468..832dc3cd6 100644 --- a/include/capi/cef_app_capi.h +++ b/include/capi/cef_app_capi.h @@ -100,6 +100,12 @@ CEF_EXPORT void cef_run_message_loop(); /// CEF_EXPORT void cef_quit_message_loop(); +/// +// Set to true (1) before calling Windows APIs like TrackPopupMenu that enter a +// modal message loop. Set to false (0) after exiting the modal message loop. +/// +CEF_EXPORT void cef_set_osmodal_loop(int osModalLoop); + /// // Implement this structure to provide handler implementations. Methods will be // called by the process and/or thread indicated. diff --git a/include/cef_app.h b/include/cef_app.h index 8cdae4f3f..5fd477b9a 100644 --- a/include/cef_app.h +++ b/include/cef_app.h @@ -107,6 +107,13 @@ void CefRunMessageLoop(); /*--cef()--*/ void CefQuitMessageLoop(); +/// +// Set to true before calling Windows APIs like TrackPopupMenu that enter a +// modal message loop. Set to false after exiting the modal message loop. +/// +/*--cef()--*/ +void CefSetOSModalLoop(bool osModalLoop); + /// // Implement this interface to provide handler implementations. Methods will be // called by the process and/or thread indicated. diff --git a/libcef/browser/context.cc b/libcef/browser/context.cc index 6395e4838..c9c9dd153 100644 --- a/libcef/browser/context.cc +++ b/libcef/browser/context.cc @@ -160,6 +160,21 @@ void CefQuitMessageLoop() { CefBrowserMessageLoop::current()->Quit(); } +void CefSetOSModalLoop(bool osModalLoop) { +#if defined(OS_WIN) + // Verify that the context is in a valid state. + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return; + } + + if (CEF_CURRENTLY_ON_UIT()) + MessageLoop::current()->set_os_modal_loop(osModalLoop); + else + CEF_POST_TASK(CEF_UIT, base::Bind(CefSetOSModalLoop, osModalLoop)); +#endif // defined(OS_WIN) +} + // CefContext diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index 769009a2b..c1d38b16f 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -267,6 +267,14 @@ CEF_EXPORT void cef_quit_message_loop() { CefQuitMessageLoop(); } +CEF_EXPORT void cef_set_osmodal_loop(int osModalLoop) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + CefSetOSModalLoop( + osModalLoop?true:false); +} + CEF_EXPORT int cef_get_geolocation( struct _cef_get_geolocation_callback_t* callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index 1ff8db778..372b1546a 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -259,6 +259,14 @@ CEF_GLOBAL void CefQuitMessageLoop() { cef_quit_message_loop(); } +CEF_GLOBAL void CefSetOSModalLoop(bool osModalLoop) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_set_osmodal_loop( + osModalLoop); +} + CEF_GLOBAL bool CefGetGeolocation( CefRefPtr callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 88fe55cec..6abf6e369 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -498,6 +498,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, } break; + case WM_ENTERMENULOOP: + if (!wParam) { + // Entering the menu loop for the application menu. + CefSetOSModalLoop(true); + } + break; + + case WM_EXITMENULOOP: + if (!wParam) { + // Exiting the menu loop for the application menu. + CefSetOSModalLoop(false); + } + break; + case WM_CLOSE: if (g_handler.get() && !g_handler->IsClosing()) { CefRefPtr browser = g_handler->GetBrowser();