Chromium Code Reviews| 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..c769cd268693716ab5817943d201765ef5006058 |
| --- /dev/null |
| +++ b/ui/views/style/typography.h |
| @@ -0,0 +1,102 @@ |
| +// 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 "ui/views/views_export.h" |
| + |
| +namespace views { |
| + |
| +// An enum class that can be extended by embedders without losing type safety or |
| +// the ability to use values in switch statements. Except for the way the values |
| +// are declared, the syntax for using an ExtendableEnum should be the same as a |
| +// regular enum class. Uses default copy constructor and assignment operators |
| +// but note that conversion/assignment between different template types is not |
| +// permitted. |
| +template <class ENUM> |
| +class ExtendableEnum { |
| + public: |
| + // Used to declare the enum constants. |
| + class Value; // Inherits from this, so can't be defined inline. |
| + |
| + // The enum value, available at compile time when using a Value directly. |
| + constexpr int value() const { return value_; } |
| + |
| + protected: |
| + explicit constexpr ExtendableEnum(int value) : value_(value) {} |
| + |
| + private: |
| + int value_; |
| +}; |
| + |
| +template <class ENUM> |
| +class ExtendableEnum<ENUM>::Value : public ExtendableEnum<ENUM> { |
| + public: |
| + // Allows use in switch case statements. |
| + constexpr operator int() const { return this->value(); } |
| + |
| + // Allow implicit initialization from an integer literal. |
| + constexpr Value(int const_value) : ExtendableEnum(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> { |
| + public: |
| + // A title for a dialog window. Usually 15pt. Multi-line OK. |
| + static constexpr const Value DIALOG_TITLE = 1; |
|
Peter Kasting
2017/03/15 10:01:48
I don't think you need both constexpr and const on
tapted
2017/03/16 11:13:39
You are correct! (but, no longer using this)
|
| + |
| + // "Body 2". Usually 12pt. |
| + static constexpr const Value CONTROL_LABEL = 3; |
|
Peter Kasting
2017/03/15 10:01:48
Skipped 2
tapted
2017/03/16 11:13:39
no longer using this (it is perilous, clearly ;)
|
| + |
| + // A text field. Usually matches CONTROL_LABEL. |
| + static constexpr const Value FIELD = 4; |
| + |
| + // Text that appears on a button control. Usually 12pt. |
| + static constexpr const Value BUTTON_TEXT = 5; |
| + |
| + // 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 = 15 }; |
|
Peter Kasting
2017/03/15 10:01:48
15? (2 places)
tapted
2017/03/15 11:04:07
I guess I was going for
- a buffer
- not too big
Peter Kasting
2017/03/15 17:52:47
Do we need a buffer? That's only important if the
tapted
2017/03/16 11:13:39
buffer thinking was that there would be less chanc
|
| +}; |
| + |
| +// How a piece of text should be presented. This influences color and style, but |
| +// typically not size. |
| +class VIEWS_EXPORT TextStyle : public ExtendableEnum<TextStyle> { |
| + public: |
| + // Primary text: solid black, normal weight. Converts to DISABLED in some |
| + // contexts (e.g. BUTTON_TEXT, FIELD). |
| + static constexpr const Value PRIMARY = 1; |
| + |
| + // Disabled "greyed out" text. |
| + static constexpr const Value DISABLED = 2; |
| + |
| + // A solid shade of blue. |
| + static constexpr const Value LINK = 3; |
| + |
| + // Active tab in a tabbed pane. |
| + static constexpr const Value ACTIVE_TAB = 4; |
| + |
| + // Inactive tab in a tabbed pane. |
| + static constexpr const Value INACTIVE_TAB = 5; |
| + |
| + // Hovered tab in a tabbed pane. |
| + static constexpr const Value HOVERED_TAB = 6; |
| + |
| + constexpr TextStyle(const Value& value) : ExtendableEnum(value.value()) {} |
| + constexpr TextStyle() : ExtendableEnum(0) {} |
| + |
| + protected: |
| + enum { VIEWS_MAX = 15 }; |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // UI_VIEWS_STYLE_TYPOGRAPHY_H_ |