| OLD | NEW |
| 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 Loading... |
| 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) { | |
| 55 if (for_state == STATE_HOVERED) | 51 if (for_state == STATE_HOVERED) |
| 56 set_animate_on_state_change(!image.isNull()); | 52 set_animate_on_state_change(image != nullptr); |
| 57 const gfx::Size old_preferred_size = GetPreferredSize(); | 53 const gfx::Size old_preferred_size = GetPreferredSize(); |
| 58 images_[for_state] = image; | 54 images_[for_state] = image ? *image : gfx::ImageSkia(); |
| 59 | 55 |
| 60 if (old_preferred_size != GetPreferredSize()) | 56 if (old_preferred_size != GetPreferredSize()) |
| 61 PreferredSizeChanged(); | 57 PreferredSizeChanged(); |
| 62 | 58 |
| 63 if (state() == for_state) | 59 if (state() == for_state) |
| 64 SchedulePaint(); | 60 SchedulePaint(); |
| 65 } | 61 } |
| 66 | 62 |
| 67 void ImageButton::SetBackground(SkColor color, | 63 void ImageButton::SetBackground(SkColor color, |
| 68 const gfx::ImageSkia* image, | 64 const gfx::ImageSkia* image, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // ToggleImageButton, ImageButton overrides: | 243 // ToggleImageButton, ImageButton overrides: |
| 248 | 244 |
| 249 const gfx::ImageSkia& ToggleImageButton::GetImage( | 245 const gfx::ImageSkia& ToggleImageButton::GetImage( |
| 250 ButtonState image_state) const { | 246 ButtonState image_state) const { |
| 251 if (toggled_) | 247 if (toggled_) |
| 252 return alternate_images_[image_state]; | 248 return alternate_images_[image_state]; |
| 253 return images_[image_state]; | 249 return images_[image_state]; |
| 254 } | 250 } |
| 255 | 251 |
| 256 void ToggleImageButton::SetImage(ButtonState image_state, | 252 void ToggleImageButton::SetImage(ButtonState image_state, |
| 257 const gfx::ImageSkia& image) { | 253 const gfx::ImageSkia* image) { |
| 258 if (toggled_) { | 254 if (toggled_) { |
| 259 alternate_images_[image_state] = image; | 255 alternate_images_[image_state] = image ? *image : gfx::ImageSkia(); |
| 260 } else { | 256 } else { |
| 261 images_[image_state] = image; | 257 images_[image_state] = image ? *image : gfx::ImageSkia(); |
| 262 if (state() == image_state) | 258 if (state() == image_state) |
| 263 SchedulePaint(); | 259 SchedulePaint(); |
| 264 } | 260 } |
| 265 PreferredSizeChanged(); | 261 PreferredSizeChanged(); |
| 266 } | 262 } |
| 267 | 263 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
| 269 // ToggleImageButton, View overrides: | 265 // ToggleImageButton, View overrides: |
| 270 | 266 |
| 271 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, | 267 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 287 // accessible toggle button. | 283 // accessible toggle button. |
| 288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || | 284 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || |
| 289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { | 285 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { |
| 290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | 286 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| 291 if (toggled_) | 287 if (toggled_) |
| 292 node_data->AddStateFlag(ui::AX_STATE_PRESSED); | 288 node_data->AddStateFlag(ui::AX_STATE_PRESSED); |
| 293 } | 289 } |
| 294 } | 290 } |
| 295 | 291 |
| 296 } // namespace views | 292 } // namespace views |
| OLD | NEW |