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

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

Issue 1534303002: CustomButton cleanup: make protected members private, create accessors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dont move declaration randomly Created 4 years, 11 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
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/button/label_button.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/button/image_button.h" 5 #include "ui/views/controls/button/image_button.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 void ImageButton::OnBlur() { 139 void ImageButton::OnBlur() {
140 View::OnBlur(); 140 View::OnBlur();
141 if (focus_painter_.get()) 141 if (focus_painter_.get())
142 SchedulePaint(); 142 SchedulePaint();
143 } 143 }
144 144
145 gfx::ImageSkia ImageButton::GetImageToPaint() { 145 gfx::ImageSkia ImageButton::GetImageToPaint() {
146 gfx::ImageSkia img; 146 gfx::ImageSkia img;
147 147
148 if (!images_[STATE_HOVERED].isNull() && hover_animation_->is_animating()) { 148 if (!images_[STATE_HOVERED].isNull() && hover_animation().is_animating()) {
149 img = gfx::ImageSkiaOperations::CreateBlendedImage(images_[STATE_NORMAL], 149 img = gfx::ImageSkiaOperations::CreateBlendedImage(
150 images_[STATE_HOVERED], hover_animation_->GetCurrentValue()); 150 images_[STATE_NORMAL], images_[STATE_HOVERED],
151 hover_animation().GetCurrentValue());
151 } else { 152 } else {
152 img = images_[state_]; 153 img = images_[state()];
153 } 154 }
154 155
155 return !img.isNull() ? img : images_[STATE_NORMAL]; 156 return !img.isNull() ? img : images_[STATE_NORMAL];
156 } 157 }
157 158
158 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
159 // ImageButton, private: 160 // ImageButton, private:
160 161
161 gfx::Point ImageButton::ComputeImagePaintPosition(const gfx::ImageSkia& image) { 162 gfx::Point ImageButton::ComputeImagePaintPosition(const gfx::ImageSkia& image) {
162 int x = 0, y = 0; 163 int x = 0, y = 0;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 gfx::ImageSkia temp = images_[i]; 206 gfx::ImageSkia temp = images_[i];
206 images_[i] = alternate_images_[i]; 207 images_[i] = alternate_images_[i];
207 alternate_images_[i] = temp; 208 alternate_images_[i] = temp;
208 } 209 }
209 toggled_ = toggled; 210 toggled_ = toggled;
210 SchedulePaint(); 211 SchedulePaint();
211 212
212 NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true); 213 NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true);
213 } 214 }
214 215
215 void ToggleImageButton::SetToggledImage(ButtonState state, 216 void ToggleImageButton::SetToggledImage(ButtonState image_state,
216 const gfx::ImageSkia* image) { 217 const gfx::ImageSkia* image) {
217 if (toggled_) { 218 if (toggled_) {
218 images_[state] = image ? *image : gfx::ImageSkia(); 219 images_[image_state] = image ? *image : gfx::ImageSkia();
219 if (state_ == state) 220 if (state() == image_state)
220 SchedulePaint(); 221 SchedulePaint();
221 } else { 222 } else {
222 alternate_images_[state] = image ? *image : gfx::ImageSkia(); 223 alternate_images_[image_state] = image ? *image : gfx::ImageSkia();
223 } 224 }
224 } 225 }
225 226
226 void ToggleImageButton::SetToggledTooltipText(const base::string16& tooltip) { 227 void ToggleImageButton::SetToggledTooltipText(const base::string16& tooltip) {
227 toggled_tooltip_text_ = tooltip; 228 toggled_tooltip_text_ = tooltip;
228 } 229 }
229 230
230 //////////////////////////////////////////////////////////////////////////////// 231 ////////////////////////////////////////////////////////////////////////////////
231 // ToggleImageButton, ImageButton overrides: 232 // ToggleImageButton, ImageButton overrides:
232 233
233 const gfx::ImageSkia& ToggleImageButton::GetImage(ButtonState state) const { 234 const gfx::ImageSkia& ToggleImageButton::GetImage(
235 ButtonState image_state) const {
234 if (toggled_) 236 if (toggled_)
235 return alternate_images_[state]; 237 return alternate_images_[image_state];
236 return images_[state]; 238 return images_[image_state];
237 } 239 }
238 240
239 void ToggleImageButton::SetImage(ButtonState state, 241 void ToggleImageButton::SetImage(ButtonState image_state,
240 const gfx::ImageSkia* image) { 242 const gfx::ImageSkia* image) {
241 if (toggled_) { 243 if (toggled_) {
242 alternate_images_[state] = image ? *image : gfx::ImageSkia(); 244 alternate_images_[image_state] = image ? *image : gfx::ImageSkia();
243 } else { 245 } else {
244 images_[state] = image ? *image : gfx::ImageSkia(); 246 images_[image_state] = image ? *image : gfx::ImageSkia();
245 if (state_ == state) 247 if (state() == image_state)
246 SchedulePaint(); 248 SchedulePaint();
247 } 249 }
248 PreferredSizeChanged(); 250 PreferredSizeChanged();
249 } 251 }
250 252
251 //////////////////////////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////////////////////////
252 // ToggleImageButton, View overrides: 254 // ToggleImageButton, View overrides:
253 255
254 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, 256 bool ToggleImageButton::GetTooltipText(const gfx::Point& p,
255 base::string16* tooltip) const { 257 base::string16* tooltip) const {
256 if (!toggled_ || toggled_tooltip_text_.empty()) 258 if (!toggled_ || toggled_tooltip_text_.empty())
257 return Button::GetTooltipText(p, tooltip); 259 return Button::GetTooltipText(p, tooltip);
258 260
259 *tooltip = toggled_tooltip_text_; 261 *tooltip = toggled_tooltip_text_;
260 return true; 262 return true;
261 } 263 }
262 264
263 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { 265 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) {
264 ImageButton::GetAccessibleState(state); 266 ImageButton::GetAccessibleState(state);
265 GetTooltipText(gfx::Point(), &state->name); 267 GetTooltipText(gfx::Point(), &state->name);
266 } 268 }
267 269
268 } // namespace views 270 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/button/label_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698