views: Fix Chrome style browser RequestFocus behavior (fixes #3819)

Fix implementation of CefBrowserView::RequestFocus for Chrome style
browsers. Match Alloy style behavior of requesting browser focus
(calling OnSetFocus) after initial navigation. Add CefView::HasFocus
and CefWindow::GetFocusedView that can be used in combination with
CefWindow::IsActive to determine global keyboard focus.

Update sample applications for the new behavior.

In cefclient:
- Browser receives initial focus via ViewsWindow::RequestBrowserFocus.
- When running with `--show-overlay-browser` (see #3790):
  - Give initial focus to the overlay browser.
  - Change the overlay popout shortcut to CTRL+SHIFT+O to avoid
    assigning focus to the menu in the main window.
  - Switching from overlay in the main window to popout browser
    window will give focus to the popout browser.
  - Switching from popout browser to overlay will leave current focus
    unchanged (e.g. in the overlay browser, or somewhere else). User
    gesture to activate the main window may be required on Mac/Linux.
- When running with `--no-active` don't give initial focus to either
  browser.

In cefsimple:
- Browser receives initial focus via default handling.
This commit is contained in:
Marshall Greenblatt
2024-11-05 14:58:45 -05:00
parent b070564ec5
commit b660522983
53 changed files with 652 additions and 91 deletions

View File

@ -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<cef_view_t*>(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();

View File

@ -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<CefBrowserViewCToCpp,
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;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f71e4f87086a3fb6d20a922af417bc47c81dbc7c$
// $hash=b829a205a55586221ebdcc65b618c09761980150$
//
#include "libcef_dll/ctocpp/views/button_ctocpp.h"
@ -816,6 +816,23 @@ NO_SANITIZE("cfi-icall") bool CefButtonCToCpp::IsAccessibilityFocusable() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefButtonCToCpp::HasFocus() {
shutdown_checker::AssertNotShutdown();
cef_view_t* _struct = reinterpret_cast<cef_view_t*>(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();

View File

@ -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;

View File

@ -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<cef_view_t*>(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();

View File

@ -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<CefLabelButtonCToCpp,
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;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=510f6e414ccd2152a39fdcd12447071794b649c2$
// $hash=c49d0468a28969b21847b95f9d9a545af7a6039b$
//
#include "libcef_dll/ctocpp/views/menu_button_ctocpp.h"
@ -1091,6 +1091,23 @@ NO_SANITIZE("cfi-icall") bool CefMenuButtonCToCpp::IsAccessibilityFocusable() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefMenuButtonCToCpp::HasFocus() {
shutdown_checker::AssertNotShutdown();
cef_view_t* _struct = reinterpret_cast<cef_view_t*>(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();

View File

@ -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<CefMenuButtonCToCpp,
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;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=b7f89f3d93bb41c5f952ba85b6cd8ebc826dd45d$
// $hash=0d9f8c7c00d7b2e59b4fbf35927a53ce335a8304$
//
#include "libcef_dll/ctocpp/views/panel_ctocpp.h"
@ -958,6 +958,23 @@ NO_SANITIZE("cfi-icall") bool CefPanelCToCpp::IsAccessibilityFocusable() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefPanelCToCpp::HasFocus() {
shutdown_checker::AssertNotShutdown();
cef_view_t* _struct = reinterpret_cast<cef_view_t*>(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();

View File

@ -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;

View File

@ -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<cef_view_t*>(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();

View File

@ -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<CefScrollViewCToCpp,
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;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=77c2df71313e5075c9a25bde8a4cd7ee13ec5ac2$
// $hash=15fd2f3ae41c973eccf6359eac04070d03c5e27e$
//
#include "libcef_dll/ctocpp/views/textfield_ctocpp.h"
@ -1264,6 +1264,23 @@ NO_SANITIZE("cfi-icall") bool CefTextfieldCToCpp::IsAccessibilityFocusable() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefTextfieldCToCpp::HasFocus() {
shutdown_checker::AssertNotShutdown();
cef_view_t* _struct = reinterpret_cast<cef_view_t*>(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();

View File

@ -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 CefCToCppRefCounted<CefTextfieldCToCpp,
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;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=8bbe8af593158eac1cbbdaa09313216872488f86$
// $hash=67a76403dae45d17abb6f94aec1ecea22323bca0$
//
#include "libcef_dll/ctocpp/views/view_ctocpp.h"
@ -708,6 +708,23 @@ NO_SANITIZE("cfi-icall") bool CefViewCToCpp::IsAccessibilityFocusable() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefViewCToCpp::HasFocus() {
shutdown_checker::AssertNotShutdown();
cef_view_t* _struct = 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 CefViewCToCpp::RequestFocus() {
shutdown_checker::AssertNotShutdown();

View File

@ -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;

View File

@ -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<CefView> 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<cef_view_t*>(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();

View File

@ -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 <vector>
#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<CefView> GetFocusedView() override;
void SetTitle(const CefString& title) override;
CefString GetTitle() override;
void SetWindowIcon(CefRefPtr<CefImage> 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;