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. | |
70 if (foreground_color != SK_ColorBLACK) { | |
71 switch (style) { | |
72 case views::style::STYLE_DISABLED: | |
73 case STYLE_SECONDARY: | |
74 case STYLE_HINT: | |
75 return theme.GetSystemColor( | |
76 ui::NativeTheme::kColorId_LabelDisabledColor); | |
77 case views::style::STYLE_LINK: | |
78 return theme.GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | |
79 case STYLE_RED: | |
80 return foreground_color == SK_ColorWHITE ? gfx::kGoogleRed300 | |
81 : gfx::kGoogleRed700; | |
Peter Kasting
2017/06/01 19:08:01
Can we handle this automatically by doing somethin
tapted
2017/06/02 01:29:15
Getting the background color in a generic way is r
| |
82 case STYLE_GREEN: | |
83 return foreground_color == SK_ColorWHITE ? gfx::kGoogleGreen300 | |
84 : gfx::kGoogleGreen700; | |
85 } | |
86 return foreground_color; | |
87 } | |
88 | |
89 switch (style) { | |
90 case views::style::STYLE_DIALOG_BUTTON_DEFAULT: | |
91 return SK_ColorWHITE; | |
92 case views::style::STYLE_DISABLED: | |
93 return SkColorSetRGB(0x9e, 0x9e, 0x9e); | |
94 case views::style::STYLE_LINK: | |
95 return gfx::kGoogleBlue700; | |
96 case STYLE_SECONDARY: | |
97 case STYLE_HINT: | |
98 return SkColorSetRGB(0x75, 0x75, 0x75); | |
99 case STYLE_RED: | |
100 return gfx::kGoogleRed700; | |
101 case STYLE_GREEN: | |
102 return gfx::kGoogleGreen700; | |
103 } | |
104 return SkColorSetRGB(0x21, 0x21, 0x21); // Primary for everything else. | |
63 } | 105 } |
64 | 106 |
65 int HarmonyTypographyProvider::GetLineHeight(int text_context, | 107 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 | 108 // "Target" line height constants from the Harmony spec. A default OS |
68 // configuration should use these heights. However, if the user overrides OS | 109 // configuration should use these heights. However, if the user overrides OS |
69 // defaults, then GetLineHeight() should return the height that would add the | 110 // defaults, then GetLineHeight() should return the height that would add the |
70 // same extra space between lines as the default configuration would have. | 111 // same extra space between lines as the default configuration would have. |
71 constexpr int kHeadlineHeight = 32; | 112 constexpr int kHeadlineHeight = 32; |
72 constexpr int kTitleHeight = 22; | 113 constexpr int kTitleHeight = 22; |
73 constexpr int kBodyHeight = 20; // For both large and small. | 114 constexpr int kBodyHeight = 20; // For both large and small. |
74 | 115 |
75 // Button text should always use the minimum line height for a font to avoid | 116 // Button text should always use the minimum line height for a font to avoid |
76 // unnecessarily influencing the height of a button. | 117 // 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 = | 150 static const int title_height = |
110 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - | 151 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - |
111 kTitlePlatformHeight + kTitleHeight; | 152 kTitlePlatformHeight + kTitleHeight; |
112 static const int body_large_height = | 153 static const int body_large_height = |
113 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - | 154 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - |
114 kBodyTextLargePlatformHeight + kBodyHeight; | 155 kBodyTextLargePlatformHeight + kBodyHeight; |
115 static const int default_height = | 156 static const int default_height = |
116 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - | 157 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - |
117 kBodyTextSmallPlatformHeight + kBodyHeight; | 158 kBodyTextSmallPlatformHeight + kBodyHeight; |
118 | 159 |
119 switch (text_context) { | 160 switch (context) { |
120 case views::style::CONTEXT_BUTTON: | 161 case views::style::CONTEXT_BUTTON: |
121 case views::style::CONTEXT_BUTTON_MD: | 162 case views::style::CONTEXT_BUTTON_MD: |
122 return kButtonAbsoluteHeight; | 163 return kButtonAbsoluteHeight; |
123 case views::style::CONTEXT_DIALOG_TITLE: | 164 case views::style::CONTEXT_DIALOG_TITLE: |
124 return title_height; | 165 return title_height; |
125 case CONTEXT_BODY_TEXT_LARGE: | 166 case CONTEXT_BODY_TEXT_LARGE: |
126 return body_large_height; | 167 return body_large_height; |
127 case CONTEXT_HEADLINE: | 168 case CONTEXT_HEADLINE: |
128 return headline_height; | 169 return headline_height; |
129 default: | 170 default: |
130 return default_height; | 171 return default_height; |
131 } | 172 } |
132 } | 173 } |
OLD | NEW |