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

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=713287303ab9bbb6db24d8aabb340766f5e69461$
// $hash=48bce7be945d4e74682ffa41e8b45eb46a4f7589$
//
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
@ -553,6 +553,73 @@ request_context_set_content_setting(struct _cef_request_context_t* self,
CefString(requesting_url), CefString(top_level_url), content_type, value);
}
void CEF_CALLBACK
request_context_set_chrome_color_scheme(struct _cef_request_context_t* self,
cef_color_variant_t variant,
cef_color_t user_color) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return;
}
// Execute
CefRequestContextCppToC::Get(self)->SetChromeColorScheme(variant, user_color);
}
cef_color_variant_t CEF_CALLBACK request_context_get_chrome_color_scheme_mode(
struct _cef_request_context_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return CEF_COLOR_VARIANT_SYSTEM;
}
// Execute
cef_color_variant_t _retval =
CefRequestContextCppToC::Get(self)->GetChromeColorSchemeMode();
// Return type: simple
return _retval;
}
cef_color_t CEF_CALLBACK request_context_get_chrome_color_scheme_color(
struct _cef_request_context_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Execute
cef_color_t _retval =
CefRequestContextCppToC::Get(self)->GetChromeColorSchemeColor();
// Return type: simple
return _retval;
}
cef_color_variant_t CEF_CALLBACK
request_context_get_chrome_color_scheme_variant(
struct _cef_request_context_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return CEF_COLOR_VARIANT_SYSTEM;
}
// Execute
cef_color_variant_t _retval =
CefRequestContextCppToC::Get(self)->GetChromeColorSchemeVariant();
// Return type: simple
return _retval;
}
int CEF_CALLBACK
request_context_has_preference(struct _cef_preference_manager_t* self,
const cef_string_t* name) {
@ -713,6 +780,14 @@ CefRequestContextCppToC::CefRequestContextCppToC() {
GetStruct()->set_website_setting = request_context_set_website_setting;
GetStruct()->get_content_setting = request_context_get_content_setting;
GetStruct()->set_content_setting = request_context_set_content_setting;
GetStruct()->set_chrome_color_scheme =
request_context_set_chrome_color_scheme;
GetStruct()->get_chrome_color_scheme_mode =
request_context_get_chrome_color_scheme_mode;
GetStruct()->get_chrome_color_scheme_color =
request_context_get_chrome_color_scheme_color;
GetStruct()->get_chrome_color_scheme_variant =
request_context_get_chrome_color_scheme_variant;
GetStruct()->base.has_preference = request_context_has_preference;
GetStruct()->base.get_preference = request_context_get_preference;
GetStruct()->base.get_all_preferences = request_context_get_all_preferences;