views: Add support for OS and Chrome themes (fixes #3610, fixes #3671)

Controls now respect OS and Chrome themes by default for both Alloy
and Chrome runtimes. Chrome themes (mode and colors) can be configured
using the new CefRequestContext::SetChromeColorScheme method. Individual
theme colors can be overridden using the new CefWindowDelegate::
OnThemeColorsChanged and CefWindow::SetThemeColor methods.

The `--force-light-mode` and `--force-dark-mode` command-line flags are
now respected on all platforms as an override for the OS theme.

The current Chrome theme, if any, will take precedence over the OS theme
when determining light/dark status. On Windows and MacOS the titlebar
color will also be updated to match the light/dark theme.

Testable as follows:
- Run: `cefclient --enable-chrome-runtime` OR
       `cefclient --use-views --persist-user-preferences --cache-path=...`
  - App launches with default OS light/dark theme colors.
  - Change OS dark/light theme under system settings. Notice that theme
    colors change as expected.
  - Right click, select items from the new Theme sub-menu. Notice that
    theme colors behave as expected.
  - Exit and relaunch the app. Notice that the last-used theme colors are
    applied on app restart.
- Add `--background-color=green` to above command-line.
  - Perform the same actions as above. Notice that all controls start
    and remain green throughout (except some icons with Chrome runtime).
- Add `--force-light-mode` or `--force-dark-mode` to above command-line.
  - Perform the same actions as above. Notice that OS dark/light theme
    changes are ignored, but Chrome theme changes work as expected.
This commit is contained in:
Marshall Greenblatt
2024-03-29 12:48:33 -04:00
parent 29c21f58e8
commit f60476b848
97 changed files with 2976 additions and 206 deletions

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=c1c2705cdef7d9189557b57531dc2d53e9f68d0c$
// $hash=b292cdf6e293dfd42c30ea9189b2a8a2ed77ba7a$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_WINDOW_DELEGATE_CAPI_H_
@@ -224,6 +224,43 @@ typedef struct _cef_window_delegate_t {
int(CEF_CALLBACK* on_key_event)(struct _cef_window_delegate_t* self,
struct _cef_window_t* window,
const cef_key_event_t* event);
///
/// Called after the native/OS or Chrome theme for |window| has changed.
/// |chrome_theme| will be true (1) if the notification is for a Chrome theme.
///
/// Native/OS theme colors are configured globally and do not need to be
/// customized for each Window individually. An example of a native/OS theme
/// change that triggers this callback is when the user switches between dark
/// and light mode during application lifespan. Native/OS theme changes can be
/// disabled by passing the `--force-dark-mode` or `--force-light-mode`
/// command-line flag.
///
/// Chrome theme colors will be applied and this callback will be triggered
/// if/when a BrowserView is added to the Window's component hierarchy. Chrome
/// theme colors can be configured on a per-RequestContext basis using
/// cef_request_context_t::SetChromeColorScheme or (Chrome runtime only) by
/// visiting chrome://settings/manageProfile. Any theme changes using those
/// mechanisms will also trigger this callback. Chrome theme colors will be
/// persisted and restored from disk cache with the Chrome runtime, and with
/// the Alloy runtime if persist_user_preferences is set to true (1) via
/// CefSettings or cef_request_context_tSettings.
///
/// This callback is not triggered on Window creation so clients that wish to
/// customize the initial native/OS theme must call
/// cef_window_t::SetThemeColor and cef_window_t::ThemeChanged before showing
/// the first Window.
///
/// Theme colors will be reset to standard values before this callback is
/// called for the first affected Window. Call cef_window_t::SetThemeColor
/// from inside this callback to override a standard color or add a custom
/// color. cef_view_delegate_t::OnThemeChanged will be called after this
/// callback for the complete |window| component hierarchy.
///
void(CEF_CALLBACK* on_theme_colors_changed)(
struct _cef_window_delegate_t* self,
struct _cef_window_t* window,
int chrome_theme);
} cef_window_delegate_t;
#ifdef __cplusplus