Chromium Code Reviews| 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 | |
|
Peter Kasting
2017/03/17 02:26:00
Nit: TOOD? :)
tapted
2017/03/17 10:33:10
whoops. fixed. (I have spell checking for comments
| |
| 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 { | |
|
Peter Kasting
2017/03/17 02:26:00
Nit: Just for the sake of keeping the diff minimal
tapted
2017/03/17 10:33:10
Yeah, I also want any new code to be considering a
| |
| 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 typography::CONTEXT_CONTROL_LABEL and | |
| 51 // typography::STYLE_PRIMARY. | |
| 52 // TODO(tapted): Remove these. Callers must specify a context or use the | |
| 53 // constructor taking a CustomFont. | |
| 36 Label(); | 54 Label(); |
| 37 explicit Label(const base::string16& text); | 55 explicit Label(const base::string16& text); |
| 38 Label(const base::string16& text, const gfx::FontList& font_list); | 56 |
| 57 // Construct a Label in the given |text_context|. The text_style can change | |
|
Peter Kasting
2017/03/17 02:26:00
Nit: Use || consistently
tapted
2017/03/17 10:33:10
Done.
| |
| 58 // later, so provide a default. The |text_context| is fixed. | |
| 59 Label(const base::string16& text, | |
| 60 int text_context, | |
| 61 int text_style = typography::STYLE_PRIMARY); | |
| 62 | |
| 63 // Construct a Label with the given |font| description. | |
| 64 Label(const base::string16& text, const CustomFont& font); | |
| 65 | |
| 39 ~Label() override; | 66 ~Label() override; |
| 40 | 67 |
| 41 static const gfx::FontList& GetDefaultFontList(); | 68 static const gfx::FontList& GetDefaultFontList(); |
| 42 | 69 |
| 43 // Gets or sets the fonts used by this label. | 70 // Gets or sets the fonts used by this label. |
| 44 const gfx::FontList& font_list() const { return render_text_->font_list(); } | 71 const gfx::FontList& font_list() const { return render_text_->font_list(); } |
| 45 | 72 |
| 73 // TODO(tapted): Replace this with a private method, e.g., OnFontChanged(). | |
| 46 virtual void SetFontList(const gfx::FontList& font_list); | 74 virtual void SetFontList(const gfx::FontList& font_list); |
| 47 | 75 |
| 48 // Get or set the label text. | 76 // Get or set the label text. |
| 49 const base::string16& text() const { return render_text_->text(); } | 77 const base::string16& text() const { return render_text_->text(); } |
| 50 virtual void SetText(const base::string16& text); | 78 virtual void SetText(const base::string16& text); |
| 51 | 79 |
| 52 // Enables or disables auto-color-readability (enabled by default). If this | 80 // Enables or disables auto-color-readability (enabled by default). If this |
| 53 // is enabled, then calls to set any foreground or background color will | 81 // is enabled, then calls to set any foreground or background color will |
| 54 // trigger an automatic mapper that uses color_utils::GetReadableColor() to | 82 // trigger an automatic mapper that uses color_utils::GetReadableColor() to |
| 55 // ensure that the foreground colors are readable over the background color. | 83 // 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. | 378 // Context menu related members. |
| 351 ui::SimpleMenuModel context_menu_contents_; | 379 ui::SimpleMenuModel context_menu_contents_; |
| 352 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 380 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
| 353 | 381 |
| 354 DISALLOW_COPY_AND_ASSIGN(Label); | 382 DISALLOW_COPY_AND_ASSIGN(Label); |
| 355 }; | 383 }; |
| 356 | 384 |
| 357 } // namespace views | 385 } // namespace views |
| 358 | 386 |
| 359 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 387 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |