Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: views/controls/button/image_button.cc

Issue 119025: Add ability to theme our buttons.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "views/controls/button/image_button.h" 5 #include "views/controls/button/image_button.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/throb_animation.h" 8 #include "app/throb_animation.h"
9 #include "skia/ext/image_operations.h" 9 #include "skia/ext/image_operations.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 static const int kDefaultWidth = 16; // Default button width if no theme. 13 static const int kDefaultWidth = 16; // Default button width if no theme.
14 static const int kDefaultHeight = 14; // Default button height if no theme. 14 static const int kDefaultHeight = 14; // Default button height if no theme.
15 15
16 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
17 // ImageButton, public: 17 // ImageButton, public:
18 18
19 ImageButton::ImageButton(ButtonListener* listener) 19 ImageButton::ImageButton(ButtonListener* listener)
20 : CustomButton(listener), 20 : CustomButton(listener),
21 h_alignment_(ALIGN_LEFT), 21 h_alignment_(ALIGN_LEFT),
22 v_alignment_(ALIGN_TOP) { 22 v_alignment_(ALIGN_TOP),
23 background_image_(NULL) {
23 // By default, we request that the gfx::Canvas passed to our View::Paint() 24 // By default, we request that the gfx::Canvas passed to our View::Paint()
24 // implementation is flipped horizontally so that the button's bitmaps are 25 // implementation is flipped horizontally so that the button's bitmaps are
25 // mirrored when the UI directionality is right-to-left. 26 // mirrored when the UI directionality is right-to-left.
26 EnableCanvasFlippingForRTLUI(true); 27 EnableCanvasFlippingForRTLUI(true);
27 } 28 }
28 29
29 ImageButton::~ImageButton() { 30 ImageButton::~ImageButton() {
30 } 31 }
31 32
32 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) { 33 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) {
33 images_[aState] = anImage ? *anImage : SkBitmap(); 34 images_[aState] = anImage ? *anImage : SkBitmap();
34 } 35 }
35 36
37 void ImageButton::SetBackground(SkColor color,
38 SkBitmap* image,
39 SkBitmap* mask) {
40 if (!color && !image)
41 background_image_ = NULL;
42
43 background_image_ = new SkBitmap(
44 skia::ImageOperations::CreateButtonBackground(color, *image, *mask));
45 }
46
36 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, 47 void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
37 VerticalAlignment v_align) { 48 VerticalAlignment v_align) {
38 h_alignment_ = h_align; 49 h_alignment_ = h_align;
39 v_alignment_ = v_align; 50 v_alignment_ = v_align;
40 SchedulePaint(); 51 SchedulePaint();
41 } 52 }
42 53
43 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
44 // ImageButton, View overrides: 55 // ImageButton, View overrides:
45 56
(...skipping 15 matching lines...) Expand all
61 if (h_alignment_ == ALIGN_CENTER) 72 if (h_alignment_ == ALIGN_CENTER)
62 x = (width() - img.width()) / 2; 73 x = (width() - img.width()) / 2;
63 else if (h_alignment_ == ALIGN_RIGHT) 74 else if (h_alignment_ == ALIGN_RIGHT)
64 x = width() - img.width(); 75 x = width() - img.width();
65 76
66 if (v_alignment_ == ALIGN_MIDDLE) 77 if (v_alignment_ == ALIGN_MIDDLE)
67 y = (height() - img.height()) / 2; 78 y = (height() - img.height()) / 2;
68 else if (v_alignment_ == ALIGN_BOTTOM) 79 else if (v_alignment_ == ALIGN_BOTTOM)
69 y = height() - img.height(); 80 y = height() - img.height();
70 81
82 if (background_image_)
83 canvas->DrawBitmapInt(*background_image_, x, y);
71 canvas->DrawBitmapInt(img, x, y); 84 canvas->DrawBitmapInt(img, x, y);
72 } 85 }
73 PaintFocusBorder(canvas); 86 PaintFocusBorder(canvas);
74 } 87 }
75 88
76 //////////////////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////////////////
77 // ImageButton, protected: 90 // ImageButton, protected:
78 91
79 SkBitmap ImageButton::GetImageToPaint() { 92 SkBitmap ImageButton::GetImageToPaint() {
80 SkBitmap img; 93 SkBitmap img;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 158
146 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) { 159 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
147 if (!toggled_ || toggled_tooltip_text_.empty()) 160 if (!toggled_ || toggled_tooltip_text_.empty())
148 return Button::GetTooltipText(x, y, tooltip); 161 return Button::GetTooltipText(x, y, tooltip);
149 162
150 *tooltip = toggled_tooltip_text_; 163 *tooltip = toggled_tooltip_text_;
151 return true; 164 return true;
152 } 165 }
153 166
154 } // namespace views 167 } // namespace views
OLDNEW
« chrome/common/extensions/extension.cc ('K') | « views/controls/button/image_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698