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=3c4cb278397e9a07c8e5754650fe6944dd2a20ed$
// $hash=4e2f75d68d804ad2414eb34b9f273b8f558c3dab$
//
#include "libcef_dll/cpptoc/views/button_cpptoc.h"
@ -950,6 +950,26 @@ cef_color_t CEF_CALLBACK button_get_background_color(struct _cef_view_t* self) {
return _retval;
}
cef_color_t CEF_CALLBACK button_get_theme_color(struct _cef_view_t* self,
int color_id) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Execute
cef_color_t _retval =
CefButtonCppToC::Get(reinterpret_cast<cef_button_t*>(self))
->GetThemeColor(color_id);
// Return type: simple
return _retval;
}
int CEF_CALLBACK button_convert_point_to_screen(struct _cef_view_t* self,
cef_point_t* point) {
shutdown_checker::AssertNotShutdown();
@ -1212,6 +1232,7 @@ CefButtonCppToC::CefButtonCppToC() {
GetStruct()->base.request_focus = button_request_focus;
GetStruct()->base.set_background_color = button_set_background_color;
GetStruct()->base.get_background_color = button_get_background_color;
GetStruct()->base.get_theme_color = button_get_theme_color;
GetStruct()->base.convert_point_to_screen = button_convert_point_to_screen;
GetStruct()->base.convert_point_from_screen =
button_convert_point_from_screen;