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 = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; 35 empty_document.state = 36 1 << AccessibilityNodeData::STATE_READONLY; 37 return empty_document; 38 } 39 40 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( 41 int type, 42 BrowserAccessibility* node) { 43 if (!node->IsNative()) 44 return; 45 46 // Refer to AXObjectCache.mm (webkit). 47 NSString* event_id = @""; 48 switch (type) { 49 case AccessibilityNotificationActiveDescendantChanged: 50 if (node->role() == AccessibilityNodeData::ROLE_TREE) 51 event_id = NSAccessibilitySelectedRowsChangedNotification; 52 else 53 event_id = NSAccessibilityFocusedUIElementChangedNotification; 54 break; 55 case AccessibilityNotificationAlert: 56 // Not used on Mac. 57 return; 58 case AccessibilityNotificationBlur: 59 // A no-op on Mac. 60 return; 61 case AccessibilityNotificationCheckStateChanged: 62 // Not used on Mac. 63 return; 64 case AccessibilityNotificationChildrenChanged: 65 // TODO(dtseng): no clear equivalent on Mac. 66 return; 67 case AccessibilityNotificationFocusChanged: 68 event_id = NSAccessibilityFocusedUIElementChangedNotification; 69 break; 70 case AccessibilityNotificationLayoutComplete: 71 event_id = @"AXLayoutComplete"; 72 break; 73 case AccessibilityNotificationLiveRegionChanged: 74 event_id = @"AXLiveRegionChanged"; 75 break; 76 case AccessibilityNotificationLoadComplete: 77 event_id = @"AXLoadComplete"; 78 break; 79 case AccessibilityNotificationMenuListValueChanged: 80 // Not used on Mac. 81 return; 82 case AccessibilityNotificationObjectShow: 83 // Not used on Mac. 84 return; 85 case AccessibilityNotificationObjectHide: 86 // Not used on Mac. 87 return; 88 case AccessibilityNotificationRowCountChanged: 89 event_id = NSAccessibilityRowCountChangedNotification; 90 break; 91 case AccessibilityNotificationRowCollapsed: 92 event_id = @"AXRowCollapsed"; 93 break; 94 case AccessibilityNotificationRowExpanded: 95 event_id = @"AXRowExpanded"; 96 break; 97 case AccessibilityNotificationScrolledToAnchor: 98 // Not used on Mac. 99 return; 100 case AccessibilityNotificationSelectedChildrenChanged: 101 event_id = NSAccessibilitySelectedChildrenChangedNotification; 102 break; 103 case AccessibilityNotificationSelectedTextChanged: 104 event_id = NSAccessibilitySelectedTextChangedNotification; 105 break; 106 case AccessibilityNotificationTextInserted: 107 // Not used on Mac. 108 return; 109 case AccessibilityNotificationTextRemoved: 110 // Not used on Mac. 111 return; 112 case AccessibilityNotificationValueChanged: 113 event_id = NSAccessibilityValueChangedNotification; 114 break; 115 } 116 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa(); 117 DCHECK(native_node); 118 NSAccessibilityPostNotification(native_node, event_id); 119 } 120 121 } // namespace content 122