| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
| 9 #include "ui/gfx/animation/throb_animation.h" | 9 #include "ui/gfx/animation/throb_animation.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const gfx::ImageSkia* image) { | 213 const gfx::ImageSkia* image) { |
| 214 if (toggled_) { | 214 if (toggled_) { |
| 215 images_[state] = image ? *image : gfx::ImageSkia(); | 215 images_[state] = image ? *image : gfx::ImageSkia(); |
| 216 if (state_ == state) | 216 if (state_ == state) |
| 217 SchedulePaint(); | 217 SchedulePaint(); |
| 218 } else { | 218 } else { |
| 219 alternate_images_[state] = image ? *image : gfx::ImageSkia(); | 219 alternate_images_[state] = image ? *image : gfx::ImageSkia(); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ToggleImageButton::SetToggledTooltipText(const string16& tooltip) { | 223 void ToggleImageButton::SetToggledTooltipText(const base::string16& tooltip) { |
| 224 toggled_tooltip_text_ = tooltip; | 224 toggled_tooltip_text_ = tooltip; |
| 225 } | 225 } |
| 226 | 226 |
| 227 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 228 // ToggleImageButton, ImageButton overrides: | 228 // ToggleImageButton, ImageButton overrides: |
| 229 | 229 |
| 230 const gfx::ImageSkia& ToggleImageButton::GetImage(ButtonState state) const { | 230 const gfx::ImageSkia& ToggleImageButton::GetImage(ButtonState state) const { |
| 231 if (toggled_) | 231 if (toggled_) |
| 232 return alternate_images_[state]; | 232 return alternate_images_[state]; |
| 233 return images_[state]; | 233 return images_[state]; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ToggleImageButton::SetImage(ButtonState state, | 236 void ToggleImageButton::SetImage(ButtonState state, |
| 237 const gfx::ImageSkia* image) { | 237 const gfx::ImageSkia* image) { |
| 238 if (toggled_) { | 238 if (toggled_) { |
| 239 alternate_images_[state] = image ? *image : gfx::ImageSkia(); | 239 alternate_images_[state] = image ? *image : gfx::ImageSkia(); |
| 240 } else { | 240 } else { |
| 241 images_[state] = image ? *image : gfx::ImageSkia(); | 241 images_[state] = image ? *image : gfx::ImageSkia(); |
| 242 if (state_ == state) | 242 if (state_ == state) |
| 243 SchedulePaint(); | 243 SchedulePaint(); |
| 244 } | 244 } |
| 245 PreferredSizeChanged(); | 245 PreferredSizeChanged(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 //////////////////////////////////////////////////////////////////////////////// | 248 //////////////////////////////////////////////////////////////////////////////// |
| 249 // ToggleImageButton, View overrides: | 249 // ToggleImageButton, View overrides: |
| 250 | 250 |
| 251 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, | 251 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, |
| 252 string16* tooltip) const { | 252 base::string16* tooltip) const { |
| 253 if (!toggled_ || toggled_tooltip_text_.empty()) | 253 if (!toggled_ || toggled_tooltip_text_.empty()) |
| 254 return Button::GetTooltipText(p, tooltip); | 254 return Button::GetTooltipText(p, tooltip); |
| 255 | 255 |
| 256 *tooltip = toggled_tooltip_text_; | 256 *tooltip = toggled_tooltip_text_; |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 void ToggleImageButton::GetAccessibleState(ui::AccessibleViewState* state) { | 260 void ToggleImageButton::GetAccessibleState(ui::AccessibleViewState* state) { |
| 261 ImageButton::GetAccessibleState(state); | 261 ImageButton::GetAccessibleState(state); |
| 262 GetTooltipText(gfx::Point(), &state->name); | 262 GetTooltipText(gfx::Point(), &state->name); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace views | 265 } // namespace views |
| OLD | NEW |