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_BUTTON_LABEL_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 // LabelButton is a button with text and an icon, it's not focusable by default. | 22 // LabelButton is a button with text and an icon, it's not focusable by default. |
23 class VIEWS_EXPORT LabelButton : public CustomButton, | 23 class VIEWS_EXPORT LabelButton : public CustomButton, |
24 public NativeThemeDelegate { | 24 public NativeThemeDelegate { |
25 public: | 25 public: |
26 // The length of the hover fade animation. | 26 // The length of the hover fade animation. |
27 static const int kHoverAnimationDurationMs; | 27 static const int kHoverAnimationDurationMs; |
28 | 28 |
29 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
30 | 30 |
31 // Construct an uninitialized LabelButton with a Listener. Client code must | |
32 // also call Init() or InitAsButton() to initialize the (possibly themed) | |
33 // button borders. | |
34 explicit LabelButton(ButtonListener* listener); | |
35 | |
36 // Deprecated (calls virtual methods). TODO(tapted): Remove this overload. | |
31 LabelButton(ButtonListener* listener, const base::string16& text); | 37 LabelButton(ButtonListener* listener, const base::string16& text); |
38 | |
32 ~LabelButton() override; | 39 ~LabelButton() override; |
33 | 40 |
41 // Initializes the LabelButton. If borders have not been set with SetBorder(), | |
42 // creates default themed borders for the current ButtonStyle. The default | |
43 // button style defaults to STYLE_TEXTBUTTON, or it be set by a subclass. | |
sadrul
2015/07/08 05:59:11
Can there be a single 'Init(text, style)' instead?
tapted
2015/07/08 06:31:33
I actually started with Init(style, text) in Patch
tapted
2015/07/09 00:53:48
Done. (went with Textbutton over TextButton to mat
| |
44 void Init(const base::string16& text); | |
45 | |
46 // Calls Init() after setting the ButtonStyle to STYLE_BUTTON. | |
47 void InitAsButton(const base::string16& text); | |
48 | |
34 // Get or set the image shown for the specified button state. | 49 // Get or set the image shown for the specified button state. |
35 // GetImage returns the image for STATE_NORMAL if the state's image is empty. | 50 // GetImage returns the image for STATE_NORMAL if the state's image is empty. |
36 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); | 51 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); |
37 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 52 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
38 | 53 |
39 // Get or set the text shown on the button. | 54 // Get or set the text shown on the button. |
40 const base::string16& GetText() const; | 55 const base::string16& GetText() const; |
41 virtual void SetText(const base::string16& text); | 56 virtual void SetText(const base::string16& text); |
42 | 57 |
43 // Set the text color shown for the specified button state. | 58 // Set the text color shown for the specified button state. |
(...skipping 22 matching lines...) Expand all Loading... | |
66 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); | 81 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); |
67 | 82 |
68 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size. | 83 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size. |
69 void SetMinSize(const gfx::Size& min_size); | 84 void SetMinSize(const gfx::Size& min_size); |
70 void SetMaxSize(const gfx::Size& max_size); | 85 void SetMaxSize(const gfx::Size& max_size); |
71 | 86 |
72 // Get or set the option to handle the return key; false by default. | 87 // Get or set the option to handle the return key; false by default. |
73 bool is_default() const { return is_default_; } | 88 bool is_default() const { return is_default_; } |
74 void SetIsDefault(bool is_default); | 89 void SetIsDefault(bool is_default); |
75 | 90 |
76 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. | 91 // Gets the button's overall style; the default is |STYLE_TEXTBUTTON|. |
77 ButtonStyle style() const { return style_; } | 92 ButtonStyle style() const { return style_; } |
93 | |
94 // Sets the button style and updates (possibly themed) borders. TODO(tapted): | |
95 // Make this method protected after callers have switched to InitAsButton(). | |
78 void SetStyle(ButtonStyle style); | 96 void SetStyle(ButtonStyle style); |
79 | 97 |
80 // Set the spacing between the image and the text. Shrinking the spacing | 98 // Set the spacing between the image and the text. Shrinking the spacing |
81 // will not shrink the overall button size, as it is monotonically increasing. | 99 // will not shrink the overall button size, as it is monotonically increasing. |
82 // Call SetMinSize(gfx::Size()) to clear the size if needed. | 100 // Call SetMinSize(gfx::Size()) to clear the size if needed. |
83 void SetImageLabelSpacing(int spacing); | 101 void SetImageLabelSpacing(int spacing); |
84 | 102 |
85 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 103 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
86 Painter* focus_painter() { return focus_painter_.get(); } | 104 Painter* focus_painter() { return focus_painter_.get(); } |
87 | 105 |
88 // View: | 106 // View: |
89 void SetBorder(scoped_ptr<Border> border) override; | 107 void SetBorder(scoped_ptr<Border> border) override; |
90 gfx::Size GetPreferredSize() const override; | 108 gfx::Size GetPreferredSize() const override; |
91 int GetHeightForWidth(int w) const override; | 109 int GetHeightForWidth(int w) const override; |
92 void Layout() override; | 110 void Layout() override; |
93 const char* GetClassName() const override; | 111 const char* GetClassName() const override; |
94 | 112 |
95 protected: | 113 protected: |
96 ImageView* image() const { return image_; } | 114 ImageView* image() const { return image_; } |
97 Label* label() const { return label_; } | 115 Label* label() const { return label_; } |
98 | 116 |
117 // Called by a subclass constructor to cause the Init(const string16&) | |
118 // overload to use a default style other than STYLE_TEXTBUTTON. | |
119 void SetDefaultStyle(ButtonStyle style); | |
120 | |
99 // Returns the available area for the label and image. Subclasses can change | 121 // Returns the available area for the label and image. Subclasses can change |
100 // these bounds if they need room to do manual painting. | 122 // these bounds if they need room to do manual painting. |
101 virtual gfx::Rect GetChildAreaBounds(); | 123 virtual gfx::Rect GetChildAreaBounds(); |
102 | 124 |
103 // View: | 125 // View: |
104 void OnPaint(gfx::Canvas* canvas) override; | 126 void OnPaint(gfx::Canvas* canvas) override; |
105 void OnFocus() override; | 127 void OnFocus() override; |
106 void OnBlur() override; | 128 void OnBlur() override; |
107 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 129 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
108 | 130 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 int image_label_spacing_; | 214 int image_label_spacing_; |
193 | 215 |
194 scoped_ptr<Painter> focus_painter_; | 216 scoped_ptr<Painter> focus_painter_; |
195 | 217 |
196 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 218 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
197 }; | 219 }; |
198 | 220 |
199 } // namespace views | 221 } // namespace views |
200 | 222 |
201 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 223 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |