OLD | NEW |
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 "content/browser/accessibility/browser_accessibility_manager_mac.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
6 | 6 |
7 #import "base/logging.h" | 7 #import "base/logging.h" |
8 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 8 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
9 #import "content/browser/accessibility/browser_accessibility_mac.h" | 9 #import "content/browser/accessibility/browser_accessibility_mac.h" |
10 #include "content/common/accessibility_messages.h" | 10 #include "content/common/accessibility_messages.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; | 37 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; |
38 empty_document.state = | 38 empty_document.state = |
39 1 << ui::AX_STATE_READ_ONLY; | 39 1 << ui::AX_STATE_READ_ONLY; |
40 ui::AXTreeUpdate update; | 40 ui::AXTreeUpdate update; |
41 update.nodes.push_back(empty_document); | 41 update.nodes.push_back(empty_document); |
42 return update; | 42 return update; |
43 } | 43 } |
44 | 44 |
45 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus( | 45 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus( |
46 BrowserAccessibility* root) { | 46 BrowserAccessibility* root) { |
47 BrowserAccessibility* node = GetActiveDescendantFocus(root); | 47 // On Mac, list boxes should always get focus on the whole list, otherwise |
48 return node; | 48 // information about the number of selected items will never be reported. |
| 49 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(root); |
| 50 if (node && node->GetRole() == ui::AX_ROLE_LIST_BOX) |
| 51 return node; |
| 52 |
| 53 // For other roles, follow the active descendant. |
| 54 return GetActiveDescendantFocus(root); |
49 } | 55 } |
50 | 56 |
51 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( | 57 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( |
52 ui::AXEvent event_type, | 58 ui::AXEvent event_type, |
53 BrowserAccessibility* node) { | 59 BrowserAccessibility* node) { |
54 if (!node->IsNative()) | 60 if (!node->IsNative()) |
55 return; | 61 return; |
56 | 62 |
| 63 if (event_type == ui::AX_EVENT_FOCUS && |
| 64 node->GetRole() == ui::AX_ROLE_LIST_BOX_OPTION && |
| 65 node->HasState(ui::AX_STATE_SELECTED) && |
| 66 node->GetParent() && |
| 67 node->GetParent()->GetRole() == ui::AX_ROLE_LIST_BOX) { |
| 68 node = node->GetParent(); |
| 69 SetFocus(node, false); |
| 70 } |
| 71 |
57 // Refer to AXObjectCache.mm (webkit). | 72 // Refer to AXObjectCache.mm (webkit). |
58 NSString* event_id = @""; | 73 NSString* event_id = @""; |
59 switch (event_type) { | 74 switch (event_type) { |
60 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: | 75 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: |
61 if (node->GetRole() == ui::AX_ROLE_TREE) { | 76 if (node->GetRole() == ui::AX_ROLE_TREE) { |
62 event_id = NSAccessibilitySelectedRowsChangedNotification; | 77 event_id = NSAccessibilitySelectedRowsChangedNotification; |
63 } else { | 78 } else { |
64 event_id = NSAccessibilityFocusedUIElementChangedNotification; | 79 event_id = NSAccessibilityFocusedUIElementChangedNotification; |
65 BrowserAccessibility* active_descendant_focus = | 80 BrowserAccessibility* active_descendant_focus = |
66 GetActiveDescendantFocus(GetRoot()); | 81 GetActiveDescendantFocus(GetRoot()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 case ui::AX_EVENT_MENU_LIST_ITEM_SELECTED: | 147 case ui::AX_EVENT_MENU_LIST_ITEM_SELECTED: |
133 // Not used on Mac. | 148 // Not used on Mac. |
134 return; | 149 return; |
135 case ui::AX_EVENT_TEXT_CHANGED: | 150 case ui::AX_EVENT_TEXT_CHANGED: |
136 // Not used on Mac. | 151 // Not used on Mac. |
137 return; | 152 return; |
138 default: | 153 default: |
139 LOG(WARNING) << "Unknown accessibility event: " << event_type; | 154 LOG(WARNING) << "Unknown accessibility event: " << event_type; |
140 return; | 155 return; |
141 } | 156 } |
| 157 |
142 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa(); | 158 BrowserAccessibilityCocoa* native_node = node->ToBrowserAccessibilityCocoa(); |
143 DCHECK(native_node); | 159 DCHECK(native_node); |
144 NSAccessibilityPostNotification(native_node, event_id); | 160 NSAccessibilityPostNotification(native_node, event_id); |
145 } | 161 } |
146 | 162 |
147 void BrowserAccessibilityManagerMac::OnAtomicUpdateFinished( | 163 void BrowserAccessibilityManagerMac::OnAtomicUpdateFinished( |
148 bool root_changed, const std::vector<ui::AXTreeDelegate::Change>& changes) { | 164 bool root_changed, const std::vector<ui::AXTreeDelegate::Change>& changes) { |
149 BrowserAccessibilityManager::OnAtomicUpdateFinished(root_changed, changes); | 165 BrowserAccessibilityManager::OnAtomicUpdateFinished(root_changed, changes); |
150 | 166 |
151 bool created_live_region = false; | 167 bool created_live_region = false; |
(...skipping 15 matching lines...) Expand all Loading... |
167 // page for live regions once. By recreating the NSAccessibility | 183 // page for live regions once. By recreating the NSAccessibility |
168 // object for the root of the tree, we force VoiceOver to clear out its | 184 // object for the root of the tree, we force VoiceOver to clear out its |
169 // internal state and find newly-added live regions this time. | 185 // internal state and find newly-added live regions this time. |
170 BrowserAccessibilityMac* root = | 186 BrowserAccessibilityMac* root = |
171 static_cast<BrowserAccessibilityMac*>(GetRoot()); | 187 static_cast<BrowserAccessibilityMac*>(GetRoot()); |
172 root->RecreateNativeObject(); | 188 root->RecreateNativeObject(); |
173 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, root); | 189 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, root); |
174 } | 190 } |
175 | 191 |
176 } // namespace content | 192 } // namespace content |
OLD | NEW |