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

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

Issue 2418003: Added const to image parameters for ImageButton class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/throb_animation.h" 7 #include "app/throb_animation.h"
8 #include "gfx/canvas.h" 8 #include "gfx/canvas.h"
9 #include "gfx/skbitmap_operations.h" 9 #include "gfx/skbitmap_operations.h"
10 10
(...skipping 11 matching lines...) Expand all
22 v_alignment_(ALIGN_TOP) { 22 v_alignment_(ALIGN_TOP) {
23 // 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()
24 // implementation is flipped horizontally so that the button's bitmaps are 24 // implementation is flipped horizontally so that the button's bitmaps are
25 // mirrored when the UI directionality is right-to-left. 25 // mirrored when the UI directionality is right-to-left.
26 EnableCanvasFlippingForRTLUI(true); 26 EnableCanvasFlippingForRTLUI(true);
27 } 27 }
28 28
29 ImageButton::~ImageButton() { 29 ImageButton::~ImageButton() {
30 } 30 }
31 31
32 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) { 32 void ImageButton::SetImage(ButtonState aState, const SkBitmap* anImage) {
33 images_[aState] = anImage ? *anImage : SkBitmap(); 33 images_[aState] = anImage ? *anImage : SkBitmap();
34 } 34 }
35 35
36 void ImageButton::SetBackground(SkColor color, 36 void ImageButton::SetBackground(SkColor color,
37 SkBitmap* image, 37 const SkBitmap* image,
38 SkBitmap* mask) { 38 const SkBitmap* mask) {
39 if (!image || !mask) { 39 if (!image || !mask) {
40 background_image_.reset(); 40 background_image_.reset();
41 return; 41 return;
42 } 42 }
43 43
44 background_image_ = 44 background_image_ =
45 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); 45 SkBitmapOperations::CreateButtonBackground(color, *image, *mask);
46 } 46 }
47 47
48 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, 48 void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 for (int i = 0; i < BS_COUNT; ++i) { 121 for (int i = 0; i < BS_COUNT; ++i) {
122 SkBitmap temp = images_[i]; 122 SkBitmap temp = images_[i];
123 images_[i] = alternate_images_[i]; 123 images_[i] = alternate_images_[i];
124 alternate_images_[i] = temp; 124 alternate_images_[i] = temp;
125 } 125 }
126 toggled_ = toggled; 126 toggled_ = toggled;
127 SchedulePaint(); 127 SchedulePaint();
128 } 128 }
129 129
130 void ToggleImageButton::SetToggledImage(ButtonState state, SkBitmap* image) { 130 void ToggleImageButton::SetToggledImage(ButtonState state,
131 const SkBitmap* image) {
131 if (toggled_) { 132 if (toggled_) {
132 images_[state] = image ? *image : SkBitmap(); 133 images_[state] = image ? *image : SkBitmap();
133 if (state_ == state) 134 if (state_ == state)
134 SchedulePaint(); 135 SchedulePaint();
135 } else { 136 } else {
136 alternate_images_[state] = image ? *image : SkBitmap(); 137 alternate_images_[state] = image ? *image : SkBitmap();
137 } 138 }
138 } 139 }
139 140
140 void ToggleImageButton::SetToggledTooltipText(const std::wstring& tooltip) { 141 void ToggleImageButton::SetToggledTooltipText(const std::wstring& tooltip) {
141 toggled_tooltip_text_.assign(tooltip); 142 toggled_tooltip_text_.assign(tooltip);
142 } 143 }
143 144
144 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
145 // ToggleImageButton, ImageButton overrides: 146 // ToggleImageButton, ImageButton overrides:
146 147
147 void ToggleImageButton::SetImage(ButtonState state, SkBitmap* image) { 148 void ToggleImageButton::SetImage(ButtonState state, const SkBitmap* image) {
148 if (toggled_) { 149 if (toggled_) {
149 alternate_images_[state] = image ? *image : SkBitmap(); 150 alternate_images_[state] = image ? *image : SkBitmap();
150 } else { 151 } else {
151 images_[state] = image ? *image : SkBitmap(); 152 images_[state] = image ? *image : SkBitmap();
152 if (state_ == state) 153 if (state_ == state)
153 SchedulePaint(); 154 SchedulePaint();
154 } 155 }
155 } 156 }
156 157
157 //////////////////////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////////////////
158 // ToggleImageButton, View overrides: 159 // ToggleImageButton, View overrides:
159 160
160 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, 161 bool ToggleImageButton::GetTooltipText(const gfx::Point& p,
161 std::wstring* tooltip) { 162 std::wstring* tooltip) {
162 if (!toggled_ || toggled_tooltip_text_.empty()) 163 if (!toggled_ || toggled_tooltip_text_.empty())
163 return Button::GetTooltipText(p, tooltip); 164 return Button::GetTooltipText(p, tooltip);
164 165
165 *tooltip = toggled_tooltip_text_; 166 *tooltip = toggled_tooltip_text_;
166 return true; 167 return true;
167 } 168 }
168 169
169 } // namespace views 170 } // 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