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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 | 14 |
15 // An image button. | 15 // An image button. |
16 | 16 |
17 // Note that this type of button is not focusable by default and will not be | 17 // Note that this type of button is not focusable by default and will not be |
18 // part of the focus chain. Call set_focusable(true) to make it part of the | 18 // part of the focus chain. Call set_focusable(true) to make it part of the |
19 // focus chain. | 19 // focus chain. |
20 | 20 |
21 class VIEWS_EXPORT ImageButton : public CustomButton { | 21 class VIEWS_EXPORT ImageButton : public CustomButton { |
22 public: | 22 public: |
| 23 enum HorizontalAlignment { |
| 24 ALIGN_LEFT = 0, |
| 25 ALIGN_CENTER, |
| 26 ALIGN_RIGHT |
| 27 }; |
| 28 |
| 29 enum VerticalAlignment { |
| 30 ALIGN_TOP = 0, |
| 31 ALIGN_MIDDLE, |
| 32 ALIGN_BOTTOM |
| 33 }; |
| 34 |
23 explicit ImageButton(ButtonListener* listener); | 35 explicit ImageButton(ButtonListener* listener); |
24 virtual ~ImageButton(); | 36 virtual ~ImageButton(); |
25 | 37 |
26 // Set the image the button should use for the provided state. | 38 // Set the image the button should use for the provided state. |
27 virtual void SetImage(ButtonState state, const SkBitmap* image); | 39 virtual void SetImage(ButtonState state, const SkBitmap* image); |
28 | 40 |
29 // Set the background details. | 41 // Set the background details. |
30 void SetBackground(SkColor color, | 42 void SetBackground(SkColor color, |
31 const SkBitmap* image, | 43 const SkBitmap* image, |
32 const SkBitmap* mask); | 44 const SkBitmap* mask); |
33 | 45 |
34 // Set an |image| to draw on top of the normal / hot / pushed image. | 46 // Set an |image| to draw on top of the normal / hot / pushed image. |
35 // Pass NULL for no image. | 47 // Pass NULL for no image. |
36 void SetOverlayImage(const SkBitmap* image); | 48 void SetOverlayImage(const SkBitmap* image); |
37 | 49 |
38 enum HorizontalAlignment { ALIGN_LEFT = 0, | |
39 ALIGN_CENTER, | |
40 ALIGN_RIGHT, }; | |
41 | |
42 enum VerticalAlignment { ALIGN_TOP = 0, | |
43 ALIGN_MIDDLE, | |
44 ALIGN_BOTTOM }; | |
45 | |
46 // Sets how the image is laid out within the button's bounds. | 50 // Sets how the image is laid out within the button's bounds. |
47 void SetImageAlignment(HorizontalAlignment h_align, | 51 void SetImageAlignment(HorizontalAlignment h_align, |
48 VerticalAlignment v_align); | 52 VerticalAlignment v_align); |
49 | 53 |
50 // Overridden from View: | 54 // Overridden from View: |
51 virtual gfx::Size GetPreferredSize() OVERRIDE; | 55 virtual gfx::Size GetPreferredSize() OVERRIDE; |
52 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 56 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
53 | 57 |
54 // Sets preferred size, so it could be correctly positioned in layout even if | 58 // Sets preferred size, so it could be correctly positioned in layout even if |
55 // it is NULL. | 59 // it is NULL. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 103 |
100 // Like ImageButton::SetImage(), but to set the graphics used for the | 104 // Like ImageButton::SetImage(), but to set the graphics used for the |
101 // "has been toggled" state. Must be called for each button state | 105 // "has been toggled" state. Must be called for each button state |
102 // before the button is toggled. | 106 // before the button is toggled. |
103 void SetToggledImage(ButtonState state, const SkBitmap* image); | 107 void SetToggledImage(ButtonState state, const SkBitmap* image); |
104 | 108 |
105 // Set the tooltip text displayed when the button is toggled. | 109 // Set the tooltip text displayed when the button is toggled. |
106 void SetToggledTooltipText(const string16& tooltip); | 110 void SetToggledTooltipText(const string16& tooltip); |
107 | 111 |
108 // Overridden from ImageButton: | 112 // Overridden from ImageButton: |
109 virtual void SetImage(ButtonState aState, const SkBitmap* anImage) OVERRIDE; | 113 virtual void SetImage(ButtonState state, const SkBitmap* image) OVERRIDE; |
110 | 114 |
111 // Overridden from View: | 115 // Overridden from View: |
112 virtual bool GetTooltipText(const gfx::Point& p, | 116 virtual bool GetTooltipText(const gfx::Point& p, |
113 string16* tooltip) const OVERRIDE; | 117 string16* tooltip) const OVERRIDE; |
114 | 118 |
115 private: | 119 private: |
116 // The parent class's images_ member is used for the current images, | 120 // The parent class's images_ member is used for the current images, |
117 // and this array is used to hold the alternative images. | 121 // and this array is used to hold the alternative images. |
118 // We swap between the two when toggling. | 122 // We swap between the two when toggling. |
119 SkBitmap alternate_images_[BS_COUNT]; | 123 SkBitmap alternate_images_[BS_COUNT]; |
120 | 124 |
121 // True if the button is currently toggled. | 125 // True if the button is currently toggled. |
122 bool toggled_; | 126 bool toggled_; |
123 | 127 |
124 // The parent class's tooltip_text_ is displayed when not toggled, and | 128 // The parent class's tooltip_text_ is displayed when not toggled, and |
125 // this one is shown when toggled. | 129 // this one is shown when toggled. |
126 string16 toggled_tooltip_text_; | 130 string16 toggled_tooltip_text_; |
127 | 131 |
128 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); | 132 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); |
129 }; | 133 }; |
130 | 134 |
131 } // namespace views | 135 } // namespace views |
132 | 136 |
133 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 137 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
OLD | NEW |