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

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

Issue 2765883004: Implement Harmony typography spec. (Closed)
Patch Set: respond to comments Created 3 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/harmony/harmony_typography_provider.h"
6
7 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/platform_font.h"
10
11 const gfx::FontList& HarmonyTypographyProvider::GetFont(int text_context,
12 int text_style) const {
13 // "Target" font size constants from the Harmony spec.
14 constexpr int kHeadlineSize = 20;
15 constexpr int kTitleSize = 15;
16 constexpr int kBodyTextLargeSize = 13;
17 constexpr int kDefaultSize = 12;
18
19 #if defined(OS_WIN)
20 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::BOLD;
21 #else
22 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::MEDIUM;
23 #endif
24
25 int size_delta = kDefaultSize - gfx::PlatformFont::kDefaultBaseFontSize;
26 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL;
27 switch (text_context) {
28 case CONTEXT_HEADLINE:
29 size_delta = kHeadlineSize - gfx::PlatformFont::kDefaultBaseFontSize;
30 break;
31 case views::style::CONTEXT_DIALOG_TITLE:
32 size_delta = kTitleSize - gfx::PlatformFont::kDefaultBaseFontSize;
33 break;
34 case CONTEXT_BODY_TEXT_LARGE:
35 size_delta = kBodyTextLargeSize - gfx::PlatformFont::kDefaultBaseFontSize;
36 break;
37 case views::style::CONTEXT_BUTTON:
38 font_weight = kButtonFontWeight;
39 break;
40 default:
41 break;
42 }
43
44 // Ignore |text_style| since it only affects color in the Harmony spec.
45 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
46 size_delta, gfx::Font::NORMAL, font_weight);
47 }
48
49 SkColor HarmonyTypographyProvider::GetColor(int text_context,
50 int text_style) const {
51 // TODO(tapted): Look up colors from the spec.
52 return SK_ColorBLACK;
53 }
54
55 int HarmonyTypographyProvider::GetLineHeight(int text_context,
56 int text_style) const {
57 // "Target" line height constants from the Harmony spec. A default OS
58 // configuration should use these heights. However, if the user overrides OS
59 // defaults, then GetLineHeight() should return the height that would add the
60 // same extra space between lines as the default configuration would have.
61 constexpr int kHeadlineHeight = 32;
62 constexpr int kTitleHeight = 22;
63 constexpr int kBodyHeight = 20; // For both large and small.
64
65 // Button text should always use the minimum line height for a font to avoid
66 // unnecessarily influencing the height of a button.
67 constexpr int kButtonAbsoluteHeight = 0;
68
69 // The platform-specific heights (i.e. gfx::Font::GetHeight()) that result when
70 // asking for the target size constants in HarmonyTypographyProvider::GetFont()
71 // in a default OS configuration.
72 // TODO(tapted): Update these with constants specific to an OS point version.
73 #if defined(OS_MACOSX)
74 constexpr int kHeadlinePlatformHeight = 25;
75 constexpr int kTitlePlatformHeight = 19;
76 constexpr int kBodyTextLargePlatformHeight = 16;
77 constexpr int kBodyTextSmallPlatformHeight = 15;
78 #elif defined(OS_WIN)
79 constexpr int kHeadlinePlatformHeight = 28;
80 constexpr int kTitlePlatformHeight = 20;
81 constexpr int kBodyTextLargePlatformHeight = 17;
82 constexpr int kBodyTextSmallPlatformHeight = 15;
83 #else
84 constexpr int kHeadlinePlatformHeight = 24;
85 constexpr int kTitlePlatformHeight = 18;
86 constexpr int kBodyTextLargePlatformHeight = 17;
87 constexpr int kBodyTextSmallPlatformHeight = 15;
88 #endif
89
90 // The style of the system font used to determine line heights.
91 constexpr int kTemplateStyle = views::style::STYLE_PRIMARY;
92
93 // TODO(tapted): These statics should be cleared out when something invokes
94 // ResourceBundle::ReloadFonts(). Currently that only happens on ChromeOS.
95 // See http://crbug.com/708943.
96 static const int headline_height =
97 GetFont(CONTEXT_HEADLINE, kTemplateStyle).GetHeight() -
98 kHeadlinePlatformHeight + kHeadlineHeight;
99 static const int title_height =
100 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() -
101 kTitlePlatformHeight + kTitleHeight;
102 static const int body_large_height =
103 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() -
104 kBodyTextLargePlatformHeight + kBodyHeight;
105 static const int default_height =
106 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() -
107 kBodyTextSmallPlatformHeight + kBodyHeight;
108
109 switch (text_context) {
110 case CONTEXT_HEADLINE:
111 return headline_height;
112 case views::style::CONTEXT_DIALOG_TITLE:
113 return title_height;
114 case CONTEXT_BODY_TEXT_LARGE:
115 return body_large_height;
116 case views::style::CONTEXT_BUTTON:
117 return kButtonAbsoluteHeight;
118 default:
119 return default_height;
120 }
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698