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 InitAsTextbutton() or InitAsButton() to initialize the |
| 33 // (possibly themed) 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 with STYLE_TEXTBUTTON. If borders have not been |
| 42 // set with SetBorder(), creates default themed borders. These may also be |
| 43 // customized by a subclass via CreateDefaultBorder(). |
| 44 void InitAsTextbutton(const base::string16& text); |
| 45 |
| 46 // Initializes with STYLE_BUTTON and creates default borders if SetBorder() |
| 47 // has not already been called. |
| 48 void InitAsButton(const base::string16& text); |
| 49 |
34 // Get or set the image shown for the specified button state. | 50 // 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. | 51 // GetImage returns the image for STATE_NORMAL if the state's image is empty. |
36 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); | 52 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); |
37 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 53 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
38 | 54 |
39 // Get or set the text shown on the button. | 55 // Get or set the text shown on the button. |
40 const base::string16& GetText() const; | 56 const base::string16& GetText() const; |
41 virtual void SetText(const base::string16& text); | 57 virtual void SetText(const base::string16& text); |
42 | 58 |
43 // Set the text color shown for the specified button state. | 59 // Set the text color shown for the specified button state. |
(...skipping 22 matching lines...) Expand all Loading... |
66 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); | 82 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); |
67 | 83 |
68 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size. | 84 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size. |
69 void SetMinSize(const gfx::Size& min_size); | 85 void SetMinSize(const gfx::Size& min_size); |
70 void SetMaxSize(const gfx::Size& max_size); | 86 void SetMaxSize(const gfx::Size& max_size); |
71 | 87 |
72 // Get or set the option to handle the return key; false by default. | 88 // Get or set the option to handle the return key; false by default. |
73 bool is_default() const { return is_default_; } | 89 bool is_default() const { return is_default_; } |
74 void SetIsDefault(bool is_default); | 90 void SetIsDefault(bool is_default); |
75 | 91 |
76 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. | 92 // Gets the button's overall style. |
77 ButtonStyle style() const { return style_; } | 93 ButtonStyle style() const { return style_; } |
| 94 |
| 95 // Sets the button style and updates (possibly themed) borders. TODO(tapted): |
| 96 // Make this method protected after callers have switched to InitAsButton(). |
78 void SetStyle(ButtonStyle style); | 97 void SetStyle(ButtonStyle style); |
79 | 98 |
80 // Set the spacing between the image and the text. Shrinking the spacing | 99 // 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. | 100 // will not shrink the overall button size, as it is monotonically increasing. |
82 // Call SetMinSize(gfx::Size()) to clear the size if needed. | 101 // Call SetMinSize(gfx::Size()) to clear the size if needed. |
83 void SetImageLabelSpacing(int spacing); | 102 void SetImageLabelSpacing(int spacing); |
84 | 103 |
85 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 104 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
86 Painter* focus_painter() { return focus_painter_.get(); } | 105 Painter* focus_painter() { return focus_painter_.get(); } |
87 | 106 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 void UpdateImage(); | 139 void UpdateImage(); |
121 | 140 |
122 // Updates the border as per the NativeTheme, unless a different border was | 141 // Updates the border as per the NativeTheme, unless a different border was |
123 // set with SetBorder. | 142 // set with SetBorder. |
124 void UpdateThemedBorder(); | 143 void UpdateThemedBorder(); |
125 | 144 |
126 // NativeThemeDelegate: | 145 // NativeThemeDelegate: |
127 gfx::Rect GetThemePaintRect() const override; | 146 gfx::Rect GetThemePaintRect() const override; |
128 | 147 |
129 private: | 148 private: |
| 149 FRIEND_TEST_ALL_PREFIXES(BlueButtonTest, Border); |
130 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | 150 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); |
131 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); | 151 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); |
132 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); | 152 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); |
133 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); | 153 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); |
134 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, FontList); | 154 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, FontList); |
135 | 155 |
136 // CustomButton: | 156 // CustomButton: |
137 void StateChanged() override; | 157 void StateChanged() override; |
138 | 158 |
139 // View: | 159 // View: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 int image_label_spacing_; | 212 int image_label_spacing_; |
193 | 213 |
194 scoped_ptr<Painter> focus_painter_; | 214 scoped_ptr<Painter> focus_painter_; |
195 | 215 |
196 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 216 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
197 }; | 217 }; |
198 | 218 |
199 } // namespace views | 219 } // namespace views |
200 | 220 |
201 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 221 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |