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_IMAGE_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 ALIGN_BOTTOM | 37 ALIGN_BOTTOM |
38 }; | 38 }; |
39 | 39 |
40 explicit ImageButton(ButtonListener* listener); | 40 explicit ImageButton(ButtonListener* listener); |
41 ~ImageButton() override; | 41 ~ImageButton() override; |
42 | 42 |
43 // Returns the image for a given |state|. | 43 // Returns the image for a given |state|. |
44 virtual const gfx::ImageSkia& GetImage(ButtonState state) const; | 44 virtual const gfx::ImageSkia& GetImage(ButtonState state) const; |
45 | 45 |
46 // Set the image the button should use for the provided state. | 46 // Set the image the button should use for the provided state. |
47 virtual void SetImage(ButtonState state, const gfx::ImageSkia* image); | 47 void SetImage(ButtonState state, const gfx::ImageSkia* image); |
| 48 |
| 49 // As above, but takes a const ref. TODO(estade): all callers should be |
| 50 // updated to use this version, and then the implementations can be |
| 51 // consolidated. |
| 52 virtual void SetImage(ButtonState state, const gfx::ImageSkia& image); |
48 | 53 |
49 // Set the background details. | 54 // Set the background details. |
50 void SetBackground(SkColor color, | 55 void SetBackground(SkColor color, |
51 const gfx::ImageSkia* image, | 56 const gfx::ImageSkia* image, |
52 const gfx::ImageSkia* mask); | 57 const gfx::ImageSkia* mask); |
53 | 58 |
54 // Sets how the image is laid out within the button's bounds. | 59 // Sets how the image is laid out within the button's bounds. |
55 void SetImageAlignment(HorizontalAlignment h_align, | 60 void SetImageAlignment(HorizontalAlignment h_align, |
56 VerticalAlignment v_align); | 61 VerticalAlignment v_align); |
57 | 62 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Like ImageButton::SetImage(), but to set the graphics used for the | 140 // Like ImageButton::SetImage(), but to set the graphics used for the |
136 // "has been toggled" state. Must be called for each button state | 141 // "has been toggled" state. Must be called for each button state |
137 // before the button is toggled. | 142 // before the button is toggled. |
138 void SetToggledImage(ButtonState state, const gfx::ImageSkia* image); | 143 void SetToggledImage(ButtonState state, const gfx::ImageSkia* image); |
139 | 144 |
140 // Set the tooltip text displayed when the button is toggled. | 145 // Set the tooltip text displayed when the button is toggled. |
141 void SetToggledTooltipText(const base::string16& tooltip); | 146 void SetToggledTooltipText(const base::string16& tooltip); |
142 | 147 |
143 // Overridden from ImageButton: | 148 // Overridden from ImageButton: |
144 const gfx::ImageSkia& GetImage(ButtonState state) const override; | 149 const gfx::ImageSkia& GetImage(ButtonState state) const override; |
145 void SetImage(ButtonState state, const gfx::ImageSkia* image) override; | 150 void SetImage(ButtonState state, const gfx::ImageSkia& image) override; |
146 | 151 |
147 // Overridden from View: | 152 // Overridden from View: |
148 bool GetTooltipText(const gfx::Point& p, | 153 bool GetTooltipText(const gfx::Point& p, |
149 base::string16* tooltip) const override; | 154 base::string16* tooltip) const override; |
150 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 155 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
151 | 156 |
152 private: | 157 private: |
153 // The parent class's images_ member is used for the current images, | 158 // The parent class's images_ member is used for the current images, |
154 // and this array is used to hold the alternative images. | 159 // and this array is used to hold the alternative images. |
155 // We swap between the two when toggling. | 160 // We swap between the two when toggling. |
156 gfx::ImageSkia alternate_images_[STATE_COUNT]; | 161 gfx::ImageSkia alternate_images_[STATE_COUNT]; |
157 | 162 |
158 // True if the button is currently toggled. | 163 // True if the button is currently toggled. |
159 bool toggled_; | 164 bool toggled_; |
160 | 165 |
161 // The parent class's tooltip_text_ is displayed when not toggled, and | 166 // The parent class's tooltip_text_ is displayed when not toggled, and |
162 // this one is shown when toggled. | 167 // this one is shown when toggled. |
163 base::string16 toggled_tooltip_text_; | 168 base::string16 toggled_tooltip_text_; |
164 | 169 |
165 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); | 170 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); |
166 }; | 171 }; |
167 | 172 |
168 } // namespace views | 173 } // namespace views |
169 | 174 |
170 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 175 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
OLD | NEW |