Chromium Code Reviews| Index: chrome/browser/ui/views/harmony/harmony_typography_provider.cc |
| diff --git a/chrome/browser/ui/views/harmony/harmony_typography_provider.cc b/chrome/browser/ui/views/harmony/harmony_typography_provider.cc |
| index 939f5a5844dd0adedd803aac227a3fefd92ce7df..abbf650f772e2733be9daf01537661a8d4f3397f 100644 |
| --- a/chrome/browser/ui/views/harmony/harmony_typography_provider.cc |
| +++ b/chrome/browser/ui/views/harmony/harmony_typography_provider.cc |
| @@ -4,16 +4,89 @@ |
| #include "chrome/browser/ui/views/harmony/harmony_typography_provider.h" |
| +#include "build/build_config.h" |
| #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/color_palette.h" |
| #include "ui/gfx/platform_font.h" |
| #include "ui/native_theme/native_theme.h" |
| +#if defined(OS_WIN) |
| +#include "ui/native_theme/native_theme_win.h" |
| +#endif |
| + |
| #if defined(USE_ASH) |
| #include "ash/public/cpp/ash_typography.h" // nogncheck |
| #endif |
| +namespace { |
| + |
| +// If the default foreground color from the native theme isn't black, the rest |
| +// of the Harmony spec isn't going to work. Also skip Harmony if a Windows |
| +// High Contrast theme is enabled. One of the four standard High Contrast themes |
| +// in Windows 10 still has black text, but (since the user wants high contrast) |
| +// the grey text shades in Harmony should not be used. |
| +bool ShouldIgnoreHarmonySpec(const ui::NativeTheme& theme) { |
| +#if defined(OS_WIN) |
| + if (ui::NativeThemeWin::IsUsingHighContrastTheme()) |
| + return true; |
| +#endif |
| + constexpr auto kTestColorId = ui::NativeTheme::kColorId_LabelEnabledColor; |
| + return theme.GetSystemColor(kTestColorId) != SK_ColorBLACK; |
| +} |
| + |
| +// Returns a color for a possibly inverted or high-contrast OS color theme. |
| +SkColor GetHarmonyTextColorForNonStandardNativeTheme( |
| + int context, |
| + int style, |
| + const ui::NativeTheme& theme) { |
| + // At the time of writing, very few UI surfaces need typography for a Chrome- |
| + // provided theme. Typically just incognito browser windows (when the native |
| + // theme is NativeThemeDarkAura). Instead, this method is consulted when the |
| + // actual OS theme is configured in a special way. So pick from a small number |
| + // of NativeTheme constants that are known to adapt properly to distinct |
| + // colors when configuring the OS to use a high-contrast theme. For example, |
| + // ::GetSysColor() on Windows has 8 text colors: BTNTEXT, CAPTIONTEXT, |
| + // GRAYTEXT, HIGHLIGHTTEXT, INACTIVECAPTIONTEXT, INFOTEXT (tool tips), |
| + // MENUTEXT, and WINDOWTEXT. There's also hyperlinks: COLOR_HOTLIGHT. |
| + // Diverging from these risks using a color that doesn't match user |
| + // expectations. |
| + |
| + // Heuristically determine whether the color scheme is inverted. The three |
| + // standard inverted high contrast themes in Windows 10 use a white button |
| + // text, so that's a good indicator. |
| + 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
|
| + theme.GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor) == |
| + SK_ColorWHITE; |
| + |
| + // Start with BTNTEXT for buttons, otherwise WINDOWTEXT. Note RED and GREEN |
| + // 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
|
| + ui::NativeTheme::ColorId color_id = |
| + (context == views::style::CONTEXT_BUTTON || |
| + context == views::style::CONTEXT_BUTTON_MD) |
| + ? ui::NativeTheme::kColorId_ButtonEnabledColor |
| + : ui::NativeTheme::kColorId_TextfieldDefaultColor; |
| + switch (style) { |
| + case views::style::STYLE_DIALOG_BUTTON_DEFAULT: |
| + // This is just white in Harmony and, even in inverted themes, prominent |
| + // buttons have a dark background, so white will maximize contrast. |
| + return SK_ColorWHITE; |
| + case views::style::STYLE_DISABLED: |
| + color_id = ui::NativeTheme::kColorId_LabelDisabledColor; // GRAYTEXT. |
| + break; |
| + case views::style::STYLE_LINK: |
| + color_id = ui::NativeTheme::kColorId_LinkEnabled; // HOTLIGHT. |
| + break; |
| + case STYLE_RED: |
| + return inverted_scheme ? gfx::kGoogleRed300 : gfx::kGoogleRed700; |
| + case STYLE_GREEN: |
| + return inverted_scheme ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700; |
| + } |
| + return theme.GetSystemColor(color_id); |
| +} |
| + |
| +} // namespace |
| + |
| const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, |
| int style) const { |
| // "Target" font size constants from the Harmony spec. |
| @@ -56,32 +129,18 @@ SkColor HarmonyTypographyProvider::GetColor( |
| int context, |
| int style, |
| const ui::NativeTheme& theme) const { |
| - const SkColor foreground_color = |
| - theme.GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); |
| - |
| - // If the default foreground color from the native theme isn't black, the rest |
| - // of the Harmony spec isn't going to work. TODO(tapted): Something more |
| - // generic would be nice here, but that requires knowing the background color |
| - // for the text. At the time of writing, very few UI surfaces need native- |
| - // themed typography with a custom native theme. Typically just incognito |
| - // browser windows, when the native theme is NativeThemeDarkAura. |
| - if (foreground_color != SK_ColorBLACK) { |
| + if (ShouldIgnoreHarmonySpec(theme)) |
| + return GetHarmonyTextColorForNonStandardNativeTheme(context, style, theme); |
| + |
| + if (context == views::style::CONTEXT_BUTTON_MD) { |
| switch (style) { |
| + case views::style::STYLE_DIALOG_BUTTON_DEFAULT: |
| + return SK_ColorWHITE; |
| case views::style::STYLE_DISABLED: |
| - case STYLE_SECONDARY: |
| - case STYLE_HINT: |
| - return theme.GetSystemColor( |
| - ui::NativeTheme::kColorId_LabelDisabledColor); |
| - case views::style::STYLE_LINK: |
| - return theme.GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| - case STYLE_RED: |
| - return foreground_color == SK_ColorWHITE ? gfx::kGoogleRed300 |
| - : gfx::kGoogleRed700; |
| - case STYLE_GREEN: |
| - return foreground_color == SK_ColorWHITE ? gfx::kGoogleGreen300 |
| - : gfx::kGoogleGreen700; |
| + 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
|
| + default: |
| + 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
|
| } |
| - return foreground_color; |
| } |
| switch (style) { |