diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
commit | 6e853c3ad131fe6713ce8efbac2270fee26ab5b2 (patch) | |
tree | d0c9c8a5d1949cbdd108059add44b86b989514f4 /views | |
parent | 26e99ffd2a4179aefe5dbf8cbd5da74c0bc7a76b (diff) | |
download | chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.zip chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.gz chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.bz2 |
Add ability to theme our buttons.
BUG=12762
TEST=Verify that buttons can be themed.
Review URL: http://codereview.chromium.org/119025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/image_button.cc | 15 | ||||
-rw-r--r-- | views/controls/button/image_button.h | 6 |
2 files changed, 20 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); diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h index ec3b9ae..c3edceb 100644 --- a/views/controls/button/image_button.h +++ b/views/controls/button/image_button.h @@ -19,6 +19,9 @@ class ImageButton : public CustomButton { // Set the image the button should use for the provided state. virtual void SetImage(ButtonState aState, SkBitmap* anImage); + // Set the background details. + virtual void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask); + enum HorizontalAlignment { ALIGN_LEFT = 0, ALIGN_CENTER, ALIGN_RIGHT, }; @@ -43,6 +46,9 @@ class ImageButton : public CustomButton { // The images used to render the different states of this button. SkBitmap images_[BS_COUNT]; + // The background image. + SkBitmap* background_image_; + private: // Image alignment. HorizontalAlignment h_alignment_; |