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/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 void ImageButton::OnBlur() { | 137 void ImageButton::OnBlur() { |
138 View::OnBlur(); | 138 View::OnBlur(); |
139 if (focus_painter_.get()) | 139 if (focus_painter_.get()) |
140 SchedulePaint(); | 140 SchedulePaint(); |
141 } | 141 } |
142 | 142 |
143 gfx::ImageSkia ImageButton::GetImageToPaint() { | 143 gfx::ImageSkia ImageButton::GetImageToPaint() { |
144 gfx::ImageSkia img; | 144 gfx::ImageSkia img; |
145 | 145 |
146 if (!images_[STATE_HOVERED].isNull() && hover_animation_->is_animating()) { | 146 if (!images_[STATE_HOVERED].isNull() && hover_animation().is_animating()) { |
147 img = gfx::ImageSkiaOperations::CreateBlendedImage(images_[STATE_NORMAL], | 147 img = gfx::ImageSkiaOperations::CreateBlendedImage( |
148 images_[STATE_HOVERED], hover_animation_->GetCurrentValue()); | 148 images_[STATE_NORMAL], images_[STATE_HOVERED], |
| 149 hover_animation().GetCurrentValue()); |
149 } else { | 150 } else { |
150 img = images_[state_]; | 151 img = images_[state()]; |
151 } | 152 } |
152 | 153 |
153 return !img.isNull() ? img : images_[STATE_NORMAL]; | 154 return !img.isNull() ? img : images_[STATE_NORMAL]; |
154 } | 155 } |
155 | 156 |
156 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
157 // ImageButton, private: | 158 // ImageButton, private: |
158 | 159 |
159 gfx::Point ImageButton::ComputeImagePaintPosition(const gfx::ImageSkia& image) { | 160 gfx::Point ImageButton::ComputeImagePaintPosition(const gfx::ImageSkia& image) { |
160 int x = 0, y = 0; | 161 int x = 0, y = 0; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 gfx::ImageSkia temp = images_[i]; | 204 gfx::ImageSkia temp = images_[i]; |
204 images_[i] = alternate_images_[i]; | 205 images_[i] = alternate_images_[i]; |
205 alternate_images_[i] = temp; | 206 alternate_images_[i] = temp; |
206 } | 207 } |
207 toggled_ = toggled; | 208 toggled_ = toggled; |
208 SchedulePaint(); | 209 SchedulePaint(); |
209 | 210 |
210 NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true); | 211 NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true); |
211 } | 212 } |
212 | 213 |
213 void ToggleImageButton::SetToggledImage(ButtonState state, | 214 void ToggleImageButton::SetToggledImage(ButtonState image_state, |
214 const gfx::ImageSkia* image) { | 215 const gfx::ImageSkia* image) { |
215 if (toggled_) { | 216 if (toggled_) { |
216 images_[state] = image ? *image : gfx::ImageSkia(); | 217 images_[image_state] = image ? *image : gfx::ImageSkia(); |
217 if (state_ == state) | 218 if (state() == image_state) |
218 SchedulePaint(); | 219 SchedulePaint(); |
219 } else { | 220 } else { |
220 alternate_images_[state] = image ? *image : gfx::ImageSkia(); | 221 alternate_images_[image_state] = image ? *image : gfx::ImageSkia(); |
221 } | 222 } |
222 } | 223 } |
223 | 224 |
224 void ToggleImageButton::SetToggledTooltipText(const base::string16& tooltip) { | 225 void ToggleImageButton::SetToggledTooltipText(const base::string16& tooltip) { |
225 toggled_tooltip_text_ = tooltip; | 226 toggled_tooltip_text_ = tooltip; |
226 } | 227 } |
227 | 228 |
228 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
229 // ToggleImageButton, ImageButton overrides: | 230 // ToggleImageButton, ImageButton overrides: |
230 | 231 |
231 const gfx::ImageSkia& ToggleImageButton::GetImage(ButtonState state) const { | 232 const gfx::ImageSkia& ToggleImageButton::GetImage( |
| 233 ButtonState image_state) const { |
232 if (toggled_) | 234 if (toggled_) |
233 return alternate_images_[state]; | 235 return alternate_images_[image_state]; |
234 return images_[state]; | 236 return images_[image_state]; |
235 } | 237 } |
236 | 238 |
237 void ToggleImageButton::SetImage(ButtonState state, | 239 void ToggleImageButton::SetImage(ButtonState image_state, |
238 const gfx::ImageSkia* image) { | 240 const gfx::ImageSkia* image) { |
239 if (toggled_) { | 241 if (toggled_) { |
240 alternate_images_[state] = image ? *image : gfx::ImageSkia(); | 242 alternate_images_[image_state] = image ? *image : gfx::ImageSkia(); |
241 } else { | 243 } else { |
242 images_[state] = image ? *image : gfx::ImageSkia(); | 244 images_[image_state] = image ? *image : gfx::ImageSkia(); |
243 if (state_ == state) | 245 if (state() == image_state) |
244 SchedulePaint(); | 246 SchedulePaint(); |
245 } | 247 } |
246 PreferredSizeChanged(); | 248 PreferredSizeChanged(); |
247 } | 249 } |
248 | 250 |
249 //////////////////////////////////////////////////////////////////////////////// | 251 //////////////////////////////////////////////////////////////////////////////// |
250 // ToggleImageButton, View overrides: | 252 // ToggleImageButton, View overrides: |
251 | 253 |
252 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, | 254 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, |
253 base::string16* tooltip) const { | 255 base::string16* tooltip) const { |
254 if (!toggled_ || toggled_tooltip_text_.empty()) | 256 if (!toggled_ || toggled_tooltip_text_.empty()) |
255 return Button::GetTooltipText(p, tooltip); | 257 return Button::GetTooltipText(p, tooltip); |
256 | 258 |
257 *tooltip = toggled_tooltip_text_; | 259 *tooltip = toggled_tooltip_text_; |
258 return true; | 260 return true; |
259 } | 261 } |
260 | 262 |
261 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { | 263 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { |
262 ImageButton::GetAccessibleState(state); | 264 ImageButton::GetAccessibleState(state); |
263 GetTooltipText(gfx::Point(), &state->name); | 265 GetTooltipText(gfx::Point(), &state->name); |
264 } | 266 } |
265 | 267 |
266 } // namespace views | 268 } // namespace views |
OLD | NEW |