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

Side by Side Diff: ui/views/style/typography.cc

Issue 2734113006: "Bootstrap" a toolkit-views Typography spec. (Closed)
Patch Set: ExtendableEnum Created 3 years, 9 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 "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;
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;
35 switch (context.value()) {
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::CONTROL_LABEL:
47 case TextContext::FIELD:
48 case TextContext::BUTTON_TEXT:
49 size_delta = ui::kLabelFontSizeDelta;
50 break;
51 }
52 switch (style) {
53 case TextStyle::WEB_DOMAIN:
54 case TextStyle::ACTIVE_TAB:
55 case TextStyle::EXTENSION_NAME:
56 font_weight = gfx::Font::Weight::BOLD;
57 break;
58 default:
59 break;
60 }
61 constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL;
62 return ResourceBundle::GetSharedInstance().GetFontListWithDelta(
63 size_delta, kFontStyle, font_weight);
64 }
65
66 SkColor DefaultProvider::GetColor(TextContext context, TextStyle style) {
67 return SK_ColorBLACK;
68 }
69
70 int DefaultProvider::GetLineSpacing(TextContext context, TextStyle style) {
71 return 0;
72 }
73
74 std::unique_ptr<TypographyProvider>& Storage() {
75 CR_DEFINE_STATIC_LOCAL(std::unique_ptr<TypographyProvider>, storage,
76 (new DefaultProvider));
77 return storage;
78 }
79
80 } // namespace
81
82 // Linker storage.
83 const TextContext::Value TextContext::HEADLINE;
84 const TextContext::Value TextContext::DIALOG_TITLE;
85 const TextContext::Value TextContext::DIALOG_MESSAGE;
86 const TextContext::Value TextContext::CONTROL_LABEL;
87 const TextContext::Value TextContext::FIELD;
88 const TextContext::Value TextContext::BUTTON_TEXT;
89
90 // static
91 void Typography::SetProvider(std::unique_ptr<TypographyProvider> provider) {
92 DCHECK(provider);
93 Storage() = std::move(provider);
94 }
95
96 // static
97 const gfx::FontList& Typography::GetFont(TextContext context, TextStyle style) {
98 return Storage()->GetFont(context, style);
99 }
100
101 // static
102 SkColor Typography::GetColor(TextContext context, TextStyle style) {
103 return Storage()->GetColor(context, style);
104 }
105
106 // static
107 int Typography::GetLineSpacing(TextContext context, TextStyle style) {
108 return Storage()->GetLineSpacing(context, style);
109 }
110
111 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698