OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ | 5 #ifndef UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ |
6 #define UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ | 6 #define UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "ui/gfx/font.h" | 10 #include "ui/gfx/font.h" |
11 #include "ui/views/views_export.h" | 11 #include "ui/views/views_export.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 class FontList; | 14 class FontList; |
15 } | 15 } |
16 | 16 |
| 17 namespace ui { |
| 18 class NativeTheme; |
| 19 } |
| 20 |
17 namespace views { | 21 namespace views { |
18 | 22 |
19 // Provides fonts to use in toolkit-views UI. | 23 // Provides fonts to use in toolkit-views UI. |
20 class VIEWS_EXPORT TypographyProvider { | 24 class VIEWS_EXPORT TypographyProvider { |
21 public: | 25 public: |
22 virtual ~TypographyProvider() = default; | 26 virtual ~TypographyProvider() = default; |
23 | 27 |
24 // Gets the FontList for the given |context| and |style|. | 28 // Gets the FontList for the given |context| and |style|. |
25 virtual const gfx::FontList& GetFont(int context, int style) const = 0; | 29 virtual const gfx::FontList& GetFont(int context, int style) const = 0; |
26 | 30 |
27 // Gets the color for the given |context| and |style|. This may consult | 31 // Gets the color for the given |context| and |style|, optionally consulting |
28 // ui::NativeTheme. | 32 // |theme|. |
29 virtual SkColor GetColor(int context, int style) const = 0; | 33 virtual SkColor GetColor(int context, |
| 34 int style, |
| 35 const ui::NativeTheme& theme) const = 0; |
30 | 36 |
31 // Gets the line spacing, or 0 if it should be provided by gfx::FontList. | 37 // Gets the line spacing, or 0 if it should be provided by gfx::FontList. |
32 virtual int GetLineHeight(int context, int style) const = 0; | 38 virtual int GetLineHeight(int context, int style) const = 0; |
33 | 39 |
34 // The system may indicate a "bold" UI font is preferred (e.g. by selecting | 40 // The system may indicate a "bold" UI font is preferred (e.g. by selecting |
35 // the "Bold" checkbox in Windows under "Change only the text size" in | 41 // the "Bold" checkbox in Windows under "Change only the text size" in |
36 // Control Panel). In this case, a user's gfx::Weight::NORMAL font will | 42 // Control Panel). In this case, a user's gfx::Weight::NORMAL font will |
37 // already be bold, and requesting a MEDIUM font will result in a font that is | 43 // already be bold, and requesting a MEDIUM font will result in a font that is |
38 // less bold. So this method returns NORMAL, if the NORMAL font is at least as | 44 // less bold. So this method returns NORMAL, if the NORMAL font is at least as |
39 // bold as |weight|. | 45 // bold as |weight|. |
40 static gfx::Font::Weight WeightNotLighterThanNormal(gfx::Font::Weight weight); | 46 static gfx::Font::Weight WeightNotLighterThanNormal(gfx::Font::Weight weight); |
41 | 47 |
42 protected: | 48 protected: |
43 TypographyProvider() = default; | 49 TypographyProvider() = default; |
44 | 50 |
45 private: | 51 private: |
46 DISALLOW_COPY_AND_ASSIGN(TypographyProvider); | 52 DISALLOW_COPY_AND_ASSIGN(TypographyProvider); |
47 }; | 53 }; |
48 | 54 |
49 // The default provider aims to provide values to match pre-Harmony constants | 55 // The default provider aims to provide values to match pre-Harmony constants |
50 // for the given contexts so that old UI does not change. | 56 // for the given contexts so that old UI does not change. |
51 class VIEWS_EXPORT DefaultTypographyProvider : public TypographyProvider { | 57 class VIEWS_EXPORT DefaultTypographyProvider : public TypographyProvider { |
52 public: | 58 public: |
53 DefaultTypographyProvider() = default; | 59 DefaultTypographyProvider() = default; |
54 | 60 |
55 // TypographyProvider: | 61 // TypographyProvider: |
56 const gfx::FontList& GetFont(int context, int style) const override; | 62 const gfx::FontList& GetFont(int context, int style) const override; |
57 SkColor GetColor(int context, int style) const override; | 63 SkColor GetColor(int context, |
| 64 int style, |
| 65 const ui::NativeTheme& theme) const override; |
58 int GetLineHeight(int context, int style) const override; | 66 int GetLineHeight(int context, int style) const override; |
59 | 67 |
60 // Sets the |size_delta| and |font_weight| that the the default GetFont() | 68 // Sets the |size_delta| and |font_weight| that the the default GetFont() |
61 // implementation uses. Always sets values, even for styles it doesn't know | 69 // implementation uses. Always sets values, even for styles it doesn't know |
62 // about. | 70 // about. |
63 static void GetDefaultFont(int context, | 71 static void GetDefaultFont(int context, |
64 int style, | 72 int style, |
65 int* size_delta, | 73 int* size_delta, |
66 gfx::Font::Weight* font_weight); | 74 gfx::Font::Weight* font_weight); |
67 | 75 |
68 private: | 76 private: |
69 DISALLOW_COPY_AND_ASSIGN(DefaultTypographyProvider); | 77 DISALLOW_COPY_AND_ASSIGN(DefaultTypographyProvider); |
70 }; | 78 }; |
71 | 79 |
72 } // namespace views | 80 } // namespace views |
73 | 81 |
74 #endif // UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ | 82 #endif // UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_ |
OLD | NEW |