diff --git a/include/capi/views/cef_view_capi.h b/include/capi/views/cef_view_capi.h index 5104cf8b3..44b594f56 100644 --- a/include/capi/views/cef_view_capi.h +++ b/include/capi/views/cef_view_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=08f13de764f30261616372dfffb7f97c57957f73$ +// $hash=4c3a47faa34c20cee64fcaa37123860319995809$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_VIEW_CAPI_H_ @@ -332,8 +332,17 @@ typedef struct _cef_view_t { int(CEF_CALLBACK* is_accessibility_focusable)(struct _cef_view_t* self); /// - /// Request keyboard focus. If this View is focusable it will become the - /// focused View. + /// Returns true (1) if this View has focus in the context of the containing + /// Window. Check both this function and cef_window_t::IsActive to determine + /// global keyboard focus. + /// + int(CEF_CALLBACK* has_focus)(struct _cef_view_t* self); + + /// + /// Request focus for this View in the context of the containing Window. If + /// this View is focusable it will become the focused View. Any focus changes + /// while a Window is not active may be applied after that Window next becomes + /// active. /// void(CEF_CALLBACK* request_focus)(struct _cef_view_t* self); diff --git a/include/capi/views/cef_window_capi.h b/include/capi/views/cef_window_capi.h index 862a56dca..210379d86 100644 --- a/include/capi/views/cef_window_capi.h +++ b/include/capi/views/cef_window_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=dd32b58ec9aca0e04a1d30ccf94a741995fcc094$ +// $hash=9de8ff77a40adc1e3edd7e2648f6c395c21a36bd$ // #ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_WINDOW_CAPI_H_ @@ -52,6 +52,7 @@ extern "C" { #endif struct _cef_browser_view_t; +struct _cef_view_t; /// /// A Window is a top-level Window/widget in the Views hierarchy. By default it @@ -177,6 +178,15 @@ typedef struct _cef_window_t { /// int(CEF_CALLBACK* is_fullscreen)(struct _cef_window_t* self); + /// + /// Returns the View that currently has focus in this Window, or nullptr if no + /// View currently has focus. A Window may have a focused View even if it is + /// not currently active. Any focus changes while a Window is not active may + /// be applied after that Window next becomes active. + /// + struct _cef_view_t*(CEF_CALLBACK* get_focused_view)( + struct _cef_window_t* self); + /// /// Set the Window title. /// diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 7400e0aff..6962b8203 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "548bb305d04b05c0ef29eb2eed88c400e7905ab1" +#define CEF_API_HASH_UNIVERSAL "38565e673fbcfcd9e4494914bcea03609b41ec30" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "b73640088f5d35912fcba870607031d8d0a0c33e" +#define CEF_API_HASH_PLATFORM "df2092177211214092ab77559596adbc37edf68d" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "01224eb3f2e4bfa18defb3e6d40c93f65231b189" +#define CEF_API_HASH_PLATFORM "aaa5bde96ceffff3de2c6fab11142c9264f44a39" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "46107dd79de8c5aab11757980c8951979cc7c266" +#define CEF_API_HASH_PLATFORM "40de77e9ae3e071eda1f3bed7e900aedcdb354e5" #endif #ifdef __cplusplus diff --git a/include/views/cef_view.h b/include/views/cef_view.h index 4795da860..bf1baa723 100644 --- a/include/views/cef_view.h +++ b/include/views/cef_view.h @@ -350,8 +350,18 @@ class CefView : public CefBaseRefCounted { virtual bool IsAccessibilityFocusable() = 0; /// - /// Request keyboard focus. If this View is focusable it will become the - /// focused View. + /// Returns true if this View has focus in the context of the containing + /// Window. Check both this method and CefWindow::IsActive to determine global + /// keyboard focus. + /// + /*--cef()--*/ + virtual bool HasFocus() = 0; + + /// + /// Request focus for this View in the context of the containing Window. If + /// this View is focusable it will become the focused View. Any focus changes + /// while a Window is not active may be applied after that Window next becomes + /// active. /// /*--cef()--*/ virtual void RequestFocus() = 0; diff --git a/include/views/cef_window.h b/include/views/cef_window.h index 83481f19b..06221be3b 100644 --- a/include/views/cef_window.h +++ b/include/views/cef_window.h @@ -46,6 +46,7 @@ #include "include/views/cef_window_delegate.h" class CefBrowserView; +class CefView; /// /// A Window is a top-level Window/widget in the Views hierarchy. By default it @@ -190,6 +191,15 @@ class CefWindow : public CefPanel { /*--cef()--*/ virtual bool IsFullscreen() = 0; + /// + /// Returns the View that currently has focus in this Window, or nullptr if no + /// View currently has focus. A Window may have a focused View even if it is + /// not currently active. Any focus changes while a Window is not active may + /// be applied after that Window next becomes active. + /// + /*--cef()--*/ + virtual CefRefPtr GetFocusedView() = 0; + /// /// Set the Window title. /// diff --git a/libcef/browser/chrome/chrome_browser_host_impl.cc b/libcef/browser/chrome/chrome_browser_host_impl.cc index c3bd9766b..c85549675 100644 --- a/libcef/browser/chrome/chrome_browser_host_impl.cc +++ b/libcef/browser/chrome/chrome_browser_host_impl.cc @@ -28,7 +28,8 @@ CefRefPtr ChromeBrowserHostImpl::Create( auto browser = CreateBrowser(params, std::nullopt); GURL url = url_util::MakeGURL(params.url, /*fixup=*/true); - if (url.is_empty()) { + const bool url_is_empty = url.is_empty(); + if (url_is_empty) { // Chrome will navigate to kChromeUINewTabURL by default. We want to keep // the current CEF behavior of not navigating at all. Use a special URL that // will be recognized in HandleNonNavigationAboutURL. @@ -50,6 +51,11 @@ CefRefPtr ChromeBrowserHostImpl::Create( ChromeBrowserHostImpl::GetBrowserForContents(web_contents); CHECK(browser_host); + if (!url_is_empty) { + // Match Alloy-style behavior of requesting focus after initial navigation. + browser_host->OnSetFocus(FOCUS_SOURCE_NAVIGATION); + } + return browser_host; } diff --git a/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.cc b/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.cc index 5696b9ba4..c1d635301 100644 --- a/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.cc +++ b/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.cc @@ -120,6 +120,12 @@ CefBrowserPlatformDelegateChromeViews::GetBrowserView() const { return browser_view_.get(); } +void CefBrowserPlatformDelegateChromeViews::SetFocus(bool setFocus) { + if (setFocus && browser_view_) { + browser_view_->RequestFocusSync(); + } +} + bool CefBrowserPlatformDelegateChromeViews::IsViewsHosted() const { return true; } diff --git a/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h b/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h index efadab2d8..ed456ac49 100644 --- a/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h +++ b/libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h @@ -32,6 +32,7 @@ class CefBrowserPlatformDelegateChromeViews views::Widget* GetWindowWidget() const override; CefRefPtr GetBrowserView() const override; void SetBrowserView(CefRefPtr browser_view) override; + void SetFocus(bool setFocus) override; bool IsViewsHosted() const override; CefBrowserViewImpl* browser_view() const { return browser_view_.get(); } diff --git a/libcef/browser/views/browser_platform_delegate_views.cc b/libcef/browser/views/browser_platform_delegate_views.cc index 2597945f6..af06b5c5f 100644 --- a/libcef/browser/views/browser_platform_delegate_views.cc +++ b/libcef/browser/views/browser_platform_delegate_views.cc @@ -154,15 +154,8 @@ void CefBrowserPlatformDelegateViews::SendTouchEvent( } void CefBrowserPlatformDelegateViews::SetFocus(bool setFocus) { - // Will activate the Widget and result in a call to WebContents::Focus(). - if (setFocus && browser_view_->root_view()) { - if (auto widget = GetWindowWidget()) { - // Don't activate a minimized Widget, or it will be shown. - if (widget->IsMinimized()) { - return; - } - } - browser_view_->root_view()->RequestFocus(); + if (setFocus && browser_view_) { + browser_view_->RequestFocusSync(); } } diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index 73e6f7fac..0e39a4f84 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -198,6 +198,20 @@ void CefBrowserViewImpl::BrowserDestroyed(CefBrowserHostBase* browser) { DCHECK(!cef_widget_); } +void CefBrowserViewImpl::RequestFocusSync() { + // With Chrome style the root_view() type (ChromeBrowserView) does not accept + // focus, so always give focus to the WebView directly. + if (web_view()) { + if (auto widget = web_view()->GetWidget(); widget->IsMinimized()) { + // Don't activate a minimized Widget, or it will be shown. + return; + } + + // Activate the Widget and indirectly call WebContents::Focus(). + web_view()->RequestFocus(); + } +} + bool CefBrowserViewImpl::HandleKeyboardEvent( const input::NativeWebKeyboardEvent& event) { if (!root_view()) { @@ -256,9 +270,8 @@ cef_runtime_style_t CefBrowserViewImpl::GetRuntimeStyle() { void CefBrowserViewImpl::RequestFocus() { CEF_REQUIRE_VALID_RETURN_VOID(); // Always execute asynchronously to work around issue #3040. - CEF_POST_TASK(CEF_UIT, - base::BindOnce(&CefBrowserViewImpl::RequestFocusInternal, - weak_ptr_factory_.GetWeakPtr())); + CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserViewImpl::RequestFocusSync, + weak_ptr_factory_.GetWeakPtr())); } void CefBrowserViewImpl::SetBackgroundColor(cef_color_t color) { @@ -481,10 +494,6 @@ bool CefBrowserViewImpl::HandleAccelerator( return false; } -void CefBrowserViewImpl::RequestFocusInternal() { - ParentClass::RequestFocus(); -} - void CefBrowserViewImpl::DisassociateFromWidget() { if (!cef_widget_) { return; diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index 3dc890c13..f21a3aae7 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -62,6 +62,7 @@ class CefBrowserViewImpl void BrowserCreated(CefBrowserHostBase* browser, base::RepeatingClosure on_bounds_changed); void BrowserDestroyed(CefBrowserHostBase* browser); + void RequestFocusSync(); // Called to handle accelerators when the event is unhandled by the web // content and the browser client. @@ -91,6 +92,7 @@ class CefBrowserViewImpl // Return the WebView representation of this object. views::WebView* web_view() const; + views::View* content_view() const override { return web_view(); } // Return the CEF specialization of BrowserView. ChromeBrowserView* chrome_browser_view() const; @@ -133,8 +135,6 @@ class CefBrowserViewImpl bool HandleAccelerator(const input::NativeWebKeyboardEvent& event, views::FocusManager* focus_manager); - void RequestFocusInternal(); - void DisassociateFromWidget(); // True if the browser is Alloy style, otherwise Chrome style. diff --git a/libcef/browser/views/view_impl.h b/libcef/browser/views/view_impl.h index 5deb1d741..9f9dce26a 100644 --- a/libcef/browser/views/view_impl.h +++ b/libcef/browser/views/view_impl.h @@ -401,6 +401,7 @@ CEF_VIEW_IMPL_T class CefViewImpl : public CefViewAdapter, public CefViewClass { void SetFocusable(bool focusable) override; bool IsFocusable() override; bool IsAccessibilityFocusable() override; + bool HasFocus() override; void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; cef_color_t GetBackgroundColor() override; @@ -656,23 +657,29 @@ CEF_VIEW_IMPL_T bool CEF_VIEW_IMPL_D::IsEnabled() { CEF_VIEW_IMPL_T void CEF_VIEW_IMPL_D::SetFocusable(bool focusable) { CEF_REQUIRE_VALID_RETURN_VOID(); - root_view()->SetFocusBehavior(focusable ? views::View::FocusBehavior::ALWAYS - : views::View::FocusBehavior::NEVER); + content_view()->SetFocusBehavior(focusable + ? views::View::FocusBehavior::ALWAYS + : views::View::FocusBehavior::NEVER); } CEF_VIEW_IMPL_T bool CEF_VIEW_IMPL_D::IsFocusable() { CEF_REQUIRE_VALID_RETURN(false); - return root_view()->IsFocusable(); + return content_view()->IsFocusable(); } CEF_VIEW_IMPL_T bool CEF_VIEW_IMPL_D::IsAccessibilityFocusable() { CEF_REQUIRE_VALID_RETURN(false); - return root_view()->GetViewAccessibility().IsAccessibilityFocusable(); + return content_view()->GetViewAccessibility().IsAccessibilityFocusable(); +} + +CEF_VIEW_IMPL_T bool CEF_VIEW_IMPL_D::HasFocus() { + CEF_REQUIRE_VALID_RETURN(false); + return content_view()->HasFocus(); } CEF_VIEW_IMPL_T void CEF_VIEW_IMPL_D::RequestFocus() { CEF_REQUIRE_VALID_RETURN_VOID(); - root_view()->RequestFocus(); + content_view()->RequestFocus(); } CEF_VIEW_IMPL_T void CEF_VIEW_IMPL_D::SetBackgroundColor(cef_color_t color) { diff --git a/libcef/browser/views/window_impl.cc b/libcef/browser/views/window_impl.cc index a63b9bf6d..40e236030 100644 --- a/libcef/browser/views/window_impl.cc +++ b/libcef/browser/views/window_impl.cc @@ -298,6 +298,16 @@ bool CefWindowImpl::IsFullscreen() { return false; } +CefRefPtr CefWindowImpl::GetFocusedView() { + CEF_REQUIRE_VALID_RETURN(nullptr); + if (widget_ && widget_->GetFocusManager()) { + if (auto* focused_view = widget_->GetFocusManager()->GetFocusedView()) { + return view_util::GetFor(focused_view, /*find_known_parent=*/true); + } + } + return nullptr; +} + void CefWindowImpl::SetTitle(const CefString& title) { CEF_REQUIRE_VALID_RETURN_VOID(); if (root_view()) { diff --git a/libcef/browser/views/window_impl.h b/libcef/browser/views/window_impl.h index 9944cb381..36ec4fd8a 100644 --- a/libcef/browser/views/window_impl.h +++ b/libcef/browser/views/window_impl.h @@ -58,6 +58,7 @@ class CefWindowImpl bool IsMaximized() override; bool IsMinimized() override; bool IsFullscreen() override; + CefRefPtr GetFocusedView() override; void SetTitle(const CefString& title) override; CefString GetTitle() override; void SetWindowIcon(CefRefPtr image) override; diff --git a/libcef_dll/cpptoc/views/browser_view_cpptoc.cc b/libcef_dll/cpptoc/views/browser_view_cpptoc.cc index 33e7b36a3..e5ef77785 100644 --- a/libcef_dll/cpptoc/views/browser_view_cpptoc.cc +++ b/libcef_dll/cpptoc/views/browser_view_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=34539b590718fa83d794a6cfcb34876da8a03d26$ +// $hash=f6c0c1dc3de70dab819ba42db591025c48667379$ // #include "libcef_dll/cpptoc/views/browser_view_cpptoc.h" @@ -964,6 +964,25 @@ browser_view_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK browser_view_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefBrowserViewCppToC::Get(reinterpret_cast(self)) + ->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK browser_view_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1299,6 +1318,7 @@ CefBrowserViewCppToC::CefBrowserViewCppToC() { GetStruct()->base.is_focusable = browser_view_is_focusable; GetStruct()->base.is_accessibility_focusable = browser_view_is_accessibility_focusable; + GetStruct()->base.has_focus = browser_view_has_focus; GetStruct()->base.request_focus = browser_view_request_focus; GetStruct()->base.set_background_color = browser_view_set_background_color; GetStruct()->base.get_background_color = browser_view_get_background_color; diff --git a/libcef_dll/cpptoc/views/button_cpptoc.cc b/libcef_dll/cpptoc/views/button_cpptoc.cc index 913cc5840..e5c5e92a8 100644 --- a/libcef_dll/cpptoc/views/button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/button_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=4e2f75d68d804ad2414eb34b9f273b8f558c3dab$ +// $hash=2dc1cc5c216bf39628e9e67dad6432705c1b5123$ // #include "libcef_dll/cpptoc/views/button_cpptoc.h" @@ -902,6 +902,24 @@ int CEF_CALLBACK button_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK button_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefButtonCppToC::Get(reinterpret_cast(self))->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK button_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1230,6 +1248,7 @@ CefButtonCppToC::CefButtonCppToC() { GetStruct()->base.is_focusable = button_is_focusable; GetStruct()->base.is_accessibility_focusable = button_is_accessibility_focusable; + GetStruct()->base.has_focus = button_has_focus; GetStruct()->base.request_focus = button_request_focus; GetStruct()->base.set_background_color = button_set_background_color; GetStruct()->base.get_background_color = button_get_background_color; diff --git a/libcef_dll/cpptoc/views/label_button_cpptoc.cc b/libcef_dll/cpptoc/views/label_button_cpptoc.cc index a2e0b17e4..81f4304c8 100644 --- a/libcef_dll/cpptoc/views/label_button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/label_button_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=51a06f8ad654129497df44179105e8523e1234af$ +// $hash=a1d17102b2aa9df60fa0296cafe9f43d879e20ea$ // #include "libcef_dll/cpptoc/views/label_button_cpptoc.h" @@ -1178,6 +1178,25 @@ label_button_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK label_button_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefLabelButtonCppToC::Get(reinterpret_cast(self)) + ->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK label_button_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1528,6 +1547,7 @@ CefLabelButtonCppToC::CefLabelButtonCppToC() { GetStruct()->base.base.is_focusable = label_button_is_focusable; GetStruct()->base.base.is_accessibility_focusable = label_button_is_accessibility_focusable; + GetStruct()->base.base.has_focus = label_button_has_focus; GetStruct()->base.base.request_focus = label_button_request_focus; GetStruct()->base.base.set_background_color = label_button_set_background_color; diff --git a/libcef_dll/cpptoc/views/menu_button_cpptoc.cc b/libcef_dll/cpptoc/views/menu_button_cpptoc.cc index 9567e63b6..db039744d 100644 --- a/libcef_dll/cpptoc/views/menu_button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/menu_button_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=02040c0851514ead9307d3901c117d94d4fffb41$ +// $hash=d6f8f7a25fae4188fcced83882c2ec51f134e312$ // #include "libcef_dll/cpptoc/views/menu_button_cpptoc.h" @@ -1231,6 +1231,25 @@ menu_button_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK menu_button_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefMenuButtonCppToC::Get(reinterpret_cast(self)) + ->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK menu_button_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1585,6 +1604,7 @@ CefMenuButtonCppToC::CefMenuButtonCppToC() { GetStruct()->base.base.base.is_focusable = menu_button_is_focusable; GetStruct()->base.base.base.is_accessibility_focusable = menu_button_is_accessibility_focusable; + GetStruct()->base.base.base.has_focus = menu_button_has_focus; GetStruct()->base.base.base.request_focus = menu_button_request_focus; GetStruct()->base.base.base.set_background_color = menu_button_set_background_color; diff --git a/libcef_dll/cpptoc/views/panel_cpptoc.cc b/libcef_dll/cpptoc/views/panel_cpptoc.cc index 7eafceef7..b0d597551 100644 --- a/libcef_dll/cpptoc/views/panel_cpptoc.cc +++ b/libcef_dll/cpptoc/views/panel_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=4c768c4065540d40bfcc8da63dfa1916ca09f6f7$ +// $hash=3ec9c298cd10893df63c6f7fd360968a5560a48c$ // #include "libcef_dll/cpptoc/views/panel_cpptoc.h" @@ -1040,6 +1040,24 @@ int CEF_CALLBACK panel_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK panel_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefPanelCppToC::Get(reinterpret_cast(self))->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK panel_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1374,6 +1392,7 @@ CefPanelCppToC::CefPanelCppToC() { GetStruct()->base.is_focusable = panel_is_focusable; GetStruct()->base.is_accessibility_focusable = panel_is_accessibility_focusable; + GetStruct()->base.has_focus = panel_has_focus; GetStruct()->base.request_focus = panel_request_focus; GetStruct()->base.set_background_color = panel_set_background_color; GetStruct()->base.get_background_color = panel_get_background_color; diff --git a/libcef_dll/cpptoc/views/scroll_view_cpptoc.cc b/libcef_dll/cpptoc/views/scroll_view_cpptoc.cc index e6a40b855..d4a94f89a 100644 --- a/libcef_dll/cpptoc/views/scroll_view_cpptoc.cc +++ b/libcef_dll/cpptoc/views/scroll_view_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=9c4a2548745464359046f080fa2a07d1438c208b$ +// $hash=1a624e78c1f34412717a3bf45bacc306fbde2b9c$ // #include "libcef_dll/cpptoc/views/scroll_view_cpptoc.h" @@ -967,6 +967,25 @@ scroll_view_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK scroll_view_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefScrollViewCppToC::Get(reinterpret_cast(self)) + ->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK scroll_view_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1304,6 +1323,7 @@ CefScrollViewCppToC::CefScrollViewCppToC() { GetStruct()->base.is_focusable = scroll_view_is_focusable; GetStruct()->base.is_accessibility_focusable = scroll_view_is_accessibility_focusable; + GetStruct()->base.has_focus = scroll_view_has_focus; GetStruct()->base.request_focus = scroll_view_request_focus; GetStruct()->base.set_background_color = scroll_view_set_background_color; GetStruct()->base.get_background_color = scroll_view_get_background_color; diff --git a/libcef_dll/cpptoc/views/textfield_cpptoc.cc b/libcef_dll/cpptoc/views/textfield_cpptoc.cc index 85cb9126c..7c6c48eb7 100644 --- a/libcef_dll/cpptoc/views/textfield_cpptoc.cc +++ b/libcef_dll/cpptoc/views/textfield_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=5407c7f442b7787de087a85d5613fffb384288c8$ +// $hash=09a4dcefc71b4554d12a950d4c8879c0e2fd2521$ // #include "libcef_dll/cpptoc/views/textfield_cpptoc.h" @@ -1397,6 +1397,25 @@ textfield_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK textfield_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefTextfieldCppToC::Get(reinterpret_cast(self)) + ->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK textfield_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1759,6 +1778,7 @@ CefTextfieldCppToC::CefTextfieldCppToC() { GetStruct()->base.is_focusable = textfield_is_focusable; GetStruct()->base.is_accessibility_focusable = textfield_is_accessibility_focusable; + GetStruct()->base.has_focus = textfield_has_focus; GetStruct()->base.request_focus = textfield_request_focus; GetStruct()->base.set_background_color = textfield_set_background_color; GetStruct()->base.get_background_color = textfield_get_background_color; diff --git a/libcef_dll/cpptoc/views/view_cpptoc.cc b/libcef_dll/cpptoc/views/view_cpptoc.cc index 26372bf1d..47a200c71 100644 --- a/libcef_dll/cpptoc/views/view_cpptoc.cc +++ b/libcef_dll/cpptoc/views/view_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=ae22b240b761b1bd2e9f168de2859ae0085191f6$ +// $hash=489b647764397f8cfba17ea7bccdd1153f0cc1a5$ // #include "libcef_dll/cpptoc/views/view_cpptoc.h" @@ -743,6 +743,23 @@ int CEF_CALLBACK view_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK view_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = CefViewCppToC::Get(self)->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK view_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -1053,6 +1070,7 @@ CefViewCppToC::CefViewCppToC() { GetStruct()->set_focusable = view_set_focusable; GetStruct()->is_focusable = view_is_focusable; GetStruct()->is_accessibility_focusable = view_is_accessibility_focusable; + GetStruct()->has_focus = view_has_focus; GetStruct()->request_focus = view_request_focus; GetStruct()->set_background_color = view_set_background_color; GetStruct()->get_background_color = view_get_background_color; diff --git a/libcef_dll/cpptoc/views/window_cpptoc.cc b/libcef_dll/cpptoc/views/window_cpptoc.cc index fe8211718..dbbd9c4d2 100644 --- a/libcef_dll/cpptoc/views/window_cpptoc.cc +++ b/libcef_dll/cpptoc/views/window_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=e0e9fa1a9ab6826b9dda799e4a1fc3b8c133eeab$ +// $hash=374db873cd7af7312f9dd7c2bc6440e0f6f8cc02$ // #include "libcef_dll/cpptoc/views/window_cpptoc.h" @@ -356,6 +356,23 @@ int CEF_CALLBACK window_is_fullscreen(struct _cef_window_t* self) { return _retval; } +cef_view_t* CEF_CALLBACK window_get_focused_view(struct _cef_window_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return NULL; + } + + // Execute + CefRefPtr _retval = CefWindowCppToC::Get(self)->GetFocusedView(); + + // Return type: refptr_same + return CefViewCppToC::Wrap(_retval); +} + void CEF_CALLBACK window_set_title(struct _cef_window_t* self, const cef_string_t* title) { shutdown_checker::AssertNotShutdown(); @@ -1784,6 +1801,24 @@ int CEF_CALLBACK window_is_accessibility_focusable(struct _cef_view_t* self) { return _retval; } +int CEF_CALLBACK window_has_focus(struct _cef_view_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefWindowCppToC::Get(reinterpret_cast(self))->HasFocus(); + + // Return type: bool + return _retval; +} + void CEF_CALLBACK window_request_focus(struct _cef_view_t* self) { shutdown_checker::AssertNotShutdown(); @@ -2084,6 +2119,7 @@ CefWindowCppToC::CefWindowCppToC() { GetStruct()->is_maximized = window_is_maximized; GetStruct()->is_minimized = window_is_minimized; GetStruct()->is_fullscreen = window_is_fullscreen; + GetStruct()->get_focused_view = window_get_focused_view; GetStruct()->set_title = window_set_title; GetStruct()->get_title = window_get_title; GetStruct()->set_window_icon = window_set_window_icon; @@ -2161,6 +2197,7 @@ CefWindowCppToC::CefWindowCppToC() { GetStruct()->base.base.is_focusable = window_is_focusable; GetStruct()->base.base.is_accessibility_focusable = window_is_accessibility_focusable; + GetStruct()->base.base.has_focus = window_has_focus; GetStruct()->base.base.request_focus = window_request_focus; GetStruct()->base.base.set_background_color = window_set_background_color; GetStruct()->base.base.get_background_color = window_get_background_color; diff --git a/libcef_dll/cpptoc/views/window_cpptoc.h b/libcef_dll/cpptoc/views/window_cpptoc.h index 8a2065537..597d53c39 100644 --- a/libcef_dll/cpptoc/views/window_cpptoc.h +++ b/libcef_dll/cpptoc/views/window_cpptoc.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=b1cca0d792a8c1aa71ec2aeda294b380b82e48fd$ +// $hash=519bc28c076065156644994840f486d3390ccd3e$ // #ifndef CEF_LIBCEF_DLL_CPPTOC_VIEWS_WINDOW_CPPTOC_H_ @@ -21,8 +21,10 @@ #endif #include "include/capi/views/cef_browser_view_capi.h" +#include "include/capi/views/cef_view_capi.h" #include "include/capi/views/cef_window_capi.h" #include "include/views/cef_browser_view.h" +#include "include/views/cef_view.h" #include "include/views/cef_window.h" #include "libcef_dll/cpptoc/cpptoc_ref_counted.h" diff --git a/libcef_dll/ctocpp/views/browser_view_ctocpp.cc b/libcef_dll/ctocpp/views/browser_view_ctocpp.cc index e5cc33e51..3a33c1795 100644 --- a/libcef_dll/ctocpp/views/browser_view_ctocpp.cc +++ b/libcef_dll/ctocpp/views/browser_view_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=88f55766622ea99679e1b4c2748103d397e32117$ +// $hash=2ce9337436d62fd27d9ae7830811f3edeae693c2$ // #include "libcef_dll/ctocpp/views/browser_view_ctocpp.h" @@ -836,6 +836,23 @@ NO_SANITIZE("cfi-icall") bool CefBrowserViewCToCpp::IsAccessibilityFocusable() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") bool CefBrowserViewCToCpp::HasFocus() { + shutdown_checker::AssertNotShutdown(); + + cef_view_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefBrowserViewCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/browser_view_ctocpp.h b/libcef_dll/ctocpp/views/browser_view_ctocpp.h index ef41e933b..8b5b31752 100644 --- a/libcef_dll/ctocpp/views/browser_view_ctocpp.h +++ b/libcef_dll/ctocpp/views/browser_view_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=a61b633e9b8e4156fd4cdcb778ad54e38106dc0d$ +// $hash=ef7142f37fb7b2312373a6cf1c4df49f6a171623$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_BROWSER_VIEW_CTOCPP_H_ @@ -81,6 +81,7 @@ class CefBrowserViewCToCpp : public CefCToCppRefCounted(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefButtonCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/button_ctocpp.h b/libcef_dll/ctocpp/views/button_ctocpp.h index b2b6dd4be..0c769cea0 100644 --- a/libcef_dll/ctocpp/views/button_ctocpp.h +++ b/libcef_dll/ctocpp/views/button_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=c8c1e03aa10a0ea469774ccd59640fcec2487513$ +// $hash=fabfb73c073981506fb91b409bf85db47176f347$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_BUTTON_CTOCPP_H_ @@ -84,6 +84,7 @@ class CefButtonCToCpp void SetFocusable(bool focusable) override; bool IsFocusable() override; bool IsAccessibilityFocusable() override; + bool HasFocus() override; void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; cef_color_t GetBackgroundColor() override; diff --git a/libcef_dll/ctocpp/views/label_button_ctocpp.cc b/libcef_dll/ctocpp/views/label_button_ctocpp.cc index 9502ed3f5..5e1995e2d 100644 --- a/libcef_dll/ctocpp/views/label_button_ctocpp.cc +++ b/libcef_dll/ctocpp/views/label_button_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=771ab2674e580450d8a0478435305bccc2440cae$ +// $hash=abd223cdf6d809bf1a7e2ed11b36f5427ea892a9$ // #include "libcef_dll/ctocpp/views/label_button_ctocpp.h" @@ -1043,6 +1043,23 @@ NO_SANITIZE("cfi-icall") bool CefLabelButtonCToCpp::IsAccessibilityFocusable() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") bool CefLabelButtonCToCpp::HasFocus() { + shutdown_checker::AssertNotShutdown(); + + cef_view_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefLabelButtonCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/label_button_ctocpp.h b/libcef_dll/ctocpp/views/label_button_ctocpp.h index 67f3f36a2..696e43291 100644 --- a/libcef_dll/ctocpp/views/label_button_ctocpp.h +++ b/libcef_dll/ctocpp/views/label_button_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=3ba705772b9bd57b5abac5f7128bc5afe148c83a$ +// $hash=c1f0efa7f36eff25faec6ababe5872a30d31e0f8$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_LABEL_BUTTON_CTOCPP_H_ @@ -99,6 +99,7 @@ class CefLabelButtonCToCpp : public CefCToCppRefCounted(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefMenuButtonCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/menu_button_ctocpp.h b/libcef_dll/ctocpp/views/menu_button_ctocpp.h index 04434ee3e..d27dc7775 100644 --- a/libcef_dll/ctocpp/views/menu_button_ctocpp.h +++ b/libcef_dll/ctocpp/views/menu_button_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=fbe53f51eb991aeebc5d66da40a894880374e248$ +// $hash=544585f39ed5faa5230674c6a6d636cd12ba344e$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_MENU_BUTTON_CTOCPP_H_ @@ -103,6 +103,7 @@ class CefMenuButtonCToCpp : public CefCToCppRefCounted(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefPanelCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/panel_ctocpp.h b/libcef_dll/ctocpp/views/panel_ctocpp.h index 1a2f68c24..310f144c5 100644 --- a/libcef_dll/ctocpp/views/panel_ctocpp.h +++ b/libcef_dll/ctocpp/views/panel_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=3ab4fe06360d8ad1837683efb6ae5229b4c01f91$ +// $hash=5bd226a43d338c78c1bf8698b6160dad88794591$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_PANEL_CTOCPP_H_ @@ -97,6 +97,7 @@ class CefPanelCToCpp void SetFocusable(bool focusable) override; bool IsFocusable() override; bool IsAccessibilityFocusable() override; + bool HasFocus() override; void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; cef_color_t GetBackgroundColor() override; diff --git a/libcef_dll/ctocpp/views/scroll_view_ctocpp.cc b/libcef_dll/ctocpp/views/scroll_view_ctocpp.cc index 25a85da18..30905786f 100644 --- a/libcef_dll/ctocpp/views/scroll_view_ctocpp.cc +++ b/libcef_dll/ctocpp/views/scroll_view_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=f74bed30da72caaf40fb59b2e34b1c99aa647105$ +// $hash=037b63e599b503cbc2800814057d8f866473f998$ // #include "libcef_dll/ctocpp/views/scroll_view_ctocpp.h" @@ -856,6 +856,23 @@ NO_SANITIZE("cfi-icall") bool CefScrollViewCToCpp::IsAccessibilityFocusable() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") bool CefScrollViewCToCpp::HasFocus() { + shutdown_checker::AssertNotShutdown(); + + cef_view_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefScrollViewCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/scroll_view_ctocpp.h b/libcef_dll/ctocpp/views/scroll_view_ctocpp.h index 42c8d4c09..3fdfcf4c1 100644 --- a/libcef_dll/ctocpp/views/scroll_view_ctocpp.h +++ b/libcef_dll/ctocpp/views/scroll_view_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=1b896bea52b0d62490a5b78a86dee729a4236cda$ +// $hash=b466f3a709cc15c08f77ec31fe845fe2c7e096a7$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_SCROLL_VIEW_CTOCPP_H_ @@ -84,6 +84,7 @@ class CefScrollViewCToCpp : public CefCToCppRefCounted(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefTextfieldCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/textfield_ctocpp.h b/libcef_dll/ctocpp/views/textfield_ctocpp.h index 0b2f3daa7..39511aa8b 100644 --- a/libcef_dll/ctocpp/views/textfield_ctocpp.h +++ b/libcef_dll/ctocpp/views/textfield_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=70c79d683dbcf742579a22c2543d6ed1b40453ea$ +// $hash=58cc17237e5497548ee5093eaaa74102faeac62b$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_TEXTFIELD_CTOCPP_H_ @@ -110,6 +110,7 @@ class CefTextfieldCToCpp : public CefCToCppRefCountedhas_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefViewCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/view_ctocpp.h b/libcef_dll/ctocpp/views/view_ctocpp.h index 02cec7468..84274701b 100644 --- a/libcef_dll/ctocpp/views/view_ctocpp.h +++ b/libcef_dll/ctocpp/views/view_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=e9c4f3a121d3ab9a2d9d8a8ea8b51bddfd4845db$ +// $hash=a2b62cb88fb80659a49ece865b1d05ea422a6e40$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_VIEW_CTOCPP_H_ @@ -86,6 +86,7 @@ class CefViewCToCpp void SetFocusable(bool focusable) override; bool IsFocusable() override; bool IsAccessibilityFocusable() override; + bool HasFocus() override; void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; cef_color_t GetBackgroundColor() override; diff --git a/libcef_dll/ctocpp/views/window_ctocpp.cc b/libcef_dll/ctocpp/views/window_ctocpp.cc index 23b2529fa..05d5de4f5 100644 --- a/libcef_dll/ctocpp/views/window_ctocpp.cc +++ b/libcef_dll/ctocpp/views/window_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=6ebaa8a85615b3a4ea46cf32893e4297667f81a4$ +// $hash=c6c8223d5505cf28b00dcfaa1e16047d4ed45520$ // #include "libcef_dll/ctocpp/views/window_ctocpp.h" @@ -346,6 +346,23 @@ NO_SANITIZE("cfi-icall") bool CefWindowCToCpp::IsFullscreen() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") CefRefPtr CefWindowCToCpp::GetFocusedView() { + shutdown_checker::AssertNotShutdown(); + + cef_window_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, get_focused_view)) { + return nullptr; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_view_t* _retval = _struct->get_focused_view(_struct); + + // Return type: refptr_same + return CefViewCToCpp::Wrap(_retval); +} + NO_SANITIZE("cfi-icall") void CefWindowCToCpp::SetTitle(const CefString& title) { shutdown_checker::AssertNotShutdown(); @@ -1669,6 +1686,23 @@ NO_SANITIZE("cfi-icall") bool CefWindowCToCpp::IsAccessibilityFocusable() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") bool CefWindowCToCpp::HasFocus() { + shutdown_checker::AssertNotShutdown(); + + cef_view_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, has_focus)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->has_focus(_struct); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") void CefWindowCToCpp::RequestFocus() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/views/window_ctocpp.h b/libcef_dll/ctocpp/views/window_ctocpp.h index c077e7139..fbde2e2f2 100644 --- a/libcef_dll/ctocpp/views/window_ctocpp.h +++ b/libcef_dll/ctocpp/views/window_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=d0c83991173ca5acb77c4bb8525cca3b645a2b19$ +// $hash=57275bfe260c39a2103f811886704009eb5688fd$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_WINDOW_CTOCPP_H_ @@ -23,8 +23,10 @@ #include #include "include/capi/views/cef_browser_view_capi.h" +#include "include/capi/views/cef_view_capi.h" #include "include/capi/views/cef_window_capi.h" #include "include/views/cef_browser_view.h" +#include "include/views/cef_view.h" #include "include/views/cef_window.h" #include "libcef_dll/ctocpp/ctocpp_ref_counted.h" @@ -57,6 +59,7 @@ class CefWindowCToCpp bool IsMaximized() override; bool IsMinimized() override; bool IsFullscreen() override; + CefRefPtr GetFocusedView() override; void SetTitle(const CefString& title) override; CefString GetTitle() override; void SetWindowIcon(CefRefPtr image) override; @@ -150,6 +153,7 @@ class CefWindowCToCpp void SetFocusable(bool focusable) override; bool IsFocusable() override; bool IsAccessibilityFocusable() override; + bool HasFocus() override; void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; cef_color_t GetBackgroundColor() override; diff --git a/tests/cefclient/browser/base_client_handler.cc b/tests/cefclient/browser/base_client_handler.cc index e4dcec807..c2886fb26 100644 --- a/tests/cefclient/browser/base_client_handler.cc +++ b/tests/cefclient/browser/base_client_handler.cc @@ -4,8 +4,10 @@ #include "tests/cefclient/browser/base_client_handler.h" +#include "include/cef_command_line.h" #include "tests/cefclient/browser/main_context.h" #include "tests/cefclient/browser/root_window_manager.h" +#include "tests/shared/common/client_switches.h" namespace client { @@ -36,6 +38,11 @@ bool BaseClientHandler::OnProcessMessageReceived( source_process, message); } +bool BaseClientHandler::OnSetFocus(CefRefPtr browser, + FocusSource source) { + return !ShouldRequestFocus(); +} + void BaseClientHandler::OnAfterCreated(CefRefPtr browser) { CEF_REQUIRE_UI_THREAD(); @@ -76,6 +83,17 @@ void BaseClientHandler::OnBeforeClose(CefRefPtr browser) { } } +void BaseClientHandler::OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) { + CEF_REQUIRE_UI_THREAD(); + + if (!isLoading && initial_navigation_) { + initial_navigation_ = false; + } +} + bool BaseClientHandler::OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, @@ -168,4 +186,19 @@ BaseClientHandler::HangAction BaseClientHandler::GetHangAction() const { return hang_action_; } +bool BaseClientHandler::ShouldRequestFocus() { + CEF_REQUIRE_UI_THREAD(); + + if (initial_navigation_) { + CefRefPtr command_line = + CefCommandLine::GetGlobalCommandLine(); + if (command_line->HasSwitch(switches::kNoActivate)) { + // Don't give focus to the browser on creation. + return false; + } + } + + return true; +} + } // namespace client diff --git a/tests/cefclient/browser/base_client_handler.h b/tests/cefclient/browser/base_client_handler.h index 1fd96ff19..b06756f0f 100644 --- a/tests/cefclient/browser/base_client_handler.h +++ b/tests/cefclient/browser/base_client_handler.h @@ -14,7 +14,9 @@ namespace client { // Abstract base class for client handlers. class BaseClientHandler : public CefClient, + public CefFocusHandler, public CefLifeSpanHandler, + public CefLoadHandler, public CefRequestHandler, public CefResourceRequestHandler { public: @@ -28,17 +30,28 @@ class BaseClientHandler : public CefClient, static CefRefPtr GetForClient(CefRefPtr client); // CefClient methods + CefRefPtr GetFocusHandler() override { return this; } CefRefPtr GetLifeSpanHandler() override { return this; } + CefRefPtr GetLoadHandler() override { return this; } CefRefPtr GetRequestHandler() override { return this; } bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId source_process, CefRefPtr message) override; + // CefFocusHandler methods + bool OnSetFocus(CefRefPtr browser, FocusSource source) override; + // CefLifeSpanHandler methods void OnAfterCreated(CefRefPtr browser) override; void OnBeforeClose(CefRefPtr browser) override; + // CefLoadHandler methods + void OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) override; + // CefRequestHandler methods bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, @@ -95,6 +108,8 @@ class BaseClientHandler : public CefClient, void SetHangAction(HangAction action); HangAction GetHangAction() const; + bool ShouldRequestFocus(); + // Used to determine the object type for each concrete implementation. virtual const void* GetTypeKey() const = 0; @@ -129,6 +144,9 @@ class BaseClientHandler : public CefClient, HangAction hang_action_ = HangAction::kDefault; + // True for the initial navigation after browser creation. + bool initial_navigation_ = true; + DISALLOW_COPY_AND_ASSIGN(BaseClientHandler); }; diff --git a/tests/cefclient/browser/client_handler.cc b/tests/cefclient/browser/client_handler.cc index 3d1dc3c98..39e93316b 100644 --- a/tests/cefclient/browser/client_handler.cc +++ b/tests/cefclient/browser/client_handler.cc @@ -888,13 +888,12 @@ bool ClientHandler::OnSetFocus(CefRefPtr browser, FocusSource source) { CEF_REQUIRE_UI_THREAD(); - if (initial_navigation_) { - CefRefPtr command_line = - CefCommandLine::GetGlobalCommandLine(); - if (command_line->HasSwitch(switches::kNoActivate)) { - // Don't give focus to the browser on creation. - return true; - } + if (BaseClientHandler::OnSetFocus(browser, source)) { + return true; + } + + if (delegate_ && delegate_->OnSetFocus(source)) { + return true; } return false; @@ -1009,9 +1008,8 @@ void ClientHandler::OnLoadingStateChange(CefRefPtr browser, bool canGoForward) { CEF_REQUIRE_UI_THREAD(); - if (!isLoading && initial_navigation_) { - initial_navigation_ = false; - } + BaseClientHandler::OnLoadingStateChange(browser, isLoading, canGoBack, + canGoForward); NotifyLoadingState(isLoading, canGoBack, canGoForward); } diff --git a/tests/cefclient/browser/client_handler.h b/tests/cefclient/browser/client_handler.h index 6eb9d4517..42e86cdf3 100644 --- a/tests/cefclient/browser/client_handler.h +++ b/tests/cefclient/browser/client_handler.h @@ -32,9 +32,7 @@ class ClientHandler : public BaseClientHandler, public CefDisplayHandler, public CefDownloadHandler, public CefDragHandler, - public CefFocusHandler, public CefKeyboardHandler, - public CefLoadHandler, public CefPermissionHandler { public: // Implement this interface to receive notification of ClientHandler @@ -82,6 +80,9 @@ class ClientHandler : public BaseClientHandler, virtual void OnSetDraggableRegions( const std::vector& regions) = 0; + // Called on the UI thread to optionally handle the browser gaining focus. + virtual bool OnSetFocus(cef_focus_source_t source) { return false; } + // Set focus to the next/previous control. virtual void OnTakeFocus(bool next) {} @@ -111,9 +112,7 @@ class ClientHandler : public BaseClientHandler, CefRefPtr GetDisplayHandler() override { return this; } CefRefPtr GetDownloadHandler() override { return this; } CefRefPtr GetDragHandler() override { return this; } - CefRefPtr GetFocusHandler() override { return this; } CefRefPtr GetKeyboardHandler() override { return this; } - CefRefPtr GetLoadHandler() override { return this; } CefRefPtr GetPermissionHandler() override { return this; } @@ -423,9 +422,6 @@ class ClientHandler : public BaseClientHandler, // True if an editable field currently has focus. bool focus_on_editable_field_ = false; - // True for the initial navigation after browser creation. - bool initial_navigation_ = true; - DISALLOW_COPY_AND_ASSIGN(ClientHandler); }; diff --git a/tests/cefclient/browser/root_window_views.cc b/tests/cefclient/browser/root_window_views.cc index 5a9f856ee..d39bf9f0d 100644 --- a/tests/cefclient/browser/root_window_views.cc +++ b/tests/cefclient/browser/root_window_views.cc @@ -451,6 +451,14 @@ void RootWindowViews::OnSetDraggableRegions( } } +bool RootWindowViews::OnSetFocus(cef_focus_source_t source) { + CEF_REQUIRE_UI_THREAD(); + if (window_) { + return window_->OnSetFocus(source); + } + return false; +} + void RootWindowViews::OnTakeFocus(bool next) { if (!CefCurrentlyOn(TID_UI)) { // Execute this method on the UI thread. diff --git a/tests/cefclient/browser/root_window_views.h b/tests/cefclient/browser/root_window_views.h index 787591475..e36ad51d1 100644 --- a/tests/cefclient/browser/root_window_views.h +++ b/tests/cefclient/browser/root_window_views.h @@ -85,6 +85,7 @@ class RootWindowViews : public RootWindow, bool canGoForward) override; void OnSetDraggableRegions( const std::vector& regions) override; + bool OnSetFocus(cef_focus_source_t source) override; void OnTakeFocus(bool next) override; void OnBeforeContextMenu(CefRefPtr model) override; diff --git a/tests/cefclient/browser/views_overlay_browser.cc b/tests/cefclient/browser/views_overlay_browser.cc index 5a8b4d574..867e558d6 100644 --- a/tests/cefclient/browser/views_overlay_browser.cc +++ b/tests/cefclient/browser/views_overlay_browser.cc @@ -15,8 +15,8 @@ namespace { void AddPopOutAccelerator(CefRefPtr window) { // Add an accelerator to toggle the BrowserView popout. OnAccelerator will be // called when the accelerator is triggered. - window->SetAccelerator(ID_POPOUT_OVERLAY, 'O', /*shift_pressed=*/false, - /*ctrl_pressed=*/false, /*alt_pressed=*/true, + window->SetAccelerator(ID_POPOUT_OVERLAY, 'O', /*shift_pressed=*/true, + /*ctrl_pressed=*/true, /*alt_pressed=*/false, /*high_priority=*/true); } @@ -201,10 +201,15 @@ void ViewsOverlayBrowser::PopOutBrowserView() { void ViewsOverlayBrowser::PopInBrowserView() { CHECK(!browser_view_); + CefRefPtr last_focused_view = window_->GetFocusedView(); + // Resume ownership of the BrowserView and close the popout Window. CHECK(popout_window_); browser_view_ = PopoutWindowDelegate::GetForWindow(popout_window_)->DetachBrowserView(); + + const bool should_focus_browser = + popout_window_->IsActive() && browser_view_->HasFocus(); popout_window_->RemoveChildView(browser_view_); popout_window_->Close(); popout_window_ = nullptr; @@ -219,6 +224,14 @@ void ViewsOverlayBrowser::PopInBrowserView() { // Make sure the overlay is positioned correctly. UpdateBounds(last_insets_); + + if (should_focus_browser) { + // Keep the BrowserView focused. + browser_view_->RequestFocus(); + } else if (last_focused_view) { + // Keep focus unchanged in the main Window. + last_focused_view->RequestFocus(); + } } void ViewsOverlayBrowser::UpdateBounds(CefInsets insets) { @@ -270,6 +283,14 @@ void ViewsOverlayBrowser::PopOutWindowDestroyed() { popout_window_ = nullptr; } +bool ViewsOverlayBrowser::RequestFocus() { + if (browser_view_) { + browser_view_->RequestFocus(); + return true; + } + return false; +} + CefSize ViewsOverlayBrowser::GetMinimumSize(CefRefPtr view) { return CefSize(200, 200); } diff --git a/tests/cefclient/browser/views_overlay_browser.h b/tests/cefclient/browser/views_overlay_browser.h index 1dea50059..900b2402e 100644 --- a/tests/cefclient/browser/views_overlay_browser.h +++ b/tests/cefclient/browser/views_overlay_browser.h @@ -44,6 +44,8 @@ class ViewsOverlayBrowser : public CefBrowserViewDelegate { void PopOutWindowDestroyed(); + bool RequestFocus(); + private: // CefViewDelegate methods: CefSize GetMinimumSize(CefRefPtr view) override; diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 497e189f5..511701abf 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -12,6 +12,7 @@ #include "include/cef_i18n_util.h" #include "include/views/cef_box_layout.h" #include "include/wrapper/cef_helpers.h" +#include "tests/cefclient/browser/base_client_handler.h" #include "tests/cefclient/browser/default_client_handler.h" #include "tests/cefclient/browser/main_context.h" #include "tests/cefclient/browser/resource.h" @@ -201,10 +202,7 @@ void ViewsWindow::Show() { window_->Show(); } } - if (browser_view_ && !window_->IsMinimized()) { - // Give keyboard focus to the BrowserView. - browser_view_->RequestFocus(); - } + MaybeRequestBrowserFocus(); } void ViewsWindow::Hide() { @@ -378,6 +376,18 @@ void ViewsWindow::SetDraggableRegions( window_->SetDraggableRegions(window_regions); } +bool ViewsWindow::OnSetFocus(cef_focus_source_t source) { + CEF_REQUIRE_UI_THREAD(); + + // No special handling of focus requests originating from the system. + if (source == FOCUS_SOURCE_SYSTEM) { + return false; + } + + RequestBrowserFocus(); + return true; +} + void ViewsWindow::TakeFocus(bool next) { CEF_REQUIRE_UI_THREAD(); @@ -1396,4 +1406,31 @@ void ViewsWindow::NudgeWindow() { } #endif +void ViewsWindow::MaybeRequestBrowserFocus() { + if (browser_view_) { + // BaseClientHandler has some state that we need to query. + if (auto handler = + BaseClientHandler::GetForBrowser(browser_view_->GetBrowser()); + handler->ShouldRequestFocus()) { + RequestBrowserFocus(); + } + } +} + +void ViewsWindow::RequestBrowserFocus() { + if (window_->IsMinimized()) { + return; + } + + // Maybe give keyboard focus to the overlay BrowserView. + if (overlay_browser_ && overlay_browser_->RequestFocus()) { + return; + } + + // Give keyboard focus to the main BrowserView. + if (browser_view_) { + browser_view_->RequestFocus(); + } +} + } // namespace client diff --git a/tests/cefclient/browser/views_window.h b/tests/cefclient/browser/views_window.h index 0ad0b7a20..0f39c2890 100644 --- a/tests/cefclient/browser/views_window.h +++ b/tests/cefclient/browser/views_window.h @@ -120,6 +120,7 @@ class ViewsWindow : public CefBrowserViewDelegate, void SetAlwaysOnTop(bool on_top); void SetLoadingState(bool isLoading, bool canGoBack, bool canGoForward); void SetDraggableRegions(const std::vector& regions); + bool OnSetFocus(cef_focus_source_t source); void TakeFocus(bool next); void OnBeforeContextMenu(CefRefPtr model); @@ -253,6 +254,9 @@ class ViewsWindow : public CefBrowserViewDelegate, void NudgeWindow(); + void MaybeRequestBrowserFocus(); + void RequestBrowserFocus(); + const WindowType type_; Delegate* const delegate_; // Not owned by this object. const bool use_alloy_style_; diff --git a/tests/cefsimple/simple_app.cc b/tests/cefsimple/simple_app.cc index 79d31d96b..6cec793cc 100644 --- a/tests/cefsimple/simple_app.cc +++ b/tests/cefsimple/simple_app.cc @@ -33,12 +33,6 @@ class SimpleWindowDelegate : public CefWindowDelegate { if (initial_show_state_ != CEF_SHOW_STATE_HIDDEN) { window->Show(); } - - if (initial_show_state_ != CEF_SHOW_STATE_MINIMIZED && - initial_show_state_ != CEF_SHOW_STATE_HIDDEN) { - // Give keyboard focus to the browser view. - browser_view_->RequestFocus(); - } } void OnWindowDestroyed(CefRefPtr window) override {