Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 18 #import "tmp-traceclass.h" | |
| 19 | |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 struct RoleMapEntry { | 22 struct RoleMapEntry { |
| 20 ui::AXRole value; | 23 ui::AXRole value; |
| 21 NSString* nativeValue; | 24 NSString* nativeValue; |
| 22 }; | 25 }; |
| 23 | 26 |
| 24 struct EventMapEntry { | 27 struct EventMapEntry { |
| 25 ui::AXEvent value; | 28 ui::AXEvent value; |
| 26 NSString* nativeValue; | 29 NSString* nativeValue; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 }; | 193 }; |
| 191 | 194 |
| 192 RoleMap subrole_map; | 195 RoleMap subrole_map; |
| 193 for (size_t i = 0; i < arraysize(subroles); ++i) | 196 for (size_t i = 0; i < arraysize(subroles); ++i) |
| 194 subrole_map[subroles[i].value] = subroles[i].nativeValue; | 197 subrole_map[subroles[i].value] = subroles[i].nativeValue; |
| 195 return subrole_map; | 198 return subrole_map; |
| 196 } | 199 } |
| 197 | 200 |
| 198 EventMap BuildEventMap() { | 201 EventMap BuildEventMap() { |
| 199 const EventMapEntry events[] = { | 202 const EventMapEntry events[] = { |
| 203 {ui::AX_EVENT_FOCUS, NSAccessibilityFocusedUIElementChangedNotification}, | |
| 200 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification}, | 204 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification}, |
| 201 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification}, | 205 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification}, |
| 202 {ui::AX_EVENT_TEXT_SELECTION_CHANGED, | 206 {ui::AX_EVENT_TEXT_SELECTION_CHANGED, |
| 203 NSAccessibilitySelectedTextChangedNotification}, | 207 NSAccessibilitySelectedTextChangedNotification}, |
| 204 // TODO(patricialor): Add more events. | 208 // TODO(patricialor): Add more events. |
| 205 }; | 209 }; |
| 206 | 210 |
| 207 EventMap event_map; | 211 EventMap event_map; |
| 208 for (size_t i = 0; i < arraysize(events); ++i) | 212 for (size_t i = 0; i < arraysize(events); ++i) |
| 209 event_map[events[i].value] = events[i].nativeValue; | 213 event_map[events[i].value] = events[i].nativeValue; |
| 210 return event_map; | 214 return event_map; |
| 211 } | 215 } |
| 212 | 216 |
| 213 void NotifyMacEvent(NSView* target, ui::AXEvent event_type) { | 217 void NotifyMacEvent(id target, ui::AXEvent event_type) { |
| 214 NSAccessibilityPostNotification( | 218 NSAccessibilityPostNotification( |
| 215 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); | 219 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); |
| 216 } | 220 } |
| 217 | 221 |
| 218 } // namespace | 222 } // namespace |
| 219 | 223 |
| 220 @interface AXPlatformNodeCocoa () | 224 @interface AXPlatformNodeCocoa () |
| 221 // Helper function for string attributes that don't require extra processing. | 225 // Helper function for string attributes that don't require extra processing. |
| 222 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; | 226 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; |
| 223 @end | 227 @end |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 245 return it != event_map.end() ? it->second : nil; | 249 return it != event_map.end() ? it->second : nil; |
| 246 } | 250 } |
| 247 | 251 |
| 248 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node { | 252 - (instancetype)initWithNode:(ui::AXPlatformNodeBase*)node { |
| 249 if ((self = [super init])) { | 253 if ((self = [super init])) { |
| 250 node_ = node; | 254 node_ = node; |
| 251 } | 255 } |
| 252 return self; | 256 return self; |
| 253 } | 257 } |
| 254 | 258 |
| 259 - (BOOL)isEqual:(id)object { | |
| 260 if (![object isKindOfClass:[AXPlatformNodeCocoa class]]) | |
| 261 return NO; | |
| 262 return ([self hash] == [object hash]); | |
| 263 } | |
| 264 | |
| 265 - (NSUInteger)hash { | |
| 266 // Potentially called during dealloc. | |
| 267 if (!node_) | |
| 268 return [super hash]; | |
| 269 return node_->GetData().id; | |
| 270 } | |
| 271 | |
| 255 - (void)detach { | 272 - (void)detach { |
| 273 if (!node_) | |
| 274 return; | |
| 275 NSAccessibilityPostNotification( | |
| 276 self, NSAccessibilityUIElementDestroyedNotification); | |
| 277 NSAccessibilityUnregisterUniqueIdForUIElement(self); | |
| 256 node_ = nil; | 278 node_ = nil; |
| 257 } | 279 } |
| 258 | 280 |
| 259 - (NSRect)boundsInScreen { | 281 - (NSRect)boundsInScreen { |
| 260 if (!node_) | 282 if (!node_) |
| 261 return NSZeroRect; | 283 return NSZeroRect; |
| 262 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); | 284 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); |
| 263 } | 285 } |
| 264 | 286 |
| 265 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { | 287 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 276 } | 298 } |
| 277 | 299 |
| 278 - (id)accessibilityHitTest:(NSPoint)point { | 300 - (id)accessibilityHitTest:(NSPoint)point { |
| 279 for (AXPlatformNodeCocoa* child in [self AXChildren]) { | 301 for (AXPlatformNodeCocoa* child in [self AXChildren]) { |
| 280 if (NSPointInRect(point, child.boundsInScreen)) | 302 if (NSPointInRect(point, child.boundsInScreen)) |
| 281 return [child accessibilityHitTest:point]; | 303 return [child accessibilityHitTest:point]; |
| 282 } | 304 } |
| 283 return NSAccessibilityUnignoredAncestor(self); | 305 return NSAccessibilityUnignoredAncestor(self); |
| 284 } | 306 } |
| 285 | 307 |
| 308 - (BOOL)accessibilityNotifiesWhenDestroyed { | |
| 309 return YES; | |
| 310 } | |
| 311 | |
| 312 - (BOOL)accessibilityShouldUseUniqueId { | |
| 313 return YES; | |
| 314 } | |
| 315 | |
| 286 - (NSArray*)accessibilityActionNames { | 316 - (NSArray*)accessibilityActionNames { |
| 287 return nil; | 317 return nil; |
| 288 } | 318 } |
| 289 | 319 |
| 290 - (NSArray*)accessibilityAttributeNames { | 320 - (NSArray*)accessibilityAttributeNames { |
| 291 // These attributes are required on all accessibility objects. | 321 // These attributes are required on all accessibility objects. |
| 292 NSArray* const kAllRoleAttributes = @[ | 322 NSArray* const kAllRoleAttributes = @[ |
| 293 NSAccessibilityChildrenAttribute, | 323 NSAccessibilityChildrenAttribute, |
| 294 NSAccessibilityParentAttribute, | 324 NSAccessibilityParentAttribute, |
| 295 NSAccessibilityPositionAttribute, | 325 NSAccessibilityPositionAttribute, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 AXPlatformNodeBase::Destroy(); | 538 AXPlatformNodeBase::Destroy(); |
| 509 } | 539 } |
| 510 | 540 |
| 511 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() { | 541 gfx::NativeViewAccessible AXPlatformNodeMac::GetNativeViewAccessible() { |
| 512 if (!native_node_) | 542 if (!native_node_) |
| 513 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]); | 543 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]); |
| 514 return native_node_.get(); | 544 return native_node_.get(); |
| 515 } | 545 } |
| 516 | 546 |
| 517 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { | 547 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { |
| 518 NSView* target = GetDelegate()->GetTargetForNativeAccessibilityEvent(); | 548 if (!native_node_) |
| 519 | 549 GetNativeViewAccessible(); |
| 520 // Add mappings between ui::AXEvent and NSAccessibility notifications using | 550 // Add mappings between ui::AXEvent and NSAccessibility notifications using |
| 521 // the EventMap above. This switch contains exceptions to those mappings. | 551 // the EventMap above. This switch contains exceptions to those mappings. |
| 522 switch (event_type) { | 552 switch (event_type) { |
| 553 case ui::AX_EVENT_FOCUS: | |
| 554 [Tracer startTracePlatformNode]; | |
| 555 NSAccessibilityPostNotification( | |
| 556 native_node_, NSAccessibilityFocusedUIElementChangedNotification); | |
| 557 [Tracer platformNodeEndTrace]; | |
| 558 return; | |
|
Patti Lor
2016/08/04 02:06:26
With tracing removed, this whole hunk shouldn't be
| |
| 523 case ui::AX_EVENT_TEXT_CHANGED: | 559 case ui::AX_EVENT_TEXT_CHANGED: |
| 524 // If the view is a user-editable textfield, this should change the value. | 560 // If the view is a user-editable textfield, this should change the value. |
| 525 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) { | 561 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) { |
| 526 NotifyMacEvent(target, ui::AX_EVENT_VALUE_CHANGED); | 562 NotifyMacEvent(native_node_, ui::AX_EVENT_VALUE_CHANGED); |
| 527 return; | 563 return; |
| 528 } | 564 } |
| 529 break; | 565 break; |
| 530 default: | 566 default: |
| 531 break; | 567 break; |
| 532 } | 568 } |
| 533 NotifyMacEvent(target, event_type); | 569 NotifyMacEvent(native_node_, event_type); |
| 534 } | 570 } |
| 535 | 571 |
| 536 int AXPlatformNodeMac::GetIndexInParent() { | 572 int AXPlatformNodeMac::GetIndexInParent() { |
| 537 // TODO(dmazzoni): implement this. http://crbug.com/396137 | 573 // TODO(dmazzoni): implement this. http://crbug.com/396137 |
| 538 return -1; | 574 return -1; |
| 539 } | 575 } |
| 540 | 576 |
| 541 } // namespace ui | 577 } // namespace ui |
| OLD | NEW |