From 1c2f102bb0dba69df5a21a8c8ff41da22e779fb1 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 7 Oct 2011 10:30:10 +0000 Subject: [PATCH] Add a FocusSource parameter to OnSetFocus() that indicates where the focus request is originating from (issue #369). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@306 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/cef.h | 11 ++++++----- include/cef_capi.h | 9 ++++----- include/internal/cef_types.h | 19 +++++++++++++++++++ libcef/browser_impl.cc | 3 ++- libcef/browser_impl_win.cc | 2 +- libcef/browser_webview_delegate.cc | 2 +- libcef/browser_webview_mac.mm | 4 +++- libcef_dll/cpptoc/focus_handler_cpptoc.cc | 4 ++-- libcef_dll/ctocpp/focus_handler_ctocpp.cc | 4 ++-- libcef_dll/ctocpp/focus_handler_ctocpp.h | 2 +- 10 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/cef.h b/include/cef.h index 1995287f8..f414621df 100644 --- a/include/cef.h +++ b/include/cef.h @@ -1311,6 +1311,8 @@ public: class CefFocusHandler : public virtual CefBase { public: + typedef cef_handler_focus_source_t FocusSource; + /// // Called when the browser component is about to loose focus. For instance, if // focus was on the last HTML element and the user pressed the TAB key. |next| @@ -1322,14 +1324,13 @@ public: bool next) {} /// - // Called when the browser component is requesting focus. |isWidget| will be - // true if the focus is requested for a child widget of the browser window. - // Return false to allow the focus to be set or true to cancel setting the - // focus. + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false to allow the + // focus to be set or true to cancel setting the focus. /// /*--cef()--*/ virtual bool OnSetFocus(CefRefPtr browser, - bool isWidget) { return false; } + FocusSource source) { return false; } }; diff --git a/include/cef_capi.h b/include/cef_capi.h index 48e419d6a..b4916b754 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -1131,13 +1131,12 @@ typedef struct _cef_focus_handler_t struct _cef_browser_t* browser, int next); /// - // Called when the browser component is requesting focus. |isWidget| will be - // true (1) if the focus is requested for a child widget of the browser - // window. Return false (0) to allow the focus to be set or true (1) to cancel - // setting the focus. + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false (0) to allow the + // focus to be set or true (1) to cancel setting the focus. /// int (CEF_CALLBACK *on_set_focus)(struct _cef_focus_handler_t* self, - struct _cef_browser_t* browser, int isWidget); + struct _cef_browser_t* browser, enum cef_handler_focus_source_t source); } cef_focus_handler_t; diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 2ae3b20d7..e164802e2 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -777,6 +777,25 @@ enum cef_weburlrequest_state_t WUR_STATE_ABORT = 6, }; +/// +// Focus sources. +/// +enum cef_handler_focus_source_t +{ + /// + // The source is explicit navigation via the API (LoadURL(), etc). + /// + FOCUS_SOURCE_NAVIGATION = 0, + /// + // The source is a system-generated focus event. + /// + FOCUS_SOURCE_SYSTEM, + /// + // The source is a child widget of the browser window requesting focus. + /// + FOCUS_SOURCE_WIDGET, +}; + /// // Key event types. /// diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index f264c541b..3ce9e0d66 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -971,7 +971,8 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, if (client_.get()) { CefRefPtr handler = client_->GetFocusHandler(); if (!handler.get() || - (handler.get() && !handler->OnSetFocus(this, false))) { + (handler.get() && + !handler->OnSetFocus(this, FOCUS_SOURCE_NAVIGATION))) { // Restore focus to the main frame prior to loading new request. // This makes sure that we don't have a focused iframe. Otherwise, that // iframe would keep focus when the SetFocus called immediately after diff --git a/libcef/browser_impl_win.cc b/libcef/browser_impl_win.cc index 886ed490b..658f9bc02 100644 --- a/libcef/browser_impl_win.cc +++ b/libcef/browser_impl_win.cc @@ -89,7 +89,7 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message, if (client.get()) { CefRefPtr handler = client->GetFocusHandler(); if (handler.get()) - handled = handler->OnSetFocus(browser, false); + handled = handler->OnSetFocus(browser, FOCUS_SOURCE_SYSTEM); } if (!handled) diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index d5f1c6509..f0e576c3e 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -521,7 +521,7 @@ void BrowserWebViewDelegate::didFocus() { if (client.get()) { CefRefPtr handler = client->GetFocusHandler(); if (handler.get()) - handled = handler->OnSetFocus(browser_, true); + handled = handler->OnSetFocus(browser_, FOCUS_SOURCE_WIDGET); } if (!handled) diff --git a/libcef/browser_webview_mac.mm b/libcef/browser_webview_mac.mm index a4c4c82a0..5f98b8c4e 100644 --- a/libcef/browser_webview_mac.mm +++ b/libcef/browser_webview_mac.mm @@ -158,8 +158,10 @@ CefRefPtr client = browser_->GetClient(); if (client.get()) { CefRefPtr handler = client->GetFocusHandler(); - if (handler.get() && handler->OnSetFocus(browser_, false)) + if (handler.get() && + handler->OnSetFocus(browser_, FOCUS_SOURCE_SYSTEM)) { return NO; + } } browser_->UIT_GetWebViewHost()->SetFocus(YES); diff --git a/libcef_dll/cpptoc/focus_handler_cpptoc.cc b/libcef_dll/cpptoc/focus_handler_cpptoc.cc index 1147991d3..e3c2bf32b 100644 --- a/libcef_dll/cpptoc/focus_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/focus_handler_cpptoc.cc @@ -29,7 +29,7 @@ void CEF_CALLBACK focus_handler_on_take_focus(struct _cef_focus_handler_t* self, } int CEF_CALLBACK focus_handler_on_set_focus(struct _cef_focus_handler_t* self, - cef_browser_t* browser, int isWidget) + cef_browser_t* browser, enum cef_handler_focus_source_t source) { DCHECK(self); DCHECK(browser); @@ -37,7 +37,7 @@ int CEF_CALLBACK focus_handler_on_set_focus(struct _cef_focus_handler_t* self, return 0; return CefFocusHandlerCppToC::Get(self)->OnSetFocus( - CefBrowserCToCpp::Wrap(browser), isWidget?true:false); + CefBrowserCToCpp::Wrap(browser), source); } diff --git a/libcef_dll/ctocpp/focus_handler_ctocpp.cc b/libcef_dll/ctocpp/focus_handler_ctocpp.cc index 5ea366cf6..edc70e1cb 100644 --- a/libcef_dll/ctocpp/focus_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/focus_handler_ctocpp.cc @@ -26,13 +26,13 @@ void CefFocusHandlerCToCpp::OnTakeFocus(CefRefPtr browser, } bool CefFocusHandlerCToCpp::OnSetFocus(CefRefPtr browser, - bool isWidget) + FocusSource source) { if (CEF_MEMBER_MISSING(struct_, on_set_focus)) return false; return struct_->on_set_focus(struct_, CefBrowserCppToC::Wrap(browser), - isWidget) ? true : false; + source) ? true : false; } diff --git a/libcef_dll/ctocpp/focus_handler_ctocpp.h b/libcef_dll/ctocpp/focus_handler_ctocpp.h index 7bdb1df63..ecc781ce3 100644 --- a/libcef_dll/ctocpp/focus_handler_ctocpp.h +++ b/libcef_dll/ctocpp/focus_handler_ctocpp.h @@ -35,7 +35,7 @@ public: // CefFocusHandler methods virtual void OnTakeFocus(CefRefPtr browser, bool next) OVERRIDE; virtual bool OnSetFocus(CefRefPtr browser, - bool isWidget) OVERRIDE; + FocusSource source) OVERRIDE; }; #endif // BUILDING_CEF_SHARED