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

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: Review comments, delete accessibilityShouldUseUniqueId. Created 4 years, 2 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"
tapted 2016/09/28 01:03:20 nit: remove?
Patti Lor 2016/10/04 05:45:14 Done, thanks for pointing them all out ><
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 }; 193 };
193 194
194 RoleMap subrole_map; 195 RoleMap subrole_map;
195 for (size_t i = 0; i < arraysize(subroles); ++i) 196 for (size_t i = 0; i < arraysize(subroles); ++i)
196 subrole_map[subroles[i].value] = subroles[i].nativeValue; 197 subrole_map[subroles[i].value] = subroles[i].nativeValue;
197 return subrole_map; 198 return subrole_map;
198 } 199 }
199 200
200 EventMap BuildEventMap() { 201 EventMap BuildEventMap() {
201 const EventMapEntry events[] = { 202 const EventMapEntry events[] = {
203 {ui::AX_EVENT_FOCUS, NSAccessibilityFocusedUIElementChangedNotification},
202 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification}, 204 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification},
203 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification}, 205 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification},
204 {ui::AX_EVENT_TEXT_SELECTION_CHANGED, 206 {ui::AX_EVENT_TEXT_SELECTION_CHANGED,
205 NSAccessibilitySelectedTextChangedNotification}, 207 NSAccessibilitySelectedTextChangedNotification},
206 // TODO(patricialor): Add more events. 208 // TODO(patricialor): Add more events.
207 }; 209 };
208 210
209 EventMap event_map; 211 EventMap event_map;
210 for (size_t i = 0; i < arraysize(events); ++i) 212 for (size_t i = 0; i < arraysize(events); ++i)
211 event_map[events[i].value] = events[i].nativeValue; 213 event_map[events[i].value] = events[i].nativeValue;
212 return event_map; 214 return event_map;
213 } 215 }
214 216
215 void NotifyMacEvent(NSView* target, ui::AXEvent event_type) { 217 void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
216 NSAccessibilityPostNotification( 218 NSAccessibilityPostNotification(
217 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); 219 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]);
218 } 220 }
219 221
220 } // namespace 222 } // namespace
221 223
222 @interface AXPlatformNodeCocoa () 224 @interface AXPlatformNodeCocoa ()
223 // Helper function for string attributes that don't require extra processing. 225 // Helper function for string attributes that don't require extra processing.
224 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; 226 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute;
225 @end 227 @end
(...skipping 22 matching lines...) Expand all
248 } 250 }
249 251
250 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node { 252 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node {
251 if ((self = [super init])) { 253 if ((self = [super init])) {
252 node_ = node; 254 node_ = node;
253 } 255 }
254 return self; 256 return self;
255 } 257 }
256 258
257 - (void)detach { 259 - (void)detach {
260 if (!node_)
261 return;
262 NSAccessibilityPostNotification(
263 self, NSAccessibilityUIElementDestroyedNotification);
258 node_ = nil; 264 node_ = nil;
259 } 265 }
260 266
261 - (NSRect)boundsInScreen { 267 - (NSRect)boundsInScreen {
262 if (!node_) 268 if (!node_)
263 return NSZeroRect; 269 return NSZeroRect;
264 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); 270 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen());
265 } 271 }
266 272
267 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { 273 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute {
(...skipping 10 matching lines...) Expand all
278 } 284 }
279 285
280 - (id)accessibilityHitTest:(NSPoint)point { 286 - (id)accessibilityHitTest:(NSPoint)point {
281 for (AXPlatformNodeCocoa* child in [self AXChildren]) { 287 for (AXPlatformNodeCocoa* child in [self AXChildren]) {
282 if (NSPointInRect(point, child.boundsInScreen)) 288 if (NSPointInRect(point, child.boundsInScreen))
283 return [child accessibilityHitTest:point]; 289 return [child accessibilityHitTest:point];
284 } 290 }
285 return NSAccessibilityUnignoredAncestor(self); 291 return NSAccessibilityUnignoredAncestor(self);
286 } 292 }
287 293
294 - (BOOL)accessibilityNotifiesWhenDestroyed {
295 return YES;
296 }
297
288 - (NSArray*)accessibilityActionNames { 298 - (NSArray*)accessibilityActionNames {
289 return nil; 299 return nil;
290 } 300 }
291 301
292 - (NSArray*)accessibilityAttributeNames { 302 - (NSArray*)accessibilityAttributeNames {
293 // These attributes are required on all accessibility objects. 303 // These attributes are required on all accessibility objects.
294 NSArray* const kAllRoleAttributes = @[ 304 NSArray* const kAllRoleAttributes = @[
295 NSAccessibilityChildrenAttribute, 305 NSAccessibilityChildrenAttribute,
296 NSAccessibilityParentAttribute, 306 NSAccessibilityParentAttribute,
297 NSAccessibilityPositionAttribute, 307 NSAccessibilityPositionAttribute,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 AXPlatformNodeBase::Destroy(); 556 AXPlatformNodeBase::Destroy();
547 } 557 }
548 558
549 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() { 559 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() {
550 if (!native_node_) 560 if (!native_node_)
551 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]); 561 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]);
552 return native_node_.get(); 562 return native_node_.get();
553 } 563 }
554 564
555 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { 565 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) {
556 NSView* target = GetDelegate()->GetTargetForNativeAccessibilityEvent(); 566 GetNativeViewAccessible();
557
558 // Add mappings between ui::AXEvent and NSAccessibility notifications using 567 // Add mappings between ui::AXEvent and NSAccessibility notifications using
559 // the EventMap above. This switch contains exceptions to those mappings. 568 // the EventMap above. This switch contains exceptions to those mappings.
560 switch (event_type) { 569 switch (event_type) {
561 case ui::AX_EVENT_TEXT_CHANGED: 570 case ui::AX_EVENT_TEXT_CHANGED:
562 // If the view is a user-editable textfield, this should change the value. 571 // If the view is a user-editable textfield, this should change the value.
563 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) { 572 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) {
564 NotifyMacEvent(target, ui::AX_EVENT_VALUE_CHANGED); 573 NotifyMacEvent(native_node_, ui::AX_EVENT_VALUE_CHANGED);
565 return; 574 return;
566 } 575 }
567 break; 576 break;
568 default: 577 default:
569 break; 578 break;
570 } 579 }
571 NotifyMacEvent(target, event_type); 580 NotifyMacEvent(native_node_, event_type);
572 } 581 }
573 582
574 int AXPlatformNodeMac::GetIndexInParent() { 583 int AXPlatformNodeMac::GetIndexInParent() {
575 // TODO(dmazzoni): implement this. http://crbug.com/396137 584 // TODO(dmazzoni): implement this. http://crbug.com/396137
576 return -1; 585 return -1;
577 } 586 }
578 587
579 } // namespace ui 588 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698