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. 4 5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" 6 7 #import "base/logging.h" 8 #import "content/browser/accessibility/browser_accessibility_cocoa.h" 9 #include "content/common/accessibility_messages.h" 10 11 namespace content { 12 13 // static 14 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( 15 const AccessibilityNodeData& src, 16 BrowserAccessibilityDelegate* delegate, 17 BrowserAccessibilityFactory* factory) { 18 return new BrowserAccessibilityManagerMac(NULL, src, delegate, factory); 19 } 20 21 BrowserAccessibilityManagerMac::BrowserAccessibilityManagerMac( 22 NSView* parent_view, 23 const AccessibilityNodeData& src, 24 BrowserAccessibilityDelegate* delegate, 25 BrowserAccessibilityFactory* factory) 26 : BrowserAccessibilityManager(src, delegate, factory), 27 parent_view_(parent_view) { 28 } 29 30 // static 31 AccessibilityNodeData BrowserAccessibilityManagerMac::GetEmptyDocument() { 32 AccessibilityNodeData empty_document; 33 empty_document.id = 0; 34 empty_document.role = blink::WebAXRoleRootWebArea; 35 empty_document.state = 36 1 << blink::WebAXStateReadonly; 37 return empty_document; 38 } 39 40 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( 41 blink::WebAXEvent event_type, 42 BrowserAccessibility* node) { 43 if (!node->IsNative()) 44 return; 45 46 // Refer to AXObjectCache.mm (webkit). 47 NSString* event_id = @""; 48 switch (event_type) { 49 case blink::WebAXEventActiveDescendantChanged: 50 if (node->role() == blink::WebAXRoleTree) 51 event_id = NSAccessibilitySelectedRowsChangedNotification; 52 else 53 event_id = NSAccessibilityFocusedUIElementChangedNotification; 54 break; 55 case blink::WebAXEventAlert: 56 // Not used on Mac. 57 return; 58 case blink::WebAXEventBlur: 59 // A no-op on Mac. 60 return; 61 case blink::WebAXEventCheckedStateChanged: 62 // Not used on Mac. 63 return; 64 case blink::WebAXEventChildrenChanged: 65 // TODO(dtseng): no clear equivalent on Mac. 66 return; 67 case blink::WebAXEventFocus: 68 event_id = NSAccessibilityFocusedUIElementChangedNotification; 69 break; 70 case blink::WebAXEventLayoutComplete: 71 event_id = @"AXLayoutComplete"; 72 break; 73 case blink::WebAXEventLiveRegionChanged: 74 event_id = @"AXLiveRegionChanged"; 75 break; 76 case blink::WebAXEventLoadComplete: 77 event_id = @"AXLoadComplete"; 78 break; 79 case blink::WebAXEventMenuListValueChanged: 80 // Not used on Mac. 81 return; 82 case blink::WebAXEventShow: 83 // Not used on Mac. 84 return; 85 case blink::WebAXEventHide: 86 // Not used on Mac. 87 return; 88 case blink::WebAXEventRowCountChanged: 89 event_id = NSAccessibilityRowCountChangedNotification; 90 break; 91 case blink::WebAXEventRowCollapsed: 92 event_id = @"AXRowCollapsed"; 93 break; 94 case blink::WebAXEventRowExpanded: 95 event_id = @"AXRowExpanded"; 96 break; 97 case blink::WebAXEventScrolledToAnchor: 98 // Not used on Mac. 99 return; 100 case blink::WebAXEventSelectedChildrenChanged: 101 event_id = NSAccessibilitySelectedChildrenChangedNotification; 102 break; 103 case blink::WebAXEventSelectedTextChanged: 104 event_id = NSAccessibilitySelectedTextChangedNotification; 105 break; 106 case blink::WebAXEventTextInserted: 107 // Not used on Mac. 108 return; 109 case blink::WebAXEventTextRemoved: 110 // Not used on Mac. 111 return; 112 case blink::WebAXEventValueChanged: 113 event_id = NSAccessibilityValueChangedNotification; 114 break; 115 case blink::WebAXEventAriaAttributeChanged: 116 // Not used on Mac. 117 return; 118 case blink::WebAXEventAutocorrectionOccured: 119 // Not used on Mac. 120 return; 121 case blink::WebAXEventInvalidStatusChanged: 122 // Not used on Mac. 123 return; 124 case blink::WebAXEventLocationChanged: 125 // Not used on Mac. 126 return; 127 case blink::WebAXEventMenuListItemSelected: 128 // Not used on Mac. 129 return; 130 case blink::WebAXEventTextChanged: 131 // Not used on Mac. 132 return; 133 default: 134 LOG(WARNING) << "Unknown accessibility event: " << event_type; 135 return; 136 } 137 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa(); 138 DCHECK(native_node); 139 NSAccessibilityPostNotification(native_node, event_id); 140 } 141 142 } // namespace content 143