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. Add foreground/ |
| 41 // background color and line spacing if needed to match views::TextContext. |
| 42 struct CustomFont { |
| 43 const gfx::FontList& font_list; |
| 44 }; |
| 45 |
| 46 // Create Labels with TextContext::CONTROL_LABEL and TextStyle::PRIMARY. |
| 47 // TODO(tapted): Remove these. Callers must specify a context or use the |
| 48 // constructor taking a CustomFont. |
36 Label(); | 49 Label(); |
37 explicit Label(const base::string16& text); | 50 explicit Label(const base::string16& text); |
38 Label(const base::string16& text, const gfx::FontList& font_list); | 51 |
| 52 // Construct a label in the given |context|. The style can change later, so |
| 53 // provide a default. The TextContext is fixed. |
| 54 Label(const base::string16& text, |
| 55 TextContext context, |
| 56 TextStyle style = TextStyle::PRIMARY); |
| 57 |
| 58 Label(const base::string16& text, const CustomFont& font); |
| 59 |
39 ~Label() override; | 60 ~Label() override; |
40 | 61 |
41 static const gfx::FontList& GetDefaultFontList(); | 62 static const gfx::FontList& GetDefaultFontList(); |
42 | 63 |
43 // Gets or sets the fonts used by this label. | 64 // Gets or sets the fonts used by this label. |
44 const gfx::FontList& font_list() const { return render_text_->font_list(); } | 65 const gfx::FontList& font_list() const { return render_text_->font_list(); } |
45 | 66 |
| 67 // TODO(tapted): Replace this with a private method, e.g., OnFontChanged(). |
46 virtual void SetFontList(const gfx::FontList& font_list); | 68 virtual void SetFontList(const gfx::FontList& font_list); |
47 | 69 |
48 // Get or set the label text. | 70 // Get or set the label text. |
49 const base::string16& text() const { return render_text_->text(); } | 71 const base::string16& text() const { return render_text_->text(); } |
50 virtual void SetText(const base::string16& text); | 72 virtual void SetText(const base::string16& text); |
51 | 73 |
52 // Enables or disables auto-color-readability (enabled by default). If this | 74 // Enables or disables auto-color-readability (enabled by default). If this |
53 // is enabled, then calls to set any foreground or background color will | 75 // is enabled, then calls to set any foreground or background color will |
54 // trigger an automatic mapper that uses color_utils::GetReadableColor() to | 76 // trigger an automatic mapper that uses color_utils::GetReadableColor() to |
55 // ensure that the foreground colors are readable over the background color. | 77 // 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. | 372 // Context menu related members. |
351 ui::SimpleMenuModel context_menu_contents_; | 373 ui::SimpleMenuModel context_menu_contents_; |
352 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 374 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
353 | 375 |
354 DISALLOW_COPY_AND_ASSIGN(Label); | 376 DISALLOW_COPY_AND_ASSIGN(Label); |
355 }; | 377 }; |
356 | 378 |
357 } // namespace views | 379 } // namespace views |
358 | 380 |
359 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 381 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |