Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 10 #include "ui/gfx/platform_font.h" | 11 #include "ui/gfx/platform_font.h" |
| 11 #include "ui/native_theme/native_theme.h" | 12 #include "ui/native_theme/native_theme.h" |
| 12 | 13 |
| 14 #if defined(OS_WIN) | |
| 15 #include "ui/native_theme/native_theme_win.h" | |
| 16 #endif | |
| 17 | |
| 13 #if defined(USE_ASH) | 18 #if defined(USE_ASH) |
| 14 #include "ash/public/cpp/ash_typography.h" // nogncheck | 19 #include "ash/public/cpp/ash_typography.h" // nogncheck |
| 15 #endif | 20 #endif |
| 16 | 21 |
| 22 namespace { | |
| 23 | |
| 24 // If the default foreground color from the native theme isn't black, the rest | |
| 25 // of the Harmony spec isn't going to work. Also skip Harmony if a Windows | |
| 26 // High Contrast theme is enabled. One of the four standard High Contrast themes | |
| 27 // in Windows 10 still has black text, but (since the user wants high contrast) | |
| 28 // the grey text shades in Harmony should not be used. | |
| 29 bool ShouldIgnoreHarmonySpec(const ui::NativeTheme& theme) { | |
| 30 #if defined(OS_WIN) | |
| 31 if (ui::NativeThemeWin::IsUsingHighContrastTheme()) | |
| 32 return true; | |
| 33 #endif | |
| 34 constexpr auto kTestColorId = ui::NativeTheme::kColorId_LabelEnabledColor; | |
| 35 return theme.GetSystemColor(kTestColorId) != SK_ColorBLACK; | |
| 36 } | |
| 37 | |
| 38 // Returns a color for a possibly inverted or high-contrast OS color theme. | |
| 39 SkColor GetHarmonyTextColorForNonStandardNativeTheme( | |
| 40 int context, | |
| 41 int style, | |
| 42 const ui::NativeTheme& theme) { | |
| 43 // At the time of writing, very few UI surfaces need typography for a Chrome- | |
| 44 // provided theme. Typically just incognito browser windows (when the native | |
| 45 // theme is NativeThemeDarkAura). Instead, this method is consulted when the | |
| 46 // actual OS theme is configured in a special way. So pick from a small number | |
| 47 // of NativeTheme constants that are known to adapt properly to distinct | |
| 48 // colors when configuring the OS to use a high-contrast theme. For example, | |
| 49 // ::GetSysColor() on Windows has 8 text colors: BTNTEXT, CAPTIONTEXT, | |
| 50 // GRAYTEXT, HIGHLIGHTTEXT, INACTIVECAPTIONTEXT, INFOTEXT (tool tips), | |
| 51 // MENUTEXT, and WINDOWTEXT. There's also hyperlinks: COLOR_HOTLIGHT. | |
| 52 // Diverging from these risks using a color that doesn't match user | |
| 53 // expectations. | |
| 54 | |
| 55 // Heuristically determine whether the color scheme is inverted. The three | |
| 56 // standard inverted high contrast themes in Windows 10 use a white button | |
| 57 // text, so that's a good indicator. | |
| 58 const bool inverted_scheme = | |
|
Peter Kasting
2017/06/30 08:56:12
Ideally, avoid looking for an inverted scheme and
tapted
2017/07/03 05:20:50
I've discovered color_utils::IsInvertedColorScheme
| |
| 59 theme.GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor) == | |
| 60 SK_ColorWHITE; | |
| 61 | |
| 62 // Start with BTNTEXT for buttons, otherwise WINDOWTEXT. Note RED and GREEN | |
| 63 // will skip the NativeTheme entirely. | |
|
Peter Kasting
2017/06/30 08:56:12
Nit: Avoid Windows-specific IDs in comments here a
tapted
2017/07/03 05:20:50
Done. However, I think it does give the reader nee
| |
| 64 ui::NativeTheme::ColorId color_id = | |
| 65 (context == views::style::CONTEXT_BUTTON || | |
| 66 context == views::style::CONTEXT_BUTTON_MD) | |
| 67 ? ui::NativeTheme::kColorId_ButtonEnabledColor | |
| 68 : ui::NativeTheme::kColorId_TextfieldDefaultColor; | |
| 69 switch (style) { | |
| 70 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: | |
| 71 // This is just white in Harmony and, even in inverted themes, prominent | |
| 72 // buttons have a dark background, so white will maximize contrast. | |
| 73 return SK_ColorWHITE; | |
| 74 case views::style::STYLE_DISABLED: | |
| 75 color_id = ui::NativeTheme::kColorId_LabelDisabledColor; // GRAYTEXT. | |
| 76 break; | |
| 77 case views::style::STYLE_LINK: | |
| 78 color_id = ui::NativeTheme::kColorId_LinkEnabled; // HOTLIGHT. | |
| 79 break; | |
| 80 case STYLE_RED: | |
| 81 return inverted_scheme ? gfx::kGoogleRed300 : gfx::kGoogleRed700; | |
| 82 case STYLE_GREEN: | |
| 83 return inverted_scheme ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700; | |
| 84 } | |
| 85 return theme.GetSystemColor(color_id); | |
| 86 } | |
| 87 | |
| 88 } // namespace | |
| 89 | |
| 17 const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, | 90 const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, |
| 18 int style) const { | 91 int style) const { |
| 19 // "Target" font size constants from the Harmony spec. | 92 // "Target" font size constants from the Harmony spec. |
| 20 constexpr int kHeadlineSize = 20; | 93 constexpr int kHeadlineSize = 20; |
| 21 constexpr int kTitleSize = 15; | 94 constexpr int kTitleSize = 15; |
| 22 constexpr int kBodyTextLargeSize = 13; | 95 constexpr int kBodyTextLargeSize = 13; |
| 23 constexpr int kDefaultSize = 12; | 96 constexpr int kDefaultSize = 12; |
| 24 | 97 |
| 25 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize; | 98 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize; |
| 26 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; | 99 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 49 // Ignore |style| since it only affects color in the Harmony spec. | 122 // Ignore |style| since it only affects color in the Harmony spec. |
| 50 | 123 |
| 51 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 124 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 52 size_delta, gfx::Font::NORMAL, font_weight); | 125 size_delta, gfx::Font::NORMAL, font_weight); |
| 53 } | 126 } |
| 54 | 127 |
| 55 SkColor HarmonyTypographyProvider::GetColor( | 128 SkColor HarmonyTypographyProvider::GetColor( |
| 56 int context, | 129 int context, |
| 57 int style, | 130 int style, |
| 58 const ui::NativeTheme& theme) const { | 131 const ui::NativeTheme& theme) const { |
| 59 const SkColor foreground_color = | 132 if (ShouldIgnoreHarmonySpec(theme)) |
| 60 theme.GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); | 133 return GetHarmonyTextColorForNonStandardNativeTheme(context, style, theme); |
| 61 | 134 |
| 62 // If the default foreground color from the native theme isn't black, the rest | 135 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) { | 136 switch (style) { |
| 137 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: | |
| 138 return SK_ColorWHITE; | |
| 70 case views::style::STYLE_DISABLED: | 139 case views::style::STYLE_DISABLED: |
| 71 case STYLE_SECONDARY: | 140 return SkColorSetRGB(0x9e, 0x9e, 0x9e); |
|
Peter Kasting
2017/06/30 08:56:12
The spec doesn't actually seem to give button-spec
tapted
2017/07/03 05:20:50
There's a "disabled" column in the 2017-06-28 spec
| |
| 72 case STYLE_HINT: | 141 default: |
| 73 return theme.GetSystemColor( | 142 return SkColorSetRGB(0x75, 0x75, 0x75); |
|
Peter Kasting
2017/06/30 08:56:12
Shouldn't this be #5a5a5a? Or am I misreading the
tapted
2017/07/03 05:20:50
That's the old color :). This change is to make it
| |
| 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 } | 143 } |
| 84 return foreground_color; | |
| 85 } | 144 } |
| 86 | 145 |
| 87 switch (style) { | 146 switch (style) { |
| 88 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: | 147 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: |
| 89 return SK_ColorWHITE; | 148 return SK_ColorWHITE; |
| 90 case views::style::STYLE_DISABLED: | 149 case views::style::STYLE_DISABLED: |
| 91 return SkColorSetRGB(0x9e, 0x9e, 0x9e); | 150 return SkColorSetRGB(0x9e, 0x9e, 0x9e); |
|
Peter Kasting
2017/06/30 08:56:12
While here: I read the spec as saying these are ac
tapted
2017/07/03 05:20:50
I think it's the opposite - if we added an alpha c
| |
| 92 case views::style::STYLE_LINK: | 151 case views::style::STYLE_LINK: |
| 93 return gfx::kGoogleBlue700; | 152 return gfx::kGoogleBlue700; |
| 94 case STYLE_SECONDARY: | 153 case STYLE_SECONDARY: |
| 95 case STYLE_HINT: | 154 case STYLE_HINT: |
| 96 return SkColorSetRGB(0x75, 0x75, 0x75); | 155 return SkColorSetRGB(0x75, 0x75, 0x75); |
| 97 case STYLE_RED: | 156 case STYLE_RED: |
| 98 return gfx::kGoogleRed700; | 157 return gfx::kGoogleRed700; |
| 99 case STYLE_GREEN: | 158 case STYLE_GREEN: |
| 100 return gfx::kGoogleGreen700; | 159 return gfx::kGoogleGreen700; |
| 101 } | 160 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 case views::style::CONTEXT_DIALOG_TITLE: | 221 case views::style::CONTEXT_DIALOG_TITLE: |
| 163 return title_height; | 222 return title_height; |
| 164 case CONTEXT_BODY_TEXT_LARGE: | 223 case CONTEXT_BODY_TEXT_LARGE: |
| 165 return body_large_height; | 224 return body_large_height; |
| 166 case CONTEXT_HEADLINE: | 225 case CONTEXT_HEADLINE: |
| 167 return headline_height; | 226 return headline_height; |
| 168 default: | 227 default: |
| 169 return default_height; | 228 return default_height; |
| 170 } | 229 } |
| 171 } | 230 } |
| OLD | NEW |