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 "ui/views/style/typography.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/base/default_style.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 | |
| 11 namespace views { | |
| 12 namespace { | |
| 13 | |
| 14 constexpr int kHeadlineDelta = 8; | |
| 15 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.
| |
| 16 | |
| 17 // The default provider aims to provide values to match pre-Harmony constants | |
| 18 // for the given contexts so that old UI does not change. | |
| 19 class DefaultProvider : public TypographyProvider { | |
| 20 public: | |
| 21 DefaultProvider() {} | |
| 22 | |
| 23 const gfx::FontList& GetFont(TextContext context, TextStyle style) override; | |
| 24 SkColor GetColor(TextContext context, TextStyle style) override; | |
| 25 int GetLineSpacing(TextContext context, TextStyle style) override; | |
| 26 | |
| 27 private: | |
| 28 DISALLOW_COPY_AND_ASSIGN(DefaultProvider); | |
| 29 }; | |
| 30 | |
| 31 const gfx::FontList& DefaultProvider::GetFont(TextContext context, | |
| 32 TextStyle style) { | |
| 33 int size_delta = 0; | |
| 34 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.
| |
| 35 switch (context) { | |
| 36 case TextContext::HEADLINE: | |
| 37 size_delta = kHeadlineDelta; | |
| 38 break; | |
| 39 case TextContext::DIALOG_TITLE: | |
| 40 size_delta = ui::kTitleFontSizeDelta; | |
| 41 break; | |
| 42 case TextContext::DIALOG_MESSAGE: | |
| 43 // Note: Not using ui::kMessageFontSizeDelta, so is 13pt in most cases. | |
| 44 size_delta = kDialogMessageDelta; | |
| 45 break; | |
| 46 case TextContext::DIALOG_TEXT_SMALL: | |
| 47 case TextContext::CONTROL_LABEL: | |
| 48 case TextContext::FIELD: | |
| 49 case TextContext::BUTTON_TEXT: | |
| 50 size_delta = ui::kLabelFontSizeDelta; | |
| 51 break; | |
| 52 case TextContext::DEPRECATED_SMALL: | |
| 53 size_delta = ResourceBundle::kSmallFontDelta; | |
| 54 break; | |
| 55 } | |
| 56 switch (style) { | |
| 57 case TextStyle::WEB_DOMAIN: | |
| 58 case TextStyle::ACTIVE_TAB: | |
| 59 case TextStyle::EXTENSION_NAME: | |
| 60 font_weight = gfx::Font::Weight::BOLD; | |
| 61 break; | |
| 62 default: | |
| 63 break; | |
| 64 } | |
| 65 constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL; | |
| 66 return ResourceBundle::GetSharedInstance().GetFontListWithDelta( | |
| 67 size_delta, kFontStyle, font_weight); | |
| 68 } | |
| 69 | |
| 70 SkColor DefaultProvider::GetColor(TextContext context, TextStyle style) { | |
| 71 return SK_ColorBLACK; | |
| 72 } | |
| 73 | |
| 74 int DefaultProvider::GetLineSpacing(TextContext context, TextStyle style) { | |
| 75 return 0; | |
| 76 } | |
| 77 | |
| 78 std::unique_ptr<TypographyProvider>& Storage() { | |
| 79 CR_DEFINE_STATIC_LOCAL(std::unique_ptr<TypographyProvider>, storage, | |
| 80 (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
| |
| 81 return storage; | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 // static | |
| 87 void Typography::SetProvider(std::unique_ptr<TypographyProvider> provider) { | |
| 88 DCHECK(provider); | |
| 89 Storage() = std::move(provider); | |
| 90 } | |
| 91 | |
| 92 // static | |
| 93 const gfx::FontList& Typography::GetFont(TextContext context, TextStyle style) { | |
| 94 return Storage()->GetFont(context, style); | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 SkColor Typography::GetColor(TextContext context, TextStyle style) { | |
| 99 return Storage()->GetColor(context, style); | |
| 100 } | |
| 101 | |
| 102 // static | |
| 103 int Typography::GetLineSpacing(TextContext context, TextStyle style) { | |
| 104 return Storage()->GetLineSpacing(context, style); | |
| 105 } | |
| 106 | |
| 107 } // namespace views | |
| OLD | NEW |