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::AXNodeData& src,
16 BrowserAccessibilityDelegate* delegate,
17 BrowserAccessibilityFactory* factory) {
18 return new BrowserAccessibilityManagerMac(NULL, src, delegate, factory);
21 BrowserAccessibilityManagerMac::BrowserAccessibilityManagerMac(
23 const ui::AXNodeData& src,
24 BrowserAccessibilityDelegate* delegate,
25 BrowserAccessibilityFactory* factory)
26 : BrowserAccessibilityManager(src, delegate, factory),
27 parent_view_(parent_view) {
31 ui::AXNodeData BrowserAccessibilityManagerMac::GetEmptyDocument() {
32 ui::AXNodeData empty_document;
33 empty_document.id = 0;
34 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA;
35 empty_document.state =
36 1 << ui::AX_STATE_READ_ONLY;
37 return empty_document;
40 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent(
41 ui::AXEvent event_type,
42 BrowserAccessibility* node) {
43 if (!node->IsNative())
46 // Refer to AXObjectCache.mm (webkit).
47 NSString* event_id = @"";
49 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED:
50 if (node->role() == ui::AX_ROLE_TREE)
51 event_id = NSAccessibilitySelectedRowsChangedNotification;
53 event_id = NSAccessibilityFocusedUIElementChangedNotification;
55 case ui::AX_EVENT_ALERT:
58 case ui::AX_EVENT_BLUR:
61 case ui::AX_EVENT_CHECKED_STATE_CHANGED:
64 case ui::AX_EVENT_CHILDREN_CHANGED:
65 // TODO(dtseng): no clear equivalent on Mac.
67 case ui::AX_EVENT_FOCUS:
68 event_id = NSAccessibilityFocusedUIElementChangedNotification;
70 case ui::AX_EVENT_LAYOUT_COMPLETE:
71 event_id = @"AXLayoutComplete";
73 case ui::AX_EVENT_LIVE_REGION_CHANGED:
74 event_id = @"AXLiveRegionChanged";
76 case ui::AX_EVENT_LOAD_COMPLETE:
77 event_id = @"AXLoadComplete";
79 case ui::AX_EVENT_MENU_LIST_VALUE_CHANGED:
82 case ui::AX_EVENT_SHOW:
85 case ui::AX_EVENT_HIDE:
88 case ui::AX_EVENT_ROW_COUNT_CHANGED:
89 event_id = NSAccessibilityRowCountChangedNotification;
91 case ui::AX_EVENT_ROW_COLLAPSED:
92 event_id = @"AXRowCollapsed";
94 case ui::AX_EVENT_ROW_EXPANDED:
95 event_id = @"AXRowExpanded";
97 case ui::AX_EVENT_SCROLLED_TO_ANCHOR:
100 case ui::AX_EVENT_SELECTED_CHILDREN_CHANGED:
101 event_id = NSAccessibilitySelectedChildrenChangedNotification;
103 case ui::AX_EVENT_SELECTED_TEXT_CHANGED:
104 event_id = NSAccessibilitySelectedTextChangedNotification;
106 case ui::AX_EVENT_TEXT_INSERTED:
109 case ui::AX_EVENT_TEXT_REMOVED:
112 case ui::AX_EVENT_VALUE_CHANGED:
113 event_id = NSAccessibilityValueChangedNotification;
115 case ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED:
118 case ui::AX_EVENT_AUTOCORRECTION_OCCURED:
121 case ui::AX_EVENT_INVALID_STATUS_CHANGED:
124 case ui::AX_EVENT_LOCATION_CHANGED:
127 case ui::AX_EVENT_MENU_LIST_ITEM_SELECTED:
130 case ui::AX_EVENT_TEXT_CHANGED:
134 LOG(WARNING) << "Unknown accessibility event: " << event_type;
137 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa();
139 NSAccessibilityPostNotification(native_node, event_id);
142 } // namespace content