Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 10 const gfx::FontList& HarmonyTypographyProvider::GetFont(int text_context, | |
| 11 int text_style) const { | |
| 12 // "Target" font size constants from the Harmony spec. | |
|
Peter Kasting
2017/04/04 00:47:58
Nit: I feel weakly like it might be better to defi
tapted
2017/04/04 06:23:00
The goal here is to call out the magic numbers tha
| |
| 13 constexpr int kHeadlineSize = 20; | |
| 14 constexpr int kTitleSize = 15; | |
| 15 constexpr int kBodyTextLargeSize = 13; | |
| 16 constexpr int kDefaultSize = 12; | |
| 17 | |
| 18 #if defined(OS_WIN) | |
| 19 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::BOLD; | |
| 20 #else | |
| 21 constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::MEDIUM; | |
| 22 #endif | |
| 23 | |
| 24 // The size that a default-constructed gfx::PlatformFont returns in a default | |
| 25 // OS configuration. | |
|
Peter Kasting
2017/04/04 00:47:58
Ultimately, can this be computed (once) at runtime
tapted
2017/04/04 06:23:00
I don't think it can be computed at runtime, since
| |
| 26 #if defined(OS_MACOSX) | |
| 27 constexpr int kPlatformFontSize = 13; | |
| 28 #else | |
| 29 constexpr int kPlatformFontSize = 12; | |
| 30 #endif | |
| 31 | |
| 32 int size_delta = kDefaultSize - kPlatformFontSize; | |
| 33 gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; | |
| 34 switch (text_context) { | |
| 35 case CONTEXT_HEADLINE: | |
| 36 size_delta = kHeadlineSize - kPlatformFontSize; | |
| 37 break; | |
| 38 case views::style::CONTEXT_DIALOG_TITLE: | |
| 39 size_delta = kTitleSize - kPlatformFontSize; | |
| 40 break; | |
| 41 case CONTEXT_BODY_TEXT_LARGE: | |
| 42 size_delta = kBodyTextLargeSize - kPlatformFontSize; | |
| 43 break; | |
| 44 case views::style::CONTEXT_BUTTON: | |
| 45 font_weight = kButtonFontWeight; | |
|
Peter Kasting
2017/04/04 00:47:58
Nit: Put break; after (no functional effect now, c
tapted
2017/04/04 06:22:59
Done. (I am ashamed to admit that I don't think th
| |
| 46 default: | |
| 47 break; | |
| 48 } | |
| 49 | |
| 50 // Ignore |text_style| since it only affects color in the Harmony spec. | |
| 51 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | |
| 52 size_delta, gfx::Font::NORMAL, font_weight); | |
| 53 } | |
| 54 | |
| 55 SkColor HarmonyTypographyProvider::GetColor(int text_context, | |
| 56 int text_style) const { | |
| 57 return SK_ColorBLACK; | |
|
Peter Kasting
2017/04/04 00:47:58
Nit: Maybe a TODO? Prolly not necessary I guess
tapted
2017/04/04 06:23:00
Done.
| |
| 58 } | |
| 59 | |
| 60 int HarmonyTypographyProvider::GetLineHeight(int text_context, | |
| 61 int text_style) const { | |
| 62 // "Target" line height constants from the Harmony spec. A default OS | |
| 63 // configuration should use these heights. However, if the user overrides OS | |
| 64 // defaults, then GetLineHeight() should return the height that would add the | |
| 65 // same extra space between lines as the default configuration would have. | |
| 66 constexpr int kHeadlineHeight = 32; | |
| 67 constexpr int kTitleHeight = 22; | |
| 68 constexpr int kBodyHeight = 20; // For both large and small. | |
| 69 | |
| 70 // Button text should always use the minimum line height for a font to avoid | |
| 71 // unnecessarily influencing the height of a button. | |
| 72 constexpr int kButtonAbsoluteHeight = 0; | |
| 73 | |
| 74 // The platform-specific heights (i.e. gfx::Font::GetHeight()) that result when | |
| 75 // asking for the target size constants in HarmonyTypographyProvider::GetFont() | |
| 76 // in a default OS configuration. | |
| 77 #if defined(OS_MACOSX) | |
|
Peter Kasting
2017/04/04 00:47:58
For all platforms, I wonder if these values are re
tapted
2017/04/04 06:23:00
So, like you say, I'm quite certain that these are
Peter Kasting
2017/04/04 08:01:17
I sent email to Alan & co. asking how, theoretical
| |
| 78 constexpr int kHeadlinePlatformHeight = 25; | |
| 79 constexpr int kTitlePlatformHeight = 19; | |
| 80 constexpr int kBodyTextLargePlatformHeight = 16; | |
| 81 constexpr int kBodyTextSmallPlatformHeight = 15; | |
| 82 #elif defined(OS_WIN) | |
| 83 constexpr int kHeadlinePlatformHeight = 28; | |
| 84 constexpr int kTitlePlatformHeight = 20; | |
| 85 constexpr int kBodyTextLargePlatformHeight = 17; | |
| 86 constexpr int kBodyTextSmallPlatformHeight = 15; | |
| 87 #else | |
| 88 constexpr int kHeadlinePlatformHeight = 24; | |
| 89 constexpr int kTitlePlatformHeight = 18; | |
| 90 constexpr int kBodyTextLargePlatformHeight = 17; | |
| 91 constexpr int kBodyTextSmallPlatformHeight = 15; | |
| 92 #endif | |
| 93 | |
| 94 // The style of the system font used to determine line heights. | |
| 95 constexpr int kTemplateStyle = views::style::STYLE_PRIMARY; | |
| 96 | |
| 97 static const int headline_height = | |
|
Peter Kasting
2017/04/04 00:47:58
These statics worry me w.r.t. handling native them
tapted
2017/04/04 06:23:00
We'd need to clear a lot more than these statics -
Peter Kasting
2017/04/06 06:17:07
I think we should file a bug saying that when we g
tapted
2017/04/06 09:11:09
Filed http://crbug.com/708943 and noted it here.
| |
| 98 GetFont(CONTEXT_HEADLINE, kTemplateStyle).GetHeight() - | |
| 99 kHeadlinePlatformHeight + kHeadlineHeight; | |
| 100 static const int title_height = | |
| 101 GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - | |
| 102 kTitlePlatformHeight + kTitleHeight; | |
| 103 static const int body_large_height = | |
| 104 GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - | |
| 105 kBodyTextLargePlatformHeight + kBodyHeight; | |
| 106 static const int default_height = | |
| 107 GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - | |
| 108 kBodyTextSmallPlatformHeight + kBodyHeight; | |
| 109 | |
| 110 switch (text_context) { | |
| 111 case CONTEXT_HEADLINE: | |
| 112 return headline_height; | |
| 113 case views::style::CONTEXT_DIALOG_TITLE: | |
| 114 return title_height; | |
| 115 case CONTEXT_BODY_TEXT_LARGE: | |
| 116 return body_large_height; | |
| 117 case views::style::CONTEXT_BUTTON: | |
| 118 return kButtonAbsoluteHeight; | |
| 119 default: | |
| 120 return default_height; | |
| 121 } | |
| 122 } | |
| OLD | NEW |