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

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