Chromium Code Reviews| 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 "chrome/browser/ui/views/accessibility/accessibility_event_router_views .h" | 5 #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views .h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 12 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "ui/base/accessibility/accessible_view_state.h" | 18 #include "ui/base/accessibility/accessible_view_state.h" |
| 19 #include "ui/views/controls/menu/menu_item_view.h" | 19 #include "ui/views/controls/menu/menu_item_view.h" |
| 20 #include "ui/views/controls/menu/submenu_view.h" | 20 #include "ui/views/controls/menu/submenu_view.h" |
| 21 #include "ui/views/controls/tree/tree_view.h" | |
| 21 #include "ui/views/focus/view_storage.h" | 22 #include "ui/views/focus/view_storage.h" |
| 22 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
| 23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 24 | 25 |
| 25 using views::FocusManager; | 26 using views::FocusManager; |
| 26 | 27 |
| 27 AccessibilityEventRouterViews::AccessibilityEventRouterViews() | 28 AccessibilityEventRouterViews::AccessibilityEventRouterViews() |
| 28 : most_recent_profile_(NULL) { | 29 : most_recent_profile_(NULL) { |
| 29 // Register for notification when profile is destroyed to ensure that all | 30 // Register for notification when profile is destroyed to ensure that all |
| 30 // observers are detatched at that time. | 31 // observers are detatched at that time. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 168 |
| 168 if (type == ui::AccessibilityTypes::EVENT_ALERT && | 169 if (type == ui::AccessibilityTypes::EVENT_ALERT && |
| 169 !(state.role == ui::AccessibilityTypes::ROLE_ALERT || | 170 !(state.role == ui::AccessibilityTypes::ROLE_ALERT || |
| 170 state.role == ui::AccessibilityTypes::ROLE_WINDOW)) { | 171 state.role == ui::AccessibilityTypes::ROLE_WINDOW)) { |
| 171 SendAlertControlNotification(view, type, profile); | 172 SendAlertControlNotification(view, type, profile); |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 | 175 |
| 175 switch (state.role) { | 176 switch (state.role) { |
| 176 case ui::AccessibilityTypes::ROLE_ALERT: | 177 case ui::AccessibilityTypes::ROLE_ALERT: |
| 178 case ui::AccessibilityTypes::ROLE_DIALOG: | |
| 177 case ui::AccessibilityTypes::ROLE_WINDOW: | 179 case ui::AccessibilityTypes::ROLE_WINDOW: |
| 178 SendWindowNotification(view, type, profile); | 180 SendWindowNotification(view, type, profile); |
| 179 break; | 181 break; |
| 180 case ui::AccessibilityTypes::ROLE_BUTTONMENU: | 182 case ui::AccessibilityTypes::ROLE_BUTTONMENU: |
| 181 case ui::AccessibilityTypes::ROLE_MENUBAR: | 183 case ui::AccessibilityTypes::ROLE_MENUBAR: |
| 182 case ui::AccessibilityTypes::ROLE_MENUPOPUP: | 184 case ui::AccessibilityTypes::ROLE_MENUPOPUP: |
| 183 SendMenuNotification(view, type, profile); | 185 SendMenuNotification(view, type, profile); |
| 184 break; | 186 break; |
| 185 case ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN: | 187 case ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN: |
| 186 case ui::AccessibilityTypes::ROLE_PUSHBUTTON: | 188 case ui::AccessibilityTypes::ROLE_PUSHBUTTON: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 200 SendTextfieldNotification(view, type, profile); | 202 SendTextfieldNotification(view, type, profile); |
| 201 break; | 203 break; |
| 202 case ui::AccessibilityTypes::ROLE_MENUITEM: | 204 case ui::AccessibilityTypes::ROLE_MENUITEM: |
| 203 SendMenuItemNotification(view, type, profile); | 205 SendMenuItemNotification(view, type, profile); |
| 204 break; | 206 break; |
| 205 case ui::AccessibilityTypes::ROLE_RADIOBUTTON: | 207 case ui::AccessibilityTypes::ROLE_RADIOBUTTON: |
| 206 // Not used anymore? | 208 // Not used anymore? |
| 207 case ui::AccessibilityTypes::ROLE_SLIDER: | 209 case ui::AccessibilityTypes::ROLE_SLIDER: |
| 208 SendSliderNotification(view, type, profile); | 210 SendSliderNotification(view, type, profile); |
| 209 break; | 211 break; |
| 212 case ui::AccessibilityTypes::ROLE_OUTLINE: | |
| 213 SendMenuNotification(view, type, profile); | |
| 214 break; | |
| 215 case ui::AccessibilityTypes::ROLE_OUTLINEITEM: | |
| 216 SendTreeItemNotification(view, type, profile); | |
| 217 break; | |
| 210 default: | 218 default: |
| 211 // If this is encountered, please file a bug with the role that wasn't | 219 // If this is encountered, please file a bug with the role that wasn't |
| 212 // caught so we can add accessibility extension API support. | 220 // caught so we can add accessibility extension API support. |
| 213 NOTREACHED(); | 221 NOTREACHED(); |
| 214 } | 222 } |
| 215 } | 223 } |
| 216 | 224 |
| 217 // static | 225 // static |
| 218 void AccessibilityEventRouterViews::SendButtonNotification( | 226 void AccessibilityEventRouterViews::SendButtonNotification( |
| 219 views::View* view, | 227 views::View* view, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 count = 0; | 274 count = 0; |
| 267 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 275 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); |
| 268 } | 276 } |
| 269 | 277 |
| 270 AccessibilityMenuItemInfo info( | 278 AccessibilityMenuItemInfo info( |
| 271 profile, name, context, has_submenu, index, count); | 279 profile, name, context, has_submenu, index, count); |
| 272 SendControlAccessibilityNotification(event, &info); | 280 SendControlAccessibilityNotification(event, &info); |
| 273 } | 281 } |
| 274 | 282 |
| 275 // static | 283 // static |
| 284 void AccessibilityEventRouterViews::SendTreeItemNotification( | |
| 285 views::View* view, | |
| 286 ui::AccessibilityTypes::Event event, | |
| 287 Profile* profile) { | |
| 288 std::string name = GetViewName(view); | |
| 289 std::string context = GetViewContext(view); | |
| 290 | |
| 291 if (strcmp(view->GetClassName(), views::TreeView::kViewClassName) != 0) { | |
| 292 NOTREACHED(); | |
| 293 return; | |
| 294 } | |
| 295 | |
| 296 views::TreeView* tree = static_cast<views::TreeView*>(view); | |
|
dmazzoni
2013/11/21 06:54:07
Why is the view with a role of OUTLINEITEM the one
zel
2013/11/22 02:34:01
moved to another CL, will be addresses there
| |
| 297 ui::TreeModelNode* selected_node = tree->GetSelectedNode(); | |
| 298 ui::TreeModel* model = tree->model(); | |
| 299 | |
| 300 bool has_submenu = false; | |
| 301 int index = -1; | |
| 302 int count = -1; | |
|
dmazzoni
2013/11/21 06:54:07
Can we set the count even if there isn't a selecte
zel
2013/11/22 02:34:01
moved to another CL, will be addresses there
| |
| 303 | |
| 304 if (selected_node) { | |
| 305 has_submenu = model->GetChildCount(selected_node); | |
| 306 ui::TreeModelNode* parent_node = model->GetParent(selected_node); | |
| 307 if (parent_node) { | |
| 308 index = model->GetIndexOf(parent_node, selected_node); | |
| 309 count = model->GetChildCount(parent_node); | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 AccessibilityMenuItemInfo info( | |
| 314 profile, name, context, has_submenu, index, count); | |
| 315 SendControlAccessibilityNotification(event, &info); | |
| 316 } | |
| 317 | |
| 318 // static | |
| 276 void AccessibilityEventRouterViews::SendTextfieldNotification( | 319 void AccessibilityEventRouterViews::SendTextfieldNotification( |
| 277 views::View* view, | 320 views::View* view, |
| 278 ui::AccessibilityTypes::Event event, | 321 ui::AccessibilityTypes::Event event, |
| 279 Profile* profile) { | 322 Profile* profile) { |
| 280 ui::AccessibleViewState state; | 323 ui::AccessibleViewState state; |
| 281 view->GetAccessibleState(&state); | 324 view->GetAccessibleState(&state); |
| 282 std::string name = UTF16ToUTF8(state.name); | 325 std::string name = UTF16ToUTF8(state.name); |
| 283 std::string context = GetViewContext(view); | 326 std::string context = GetViewContext(view); |
| 284 bool password = | 327 bool password = |
| 285 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; | 328 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 std::string AccessibilityEventRouterViews::GetViewContext(views::View* view) { | 431 std::string AccessibilityEventRouterViews::GetViewContext(views::View* view) { |
| 389 for (views::View* parent = view->parent(); | 432 for (views::View* parent = view->parent(); |
| 390 parent; | 433 parent; |
| 391 parent = parent->parent()) { | 434 parent = parent->parent()) { |
| 392 ui::AccessibleViewState state; | 435 ui::AccessibleViewState state; |
| 393 parent->GetAccessibleState(&state); | 436 parent->GetAccessibleState(&state); |
| 394 | 437 |
| 395 // Two cases are handled right now. More could be added in the future | 438 // Two cases are handled right now. More could be added in the future |
| 396 // depending on how the UI evolves. | 439 // depending on how the UI evolves. |
| 397 | 440 |
| 398 // A control in a toolbar should use the toolbar's accessible name | 441 // A control inside of alert, toolbar or dialog should use that container's |
| 399 // as the context. | 442 // accessible name. |
| 400 if (state.role == ui::AccessibilityTypes::ROLE_TOOLBAR && | 443 if ((state.role == ui::AccessibilityTypes::ROLE_ALERT || |
| 444 state.role == ui::AccessibilityTypes::ROLE_DIALOG || | |
| 445 state.role == ui::AccessibilityTypes::ROLE_TOOLBAR) && | |
| 401 !state.name.empty()) { | 446 !state.name.empty()) { |
| 402 return UTF16ToUTF8(state.name); | 447 return UTF16ToUTF8(state.name); |
| 403 } | 448 } |
| 404 | 449 |
| 405 // A control inside of an alert or dialog (including an infobar) | 450 // A control inside of an alert or dialog (including an infobar) |
| 406 // should grab the first static text descendant as the context; | 451 // should grab the first static text descendant as the context; |
| 407 // that's the prompt. | 452 // that's the prompt. |
| 408 if (state.role == ui::AccessibilityTypes::ROLE_ALERT || | 453 if (state.role == ui::AccessibilityTypes::ROLE_ALERT || |
| 409 state.role == ui::AccessibilityTypes::ROLE_DIALOG) { | 454 state.role == ui::AccessibilityTypes::ROLE_DIALOG) { |
| 410 views::View* static_text_child = FindDescendantWithAccessibleRole( | 455 views::View* static_text_child = FindDescendantWithAccessibleRole( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 return UTF16ToUTF8(state.name); | 519 return UTF16ToUTF8(state.name); |
| 475 | 520 |
| 476 for (int i = 0; i < view->child_count(); ++i) { | 521 for (int i = 0; i < view->child_count(); ++i) { |
| 477 views::View* child = view->child_at(i); | 522 views::View* child = view->child_at(i); |
| 478 std::string result = RecursiveGetStaticText(child); | 523 std::string result = RecursiveGetStaticText(child); |
| 479 if (!result.empty()) | 524 if (!result.empty()) |
| 480 return result; | 525 return result; |
| 481 } | 526 } |
| 482 return std::string(); | 527 return std::string(); |
| 483 } | 528 } |
| OLD | NEW |