OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
11 | 12 |
12 namespace views { | 13 namespace views { |
13 | 14 |
14 // An image button. | 15 // An image button. |
15 | 16 |
16 // 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 |
17 // 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 |
18 // focus chain. | 19 // focus chain. |
19 | 20 |
20 class VIEWS_EXPORT ImageButton : public CustomButton { | 21 class VIEWS_EXPORT ImageButton : public CustomButton { |
21 public: | 22 public: |
22 explicit ImageButton(ButtonListener* listener); | 23 explicit ImageButton(ButtonListener* listener); |
23 virtual ~ImageButton(); | 24 virtual ~ImageButton(); |
24 | 25 |
25 // Set the image the button should use for the provided state. | 26 // Set the image the button should use for the provided state. |
26 virtual void SetImage(ButtonState state, const SkBitmap* image); | 27 virtual void SetImage(ButtonState state, const SkBitmap* image); |
27 | 28 |
28 // Set the background details. | 29 // Set the background details. |
29 void SetBackground(SkColor color, | 30 void SetBackground(SkColor color, |
30 const SkBitmap* image, | 31 const SkBitmap* image, |
31 const SkBitmap* mask); | 32 const SkBitmap* mask); |
32 | 33 |
34 // Set an |image| to draw on top of the normal / hot / pushed image. | |
35 // Pass NULL for no image. | |
36 void SetOverlayImage(const SkBitmap* image); | |
37 | |
33 enum HorizontalAlignment { ALIGN_LEFT = 0, | 38 enum HorizontalAlignment { ALIGN_LEFT = 0, |
34 ALIGN_CENTER, | 39 ALIGN_CENTER, |
35 ALIGN_RIGHT, }; | 40 ALIGN_RIGHT, }; |
36 | 41 |
37 enum VerticalAlignment { ALIGN_TOP = 0, | 42 enum VerticalAlignment { ALIGN_TOP = 0, |
38 ALIGN_MIDDLE, | 43 ALIGN_MIDDLE, |
39 ALIGN_BOTTOM }; | 44 ALIGN_BOTTOM }; |
40 | 45 |
41 // Sets how the image is laid out within the button's bounds. | 46 // Sets how the image is laid out within the button's bounds. |
42 void SetImageAlignment(HorizontalAlignment h_align, | 47 void SetImageAlignment(HorizontalAlignment h_align, |
(...skipping 13 matching lines...) Expand all Loading... | |
56 // Returns the image to paint. This is invoked from paint and returns a value | 61 // Returns the image to paint. This is invoked from paint and returns a value |
57 // from images. | 62 // from images. |
58 virtual SkBitmap GetImageToPaint(); | 63 virtual SkBitmap GetImageToPaint(); |
59 | 64 |
60 // The images used to render the different states of this button. | 65 // The images used to render the different states of this button. |
61 SkBitmap images_[BS_COUNT]; | 66 SkBitmap images_[BS_COUNT]; |
62 | 67 |
63 // The background image. | 68 // The background image. |
64 SkBitmap background_image_; | 69 SkBitmap background_image_; |
65 | 70 |
71 // Image to draw on top of normal / hot / pushed image. Usually empty. | |
72 SkBitmap overlay_image_; | |
73 | |
66 private: | 74 private: |
75 FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, Basics); | |
76 | |
67 // Image alignment. | 77 // Image alignment. |
68 HorizontalAlignment h_alignment_; | 78 HorizontalAlignment h_alignment_; |
69 VerticalAlignment v_alignment_; | 79 VerticalAlignment v_alignment_; |
70 gfx::Size preferred_size_; | 80 gfx::Size preferred_size_; |
71 | 81 |
72 DISALLOW_COPY_AND_ASSIGN(ImageButton); | 82 DISALLOW_COPY_AND_ASSIGN(ImageButton); |
73 }; | 83 }; |
74 | 84 |
75 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
76 // | 86 // |
77 // ToggleImageButton | 87 // ToggleImageButton |
78 // | 88 // |
79 // A toggle-able ImageButton. It swaps out its graphics when toggled. | 89 // A toggle-able ImageButton. It swaps out its graphics when toggled. |
80 // | 90 // |
81 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
82 class VIEWS_EXPORT ToggleImageButton : public ImageButton { | 92 class VIEWS_EXPORT ToggleImageButton : public ImageButton { |
83 public: | 93 public: |
84 explicit ToggleImageButton(ButtonListener* listener); | 94 explicit ToggleImageButton(ButtonListener* listener); |
85 virtual ~ToggleImageButton(); | 95 virtual ~ToggleImageButton(); |
86 | 96 |
87 // Change the toggled state. | 97 // Change the toggled state. |
88 void SetToggled(bool toggled); | 98 void SetToggled(bool toggled); |
89 | 99 |
90 // Like ImageButton::SetImage(), but to set the graphics used for the | 100 // Like ImageButton::SetImage(), but to set the graphics used for the |
91 // "has been toggled" state. Must be called for each button state | 101 // "has been toggled" state. Must be called for each button state |
92 // before the button is toggled. | 102 // before the button is toggled. |
93 void SetToggledImage(ButtonState state, const SkBitmap* image); | 103 void SetToggledImage(ButtonState state, const SkBitmap* image); |
94 | 104 |
sadrul
2012/04/23 21:06:26
I suppose there could eventually be a SetToggledOv
| |
95 // Set the tooltip text displayed when the button is toggled. | 105 // Set the tooltip text displayed when the button is toggled. |
96 void SetToggledTooltipText(const string16& tooltip); | 106 void SetToggledTooltipText(const string16& tooltip); |
97 | 107 |
98 // Overridden from ImageButton: | 108 // Overridden from ImageButton: |
99 virtual void SetImage(ButtonState aState, const SkBitmap* anImage) OVERRIDE; | 109 virtual void SetImage(ButtonState aState, const SkBitmap* anImage) OVERRIDE; |
100 | 110 |
101 // Overridden from View: | 111 // Overridden from View: |
102 virtual bool GetTooltipText(const gfx::Point& p, | 112 virtual bool GetTooltipText(const gfx::Point& p, |
103 string16* tooltip) const OVERRIDE; | 113 string16* tooltip) const OVERRIDE; |
104 | 114 |
105 private: | 115 private: |
106 // The parent class's images_ member is used for the current images, | 116 // The parent class's images_ member is used for the current images, |
107 // and this array is used to hold the alternative images. | 117 // and this array is used to hold the alternative images. |
108 // We swap between the two when toggling. | 118 // We swap between the two when toggling. |
109 SkBitmap alternate_images_[BS_COUNT]; | 119 SkBitmap alternate_images_[BS_COUNT]; |
110 | 120 |
111 // True if the button is currently toggled. | 121 // True if the button is currently toggled. |
112 bool toggled_; | 122 bool toggled_; |
113 | 123 |
114 // The parent class's tooltip_text_ is displayed when not toggled, and | 124 // The parent class's tooltip_text_ is displayed when not toggled, and |
115 // this one is shown when toggled. | 125 // this one is shown when toggled. |
116 string16 toggled_tooltip_text_; | 126 string16 toggled_tooltip_text_; |
117 | 127 |
118 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); | 128 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); |
119 }; | 129 }; |
120 | 130 |
121 } // namespace views | 131 } // namespace views |
122 | 132 |
123 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ | 133 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ |
OLD | NEW |