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
3 // found in the LICENSE file.
5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
7 #import "base/logging.h"
8 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
9 #include "content/common/accessibility_messages.h"
14 BrowserAccessibilityManager* BrowserAccessibilityManager::Create(
15 const ui::AXTreeUpdate& initial_tree,
16 BrowserAccessibilityDelegate* delegate,
17 BrowserAccessibilityFactory* factory) {
18 return new BrowserAccessibilityManagerMac(
19 NULL, initial_tree, delegate, factory);
22 BrowserAccessibilityManagerMac::BrowserAccessibilityManagerMac(
24 const ui::AXTreeUpdate& initial_tree,
25 BrowserAccessibilityDelegate* delegate,
26 BrowserAccessibilityFactory* factory)
27 : BrowserAccessibilityManager(initial_tree, delegate, factory),
28 parent_view_(parent_view) {
32 ui::AXTreeUpdate BrowserAccessibilityManagerMac::GetEmptyDocument() {
33 ui::AXNodeData empty_document;
34 empty_document.id = 0;
35 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA;
36 empty_document.state =
37 1 << ui::AX_STATE_READ_ONLY;
38 ui::AXTreeUpdate update;
39 update.nodes.push_back(empty_document);
43 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent(
44 ui::AXEvent event_type,
45 BrowserAccessibility* node) {
46 if (!node->IsNative())
49 // Refer to AXObjectCache.mm (webkit).
50 NSString* event_id = @"";
52 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED:
53 if (node->GetRole() == ui::AX_ROLE_TREE)
54 event_id = NSAccessibilitySelectedRowsChangedNotification;
56 event_id = NSAccessibilityFocusedUIElementChangedNotification;
58 case ui::AX_EVENT_ALERT:
61 case ui::AX_EVENT_BLUR:
64 case ui::AX_EVENT_CHECKED_STATE_CHANGED:
67 case ui::AX_EVENT_CHILDREN_CHANGED:
68 // TODO(dtseng): no clear equivalent on Mac.
70 case ui::AX_EVENT_FOCUS:
71 event_id = NSAccessibilityFocusedUIElementChangedNotification;
73 case ui::AX_EVENT_LAYOUT_COMPLETE:
74 event_id = @"AXLayoutComplete";
76 case ui::AX_EVENT_LIVE_REGION_CHANGED:
77 event_id = @"AXLiveRegionChanged";
79 case ui::AX_EVENT_LOAD_COMPLETE:
80 event_id = @"AXLoadComplete";
82 case ui::AX_EVENT_MENU_LIST_VALUE_CHANGED:
85 case ui::AX_EVENT_SHOW:
88 case ui::AX_EVENT_HIDE:
91 case ui::AX_EVENT_ROW_COUNT_CHANGED:
92 event_id = NSAccessibilityRowCountChangedNotification;
94 case ui::AX_EVENT_ROW_COLLAPSED:
95 event_id = @"AXRowCollapsed";
97 case ui::AX_EVENT_ROW_EXPANDED:
98 event_id = @"AXRowExpanded";
100 case ui::AX_EVENT_SCROLLED_TO_ANCHOR:
103 case ui::AX_EVENT_SELECTED_CHILDREN_CHANGED:
104 event_id = NSAccessibilitySelectedChildrenChangedNotification;
106 case ui::AX_EVENT_SELECTED_TEXT_CHANGED:
107 event_id = NSAccessibilitySelectedTextChangedNotification;
109 case ui::AX_EVENT_TEXT_INSERTED:
112 case ui::AX_EVENT_TEXT_REMOVED:
115 case ui::AX_EVENT_VALUE_CHANGED:
116 event_id = NSAccessibilityValueChangedNotification;
118 case ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED:
121 case ui::AX_EVENT_AUTOCORRECTION_OCCURED:
124 case ui::AX_EVENT_INVALID_STATUS_CHANGED:
127 case ui::AX_EVENT_LOCATION_CHANGED:
130 case ui::AX_EVENT_MENU_LIST_ITEM_SELECTED:
133 case ui::AX_EVENT_TEXT_CHANGED:
137 LOG(WARNING) << "Unknown accessibility event: " << event_type;
140 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa();
142 NSAccessibilityPostNotification(native_node, event_id);
145 } // namespace content