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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85e2c8384d568297c5ee71986a883e5d7977d66e |
--- /dev/null |
+++ b/chrome/browser/ui/views/harmony/harmony_typography_provider.cc |
@@ -0,0 +1,122 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/harmony/harmony_typography_provider.h" |
+ |
+#include "chrome/browser/ui/views/harmony/chrome_typography.h" |
+#include "ui/base/resource/resource_bundle.h" |
+ |
+const gfx::FontList& HarmonyTypographyProvider::GetFont(int text_context, |
+ int text_style) const { |
+ // "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
|
+ constexpr int kHeadlineSize = 20; |
+ constexpr int kTitleSize = 15; |
+ constexpr int kBodyTextLargeSize = 13; |
+ constexpr int kDefaultSize = 12; |
+ |
+#if defined(OS_WIN) |
+ constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::BOLD; |
+#else |
+ constexpr gfx::Font::Weight kButtonFontWeight = gfx::Font::Weight::MEDIUM; |
+#endif |
+ |
+// The size that a default-constructed gfx::PlatformFont returns in a default |
+// 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
|
+#if defined(OS_MACOSX) |
+ constexpr int kPlatformFontSize = 13; |
+#else |
+ constexpr int kPlatformFontSize = 12; |
+#endif |
+ |
+ int size_delta = kDefaultSize - kPlatformFontSize; |
+ gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; |
+ switch (text_context) { |
+ case CONTEXT_HEADLINE: |
+ size_delta = kHeadlineSize - kPlatformFontSize; |
+ break; |
+ case views::style::CONTEXT_DIALOG_TITLE: |
+ size_delta = kTitleSize - kPlatformFontSize; |
+ break; |
+ case CONTEXT_BODY_TEXT_LARGE: |
+ size_delta = kBodyTextLargeSize - kPlatformFontSize; |
+ break; |
+ case views::style::CONTEXT_BUTTON: |
+ 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
|
+ default: |
+ break; |
+ } |
+ |
+ // Ignore |text_style| since it only affects color in the Harmony spec. |
+ return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
+ size_delta, gfx::Font::NORMAL, font_weight); |
+} |
+ |
+SkColor HarmonyTypographyProvider::GetColor(int text_context, |
+ int text_style) const { |
+ 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.
|
+} |
+ |
+int HarmonyTypographyProvider::GetLineHeight(int text_context, |
+ int text_style) const { |
+ // "Target" line height constants from the Harmony spec. A default OS |
+ // configuration should use these heights. However, if the user overrides OS |
+ // defaults, then GetLineHeight() should return the height that would add the |
+ // same extra space between lines as the default configuration would have. |
+ constexpr int kHeadlineHeight = 32; |
+ constexpr int kTitleHeight = 22; |
+ constexpr int kBodyHeight = 20; // For both large and small. |
+ |
+ // Button text should always use the minimum line height for a font to avoid |
+ // unnecessarily influencing the height of a button. |
+ constexpr int kButtonAbsoluteHeight = 0; |
+ |
+// The platform-specific heights (i.e. gfx::Font::GetHeight()) that result when |
+// asking for the target size constants in HarmonyTypographyProvider::GetFont() |
+// in a default OS configuration. |
+#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
|
+ constexpr int kHeadlinePlatformHeight = 25; |
+ constexpr int kTitlePlatformHeight = 19; |
+ constexpr int kBodyTextLargePlatformHeight = 16; |
+ constexpr int kBodyTextSmallPlatformHeight = 15; |
+#elif defined(OS_WIN) |
+ constexpr int kHeadlinePlatformHeight = 28; |
+ constexpr int kTitlePlatformHeight = 20; |
+ constexpr int kBodyTextLargePlatformHeight = 17; |
+ constexpr int kBodyTextSmallPlatformHeight = 15; |
+#else |
+ constexpr int kHeadlinePlatformHeight = 24; |
+ constexpr int kTitlePlatformHeight = 18; |
+ constexpr int kBodyTextLargePlatformHeight = 17; |
+ constexpr int kBodyTextSmallPlatformHeight = 15; |
+#endif |
+ |
+ // The style of the system font used to determine line heights. |
+ constexpr int kTemplateStyle = views::style::STYLE_PRIMARY; |
+ |
+ 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.
|
+ GetFont(CONTEXT_HEADLINE, kTemplateStyle).GetHeight() - |
+ kHeadlinePlatformHeight + kHeadlineHeight; |
+ static const int title_height = |
+ GetFont(views::style::CONTEXT_DIALOG_TITLE, kTemplateStyle).GetHeight() - |
+ kTitlePlatformHeight + kTitleHeight; |
+ static const int body_large_height = |
+ GetFont(CONTEXT_BODY_TEXT_LARGE, kTemplateStyle).GetHeight() - |
+ kBodyTextLargePlatformHeight + kBodyHeight; |
+ static const int default_height = |
+ GetFont(CONTEXT_BODY_TEXT_SMALL, kTemplateStyle).GetHeight() - |
+ kBodyTextSmallPlatformHeight + kBodyHeight; |
+ |
+ switch (text_context) { |
+ case CONTEXT_HEADLINE: |
+ return headline_height; |
+ case views::style::CONTEXT_DIALOG_TITLE: |
+ return title_height; |
+ case CONTEXT_BODY_TEXT_LARGE: |
+ return body_large_height; |
+ case views::style::CONTEXT_BUTTON: |
+ return kButtonAbsoluteHeight; |
+ default: |
+ return default_height; |
+ } |
+} |