OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CONTROLS_LABEL_H_ | 5 #ifndef UI_VIEWS_CONTROLS_LABEL_H_ |
6 #define UI_VIEWS_CONTROLS_LABEL_H_ | 6 #define UI_VIEWS_CONTROLS_LABEL_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
12 #include "ui/gfx/render_text.h" | 12 #include "ui/gfx/render_text.h" |
13 #include "ui/views/context_menu_controller.h" | 13 #include "ui/views/context_menu_controller.h" |
14 #include "ui/views/selection_controller_delegate.h" | 14 #include "ui/views/selection_controller_delegate.h" |
15 #include "ui/views/style/typography.h" | |
15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
16 #include "ui/views/word_lookup_client.h" | 17 #include "ui/views/word_lookup_client.h" |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 class LabelSelectionTest; | 20 class LabelSelectionTest; |
20 class MenuRunner; | 21 class MenuRunner; |
21 class SelectionController; | 22 class SelectionController; |
22 | 23 |
23 // A view subclass that can display a string. | 24 // A view subclass that can display a string. |
24 class VIEWS_EXPORT Label : public View, | 25 class VIEWS_EXPORT Label : public View, |
25 public ContextMenuController, | 26 public ContextMenuController, |
26 public WordLookupClient, | 27 public WordLookupClient, |
27 public SelectionControllerDelegate, | 28 public SelectionControllerDelegate, |
28 public ui::SimpleMenuModel::Delegate { | 29 public ui::SimpleMenuModel::Delegate { |
29 public: | 30 public: |
30 // Internal class name. | 31 // Internal class name. |
31 static const char kViewClassName[]; | 32 static const char kViewClassName[]; |
32 | 33 |
33 // The padding for the focus border when rendering focused text. | 34 // The padding for the focus border when rendering focused text. |
34 static const int kFocusBorderPadding; | 35 static const int kFocusBorderPadding; |
35 | 36 |
37 // Helper to construct a Label that doesn't use the views::Typography spec. | |
38 // Using this causes Label to obtain colors from ui::NativeTheme and line | |
39 // spacing from gfx::FontList::GetHeight(). | |
40 // TOOD(tapted): Audit users of this class when MD is default. Then add | |
41 // foreground/background colors, line spacing and everything else that | |
42 // views::TextContext abstracts away so the separate setters can be removed. | |
43 struct CustomFont { | |
44 // TODO(tapted): Change this to a size delta and font weight since that's | |
45 // typically all the callers really care about, and would allow Label to | |
46 // guarantee caching of the FontList in ResourceBundle. | |
47 const gfx::FontList& font_list; | |
48 }; | |
49 | |
50 // Create Labels with TextContext::CONTROL_LABEL and TextStyle::PRIMARY. | |
Peter Kasting
2017/03/14 23:53:33
Nit: Function comments should be descriptive ("Cre
| |
51 // TODO(tapted): Remove these. Callers must specify a context or use the | |
52 // constructor taking a CustomFont. | |
36 Label(); | 53 Label(); |
37 explicit Label(const base::string16& text); | 54 explicit Label(const base::string16& text); |
38 Label(const base::string16& text, const gfx::FontList& font_list); | 55 |
56 // Construct a Label in the given |context|. The style can change later, so | |
57 // provide a default. The TextContext is fixed. | |
58 Label(const base::string16& text, | |
59 TextContext context, | |
60 TextStyle style = TextStyle::PRIMARY); | |
61 | |
62 // Construct a Label with the given |font| description. | |
63 Label(const base::string16& text, const CustomFont& font); | |
64 | |
39 ~Label() override; | 65 ~Label() override; |
40 | 66 |
41 static const gfx::FontList& GetDefaultFontList(); | 67 static const gfx::FontList& GetDefaultFontList(); |
42 | 68 |
43 // Gets or sets the fonts used by this label. | 69 // Gets or sets the fonts used by this label. |
44 const gfx::FontList& font_list() const { return render_text_->font_list(); } | 70 const gfx::FontList& font_list() const { return render_text_->font_list(); } |
45 | 71 |
72 // TODO(tapted): Replace this with a private method, e.g., OnFontChanged(). | |
46 virtual void SetFontList(const gfx::FontList& font_list); | 73 virtual void SetFontList(const gfx::FontList& font_list); |
47 | 74 |
48 // Get or set the label text. | 75 // Get or set the label text. |
49 const base::string16& text() const { return render_text_->text(); } | 76 const base::string16& text() const { return render_text_->text(); } |
50 virtual void SetText(const base::string16& text); | 77 virtual void SetText(const base::string16& text); |
51 | 78 |
52 // Enables or disables auto-color-readability (enabled by default). If this | 79 // Enables or disables auto-color-readability (enabled by default). If this |
53 // is enabled, then calls to set any foreground or background color will | 80 // is enabled, then calls to set any foreground or background color will |
54 // trigger an automatic mapper that uses color_utils::GetReadableColor() to | 81 // trigger an automatic mapper that uses color_utils::GetReadableColor() to |
55 // ensure that the foreground colors are readable over the background color. | 82 // ensure that the foreground colors are readable over the background color. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 // Context menu related members. | 377 // Context menu related members. |
351 ui::SimpleMenuModel context_menu_contents_; | 378 ui::SimpleMenuModel context_menu_contents_; |
352 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 379 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
353 | 380 |
354 DISALLOW_COPY_AND_ASSIGN(Label); | 381 DISALLOW_COPY_AND_ASSIGN(Label); |
355 }; | 382 }; |
356 | 383 |
357 } // namespace views | 384 } // namespace views |
358 | 385 |
359 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 386 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |