Index: ui/views/style/typography.cc |
diff --git a/ui/views/style/typography.cc b/ui/views/style/typography.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddfaf587a926d4a29a4dbc1fe009cb7523c9bedf |
--- /dev/null |
+++ b/ui/views/style/typography.cc |
@@ -0,0 +1,107 @@ |
+// 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 "ui/views/style/typography.h" |
+ |
+#include "base/logging.h" |
+#include "ui/base/default_style.h" |
+#include "ui/base/resource/resource_bundle.h" |
+ |
+namespace views { |
+namespace { |
+ |
+constexpr int kHeadlineDelta = 8; |
+constexpr int kDialogMessageDelta = 1; |
Peter Kasting
2017/03/14 23:53:33
Nit: I tend to find it easier to understand when c
tapted
2017/03/15 08:26:24
Done.
|
+ |
+// The default provider aims to provide values to match pre-Harmony constants |
+// for the given contexts so that old UI does not change. |
+class DefaultProvider : public TypographyProvider { |
+ public: |
+ DefaultProvider() {} |
+ |
+ const gfx::FontList& GetFont(TextContext context, TextStyle style) override; |
+ SkColor GetColor(TextContext context, TextStyle style) override; |
+ int GetLineSpacing(TextContext context, TextStyle style) override; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DefaultProvider); |
+}; |
+ |
+const gfx::FontList& DefaultProvider::GetFont(TextContext context, |
+ TextStyle style) { |
+ int size_delta = 0; |
+ gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; |
Peter Kasting
2017/03/14 23:53:33
Nit: Declare this as close to first use as possibl
tapted
2017/03/15 08:26:24
Done.
|
+ switch (context) { |
+ case TextContext::HEADLINE: |
+ size_delta = kHeadlineDelta; |
+ break; |
+ case TextContext::DIALOG_TITLE: |
+ size_delta = ui::kTitleFontSizeDelta; |
+ break; |
+ case TextContext::DIALOG_MESSAGE: |
+ // Note: Not using ui::kMessageFontSizeDelta, so is 13pt in most cases. |
+ size_delta = kDialogMessageDelta; |
+ break; |
+ case TextContext::DIALOG_TEXT_SMALL: |
+ case TextContext::CONTROL_LABEL: |
+ case TextContext::FIELD: |
+ case TextContext::BUTTON_TEXT: |
+ size_delta = ui::kLabelFontSizeDelta; |
+ break; |
+ case TextContext::DEPRECATED_SMALL: |
+ size_delta = ResourceBundle::kSmallFontDelta; |
+ break; |
+ } |
+ switch (style) { |
+ case TextStyle::WEB_DOMAIN: |
+ case TextStyle::ACTIVE_TAB: |
+ case TextStyle::EXTENSION_NAME: |
+ font_weight = gfx::Font::Weight::BOLD; |
+ break; |
+ default: |
+ break; |
+ } |
+ constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL; |
+ return ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
+ size_delta, kFontStyle, font_weight); |
+} |
+ |
+SkColor DefaultProvider::GetColor(TextContext context, TextStyle style) { |
+ return SK_ColorBLACK; |
+} |
+ |
+int DefaultProvider::GetLineSpacing(TextContext context, TextStyle style) { |
+ return 0; |
+} |
+ |
+std::unique_ptr<TypographyProvider>& Storage() { |
+ CR_DEFINE_STATIC_LOCAL(std::unique_ptr<TypographyProvider>, storage, |
+ (new DefaultProvider)); |
Peter Kasting
2017/03/14 23:53:33
Hmm. Using a unique_ptr here is kind of a mess.
tapted
2017/03/15 08:26:24
Why do we need cleanup in that case? Threads on ch
Peter Kasting
2017/03/15 10:01:48
We need to avoid leaking the thing we're replacing
tapted
2017/03/15 11:04:06
I think that's taken care of - Storage() exposes i
Peter Kasting
2017/03/15 17:52:47
That was my point -- the unique_ptr is the thing t
tapted
2017/03/15 22:43:34
I'm going to try piggy-backing off the ViewsDelega
|
+ return storage; |
+} |
+ |
+} // namespace |
+ |
+// static |
+void Typography::SetProvider(std::unique_ptr<TypographyProvider> provider) { |
+ DCHECK(provider); |
+ Storage() = std::move(provider); |
+} |
+ |
+// static |
+const gfx::FontList& Typography::GetFont(TextContext context, TextStyle style) { |
+ return Storage()->GetFont(context, style); |
+} |
+ |
+// static |
+SkColor Typography::GetColor(TextContext context, TextStyle style) { |
+ return Storage()->GetColor(context, style); |
+} |
+ |
+// static |
+int Typography::GetLineSpacing(TextContext context, TextStyle style) { |
+ return Storage()->GetLineSpacing(context, style); |
+} |
+ |
+} // namespace views |