summaryrefslogtreecommitdiffstats
path: root/views/controls/button/image_button.cc
diff options
context:
space:
mode:
Diffstat (limited to 'views/controls/button/image_button.cc')
-rw-r--r--views/controls/button/image_button.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc
index 087b4f0..a4f9123 100644
--- a/views/controls/button/image_button.cc
+++ b/views/controls/button/image_button.cc
@@ -19,7 +19,8 @@ static const int kDefaultHeight = 14; // Default button height if no theme.
ImageButton::ImageButton(ButtonListener* listener)
: CustomButton(listener),
h_alignment_(ALIGN_LEFT),
- v_alignment_(ALIGN_TOP) {
+ v_alignment_(ALIGN_TOP),
+ background_image_(NULL) {
// By default, we request that the gfx::Canvas passed to our View::Paint()
// implementation is flipped horizontally so that the button's bitmaps are
// mirrored when the UI directionality is right-to-left.
@@ -33,6 +34,16 @@ void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) {
images_[aState] = anImage ? *anImage : SkBitmap();
}
+void ImageButton::SetBackground(SkColor color,
+ SkBitmap* image,
+ SkBitmap* mask) {
+ if (!color && !image)
+ background_image_ = NULL;
+
+ background_image_ = new SkBitmap(
+ skia::ImageOperations::CreateButtonBackground(color, *image, *mask));
+}
+
void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
VerticalAlignment v_align) {
h_alignment_ = h_align;
@@ -68,6 +79,8 @@ void ImageButton::Paint(gfx::Canvas* canvas) {
else if (v_alignment_ == ALIGN_BOTTOM)
y = height() - img.height();
+ if (background_image_)
+ canvas->DrawBitmapInt(*background_image_, x, y);
canvas->DrawBitmapInt(img, x, y);
}
PaintFocusBorder(canvas);