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 "chrome/browser/ui/views/harmony/chrome_typography.h" | 7 #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/gfx/color_palette.h" |
9 #include "ui/gfx/platform_font.h" | 10 #include "ui/gfx/platform_font.h" |
| 11 #include "ui/native_theme/native_theme.h" |
10 | 12 |
11 #if defined(USE_ASH) | 13 #if defined(USE_ASH) |
12 #include "ash/public/cpp/ash_typography.h" // nogncheck | 14 #include "ash/public/cpp/ash_typography.h" // nogncheck |
13 #endif | 15 #endif |
14 | 16 |
15 const gfx::FontList& HarmonyTypographyProvider::GetFont(int text_context, | 17 const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, |
16 int text_style) const { | 18 int style) const { |
17 // "Target" font size constants from the Harmony spec. | 19 // "Target" font size constants from the Harmony spec. |
18 constexpr int kHeadlineSize = 20; | 20 constexpr int kHeadlineSize = 20; |
19 constexpr int kTitleSize = 15; | 21 constexpr int kTitleSize = 15; |
20 constexpr int kBodyTextLargeSize = 13; | 22 constexpr int kBodyTextLargeSize = 13; |
21 constexpr int kDefaultSize = 12; | 23 constexpr int kDefaultSize = 12; |
22 | 24 |
23 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
24 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::BOLD; | 26 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::BOLD; |
25 #else | 27 #else |
26 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::MEDIUM; | 28 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::MEDIUM; |
27 #endif | 29 #endif |
28 | 30 |
29 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize; | 31 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize; |
30 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; | 32 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; |
31 | 33 |
32 #if defined(USE_ASH) | 34 #if defined(USE_ASH) |
33 ash::ApplyAshFontStyles(text_context, text_style, &size_delta, &font_weight); | 35 ash::ApplyAshFontStyles(context, style, &size_delta, &font_weight); |
34 #endif | 36 #endif |
35 | 37 |
36 switch (text_context) { | 38 switch (context) { |
37 case views::style::CONTEXT_BUTTON_MD: | 39 case views::style::CONTEXT_BUTTON_MD: |
38 font_weight = WeightNotLighterThanNormal(kButtonFontWeight); | 40 font_weight = WeightNotLighterThanNormal(kButtonFontWeight); |
39 break; | 41 break; |
40 case views::style::CONTEXT_DIALOG_TITLE: | 42 case views::style::CONTEXT_DIALOG_TITLE: |
41 size_delta = kTitleSize - gfx::PlatformFont::kDefaultBaseFontSize; | 43 size_delta = kTitleSize - gfx::PlatformFont::kDefaultBaseFontSize; |
42 break; | 44 break; |
43 case CONTEXT_BODY_TEXT_LARGE: | 45 case CONTEXT_BODY_TEXT_LARGE: |
44 size_delta = kBodyTextLargeSize - gfx::PlatformFont::kDefaultBaseFontSize; | 46 size_delta = kBodyTextLargeSize - gfx::PlatformFont::kDefaultBaseFontSize; |
45 break; | 47 break; |
46 case CONTEXT_HEADLINE: | 48 case CONTEXT_HEADLINE: |
47 size_delta = kHeadlineSize - gfx::PlatformFont::kDefaultBaseFontSize; | 49 size_delta = kHeadlineSize - gfx::PlatformFont::kDefaultBaseFontSize; |
48 break; | 50 break; |
49 default: | 51 default: |
50 break; | 52 break; |
51 } | 53 } |
52 | 54 |
53 // Ignore |text_style| since it only affects color in the Harmony spec. | 55 // Ignore |style| since it only affects color in the Harmony spec. |
54 | 56 |
55 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 57 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
56 size_delta, gfx::Font::NORMAL, font_weight); | 58 size_delta, gfx::Font::NORMAL, font_weight); |
57 } | 59 } |
58 | 60 |
59 SkColor HarmonyTypographyProvider::GetColor(int text_context, | 61 SkColor HarmonyTypographyProvider::GetColor( |
60 int text_style) const { | 62 int context, |
61 // TODO(tapted): Look up colors from the spec. | 63 int style, |
62 return SK_ColorBLACK; | 64 const ui::NativeTheme& theme) const { |
| 65 const SkColor foreground_color = |
| 66 theme.GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); |
| 67 |
| 68 // If the default foreground color from the native theme isn't black, the rest |
| 69 // of the Harmony spec isn't going to work. TODO(tapted): Something more |
| 70 // generic would be nice here, but that requires knowing the background color |
| 71 // for the text. At the time of writing, very few UI surfaces need native- |
| 72 // themed typography with a custom native theme. Typically just incognito |
| 73 // browser windows, when the native theme is NativeThemeDarkAura. |
| 74 if (foreground_color != SK_ColorBLACK) { |
| 75 switch (style) { |
| 76 case views::style::STYLE_DISABLED: |
| 77 case STYLE_SECONDARY: |
| 78 case STYLE_HINT: |
| 79 return theme.GetSystemColor( |
| 80 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 81 case views::style::STYLE_LINK: |
| 82 return theme.GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| 83 case STYLE_RED: |
| 84 return foreground_color == SK_ColorWHITE ? gfx::kGoogleRed300 |
| 85 : gfx::kGoogleRed700; |
| 86 case STYLE_GREEN: |
| 87 return foreground_color == SK_ColorWHITE ? gfx::kGoogleGreen300 |
| 88 : gfx::kGoogleGreen700; |
| 89 } |
| 90 return foreground_color; |
| 91 } |
| 92 |
| 93 switch (style) { |
| 94 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: |
| 95 return SK_ColorWHITE; |
| 96 case views::style::STYLE_DISABLED: |
| 97 return SkColorSetRGB(0x9e, 0x9e, 0x9e); |
| 98 case views::style::STYLE_LINK: |
| 99 return gfx::kGoogleBlue700; |
| 100 case STYLE_SECONDARY: |
| 101 case STYLE_HINT: |
| 102 return SkColorSetRGB(0x75, 0x75, 0x75); |
| 103 case STYLE_RED: |
| 104 return gfx::kGoogleRed700; |
| 105 case STYLE_GREEN: |
| 106 return gfx::kGoogleGreen700; |
| 107 } |
| 108 return SkColorSetRGB(0x21, 0x21, 0x21); // Primary for everything else. |
63 } | 109 } |
64 | 110 |
65 int HarmonyTypographyProvider::GetLineHeight(int text_context, | 111 int HarmonyTypographyProvider::GetLineHeight(int context, int style) const { |
66 int text_style) const { | |
67 // "Target" line height constants from the Harmony spec. A default OS | 112 // "Target" line height constants from the Harmony spec. A default OS |
68 // configuration should use these heights. However, if the user overrides OS | 113 // configuration should use these heights. However, if the user overrides OS |
69 // defaults, then GetLineHeight() should return the height that would add the | 114 // defaults, then GetLineHeight() should return the height that would add the |
70 // same extra space between lines as the default configuration would have. | 115 // same extra space between lines as the default configuration would have. |
71 constexpr int kHeadlineHeight = 32; | 116 constexpr int kHeadlineHeight = 32; |
72 constexpr int kTitleHeight = 22; | 117 constexpr int kTitleHeight = 22; |
73 constexpr int kBodyHeight = 20; // For both large and small. | 118 constexpr int kBodyHeight = 20; // For both large and small. |
74 | 119 |
75 // Button text should always use the minimum line height for a font to avoid | 120 // Button text should always use the minimum line height for a font to avoid |
76 // unnecessarily influencing the height of a button. | 121 // unnecessarily influencing the height of a button. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 static const int title_height = | 154 static const int title_height = |
110 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - | 155 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - |
111 kTitlePlatformHeight + kTitleHeight; | 156 kTitlePlatformHeight + kTitleHeight; |
112 static const int body_large_height = | 157 static const int body_large_height = |
113 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - | 158 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - |
114 kBodyTextLargePlatformHeight + kBodyHeight; | 159 kBodyTextLargePlatformHeight + kBodyHeight; |
115 static const int default_height = | 160 static const int default_height = |
116 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - | 161 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - |
117 kBodyTextSmallPlatformHeight + kBodyHeight; | 162 kBodyTextSmallPlatformHeight + kBodyHeight; |
118 | 163 |
119 switch (text_context) { | 164 switch (context) { |
120 case views::style::CONTEXT_BUTTON: | 165 case views::style::CONTEXT_BUTTON: |
121 case views::style::CONTEXT_BUTTON_MD: | 166 case views::style::CONTEXT_BUTTON_MD: |
122 return kButtonAbsoluteHeight; | 167 return kButtonAbsoluteHeight; |
123 case views::style::CONTEXT_DIALOG_TITLE: | 168 case views::style::CONTEXT_DIALOG_TITLE: |
124 return title_height; | 169 return title_height; |
125 case CONTEXT_BODY_TEXT_LARGE: | 170 case CONTEXT_BODY_TEXT_LARGE: |
126 return body_large_height; | 171 return body_large_height; |
127 case CONTEXT_HEADLINE: | 172 case CONTEXT_HEADLINE: |
128 return headline_height; | 173 return headline_height; |
129 default: | 174 default: |
130 return default_height; | 175 return default_height; |
131 } | 176 } |
132 } | 177 } |
OLD | NEW |