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

Side by Side Diff: ui/accessibility/platform/ax_platform_node_mac.mm

Issue 2210763002: MacViews a11y: Sync VoiceOver cursor with keyboard focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move accessibilityFocusedUIElement from BrowserCrApplication to BridgedContentView. Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/accessibility/platform/ax_platform_node_mac.h" 5 #import "ui/accessibility/platform/ax_platform_node_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #import "base/mac/sdk_forward_declarations.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
12 #include "ui/accessibility/ax_node_data.h" 13 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 15 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
15 #import "ui/gfx/mac/coordinate_conversion.h" 16 #import "ui/gfx/mac/coordinate_conversion.h"
16 17
17 namespace { 18 namespace {
18 19
19 struct RoleMapEntry { 20 struct RoleMapEntry {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 }; 191 };
191 192
192 RoleMap subrole_map; 193 RoleMap subrole_map;
193 for (size_t i = 0; i < arraysize(subroles); ++i) 194 for (size_t i = 0; i < arraysize(subroles); ++i)
194 subrole_map[subroles[i].value] = subroles[i].nativeValue; 195 subrole_map[subroles[i].value] = subroles[i].nativeValue;
195 return subrole_map; 196 return subrole_map;
196 } 197 }
197 198
198 EventMap BuildEventMap() { 199 EventMap BuildEventMap() {
199 const EventMapEntry events[] = { 200 const EventMapEntry events[] = {
201 {ui::AX_EVENT_FOCUS, NSAccessibilityFocusedUIElementChangedNotification},
200 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification}, 202 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification},
201 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification}, 203 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification},
202 {ui::AX_EVENT_TEXT_SELECTION_CHANGED, 204 {ui::AX_EVENT_TEXT_SELECTION_CHANGED,
203 NSAccessibilitySelectedTextChangedNotification}, 205 NSAccessibilitySelectedTextChangedNotification},
204 // TODO(patricialor): Add more events. 206 // TODO(patricialor): Add more events.
205 }; 207 };
206 208
207 EventMap event_map; 209 EventMap event_map;
208 for (size_t i = 0; i < arraysize(events); ++i) 210 for (size_t i = 0; i < arraysize(events); ++i)
209 event_map[events[i].value] = events[i].nativeValue; 211 event_map[events[i].value] = events[i].nativeValue;
210 return event_map; 212 return event_map;
211 } 213 }
212 214
213 void NotifyMacEvent(NSView* target, ui::AXEvent event_type) { 215 void NotifyMacEvent(id target, ui::AXEvent event_type) {
tapted 2016/09/26 05:19:17 can this instead change from NSView* -> AXPlatform
Patti Lor 2016/09/28 00:29:14 Done.
214 NSAccessibilityPostNotification( 216 NSAccessibilityPostNotification(
215 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); 217 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]);
216 } 218 }
217 219
218 } // namespace 220 } // namespace
219 221
220 @interface AXPlatformNodeCocoa () 222 @interface AXPlatformNodeCocoa ()
221 // Helper function for string attributes that don't require extra processing. 223 // Helper function for string attributes that don't require extra processing.
222 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; 224 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute;
223 @end 225 @end
(...skipping 22 matching lines...) Expand all
246 } 248 }
247 249
248 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node { 250 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node {
249 if ((self = [super init])) { 251 if ((self = [super init])) {
250 node_ = node; 252 node_ = node;
251 } 253 }
252 return self; 254 return self;
253 } 255 }
254 256
255 - (void)detach { 257 - (void)detach {
258 if (!node_)
259 return;
260 NSAccessibilityPostNotification(
261 self, NSAccessibilityUIElementDestroyedNotification);
262 NSAccessibilityUnregisterUniqueIdForUIElement(self);
256 node_ = nil; 263 node_ = nil;
257 } 264 }
258 265
259 - (NSRect)boundsInScreen { 266 - (NSRect)boundsInScreen {
260 if (!node_) 267 if (!node_)
261 return NSZeroRect; 268 return NSZeroRect;
262 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); 269 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen());
263 } 270 }
264 271
265 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { 272 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute {
(...skipping 10 matching lines...) Expand all
276 } 283 }
277 284
278 - (id)accessibilityHitTest:(NSPoint)point { 285 - (id)accessibilityHitTest:(NSPoint)point {
279 for (AXPlatformNodeCocoa* child in [self AXChildren]) { 286 for (AXPlatformNodeCocoa* child in [self AXChildren]) {
280 if (NSPointInRect(point, child.boundsInScreen)) 287 if (NSPointInRect(point, child.boundsInScreen))
281 return [child accessibilityHitTest:point]; 288 return [child accessibilityHitTest:point];
282 } 289 }
283 return NSAccessibilityUnignoredAncestor(self); 290 return NSAccessibilityUnignoredAncestor(self);
284 } 291 }
285 292
293 - (BOOL)accessibilityNotifiesWhenDestroyed {
294 return YES;
295 }
296
297 - (BOOL)accessibilityShouldUseUniqueId {
tapted 2016/09/26 05:19:17 This needs a note that it was never part of the in
Patti Lor 2016/09/28 00:29:14 See above comment - deleted this method entirely.
298 return YES;
299 }
300
286 - (NSArray*)accessibilityActionNames { 301 - (NSArray*)accessibilityActionNames {
287 return nil; 302 return nil;
288 } 303 }
289 304
290 - (NSArray*)accessibilityAttributeNames { 305 - (NSArray*)accessibilityAttributeNames {
291 // These attributes are required on all accessibility objects. 306 // These attributes are required on all accessibility objects.
292 NSArray* const kAllRoleAttributes = @[ 307 NSArray* const kAllRoleAttributes = @[
293 NSAccessibilityChildrenAttribute, 308 NSAccessibilityChildrenAttribute,
294 NSAccessibilityParentAttribute, 309 NSAccessibilityParentAttribute,
295 NSAccessibilityPositionAttribute, 310 NSAccessibilityPositionAttribute,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 AXPlatformNodeBase::Destroy(); 523 AXPlatformNodeBase::Destroy();
509 } 524 }
510 525
511 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() { 526 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() {
512 if (!native_node_) 527 if (!native_node_)
513 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]); 528 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]);
514 return native_node_.get(); 529 return native_node_.get();
515 } 530 }
516 531
517 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { 532 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) {
518 NSView* target = GetDelegate()->GetTargetForNativeAccessibilityEvent(); 533 if (!native_node_)
tapted 2016/09/26 05:19:17 nit: This extra check isn't needed - I'd go for ju
Patti Lor 2016/09/28 00:29:14 Done.
519 534 GetNativeViewAccessible();
520 // Add mappings between ui::AXEvent and NSAccessibility notifications using 535 // Add mappings between ui::AXEvent and NSAccessibility notifications using
521 // the EventMap above. This switch contains exceptions to those mappings. 536 // the EventMap above. This switch contains exceptions to those mappings.
522 switch (event_type) { 537 switch (event_type) {
523 case ui::AX_EVENT_TEXT_CHANGED: 538 case ui::AX_EVENT_TEXT_CHANGED:
524 // If the view is a user-editable textfield, this should change the value. 539 // If the view is a user-editable textfield, this should change the value.
525 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) { 540 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) {
526 NotifyMacEvent(target, ui::AX_EVENT_VALUE_CHANGED); 541 NotifyMacEvent(native_node_, ui::AX_EVENT_VALUE_CHANGED);
527 return; 542 return;
528 } 543 }
529 break; 544 break;
530 default: 545 default:
531 break; 546 break;
532 } 547 }
533 NotifyMacEvent(target, event_type); 548 NotifyMacEvent(native_node_, event_type);
534 } 549 }
535 550
536 int AXPlatformNodeMac::GetIndexInParent() { 551 int AXPlatformNodeMac::GetIndexInParent() {
537 // TODO(dmazzoni): implement this. http://crbug.com/396137 552 // TODO(dmazzoni): implement this. http://crbug.com/396137
538 return -1; 553 return -1;
539 } 554 }
540 555
541 } // namespace ui 556 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698