2017-02-25 06:03:31 +01:00
|
|
|
// Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "tests/cefclient/browser/views_style.h"
|
|
|
|
|
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
namespace client::views_style {
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
cef_color_t g_background_color = 0;
|
|
|
|
cef_color_t g_background_hover_color = 0;
|
|
|
|
cef_color_t g_text_color = 0;
|
|
|
|
|
|
|
|
int GetShade(int component) {
|
|
|
|
return (component < 127) ? component + 75 : component - 75;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaybeInitialize() {
|
|
|
|
static bool initialized = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (initialized) {
|
2017-02-25 06:03:31 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
g_background_color = MainContext::Get()->GetBackgroundColor();
|
|
|
|
if (g_background_color != 0) {
|
|
|
|
// Use a slightly modified shade of the background color for hover.
|
2017-05-17 11:29:28 +02:00
|
|
|
g_background_hover_color =
|
|
|
|
CefColorSetARGB(255, GetShade(CefColorGetR(g_background_color)),
|
|
|
|
GetShade(CefColorGetG(g_background_color)),
|
|
|
|
GetShade(CefColorGetB(g_background_color)));
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
// Invert the background color for text.
|
2017-05-17 11:29:28 +02:00
|
|
|
g_text_color = CefColorSetARGB(255, 255 - CefColorGetR(g_background_color),
|
|
|
|
255 - CefColorGetG(g_background_color),
|
|
|
|
255 - CefColorGetB(g_background_color));
|
2017-02-25 06:03:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool IsSet() {
|
|
|
|
MaybeInitialize();
|
|
|
|
return g_background_color != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplyTo(CefRefPtr<CefMenuModel> menu_model) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!IsSet()) {
|
2017-02-25 06:03:31 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
// All text except non-hovered accelerator gets the same color.
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_TEXT, g_text_color);
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_TEXT_HOVERED, g_text_color);
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_TEXT_ACCELERATOR,
|
|
|
|
g_background_hover_color);
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_TEXT_ACCELERATOR_HOVERED,
|
|
|
|
g_text_color);
|
|
|
|
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_BACKGROUND, g_background_color);
|
|
|
|
menu_model->SetColorAt(-1, CEF_MENU_COLOR_BACKGROUND_HOVERED,
|
|
|
|
g_background_hover_color);
|
|
|
|
|
|
|
|
// Recursively color sub-menus.
|
2022-07-25 19:49:32 +02:00
|
|
|
for (size_t i = 0; i < menu_model->GetCount(); ++i) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (menu_model->GetTypeAt(i) == MENUITEMTYPE_SUBMENU) {
|
2017-02-25 06:03:31 +01:00
|
|
|
ApplyTo(menu_model->GetSubMenuAt(i));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-23 00:51:00 +01:00
|
|
|
void ApplyTo(CefRefPtr<CefView> view) {
|
|
|
|
if (!IsSet()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto button = view->AsButton()) {
|
|
|
|
if (auto label_button = button->AsLabelButton()) {
|
|
|
|
// All text except disabled gets the same color.
|
|
|
|
label_button->SetEnabledTextColors(g_text_color);
|
|
|
|
label_button->SetTextColor(CEF_BUTTON_STATE_DISABLED,
|
|
|
|
g_background_hover_color);
|
|
|
|
}
|
|
|
|
} else if (auto textfield = view->AsTextfield()) {
|
|
|
|
textfield->SetTextColor(g_text_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
view->SetBackgroundColor(g_background_color);
|
|
|
|
}
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
} // namespace client::views_style
|