Index: ui/views/style/typography.h |
diff --git a/ui/views/style/typography.h b/ui/views/style/typography.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..71b3b9cfab5bba22188b8ca972d934436247e8a5 |
--- /dev/null |
+++ b/ui/views/style/typography.h |
@@ -0,0 +1,138 @@ |
+// 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. |
+ |
+#ifndef UI_VIEWS_STYLE_TYPOGRAPHY_H_ |
+#define UI_VIEWS_STYLE_TYPOGRAPHY_H_ |
+ |
+#include <memory> |
+ |
+#include "base/macros.h" |
+#include "third_party/skia/include/core/SkColor.h" |
+#include "ui/views/views_export.h" |
+ |
+namespace gfx { |
+class FontList; |
+} |
+ |
+namespace views { |
+ |
+template <class ENUM> |
+class ExtendableEnum { |
+ public: |
+ class Value; |
+ explicit constexpr ExtendableEnum(int value) : value_(value) {} |
+ constexpr int value() const { return value_; } |
+ |
+ private: |
+ int value_; |
+}; |
+ |
+template <class ENUM> |
+class ExtendableEnum<ENUM>::Value : public ExtendableEnum<ENUM> { |
+ public: |
+ // Allows use in switch statements. |
+ constexpr operator int() const { return this->value(); } |
+ |
+ // Allow implicit initialization from an integer literal. |
+ constexpr Value(int const_value) : ExtendableEnum<ENUM>(const_value) {} |
+}; |
+ |
+// Where a piece of text appears in the UI. This influences size and weight, but |
+// typically not style or color. |
+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
|
+ public: |
+ // Headline text. Usually 20pt. Never multi-line. |
+ static constexpr const Value HEADLINE = 1; |
+ |
+ // A title for a dialog window. Usually 15pt. Multi-line OK. |
+ static constexpr const Value DIALOG_TITLE = 2; |
+ |
+ // "Body 1". Usually 13pt. |
+ static constexpr const Value DIALOG_MESSAGE = 3; |
+ |
+ // "Body 2". Usually 12pt. |
+ static constexpr const Value CONTROL_LABEL = 4; |
+ |
+ // A text field. Usually matches CONTROL_LABEL. |
+ static constexpr const Value FIELD = 5; |
+ |
+ // Text that appears on a button control. Usually 12pt. |
+ static constexpr const Value BUTTON_TEXT = 6; |
+ |
+ // Allow implicit conversion from the constants above. |
+ constexpr TextContext(const Value& value) : ExtendableEnum(value.value()) {} |
+ |
+ // Allow declaration without assignment. |
+ constexpr TextContext() : ExtendableEnum(0) {} |
+ |
+ protected: |
+ enum { VIEWS_MAX = 20 }; |
+}; |
+ |
+// How a piece of text should be presented. This influences color and style, but |
+// typically not size. |
+enum class TextStyle { |
+ // Primary text: solid black, normal weight. Converts to DISABLED in some |
+ // contexts (e.g. BUTTON_TEXT, FIELD). |
+ PRIMARY, |
+ |
+ // Secondary text: may be lighter. |
+ SECONDARY, |
+ |
+ // "Hint" text, usually a line that gives context to something more important. |
+ HINT, |
+ |
+ DISABLED, // Disabled "greyed out" text. |
+ RED, // A solid shade of red. |
+ GREEN, // A solid shade of green. |
+ LINK, // A solid shade of blue. |
+ |
+ // Legacy styles start here. |
+ |
+ ACTIVE_TAB, // Active tab in a tabbed pane. |
+ INACTIVE_TAB, // Inactive tab in a tabbed pane. |
+ HOVERED_TAB, // Hovered tab in a tabbed pane. |
+ WEB_DOMAIN, // Used to draw attention to a web domain. |
+ EXTENSION_NAME, // Used to draw attention to an extension name. |
+}; |
+ |
+// Provides fonts to use in toolkit-views UI. |
+class VIEWS_EXPORT TypographyProvider { |
+ public: |
+ // Gets the FontList for the given |context| and |style|. |
+ virtual const gfx::FontList& GetFont(TextContext context, |
+ TextStyle style) = 0; |
+ |
+ // Gets the color for the given |context| and |style|. This may consult |
+ // ui::NativeTheme. |
+ virtual SkColor GetColor(TextContext context, TextStyle style) = 0; |
+ |
+ // Gets the line spacing, or 0 if it should be provided by gfx::FontList. |
+ virtual int GetLineSpacing(TextContext context, TextStyle style) = 0; |
+ |
+ virtual ~TypographyProvider() {} |
+ |
+ protected: |
+ TypographyProvider() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TypographyProvider); |
+}; |
+ |
+// Helper class to query (or change) the current TypographyProvider. |
+class VIEWS_EXPORT Typography { |
+ public: |
+ static void SetProvider(std::unique_ptr<TypographyProvider> provider); |
+ |
+ static const gfx::FontList& GetFont(TextContext context, TextStyle style); |
+ static SkColor GetColor(TextContext context, TextStyle style); |
+ static int GetLineSpacing(TextContext context, TextStyle style); |
+ |
+ private: |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(Typography); |
+}; |
+ |
+} // namespace views |
+ |
+#endif // UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ |