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..845a593fe56d5a6a1ec544ae483d47ede9856a58 |
| --- /dev/null |
| +++ b/ui/views/style/typography.h |
| @@ -0,0 +1,100 @@ |
| +// 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 { |
| + |
| +// Where a piece of text appears in the UI. This influences size and weight, but |
| +// typically not style or color. |
| +enum class TextContext { |
|
sky
2017/03/14 17:31:47
It seems fair to enumerate the places in views tha
Peter Kasting
2017/03/14 19:35:49
I chatted briefly with Scott about this, since it
tapted
2017/03/15 08:26:24
Done.
|
| + HEADLINE, // Headline text. Usually 20pt. Never multi-line. |
| + DIALOG_TITLE, // A title for a dialog window. Usually 15pt. Multi-line OK. |
| + DIALOG_MESSAGE, // "Body 1". Usually 13pt. |
| + DIALOG_TEXT_SMALL, // "Body 2". Usually 12pt. |
| + CONTROL_LABEL, // "Body 2". Usually 12pt. |
| + FIELD, // A text field. Usually matches CONTROL_LABEL. |
| + BUTTON_TEXT, // Text that appears on a button control. Usually 12pt. |
|
tapted
2017/03/14 09:56:18
BUTTON_TEXT is different in the spec, but DIALOG_T
|
| + |
| + // Transitional contexts. |
| + DEPRECATED_SMALL, // ResourceBundle::SmallFont (11 pt). |
| +}; |
| + |
| +// How a piece of text should be presented. This influences color and style, but |
| +// typically not size. |
| +enum class TextStyle { |
|
sky
2017/03/14 17:31:47
Similar comment as to TextContext. I'm ok with enu
tapted
2017/03/15 08:26:24
Done.
|
| + // 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. |
|
Peter Kasting
2017/03/14 23:53:33
Are these intended to be "deprecated, don't add us
tapted
2017/03/15 08:26:24
It's more about a set of styles that just don't ex
|
| + |
| + 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. |
|
Peter Kasting
2017/03/14 23:53:33
I admit it's not totally clear to me how this work
tapted
2017/03/15 08:26:24
I think it does and should. views::Label has a lin
Peter Kasting
2017/03/15 10:01:48
My worry here is that that means this line spacing
tapted
2017/03/15 11:04:06
(disclaimer: I'm not a typesetting expert) I think
tapted
2017/03/15 22:43:34
bettes@ recently pointed me to https://goto.google
|
| + virtual int GetLineSpacing(TextContext context, TextStyle style) = 0; |
| + |
| + virtual ~TypographyProvider() {} |
|
Peter Kasting
2017/03/14 23:53:34
Nit: I tend to prefer "= default" to "{}" as the w
tapted
2017/03/15 08:26:24
Done.
|
| + |
| + protected: |
| + TypographyProvider() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TypographyProvider); |
| +}; |
| + |
| +// Helper class to query (or change) the current TypographyProvider. |
|
Peter Kasting
2017/03/14 23:53:34
Hmm. Is this really just a way to group some rela
tapted
2017/03/15 08:26:24
Hm - conceptually, `Typography` also encapsulates
|
| +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_ |