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

@@ -377,6 +377,43 @@ class CefWindow : public CefPanel {
///
/*--cef()--*/
virtual void RemoveAllAccelerators() = 0;
///
/// Override a standard theme color or add a custom color associated with
/// |color_id|. See cef_color_ids.h for standard ID values. Recommended usage
/// is as follows:
///
/// 1. Customize the default native/OS theme by calling SetThemeColor before
/// showing the first Window. When done setting colors call
/// CefWindow::ThemeChanged to trigger CefViewDelegate::OnThemeChanged
/// notifications.
/// 2. Customize the current native/OS or Chrome theme after it changes by
/// calling SetThemeColor from the CefWindowDelegate::OnThemeColorsChanged
/// callback. CefViewDelegate::OnThemeChanged notifications will then be
/// triggered automatically.
///
/// The configured color will be available immediately via
/// CefView::GetThemeColor and will be applied to each View in this Window's
/// component hierarchy when CefViewDelegate::OnThemeChanged is called. See
/// OnThemeColorsChanged documentation for additional details.
///
/// Clients wishing to add custom colors should use |color_id| values >=
/// CEF_ChromeColorsEnd.
///
/*--cef()--*/
virtual void SetThemeColor(int color_id, cef_color_t color) = 0;
///
/// Trigger CefViewDelegate::OnThemeChanged callbacks for each View in this
/// Window's component hierarchy. Unlike a native/OS or Chrome theme change
/// this method does not reset theme colors to standard values and does not
/// result in a call to CefWindowDelegate::OnThemeColorsChanged.
///
/// Do not call this method from CefWindowDelegate::OnThemeColorsChanged or
/// CefViewDelegate::OnThemeChanged.
///
/*--cef()--*/
virtual void ThemeChanged() = 0;
};
#endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_H_