Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: chrome/browser/ui/views/harmony/harmony_typography_provider.cc

Issue 2957263002: Update dialog button text color for Harmony per the latest button spec (Closed)
Patch Set: color_utils::IsInvertedColorScheme(), fewer Win constants Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/button/md_text_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/harmony/harmony_typography_provider.h" 5 #include "chrome/browser/ui/views/harmony/harmony_typography_provider.h"
6 6
7 #include "build/build_config.h"
7 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 8 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
8 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
11 #include "ui/gfx/color_utils.h"
10 #include "ui/gfx/platform_font.h" 12 #include "ui/gfx/platform_font.h"
11 #include "ui/native_theme/native_theme.h" 13 #include "ui/native_theme/native_theme.h"
12 14
15 #if defined(OS_WIN)
16 #include "ui/native_theme/native_theme_win.h"
17 #endif
18
13 #if defined(USE_ASH) 19 #if defined(USE_ASH)
14 #include "ash/public/cpp/ash_typography.h" // nogncheck 20 #include "ash/public/cpp/ash_typography.h" // nogncheck
15 #endif 21 #endif
16 22
23 namespace {
24
25 // If the default foreground color from the native theme isn't black, the rest
26 // of the Harmony spec isn't going to work. Also skip Harmony if a Windows
27 // High Contrast theme is enabled. One of the four standard High Contrast themes
28 // in Windows 10 still has black text, but (since the user wants high contrast)
29 // the grey text shades in Harmony should not be used.
30 bool ShouldIgnoreHarmonySpec(const ui::NativeTheme& theme) {
31 #if defined(OS_WIN)
32 if (ui::NativeThemeWin::IsUsingHighContrastTheme())
33 return true;
34 #endif
35 constexpr auto kTestColorId = ui::NativeTheme::kColorId_LabelEnabledColor;
36 return theme.GetSystemColor(kTestColorId) != SK_ColorBLACK;
37 }
38
39 // Returns a color for a possibly inverted or high-contrast OS color theme.
40 SkColor GetHarmonyTextColorForNonStandardNativeTheme(
41 int context,
42 int style,
43 const ui::NativeTheme& theme) {
44 // At the time of writing, very few UI surfaces need typography for a Chrome-
45 // provided theme. Typically just incognito browser windows (when the native
46 // theme is NativeThemeDarkAura). Instead, this method is consulted when the
47 // actual OS theme is configured in a special way. So pick from a small number
48 // of NativeTheme constants that are known to adapt properly to distinct
49 // colors when configuring the OS to use a high-contrast theme. For example,
50 // ::GetSysColor() on Windows has 8 text colors: BTNTEXT, CAPTIONTEXT,
51 // GRAYTEXT, HIGHLIGHTTEXT, INACTIVECAPTIONTEXT, INFOTEXT (tool tips),
52 // MENUTEXT, and WINDOWTEXT. There's also hyperlinks: COLOR_HOTLIGHT.
53 // Diverging from these risks using a color that doesn't match user
54 // expectations.
55
56 const bool inverted_scheme = color_utils::IsInvertedColorScheme();
57
58 ui::NativeTheme::ColorId color_id =
59 (context == views::style::CONTEXT_BUTTON ||
60 context == views::style::CONTEXT_BUTTON_MD)
61 ? ui::NativeTheme::kColorId_ButtonEnabledColor
62 : ui::NativeTheme::kColorId_TextfieldDefaultColor;
63 switch (style) {
64 case views::style::STYLE_DIALOG_BUTTON_DEFAULT:
65 // This is just white in Harmony and, even in inverted themes, prominent
66 // buttons have a dark background, so white will maximize contrast.
67 return SK_ColorWHITE;
68 case views::style::STYLE_DISABLED:
69 color_id = ui::NativeTheme::kColorId_LabelDisabledColor;
70 break;
71 case views::style::STYLE_LINK:
72 color_id = ui::NativeTheme::kColorId_LinkEnabled;
73 break;
74 case STYLE_RED:
75 return inverted_scheme ? gfx::kGoogleRed300 : gfx::kGoogleRed700;
76 case STYLE_GREEN:
77 return inverted_scheme ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700;
78 }
79 return theme.GetSystemColor(color_id);
80 }
81
82 } // namespace
83
17 const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, 84 const gfx::FontList& HarmonyTypographyProvider::GetFont(int context,
18 int style) const { 85 int style) const {
19 // "Target" font size constants from the Harmony spec. 86 // "Target" font size constants from the Harmony spec.
20 constexpr int kHeadlineSize = 20; 87 constexpr int kHeadlineSize = 20;
21 constexpr int kTitleSize = 15; 88 constexpr int kTitleSize = 15;
22 constexpr int kBodyTextLargeSize = 13; 89 constexpr int kBodyTextLargeSize = 13;
23 constexpr int kDefaultSize = 12; 90 constexpr int kDefaultSize = 12;
24 91
25 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize; 92 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize;
26 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; 93 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL;
(...skipping 22 matching lines...) Expand all
49 // Ignore |style| since it only affects color in the Harmony spec. 116 // Ignore |style| since it only affects color in the Harmony spec.
50 117
51 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 118 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
52 size_delta, gfx::Font::NORMAL, font_weight); 119 size_delta, gfx::Font::NORMAL, font_weight);
53 } 120 }
54 121
55 SkColor HarmonyTypographyProvider::GetColor( 122 SkColor HarmonyTypographyProvider::GetColor(
56 int context, 123 int context,
57 int style, 124 int style,
58 const ui::NativeTheme& theme) const { 125 const ui::NativeTheme& theme) const {
59 const SkColor foreground_color = 126 if (ShouldIgnoreHarmonySpec(theme))
60 theme.GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); 127 return GetHarmonyTextColorForNonStandardNativeTheme(context, style, theme);
61 128
62 // If the default foreground color from the native theme isn't black, the rest 129 if (context == views::style::CONTEXT_BUTTON_MD) {
63 // of the Harmony spec isn't going to work. TODO(tapted): Something more
64 // generic would be nice here, but that requires knowing the background color
65 // for the text. At the time of writing, very few UI surfaces need native-
66 // themed typography with a custom native theme. Typically just incognito
67 // browser windows, when the native theme is NativeThemeDarkAura.
68 if (foreground_color != SK_ColorBLACK) {
69 switch (style) { 130 switch (style) {
131 case views::style::STYLE_DIALOG_BUTTON_DEFAULT:
132 return SK_ColorWHITE;
70 case views::style::STYLE_DISABLED: 133 case views::style::STYLE_DISABLED:
71 case STYLE_SECONDARY: 134 return SkColorSetRGB(0x9e, 0x9e, 0x9e);
72 case STYLE_HINT: 135 default:
73 return theme.GetSystemColor( 136 return SkColorSetRGB(0x75, 0x75, 0x75);
74 ui::NativeTheme::kColorId_LabelDisabledColor);
75 case views::style::STYLE_LINK:
76 return theme.GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
77 case STYLE_RED:
78 return foreground_color == SK_ColorWHITE ? gfx::kGoogleRed300
79 : gfx::kGoogleRed700;
80 case STYLE_GREEN:
81 return foreground_color == SK_ColorWHITE ? gfx::kGoogleGreen300
82 : gfx::kGoogleGreen700;
83 } 137 }
84 return foreground_color;
85 } 138 }
86 139
87 switch (style) { 140 switch (style) {
88 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: 141 case views::style::STYLE_DIALOG_BUTTON_DEFAULT:
89 return SK_ColorWHITE; 142 return SK_ColorWHITE;
90 case views::style::STYLE_DISABLED: 143 case views::style::STYLE_DISABLED:
91 return SkColorSetRGB(0x9e, 0x9e, 0x9e); 144 return SkColorSetRGB(0x9e, 0x9e, 0x9e);
92 case views::style::STYLE_LINK: 145 case views::style::STYLE_LINK:
93 return gfx::kGoogleBlue700; 146 return gfx::kGoogleBlue700;
94 case STYLE_SECONDARY: 147 case STYLE_SECONDARY:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 case views::style::CONTEXT_DIALOG_TITLE: 215 case views::style::CONTEXT_DIALOG_TITLE:
163 return title_height; 216 return title_height;
164 case CONTEXT_BODY_TEXT_LARGE: 217 case CONTEXT_BODY_TEXT_LARGE:
165 return body_large_height; 218 return body_large_height;
166 case CONTEXT_HEADLINE: 219 case CONTEXT_HEADLINE:
167 return headline_height; 220 return headline_height;
168 default: 221 default:
169 return default_height; 222 return default_height;
170 } 223 }
171 } 224 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/button/md_text_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698