Commit 6398d1c3 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Add dropdown native theme constants

The new constants are necessary because GTK differentiates between
dropdowns (which it calls comboboxes) and menus.  On the Ambiance
theme (the default on Ubuntu), dropdowns are light but menus are dark,
so this change is necessary for consistency with GTK apps.

BUG=914974
R=pkasting

Change-Id: I4805526eee93322c4e7d57b879e0528b0998c933
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069021
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744070}
parent 9a274173
......@@ -309,8 +309,10 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
enum {
CSS_TYPE,
CSS_NAME,
CSS_OBJECT_NAME,
CSS_CLASS,
CSS_PSEUDOCLASS,
CSS_NONE,
} part_type = CSS_TYPE;
static const struct {
const char* name;
......@@ -328,7 +330,7 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
{"checked", GTK_STATE_FLAG_CHECKED},
};
GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
base::StringTokenizer t(css_node, ".:#");
base::StringTokenizer t(css_node, ".:#()");
t.set_options(base::StringTokenizer::RETURN_DELIMS);
while (t.GetNext()) {
if (t.token_is_delim()) {
......@@ -337,9 +339,15 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
gtk_widget_path_append_type(path, G_TYPE_NONE);
}
switch (*t.token_begin()) {
case '#':
case '(':
part_type = CSS_NAME;
break;
case ')':
part_type = CSS_NONE;
break;
case '#':
part_type = CSS_OBJECT_NAME;
break;
case '.':
part_type = CSS_CLASS;
break;
......@@ -355,14 +363,15 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
reinterpret_cast<GtkSetObjectName>(dlsym(
GetGtkSharedLibrary(), "gtk_widget_path_iter_set_object_name"));
switch (part_type) {
case CSS_NAME: {
if (GtkVersionCheck(3, 20)) {
case CSS_NAME:
gtk_widget_path_iter_set_name(path, -1, t.token().c_str());
break;
case CSS_OBJECT_NAME:
if (GtkVersionCheck(3, 20))
_gtk_widget_path_iter_set_object_name(path, -1, t.token().c_str());
} else {
else
gtk_widget_path_iter_add_class(path, -1, t.token().c_str());
}
break;
}
case CSS_TYPE: {
GType type = g_type_from_name(t.token().c_str());
DCHECK(type);
......@@ -373,10 +382,9 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
}
break;
}
case CSS_CLASS: {
case CSS_CLASS:
gtk_widget_path_iter_add_class(path, -1, t.token().c_str());
break;
}
case CSS_PSEUDOCLASS: {
GtkStateFlags state_flag = GTK_STATE_FLAG_NORMAL;
for (const auto& pseudo_class_entry : pseudo_classes) {
......@@ -388,6 +396,8 @@ ScopedStyleContext AppendCssNodeToStyleContext(GtkStyleContext* context,
state = static_cast<GtkStateFlags>(state | state_flag);
break;
}
case CSS_NONE:
NOTREACHED();
}
}
}
......
......@@ -126,6 +126,28 @@ base::Optional<SkColor> SkColorFromColorId(
}
return GetFgColor("GtkMenu#menu GtkMenuItem#menuitem.separator");
// Dropdown
case ui::NativeTheme::kColorId_DropdownBackgroundColor:
return GetBgColor(
"GtkComboBoxText#combobox GtkWindow#window.background.popup "
"GtkTreeMenu#menu(gtk-combobox-popup-menu) GtkMenuItem#menuitem "
"GtkCellView#cellview");
case ui::NativeTheme::kColorId_DropdownForegroundColor:
return GetFgColor(
"GtkComboBoxText#combobox GtkWindow#window.background.popup "
"GtkTreeMenu#menu(gtk-combobox-popup-menu) GtkMenuItem#menuitem "
"GtkCellView#cellview");
case ui::NativeTheme::kColorId_DropdownSelectedBackgroundColor:
return GetBgColor(
"GtkComboBoxText#combobox GtkWindow#window.background.popup "
"GtkTreeMenu#menu(gtk-combobox-popup-menu) "
"GtkMenuItem#menuitem:hover GtkCellView#cellview");
case ui::NativeTheme::kColorId_DropdownSelectedForegroundColor:
return GetFgColor(
"GtkComboBoxText#combobox GtkWindow#window.background.popup "
"GtkTreeMenu#menu(gtk-combobox-popup-menu) "
"GtkMenuItem#menuitem:hover GtkCellView#cellview");
// Label
case ui::NativeTheme::kColorId_LabelEnabledColor:
return GetFgColor("GtkLabel");
......@@ -368,6 +390,14 @@ NativeThemeGtk::NativeThemeGtk() {
g_type_class_unref(g_type_class_ref(gtk_toggle_button_get_type()));
g_type_class_unref(g_type_class_ref(gtk_tree_view_get_type()));
g_type_class_unref(g_type_class_ref(gtk_window_get_type()));
g_type_class_unref(g_type_class_ref(gtk_combo_box_text_get_type()));
g_type_class_unref(g_type_class_ref(gtk_cell_view_get_type()));
// Initialize the GtkTreeMenu type. _gtk_tree_menu_get_type() is private, so
// we need to initialize it indirectly.
ScopedGObject<GtkTreeModel> model{
GTK_TREE_MODEL(gtk_tree_store_new(1, G_TYPE_STRING))};
ScopedGObject<GtkWidget> combo{gtk_combo_box_new_with_model(model)};
OnThemeChanged(gtk_settings_get_default(), nullptr);
}
......
......@@ -37,22 +37,22 @@ int AutofillPopupBaseView::GetCornerRadius() {
SkColor AutofillPopupBaseView::GetBackgroundColor() {
return GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_MenuBackgroundColor);
ui::NativeTheme::kColorId_DropdownBackgroundColor);
}
SkColor AutofillPopupBaseView::GetForegroundColor() {
return GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
ui::NativeTheme::kColorId_DropdownForegroundColor);
}
SkColor AutofillPopupBaseView::GetSelectedBackgroundColor() {
return GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
ui::NativeTheme::kColorId_DropdownSelectedBackgroundColor);
}
SkColor AutofillPopupBaseView::GetSelectedForegroundColor() {
return GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
ui::NativeTheme::kColorId_DropdownSelectedForegroundColor);
}
SkColor AutofillPopupBaseView::GetFooterBackgroundColor() {
......
......@@ -88,17 +88,12 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
return gfx::kGoogleGrey900;
// MenuItem
case NativeTheme::kColorId_EnabledMenuItemForegroundColor:
case NativeTheme::kColorId_SelectedMenuItemForegroundColor:
case NativeTheme::kColorId_HighlightedMenuItemForegroundColor:
case NativeTheme::kColorId_MenuDropIndicator:
return gfx::kGoogleGrey200;
case NativeTheme::kColorId_MenuBorderColor:
case NativeTheme::kColorId_MenuSeparatorColor:
return gfx::kGoogleGrey800;
case NativeTheme::kColorId_MenuBackgroundColor:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
case NativeTheme::kColorId_HighlightedMenuItemBackgroundColor:
return SkColorSetRGB(0x32, 0x36, 0x39);
case NativeTheme::kColorId_MenuItemAlertBackgroundColor:
......@@ -106,6 +101,15 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_MenuItemMinorTextColor:
return gfx::kGoogleGrey500;
// Dropdown
case NativeTheme::kColorId_DropdownBackgroundColor:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
case NativeTheme::kColorId_DropdownForegroundColor:
return gfx::kGoogleGrey200;
case NativeTheme::kColorId_DropdownSelectedForegroundColor:
return gfx::kGoogleGrey200;
// Label
case NativeTheme::kColorId_LabelEnabledColor:
case NativeTheme::kColorId_LabelTextSelectionColor:
......@@ -266,21 +270,23 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
// MenuItem
case NativeTheme::kColorId_EnabledMenuItemForegroundColor:
return base_theme->GetSystemColor(
NativeTheme::kColorId_DropdownForegroundColor, color_scheme);
case NativeTheme::kColorId_SelectedMenuItemForegroundColor:
return base_theme->GetSystemColor(
NativeTheme::kColorId_DropdownSelectedForegroundColor, color_scheme);
case NativeTheme::kColorId_HighlightedMenuItemForegroundColor:
case NativeTheme::kColorId_MenuDropIndicator:
return kPrimaryTextColor;
case NativeTheme::kColorId_FocusedMenuItemBackgroundColor: {
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_MenuBackgroundColor, color_scheme);
return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.67f)
.color;
}
case NativeTheme::kColorId_FocusedMenuItemBackgroundColor:
return base_theme->GetSystemColor(
NativeTheme::kColorId_DropdownSelectedBackgroundColor, color_scheme);
case NativeTheme::kColorId_MenuBorderColor:
case NativeTheme::kColorId_MenuSeparatorColor:
return gfx::kGoogleGrey300;
case NativeTheme::kColorId_MenuBackgroundColor:
return SK_ColorWHITE;
return base_theme->GetSystemColor(
NativeTheme::kColorId_DropdownBackgroundColor, color_scheme);
case NativeTheme::kColorId_DisabledMenuItemForegroundColor: {
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_MenuBackgroundColor, color_scheme);
......@@ -296,6 +302,20 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_MenuItemAlertBackgroundColor:
return gfx::kGoogleBlue600;
// Dropdown
case NativeTheme::kColorId_DropdownBackgroundColor:
return SK_ColorWHITE;
case NativeTheme::kColorId_DropdownForegroundColor:
return kPrimaryTextColor;
case NativeTheme::kColorId_DropdownSelectedBackgroundColor: {
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_MenuBackgroundColor, color_scheme);
return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.67f)
.color;
}
case NativeTheme::kColorId_DropdownSelectedForegroundColor:
return kPrimaryTextColor;
// Label
case NativeTheme::kColorId_LabelEnabledColor:
case NativeTheme::kColorId_LabelTextSelectionColor:
......
......@@ -363,6 +363,11 @@ class NATIVE_THEME_EXPORT NativeTheme {
kColorId_HighlightedMenuItemBackgroundColor,
kColorId_HighlightedMenuItemForegroundColor,
kColorId_MenuItemAlertBackgroundColor,
// Dropdown
kColorId_DropdownBackgroundColor,
kColorId_DropdownForegroundColor,
kColorId_DropdownSelectedBackgroundColor,
kColorId_DropdownSelectedForegroundColor,
// Label
kColorId_LabelEnabledColor,
kColorId_LabelDisabledColor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment