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

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

View File

@@ -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.
///

View File

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

View File

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

View File

@@ -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<CefView> GetFocusedView() = 0;
///
/// Set the Window title.
///