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

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

Issue 2162083004: Make ToggleImageButton into an accessible toggle button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test. Created 4 years, 5 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
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return; 208 return;
209 209
210 for (int i = 0; i < STATE_COUNT; ++i) { 210 for (int i = 0; i < STATE_COUNT; ++i) {
211 gfx::ImageSkia temp = images_[i]; 211 gfx::ImageSkia temp = images_[i];
212 images_[i] = alternate_images_[i]; 212 images_[i] = alternate_images_[i];
213 alternate_images_[i] = temp; 213 alternate_images_[i] = temp;
214 } 214 }
215 toggled_ = toggled; 215 toggled_ = toggled;
216 SchedulePaint(); 216 SchedulePaint();
217 217
218 NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true); 218 NotifyAccessibilityEvent(ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED, true);
219 } 219 }
220 220
221 void ToggleImageButton::SetToggledImage(ButtonState image_state, 221 void ToggleImageButton::SetToggledImage(ButtonState image_state,
222 const gfx::ImageSkia* image) { 222 const gfx::ImageSkia* image) {
223 if (toggled_) { 223 if (toggled_) {
224 images_[image_state] = image ? *image : gfx::ImageSkia(); 224 images_[image_state] = image ? *image : gfx::ImageSkia();
225 if (state() == image_state) 225 if (state() == image_state)
226 SchedulePaint(); 226 SchedulePaint();
227 } else { 227 } else {
228 alternate_images_[image_state] = image ? *image : gfx::ImageSkia(); 228 alternate_images_[image_state] = image ? *image : gfx::ImageSkia();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (!toggled_ || toggled_tooltip_text_.empty()) 263 if (!toggled_ || toggled_tooltip_text_.empty())
264 return Button::GetTooltipText(p, tooltip); 264 return Button::GetTooltipText(p, tooltip);
265 265
266 *tooltip = toggled_tooltip_text_; 266 *tooltip = toggled_tooltip_text_;
267 return true; 267 return true;
268 } 268 }
269 269
270 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { 270 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) {
271 ImageButton::GetAccessibleState(state); 271 ImageButton::GetAccessibleState(state);
272 GetTooltipText(gfx::Point(), &state->name); 272 GetTooltipText(gfx::Point(), &state->name);
273
274 // Some subclasses only ever have one state. To get ChromeVox to read
275 // appropriately, only change the role when this control is toggled on.
276 if (toggled_) {
277 state->role = ui::AX_ROLE_TOGGLE_BUTTON;
278 state->AddStateFlag(ui::AX_STATE_PRESSED);
279 }
273 } 280 }
274 281
275 } // namespace views 282 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698