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

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

Issue 2622893003: Reland f5157480667e99269e0062e9df1df3875db with fix for compile failure. (Closed)
Patch Set: fix in two BUILD.gns Created 3 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/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) 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_node_data.h" 10 #include "ui/accessibility/ax_node_data.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 ImageButton::~ImageButton() { 43 ImageButton::~ImageButton() {
44 } 44 }
45 45
46 const gfx::ImageSkia& ImageButton::GetImage(ButtonState state) const { 46 const gfx::ImageSkia& ImageButton::GetImage(ButtonState state) const {
47 return images_[state]; 47 return images_[state];
48 } 48 }
49 49
50 void ImageButton::SetImage(ButtonState for_state, const gfx::ImageSkia* image) { 50 void ImageButton::SetImage(ButtonState for_state, const gfx::ImageSkia* image) {
51 SetImage(for_state, image ? *image : gfx::ImageSkia());
52 }
53
54 void ImageButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) {
51 if (for_state == STATE_HOVERED) 55 if (for_state == STATE_HOVERED)
52 set_animate_on_state_change(image != nullptr); 56 set_animate_on_state_change(!image.isNull());
53 const gfx::Size old_preferred_size = GetPreferredSize(); 57 const gfx::Size old_preferred_size = GetPreferredSize();
54 images_[for_state] = image ? *image : gfx::ImageSkia(); 58 images_[for_state] = image;
55 59
56 if (old_preferred_size != GetPreferredSize()) 60 if (old_preferred_size != GetPreferredSize())
57 PreferredSizeChanged(); 61 PreferredSizeChanged();
58 62
59 if (state() == for_state) 63 if (state() == for_state)
60 SchedulePaint(); 64 SchedulePaint();
61 } 65 }
62 66
63 void ImageButton::SetBackground(SkColor color, 67 void ImageButton::SetBackground(SkColor color,
64 const gfx::ImageSkia* image, 68 const gfx::ImageSkia* image,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // ToggleImageButton, ImageButton overrides: 247 // ToggleImageButton, ImageButton overrides:
244 248
245 const gfx::ImageSkia& ToggleImageButton::GetImage( 249 const gfx::ImageSkia& ToggleImageButton::GetImage(
246 ButtonState image_state) const { 250 ButtonState image_state) const {
247 if (toggled_) 251 if (toggled_)
248 return alternate_images_[image_state]; 252 return alternate_images_[image_state];
249 return images_[image_state]; 253 return images_[image_state];
250 } 254 }
251 255
252 void ToggleImageButton::SetImage(ButtonState image_state, 256 void ToggleImageButton::SetImage(ButtonState image_state,
253 const gfx::ImageSkia* image) { 257 const gfx::ImageSkia& image) {
254 if (toggled_) { 258 if (toggled_) {
255 alternate_images_[image_state] = image ? *image : gfx::ImageSkia(); 259 alternate_images_[image_state] = image;
256 } else { 260 } else {
257 images_[image_state] = image ? *image : gfx::ImageSkia(); 261 images_[image_state] = image;
258 if (state() == image_state) 262 if (state() == image_state)
259 SchedulePaint(); 263 SchedulePaint();
260 } 264 }
261 PreferredSizeChanged(); 265 PreferredSizeChanged();
262 } 266 }
263 267
264 //////////////////////////////////////////////////////////////////////////////// 268 ////////////////////////////////////////////////////////////////////////////////
265 // ToggleImageButton, View overrides: 269 // ToggleImageButton, View overrides:
266 270
267 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, 271 bool ToggleImageButton::GetTooltipText(const gfx::Point& p,
(...skipping 15 matching lines...) Expand all
283 // accessible toggle button. 287 // accessible toggle button.
284 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || 288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) ||
285 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { 289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) {
286 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; 290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON;
287 if (toggled_) 291 if (toggled_)
288 node_data->AddStateFlag(ui::AX_STATE_PRESSED); 292 node_data->AddStateFlag(ui::AX_STATE_PRESSED);
289 } 293 }
290 } 294 }
291 295
292 } // namespace views 296 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698