Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager_mac.mm

Issue 1899823002: Uses the activedescendant_changed event received from Blink to fire the right focus event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Mac compilation issue. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
125 1 << ui::AX_STATE_READ_ONLY; 125 1 << ui::AX_STATE_READ_ONLY;
126 ui::AXTreeUpdate update; 126 ui::AXTreeUpdate update;
127 update.root_id = empty_document.id; 127 update.root_id = empty_document.id;
128 update.nodes.push_back(empty_document); 128 update.nodes.push_back(empty_document);
129 return update; 129 return update;
130 } 130 }
131 131
132 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus() { 132 BrowserAccessibility* BrowserAccessibilityManagerMac::GetFocus() {
133 // On Mac, list boxes should always get focus on the whole list, otherwise 133 // On Mac, list boxes should always get focus on the whole list, otherwise
134 // information about the number of selected items will never be reported. 134 // information about the number of selected items will never be reported.
135 // For combo boxes, focus should stay on the combo box so the user will not be
dmazzoni 2016/04/29 20:55:54 Consider doing this only for combo boxes where IsE
136 // taken out of the combo box while typing.
135 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(); 137 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus();
136 if (node && node->GetRole() == ui::AX_ROLE_LIST_BOX) 138 if (node && (node->GetRole() == ui::AX_ROLE_LIST_BOX ||
139 node->GetRole() == ui::AX_ROLE_COMBO_BOX)) {
137 return node; 140 return node;
141 }
138 142
139 // For other roles, follow the active descendant. 143 // For other roles, follow the active descendant.
140 return GetActiveDescendantFocus(node); 144 return GetActiveDescendantFocus(node);
141 } 145 }
142 146
143 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent( 147 void BrowserAccessibilityManagerMac::NotifyAccessibilityEvent(
144 ui::AXEvent event_type, 148 ui::AXEvent event_type,
145 BrowserAccessibility* node) { 149 BrowserAccessibility* node) {
146 if (!node->IsNative()) 150 if (!node->IsNative())
147 return; 151 return;
148 152
149 if (event_type == ui::AX_EVENT_FOCUS) {
150 BrowserAccessibility* active_descendant = GetActiveDescendantFocus(node);
151 if (active_descendant)
152 node = active_descendant;
153
154 if (node->GetRole() == ui::AX_ROLE_LIST_BOX_OPTION &&
155 node->HasState(ui::AX_STATE_SELECTED) &&
156 node->GetParent() &&
157 node->GetParent()->GetRole() == ui::AX_ROLE_LIST_BOX) {
158 node = node->GetParent();
159 SetFocus(*node);
160 }
161 }
162
163 auto native_node = ToBrowserAccessibilityCocoa(node); 153 auto native_node = ToBrowserAccessibilityCocoa(node);
164 DCHECK(native_node); 154 DCHECK(native_node);
165 155
166 // Refer to |AXObjectCache::postPlatformNotification| in WebKit source code. 156 // Refer to |AXObjectCache::postPlatformNotification| in WebKit source code.
167 NSString* mac_notification; 157 NSString* mac_notification;
168 switch (event_type) { 158 switch (event_type) {
169 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: 159 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED:
170 if (node->GetRole() == ui::AX_ROLE_TREE) { 160 if (node->GetRole() == ui::AX_ROLE_TREE) {
171 mac_notification = NSAccessibilitySelectedRowsChangedNotification; 161 mac_notification = NSAccessibilitySelectedRowsChangedNotification;
172 } else if (node->GetRole() == ui::AX_ROLE_COMBO_BOX) { 162 } else if (node->GetRole() == ui::AX_ROLE_COMBO_BOX) {
173 // Even though the selected item in the combo box has changed, we don't 163 // Even though the selected item in the combo box has changed, we don't
174 // want to post a focus change because this will take the focus out of 164 // want to post a focus change because this will take the focus out of
175 // the combo box where the user might be typing. 165 // the combo box where the user might be typing.
176 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; 166 mac_notification = NSAccessibilitySelectedChildrenChangedNotification;
177 } else { 167 } else {
178 mac_notification = NSAccessibilityFocusedUIElementChangedNotification; 168 // In all other cases we should post
169 // |NSAccessibilityFocusedUIElementChangedNotification|, but this is
170 // handled elsewhere.
171 return;
179 } 172 }
180 break; 173 break;
181 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: 174 case ui::AX_EVENT_AUTOCORRECTION_OCCURED:
182 mac_notification = NSAccessibilityAutocorrectionOccurredNotification; 175 mac_notification = NSAccessibilityAutocorrectionOccurredNotification;
183 break; 176 break;
184 case ui::AX_EVENT_FOCUS: 177 case ui::AX_EVENT_FOCUS:
185 mac_notification = NSAccessibilityFocusedUIElementChangedNotification; 178 mac_notification = NSAccessibilityFocusedUIElementChangedNotification;
186 break; 179 break;
187 case ui::AX_EVENT_LAYOUT_COMPLETE: 180 case ui::AX_EVENT_LAYOUT_COMPLETE:
188 mac_notification = NSAccessibilityLayoutCompleteNotification; 181 mac_notification = NSAccessibilityLayoutCompleteNotification;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 445 }
453 446
454 return @{ 447 return @{
455 NSAccessibilityTextStateChangeTypeKey : @(AXTextStateChangeTypeEdit), 448 NSAccessibilityTextStateChangeTypeKey : @(AXTextStateChangeTypeEdit),
456 NSAccessibilityTextChangeValues : changes, 449 NSAccessibilityTextChangeValues : changes,
457 NSAccessibilityTextChangeElement : native_node 450 NSAccessibilityTextChangeElement : native_node
458 }; 451 };
459 } 452 }
460 453
461 } // namespace content 454 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698