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