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

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

Issue 160063: Fix for a coverity reported error (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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
« no previous file with comments | « views/controls/button/image_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 background_image_(NULL),
22 h_alignment_(ALIGN_LEFT), 21 h_alignment_(ALIGN_LEFT),
23 v_alignment_(ALIGN_TOP) { 22 v_alignment_(ALIGN_TOP) {
24 // By default, we request that the gfx::Canvas passed to our View::Paint() 23 // By default, we request that the gfx::Canvas passed to our View::Paint()
25 // implementation is flipped horizontally so that the button's bitmaps are 24 // implementation is flipped horizontally so that the button's bitmaps are
26 // mirrored when the UI directionality is right-to-left. 25 // mirrored when the UI directionality is right-to-left.
27 EnableCanvasFlippingForRTLUI(true); 26 EnableCanvasFlippingForRTLUI(true);
28 } 27 }
29 28
30 ImageButton::~ImageButton() { 29 ImageButton::~ImageButton() {
31 } 30 }
32 31
33 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) { 32 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) {
34 images_[aState] = anImage ? *anImage : SkBitmap(); 33 images_[aState] = anImage ? *anImage : SkBitmap();
35 } 34 }
36 35
37 void ImageButton::SetBackground(SkColor color, 36 void ImageButton::SetBackground(SkColor color,
38 SkBitmap* image, 37 SkBitmap* image,
39 SkBitmap* mask) { 38 SkBitmap* mask) {
40 if (!color && !image) 39 if (!image || !mask) {
41 background_image_.reset(NULL); 40 background_image_.reset();
41 return;
42 }
42 43
43 background_image_.reset(new SkBitmap( 44 background_image_ = skia::ImageOperations::CreateButtonBackground(color,
44 skia::ImageOperations::CreateButtonBackground(color, *image, *mask))); 45 *image,
46 *mask);
45 } 47 }
46 48
47 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, 49 void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
48 VerticalAlignment v_align) { 50 VerticalAlignment v_align) {
49 h_alignment_ = h_align; 51 h_alignment_ = h_align;
50 v_alignment_ = v_align; 52 v_alignment_ = v_align;
51 SchedulePaint(); 53 SchedulePaint();
52 } 54 }
53 55
54 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
(...skipping 17 matching lines...) Expand all
72 if (h_alignment_ == ALIGN_CENTER) 74 if (h_alignment_ == ALIGN_CENTER)
73 x = (width() - img.width()) / 2; 75 x = (width() - img.width()) / 2;
74 else if (h_alignment_ == ALIGN_RIGHT) 76 else if (h_alignment_ == ALIGN_RIGHT)
75 x = width() - img.width(); 77 x = width() - img.width();
76 78
77 if (v_alignment_ == ALIGN_MIDDLE) 79 if (v_alignment_ == ALIGN_MIDDLE)
78 y = (height() - img.height()) / 2; 80 y = (height() - img.height()) / 2;
79 else if (v_alignment_ == ALIGN_BOTTOM) 81 else if (v_alignment_ == ALIGN_BOTTOM)
80 y = height() - img.height(); 82 y = height() - img.height();
81 83
82 if (background_image_.get()) 84 if (!background_image_.empty())
83 canvas->DrawBitmapInt(*(background_image_.get()), x, y); 85 canvas->DrawBitmapInt(background_image_, x, y);
84 canvas->DrawBitmapInt(img, x, y); 86 canvas->DrawBitmapInt(img, x, y);
85 } 87 }
86 PaintFocusBorder(canvas); 88 PaintFocusBorder(canvas);
87 } 89 }
88 90
89 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
90 // ImageButton, protected: 92 // ImageButton, protected:
91 93
92 SkBitmap ImageButton::GetImageToPaint() { 94 SkBitmap ImageButton::GetImageToPaint() {
93 SkBitmap img; 95 SkBitmap img;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 160
159 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) { 161 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
160 if (!toggled_ || toggled_tooltip_text_.empty()) 162 if (!toggled_ || toggled_tooltip_text_.empty())
161 return Button::GetTooltipText(x, y, tooltip); 163 return Button::GetTooltipText(x, y, tooltip);
162 164
163 *tooltip = toggled_tooltip_text_; 165 *tooltip = toggled_tooltip_text_;
164 return true; 166 return true;
165 } 167 }
166 168
167 } // namespace views 169 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/image_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698