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

Side by Side Diff: chrome/browser/ui/views/accessibility/accessibility_event_router_views.cc

Issue 79543010: Added basic accessibility to TreeView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 "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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SendTextfieldNotification(view, type, profile); 202 SendTextfieldNotification(view, type, profile);
202 break; 203 break;
203 case ui::AccessibilityTypes::ROLE_MENUITEM: 204 case ui::AccessibilityTypes::ROLE_MENUITEM:
204 SendMenuItemNotification(view, type, profile); 205 SendMenuItemNotification(view, type, profile);
205 break; 206 break;
206 case ui::AccessibilityTypes::ROLE_RADIOBUTTON: 207 case ui::AccessibilityTypes::ROLE_RADIOBUTTON:
207 // Not used anymore? 208 // Not used anymore?
208 case ui::AccessibilityTypes::ROLE_SLIDER: 209 case ui::AccessibilityTypes::ROLE_SLIDER:
209 SendSliderNotification(view, type, profile); 210 SendSliderNotification(view, type, profile);
210 break; 211 break;
212 case ui::AccessibilityTypes::ROLE_OUTLINE:
213 SendTreeNotification(view, type, profile);
214 break;
215 case ui::AccessibilityTypes::ROLE_OUTLINEITEM:
216 SendTreeItemNotification(view, type, profile);
217 break;
211 default: 218 default:
212 // 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
213 // caught so we can add accessibility extension API support. 220 // caught so we can add accessibility extension API support.
214 NOTREACHED(); 221 NOTREACHED();
215 } 222 }
216 } 223 }
217 224
218 // static 225 // static
219 void AccessibilityEventRouterViews::SendButtonNotification( 226 void AccessibilityEventRouterViews::SendButtonNotification(
220 views::View* view, 227 views::View* view,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 count = 0; 274 count = 0;
268 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); 275 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count);
269 } 276 }
270 277
271 AccessibilityMenuItemInfo info( 278 AccessibilityMenuItemInfo info(
272 profile, name, context, has_submenu, index, count); 279 profile, name, context, has_submenu, index, count);
273 SendControlAccessibilityNotification(event, &info); 280 SendControlAccessibilityNotification(event, &info);
274 } 281 }
275 282
276 // static 283 // static
284 void AccessibilityEventRouterViews::SendTreeNotification(
285 views::View* view,
286 ui::AccessibilityTypes::Event event,
287 Profile* profile) {
288 AccessibilityTreeInfo info(profile, GetViewName(view));
289 SendControlAccessibilityNotification(event, &info);
290 }
291
292 // static
293 void AccessibilityEventRouterViews::SendTreeItemNotification(
294 views::View* view,
295 ui::AccessibilityTypes::Event event,
296 Profile* profile) {
297 std::string name = GetViewName(view);
298 std::string context = GetViewContext(view);
299
300 if (strcmp(view->GetClassName(), views::TreeView::kViewClassName) != 0) {
301 NOTREACHED();
302 return;
303 }
304
305 views::TreeView* tree = static_cast<views::TreeView*>(view);
306 ui::TreeModelNode* selected_node = tree->GetSelectedNode();
307 ui::TreeModel* model = tree->model();
308
309 int siblings_count = model->GetChildCount(model->GetRoot());
310 int children_count = -1;
311 int index = -1;
312 int depth = -1;
313 bool is_expanded = false;
314
315 if (selected_node) {
316 children_count = model->GetChildCount(selected_node);
317 is_expanded = tree->IsExpanded(selected_node);
318 ui::TreeModelNode* parent_node = model->GetParent(selected_node);
319 if (parent_node) {
320 index = model->GetIndexOf(parent_node, selected_node);
321 siblings_count = model->GetChildCount(parent_node);
322 }
323 // Get node depth.
324 depth = 0;
325 while (parent_node) {
326 depth++;
327 parent_node = model->GetParent(parent_node);
328 }
329 }
330
331 AccessibilityTreeItemInfo info(
332 profile, name, context, depth, index, siblings_count, children_count,
333 is_expanded);
334 SendControlAccessibilityNotification(event, &info);
335 }
336
337 // static
277 void AccessibilityEventRouterViews::SendTextfieldNotification( 338 void AccessibilityEventRouterViews::SendTextfieldNotification(
278 views::View* view, 339 views::View* view,
279 ui::AccessibilityTypes::Event event, 340 ui::AccessibilityTypes::Event event,
280 Profile* profile) { 341 Profile* profile) {
281 ui::AccessibleViewState state; 342 ui::AccessibleViewState state;
282 view->GetAccessibleState(&state); 343 view->GetAccessibleState(&state);
283 std::string name = UTF16ToUTF8(state.name); 344 std::string name = UTF16ToUTF8(state.name);
284 std::string context = GetViewContext(view); 345 std::string context = GetViewContext(view);
285 bool password = 346 bool password =
286 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; 347 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 return UTF16ToUTF8(state.name); 541 return UTF16ToUTF8(state.name);
481 542
482 for (int i = 0; i < view->child_count(); ++i) { 543 for (int i = 0; i < view->child_count(); ++i) {
483 views::View* child = view->child_at(i); 544 views::View* child = view->child_at(i);
484 std::string result = RecursiveGetStaticText(child); 545 std::string result = RecursiveGetStaticText(child);
485 if (!result.empty()) 546 if (!result.empty())
486 return result; 547 return result;
487 } 548 }
488 return std::string(); 549 return std::string();
489 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698