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

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

Powered by Google App Engine
This is Rietveld 408576698