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 #ifndef UI_VIEWS_STYLE_TYPOGRAPHY_H_ | |
| 6 #define UI_VIEWS_STYLE_TYPOGRAPHY_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "third_party/skia/include/core/SkColor.h" | |
| 12 #include "ui/views/views_export.h" | |
| 13 | |
| 14 namespace gfx { | |
| 15 class FontList; | |
| 16 } | |
| 17 | |
| 18 namespace views { | |
| 19 | |
| 20 template <class ENUM> | |
| 21 class ExtendableEnum { | |
| 22 public: | |
| 23 class Value; | |
| 24 explicit constexpr ExtendableEnum(int value) : value_(value) {} | |
| 25 constexpr int value() const { return value_; } | |
| 26 | |
| 27 private: | |
| 28 int value_; | |
| 29 }; | |
| 30 | |
| 31 template <class ENUM> | |
| 32 class ExtendableEnum<ENUM>::Value : public ExtendableEnum<ENUM> { | |
| 33 public: | |
| 34 // Allows use in switch statements. | |
| 35 constexpr operator int() const { return this->value(); } | |
| 36 | |
| 37 // Allow implicit initialization from an integer literal. | |
| 38 constexpr Value(int const_value) : ExtendableEnum<ENUM>(const_value) {} | |
| 39 }; | |
| 40 | |
| 41 // Where a piece of text appears in the UI. This influences size and weight, but | |
| 42 // typically not style or color. | |
| 43 class VIEWS_EXPORT TextContext : public ExtendableEnum<TextContext> { | |
|
tapted
2017/03/15 00:30:05
Still working on the rest, but I came up with this
Peter Kasting
2017/03/15 06:38:48
Hmm. My take on this is that overall this feels m
tapted
2017/03/15 08:26:25
The problem I see is that TextContext and TextStyl
Peter Kasting
2017/03/15 10:01:48
Hmm. The confusion between those two is a fair th
tapted
2017/03/15 11:04:07
I think if we split the class like that we never b
tapted
2017/03/15 22:43:35
I dreamed up a way that would let us have an enum
Peter Kasting
2017/03/16 00:17:47
Yeah, that'd work.
Heck, make it a bitfield and j
| |
| 44 public: | |
| 45 // Headline text. Usually 20pt. Never multi-line. | |
| 46 static constexpr const Value HEADLINE = 1; | |
| 47 | |
| 48 // A title for a dialog window. Usually 15pt. Multi-line OK. | |
| 49 static constexpr const Value DIALOG_TITLE = 2; | |
| 50 | |
| 51 // "Body 1". Usually 13pt. | |
| 52 static constexpr const Value DIALOG_MESSAGE = 3; | |
| 53 | |
| 54 // "Body 2". Usually 12pt. | |
| 55 static constexpr const Value CONTROL_LABEL = 4; | |
| 56 | |
| 57 // A text field. Usually matches CONTROL_LABEL. | |
| 58 static constexpr const Value FIELD = 5; | |
| 59 | |
| 60 // Text that appears on a button control. Usually 12pt. | |
| 61 static constexpr const Value BUTTON_TEXT = 6; | |
| 62 | |
| 63 // Allow implicit conversion from the constants above. | |
| 64 constexpr TextContext(const Value& value) : ExtendableEnum(value.value()) {} | |
| 65 | |
| 66 // Allow declaration without assignment. | |
| 67 constexpr TextContext() : ExtendableEnum(0) {} | |
| 68 | |
| 69 protected: | |
| 70 enum { VIEWS_MAX = 20 }; | |
| 71 }; | |
| 72 | |
| 73 // How a piece of text should be presented. This influences color and style, but | |
| 74 // typically not size. | |
| 75 enum class TextStyle { | |
| 76 // Primary text: solid black, normal weight. Converts to DISABLED in some | |
| 77 // contexts (e.g. BUTTON_TEXT, FIELD). | |
| 78 PRIMARY, | |
| 79 | |
| 80 // Secondary text: may be lighter. | |
| 81 SECONDARY, | |
| 82 | |
| 83 // "Hint" text, usually a line that gives context to something more important. | |
| 84 HINT, | |
| 85 | |
| 86 DISABLED, // Disabled "greyed out" text. | |
| 87 RED, // A solid shade of red. | |
| 88 GREEN, // A solid shade of green. | |
| 89 LINK, // A solid shade of blue. | |
| 90 | |
| 91 // Legacy styles start here. | |
| 92 | |
| 93 ACTIVE_TAB, // Active tab in a tabbed pane. | |
| 94 INACTIVE_TAB, // Inactive tab in a tabbed pane. | |
| 95 HOVERED_TAB, // Hovered tab in a tabbed pane. | |
| 96 WEB_DOMAIN, // Used to draw attention to a web domain. | |
| 97 EXTENSION_NAME, // Used to draw attention to an extension name. | |
| 98 }; | |
| 99 | |
| 100 // Provides fonts to use in toolkit-views UI. | |
| 101 class VIEWS_EXPORT TypographyProvider { | |
| 102 public: | |
| 103 // Gets the FontList for the given |context| and |style|. | |
| 104 virtual const gfx::FontList& GetFont(TextContext context, | |
| 105 TextStyle style) = 0; | |
| 106 | |
| 107 // Gets the color for the given |context| and |style|. This may consult | |
| 108 // ui::NativeTheme. | |
| 109 virtual SkColor GetColor(TextContext context, TextStyle style) = 0; | |
| 110 | |
| 111 // Gets the line spacing, or 0 if it should be provided by gfx::FontList. | |
| 112 virtual int GetLineSpacing(TextContext context, TextStyle style) = 0; | |
| 113 | |
| 114 virtual ~TypographyProvider() {} | |
| 115 | |
| 116 protected: | |
| 117 TypographyProvider() {} | |
| 118 | |
| 119 private: | |
| 120 DISALLOW_COPY_AND_ASSIGN(TypographyProvider); | |
| 121 }; | |
| 122 | |
| 123 // Helper class to query (or change) the current TypographyProvider. | |
| 124 class VIEWS_EXPORT Typography { | |
| 125 public: | |
| 126 static void SetProvider(std::unique_ptr<TypographyProvider> provider); | |
| 127 | |
| 128 static const gfx::FontList& GetFont(TextContext context, TextStyle style); | |
| 129 static SkColor GetColor(TextContext context, TextStyle style); | |
| 130 static int GetLineSpacing(TextContext context, TextStyle style); | |
| 131 | |
| 132 private: | |
| 133 DISALLOW_IMPLICIT_CONSTRUCTORS(Typography); | |
| 134 }; | |
| 135 | |
| 136 } // namespace views | |
| 137 | |
| 138 #endif // UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ | |
| OLD | NEW |