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