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/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
8 #import "base/mac/sdk_forward_declarations.h" | 8 #import "base/mac/sdk_forward_declarations.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; | 125 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; |
126 empty_document.state = | 126 empty_document.state = |
127 1 << ui::AX_STATE_READ_ONLY; | 127 1 << ui::AX_STATE_READ_ONLY; |
128 ui::AXTreeUpdate update; | 128 ui::AXTreeUpdate update; |
129 update.root_id = empty_document.id; | 129 update.root_id = empty_document.id; |
130 update.nodes.push_back(empty_document); | 130 update.nodes.push_back(empty_document); |
131 return update; | 131 return update; |
132 } | 132 } |
133 | 133 |
134 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus() { | 134 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus() { |
135 BrowserAccessibility* focus = BrowserAccessibilityManager::GetFocus(); | |
136 | |
137 // On Mac, list boxes should always get focus on the whole list, otherwise | 135 // On Mac, list boxes should always get focus on the whole list, otherwise |
138 // information about the number of selected items will never be reported. | 136 // information about the number of selected items will never be reported. |
139 // For editable combo boxes, focus should stay on the combo box so the user | 137 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(); |
140 // will not be taken out of the combo box while typing. | 138 if (node && node->GetRole() == ui::AX_ROLE_LIST_BOX) |
141 if (focus && (focus->GetRole() == ui::AX_ROLE_LIST_BOX || | 139 return node; |
142 (focus->GetRole() == ui::AX_ROLE_COMBO_BOX && | |
143 focus->HasState(ui::AX_STATE_EDITABLE)))) { | |
144 return focus; | |
145 } | |
146 | 140 |
147 // For other roles, follow the active descendant. | 141 // For other roles, follow the active descendant. |
148 return GetActiveDescendant(focus); | 142 return GetActiveDescendantFocus(node); |
149 } | 143 } |
150 | 144 |
151 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( | 145 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( |
152 BrowserAccessibilityEvent::Source source, | 146 BrowserAccessibilityEvent::Source source, |
153 ui::AXEvent event_type, | 147 ui::AXEvent event_type, |
154 BrowserAccessibility* node) { | 148 BrowserAccessibility* node) { |
155 if (!node->IsNative()) | 149 if (!node->IsNative()) |
156 return; | 150 return; |
157 | 151 |
| 152 if (event_type == ui::AX_EVENT_FOCUS) { |
| 153 BrowserAccessibility* active_descendant = GetActiveDescendantFocus(node); |
| 154 if (active_descendant) |
| 155 node = active_descendant; |
| 156 |
| 157 if (node->GetRole() == ui::AX_ROLE_LIST_BOX_OPTION && |
| 158 node->HasState(ui::AX_STATE_SELECTED) && |
| 159 node->GetParent() && |
| 160 node->GetParent()->GetRole() == ui::AX_ROLE_LIST_BOX) { |
| 161 node = node->GetParent(); |
| 162 SetFocus(*node); |
| 163 } |
| 164 } |
| 165 |
158 auto native_node = ToBrowserAccessibilityCocoa(node); | 166 auto native_node = ToBrowserAccessibilityCocoa(node); |
159 DCHECK(native_node); | 167 DCHECK(native_node); |
160 | 168 |
161 // Refer to |AXObjectCache::postPlatformNotification| in WebKit source code. | 169 // Refer to |AXObjectCache::postPlatformNotification| in WebKit source code. |
162 NSString* mac_notification; | 170 NSString* mac_notification; |
163 switch (event_type) { | 171 switch (event_type) { |
164 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: | 172 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: |
165 if (node->GetRole() == ui::AX_ROLE_TREE) { | 173 if (node->GetRole() == ui::AX_ROLE_TREE) { |
166 mac_notification = NSAccessibilitySelectedRowsChangedNotification; | 174 mac_notification = NSAccessibilitySelectedRowsChangedNotification; |
167 } else if (node->GetRole() == ui::AX_ROLE_COMBO_BOX) { | 175 } else if (node->GetRole() == ui::AX_ROLE_COMBO_BOX) { |
168 // Even though the selected item in the combo box has changed, we don't | 176 // Even though the selected item in the combo box has changed, we don't |
169 // want to post a focus change because this will take the focus out of | 177 // want to post a focus change because this will take the focus out of |
170 // the combo box where the user might be typing. | 178 // the combo box where the user might be typing. |
171 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; | 179 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; |
172 } else { | 180 } else { |
173 // In all other cases we should post | 181 mac_notification = NSAccessibilityFocusedUIElementChangedNotification; |
174 // |NSAccessibilityFocusedUIElementChangedNotification|, but this is | |
175 // handled elsewhere. | |
176 return; | |
177 } | 182 } |
178 break; | 183 break; |
179 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: | 184 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: |
180 mac_notification = NSAccessibilityAutocorrectionOccurredNotification; | 185 mac_notification = NSAccessibilityAutocorrectionOccurredNotification; |
181 break; | 186 break; |
182 case ui::AX_EVENT_FOCUS: | 187 case ui::AX_EVENT_FOCUS: |
183 mac_notification = NSAccessibilityFocusedUIElementChangedNotification; | 188 mac_notification = NSAccessibilityFocusedUIElementChangedNotification; |
184 break; | 189 break; |
185 case ui::AX_EVENT_LAYOUT_COMPLETE: | 190 case ui::AX_EVENT_LAYOUT_COMPLETE: |
186 mac_notification = NSAccessibilityLayoutCompleteNotification; | 191 mac_notification = NSAccessibilityLayoutCompleteNotification; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 } | 461 } |
457 | 462 |
458 return @{ | 463 return @{ |
459 NSAccessibilityTextStateChangeTypeKey : @(AXTextStateChangeTypeEdit), | 464 NSAccessibilityTextStateChangeTypeKey : @(AXTextStateChangeTypeEdit), |
460 NSAccessibilityTextChangeValues : changes, | 465 NSAccessibilityTextChangeValues : changes, |
461 NSAccessibilityTextChangeElement : native_node | 466 NSAccessibilityTextChangeElement : native_node |
462 }; | 467 }; |
463 } | 468 } |
464 | 469 |
465 } // namespace content | 470 } // namespace content |
OLD | NEW |