OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 5 #ifndef VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
6 #define VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 6 #define VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
7 | 7 |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "views/controls/button/custom_button.h" | 9 #include "views/controls/button/custom_button.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 | 12 |
13 // An image button. | 13 // An image button. |
14 | 14 |
15 // Note that this type of button is not focusable by default and will not be | 15 // Note that this type of button is not focusable by default and will not be |
16 // part of the focus chain. Call SetFocusable(true) to make it part of the | 16 // part of the focus chain. Call SetFocusable(true) to make it part of the |
17 // focus chain. | 17 // focus chain. |
18 | 18 |
19 class ImageButton : public CustomButton { | 19 class ImageButton : public CustomButton { |
20 public: | 20 public: |
| 21 enum HorizontalAlignment { ALIGN_LEFT = 0, |
| 22 ALIGN_CENTER, |
| 23 ALIGN_RIGHT, }; |
| 24 |
| 25 enum VerticalAlignment { ALIGN_TOP = 0, |
| 26 ALIGN_MIDDLE, |
| 27 ALIGN_BOTTOM }; |
| 28 |
21 explicit ImageButton(ButtonListener* listener); | 29 explicit ImageButton(ButtonListener* listener); |
22 virtual ~ImageButton(); | 30 virtual ~ImageButton(); |
23 | 31 |
24 // Set the image the button should use for the provided state. | 32 // Set the image the button should use for the provided state. |
25 virtual void SetImage(ButtonState aState, const SkBitmap* anImage); | 33 virtual void SetImage(ButtonState aState, const SkBitmap* anImage); |
26 | 34 |
27 // Set the background details. | 35 // Set the background details. |
28 void SetBackground(SkColor color, | 36 void SetBackground(SkColor color, |
29 const SkBitmap* image, | 37 const SkBitmap* image, |
30 const SkBitmap* mask); | 38 const SkBitmap* mask); |
31 | 39 |
32 enum HorizontalAlignment { ALIGN_LEFT = 0, | 40 // Explicitly sets the background image. |
33 ALIGN_CENTER, | 41 void set_background_image(const SkBitmap& background) { |
34 ALIGN_RIGHT, }; | 42 background_image_ = background; |
35 | 43 } |
36 enum VerticalAlignment { ALIGN_TOP = 0, | |
37 ALIGN_MIDDLE, | |
38 ALIGN_BOTTOM }; | |
39 | 44 |
40 // Sets how the image is laid out within the button's bounds. | 45 // Sets how the image is laid out within the button's bounds. |
41 void SetImageAlignment(HorizontalAlignment h_align, | 46 void SetImageAlignment(HorizontalAlignment h_align, |
42 VerticalAlignment v_align); | 47 VerticalAlignment v_align); |
43 | 48 |
44 // Overridden from View: | 49 // Overridden from View: |
45 virtual gfx::Size GetPreferredSize(); | 50 virtual gfx::Size GetPreferredSize(); |
46 virtual void Paint(gfx::Canvas* canvas); | 51 virtual void Paint(gfx::Canvas* canvas); |
47 | 52 |
48 protected: | 53 protected: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // The parent class's tooltip_text_ is displayed when not toggled, and | 110 // The parent class's tooltip_text_ is displayed when not toggled, and |
106 // this one is shown when toggled. | 111 // this one is shown when toggled. |
107 std::wstring toggled_tooltip_text_; | 112 std::wstring toggled_tooltip_text_; |
108 | 113 |
109 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); | 114 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); |
110 }; | 115 }; |
111 | 116 |
112 } // namespace views | 117 } // namespace views |
113 | 118 |
114 #endif // VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 119 #endif // VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
OLD | NEW |