OLD | NEW |
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 <execinfo.h> | 5 #include <execinfo.h> |
6 | 6 |
7 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 7 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 const size_t numAttributes = sizeof(attributeToMethodNameContainer) / | 300 const size_t numAttributes = sizeof(attributeToMethodNameContainer) / |
301 sizeof(attributeToMethodNameContainer[0]); | 301 sizeof(attributeToMethodNameContainer[0]); |
302 for (size_t i = 0; i < numAttributes; ++i) { | 302 for (size_t i = 0; i < numAttributes; ++i) { |
303 [dict setObject:attributeToMethodNameContainer[i].methodName | 303 [dict setObject:attributeToMethodNameContainer[i].methodName |
304 forKey:attributeToMethodNameContainer[i].attribute]; | 304 forKey:attributeToMethodNameContainer[i].attribute]; |
305 } | 305 } |
306 attributeToMethodNameMap = dict; | 306 attributeToMethodNameMap = dict; |
307 dict = nil; | 307 dict = nil; |
308 } | 308 } |
309 | 309 |
310 - (id)initWithObject:(BrowserAccessibility*)accessibility | 310 - (id)initWithObject:(BrowserAccessibility*)accessibility { |
311 delegate:(id<BrowserAccessibilityDelegateCocoa>)delegate { | 311 if ((self = [super init])) |
312 if ((self = [super init])) { | |
313 browserAccessibility_ = accessibility; | 312 browserAccessibility_ = accessibility; |
314 delegate_ = delegate; | |
315 } | |
316 return self; | 313 return self; |
317 } | 314 } |
318 | 315 |
319 - (void)detach { | 316 - (void)detach { |
320 if (browserAccessibility_) { | 317 if (browserAccessibility_) { |
321 NSAccessibilityUnregisterUniqueIdForUIElement(self); | 318 NSAccessibilityUnregisterUniqueIdForUIElement(self); |
322 browserAccessibility_ = NULL; | 319 browserAccessibility_ = NULL; |
323 } | 320 } |
324 } | 321 } |
325 | 322 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 BrowserAccessibilityManagerMac* manager = | 656 BrowserAccessibilityManagerMac* manager = |
660 static_cast<BrowserAccessibilityManagerMac*>( | 657 static_cast<BrowserAccessibilityManagerMac*>( |
661 browserAccessibility_->manager()); | 658 browserAccessibility_->manager()); |
662 return manager->parent_view(); | 659 return manager->parent_view(); |
663 } | 660 } |
664 } | 661 } |
665 | 662 |
666 - (NSValue*)position { | 663 - (NSValue*)position { |
667 NSPoint origin = [self origin]; | 664 NSPoint origin = [self origin]; |
668 NSSize size = [[self size] sizeValue]; | 665 NSSize size = [[self size] sizeValue]; |
669 NSPoint pointInScreen = | 666 NSPoint pointInScreen = [self pointInScreen:origin size:size]; |
670 [delegate_ accessibilityPointInScreen:origin size:size]; | |
671 return [NSValue valueWithPoint:pointInScreen]; | 667 return [NSValue valueWithPoint:pointInScreen]; |
672 } | 668 } |
673 | 669 |
674 - (NSNumber*)required { | 670 - (NSNumber*)required { |
675 return [NSNumber numberWithBool: | 671 return [NSNumber numberWithBool: |
676 GetState(browserAccessibility_, ui::AX_STATE_REQUIRED)]; | 672 GetState(browserAccessibility_, ui::AX_STATE_REQUIRED)]; |
677 } | 673 } |
678 | 674 |
679 // Returns an enum indicating the role from browserAccessibility_. | 675 // Returns an enum indicating the role from browserAccessibility_. |
680 - (ui::AXRole)internalRole { | 676 - (ui::AXRole)internalRole { |
681 return static_cast<ui::AXRole>(browserAccessibility_->GetRole()); | 677 return static_cast<ui::AXRole>(browserAccessibility_->GetRole()); |
682 } | 678 } |
683 | 679 |
| 680 - (content::BrowserAccessibilityDelegate*)delegate { |
| 681 return browserAccessibility_->manager() ? |
| 682 browserAccessibility_->manager()->delegate() : |
| 683 nil; |
| 684 } |
| 685 |
| 686 - (NSPoint)pointInScreen:(NSPoint)origin |
| 687 size:(NSSize)size { |
| 688 if (!browserAccessibility_) |
| 689 return NSZeroPoint; |
| 690 |
| 691 gfx::Rect bounds(origin.x, origin.y, size.width, size.height); |
| 692 gfx::Point point = [self delegate]->AccessibilityOriginInScreen(bounds); |
| 693 return NSMakePoint(point.x(), point.y()); |
| 694 } |
| 695 |
684 // Returns a string indicating the NSAccessibility role of this object. | 696 // Returns a string indicating the NSAccessibility role of this object. |
685 - (NSString*)role { | 697 - (NSString*)role { |
686 ui::AXRole role = [self internalRole]; | 698 ui::AXRole role = [self internalRole]; |
687 if (role == ui::AX_ROLE_CANVAS && | 699 if (role == ui::AX_ROLE_CANVAS && |
688 browserAccessibility_->GetBoolAttribute( | 700 browserAccessibility_->GetBoolAttribute( |
689 ui::AX_ATTR_CANVAS_HAS_FALLBACK)) { | 701 ui::AX_ATTR_CANVAS_HAS_FALLBACK)) { |
690 return NSAccessibilityGroupRole; | 702 return NSAccessibilityGroupRole; |
691 } | 703 } |
692 if (role == ui::AX_ROLE_BUTTON || role == ui::AX_ROLE_TOGGLE_BUTTON) { | 704 if (role == ui::AX_ROLE_BUTTON || role == ui::AX_ROLE_TOGGLE_BUTTON) { |
693 bool isAriaPressedDefined; | 705 bool isAriaPressedDefined; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 - (NSArray*)visibleRows { | 1010 - (NSArray*)visibleRows { |
999 return [self rows]; | 1011 return [self rows]; |
1000 } | 1012 } |
1001 | 1013 |
1002 - (NSNumber*)visited { | 1014 - (NSNumber*)visited { |
1003 return [NSNumber numberWithBool: | 1015 return [NSNumber numberWithBool: |
1004 GetState(browserAccessibility_, ui::AX_STATE_VISITED)]; | 1016 GetState(browserAccessibility_, ui::AX_STATE_VISITED)]; |
1005 } | 1017 } |
1006 | 1018 |
1007 - (id)window { | 1019 - (id)window { |
1008 return [delegate_ window]; | 1020 if (!browserAccessibility_) |
| 1021 return nil; |
| 1022 |
| 1023 BrowserAccessibilityManagerMac* manager = |
| 1024 static_cast<BrowserAccessibilityManagerMac*>( |
| 1025 browserAccessibility_->manager()); |
| 1026 return [manager->parent_view() window]; |
1009 } | 1027 } |
1010 | 1028 |
1011 - (NSString*)methodNameForAttribute:(NSString*)attribute { | 1029 - (NSString*)methodNameForAttribute:(NSString*)attribute { |
1012 return [attributeToMethodNameMap objectForKey:attribute]; | 1030 return [attributeToMethodNameMap objectForKey:attribute]; |
1013 } | 1031 } |
1014 | 1032 |
1015 // Returns the accessibility value for the given attribute. If the value isn't | 1033 // Returns the accessibility value for the given attribute. If the value isn't |
1016 // supported this will return nil. | 1034 // supported this will return nil. |
1017 - (id)accessibilityAttributeValue:(NSString*)attribute { | 1035 - (id)accessibilityAttributeValue:(NSString*)attribute { |
1018 if (!browserAccessibility_) | 1036 if (!browserAccessibility_) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 | 1172 |
1155 if ([attribute isEqualToString: | 1173 if ([attribute isEqualToString: |
1156 NSAccessibilityBoundsForRangeParameterizedAttribute]) { | 1174 NSAccessibilityBoundsForRangeParameterizedAttribute]) { |
1157 if ([self internalRole] != ui::AX_ROLE_STATIC_TEXT) | 1175 if ([self internalRole] != ui::AX_ROLE_STATIC_TEXT) |
1158 return nil; | 1176 return nil; |
1159 NSRange range = [(NSValue*)parameter rangeValue]; | 1177 NSRange range = [(NSValue*)parameter rangeValue]; |
1160 gfx::Rect rect = browserAccessibility_->GetGlobalBoundsForRange( | 1178 gfx::Rect rect = browserAccessibility_->GetGlobalBoundsForRange( |
1161 range.location, range.length); | 1179 range.location, range.length); |
1162 NSPoint origin = NSMakePoint(rect.x(), rect.y()); | 1180 NSPoint origin = NSMakePoint(rect.x(), rect.y()); |
1163 NSSize size = NSMakeSize(rect.width(), rect.height()); | 1181 NSSize size = NSMakeSize(rect.width(), rect.height()); |
1164 NSPoint pointInScreen = | 1182 NSPoint pointInScreen = [self pointInScreen:origin size:size]; |
1165 [delegate_ accessibilityPointInScreen:origin size:size]; | |
1166 NSRect nsrect = NSMakeRect( | 1183 NSRect nsrect = NSMakeRect( |
1167 pointInScreen.x, pointInScreen.y, rect.width(), rect.height()); | 1184 pointInScreen.x, pointInScreen.y, rect.width(), rect.height()); |
1168 return [NSValue valueWithRect:nsrect]; | 1185 return [NSValue valueWithRect:nsrect]; |
1169 } | 1186 } |
1170 | 1187 |
1171 // TODO(dtseng): support the following attributes. | 1188 // TODO(dtseng): support the following attributes. |
1172 if ([attribute isEqualTo: | 1189 if ([attribute isEqualTo: |
1173 NSAccessibilityRangeForPositionParameterizedAttribute] || | 1190 NSAccessibilityRangeForPositionParameterizedAttribute] || |
1174 [attribute isEqualTo: | 1191 [attribute isEqualTo: |
1175 NSAccessibilityRangeForIndexParameterizedAttribute] || | 1192 NSAccessibilityRangeForIndexParameterizedAttribute] || |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 | 1476 |
1460 return [self isIgnored]; | 1477 return [self isIgnored]; |
1461 } | 1478 } |
1462 | 1479 |
1463 // Performs the given accessibilty action on the webkit accessibility object | 1480 // Performs the given accessibilty action on the webkit accessibility object |
1464 // that backs this object. | 1481 // that backs this object. |
1465 - (void)accessibilityPerformAction:(NSString*)action { | 1482 - (void)accessibilityPerformAction:(NSString*)action { |
1466 if (!browserAccessibility_) | 1483 if (!browserAccessibility_) |
1467 return; | 1484 return; |
1468 | 1485 |
1469 // TODO(feldstein): Support more actions. | 1486 // TODO(dmazzoni): Support more actions. |
1470 if ([action isEqualToString:NSAccessibilityPressAction]) | 1487 if ([action isEqualToString:NSAccessibilityPressAction]) { |
1471 [delegate_ doDefaultAction:browserAccessibility_->GetId()]; | 1488 [self delegate]->AccessibilityDoDefaultAction( |
1472 else if ([action isEqualToString:NSAccessibilityShowMenuAction]) | 1489 browserAccessibility_->GetId()); |
1473 [delegate_ performShowMenuAction:self]; | 1490 } else if ([action isEqualToString:NSAccessibilityShowMenuAction]) { |
| 1491 [self delegate]->AccessibilityShowMenu(browserAccessibility_->GetId()); |
| 1492 } |
1474 } | 1493 } |
1475 | 1494 |
1476 // Returns the description of the given action. | 1495 // Returns the description of the given action. |
1477 - (NSString*)accessibilityActionDescription:(NSString*)action { | 1496 - (NSString*)accessibilityActionDescription:(NSString*)action { |
1478 if (!browserAccessibility_) | 1497 if (!browserAccessibility_) |
1479 return nil; | 1498 return nil; |
1480 | 1499 |
1481 return NSAccessibilityActionDescription(action); | 1500 return NSAccessibilityActionDescription(action); |
1482 } | 1501 } |
1483 | 1502 |
1484 // Sets an override value for a specific accessibility attribute. | 1503 // Sets an override value for a specific accessibility attribute. |
1485 // This class does not support this. | 1504 // This class does not support this. |
1486 - (BOOL)accessibilitySetOverrideValue:(id)value | 1505 - (BOOL)accessibilitySetOverrideValue:(id)value |
1487 forAttribute:(NSString*)attribute { | 1506 forAttribute:(NSString*)attribute { |
1488 return NO; | 1507 return NO; |
1489 } | 1508 } |
1490 | 1509 |
1491 // Sets the value for an accessibility attribute via the accessibility API. | 1510 // Sets the value for an accessibility attribute via the accessibility API. |
1492 - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute { | 1511 - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute { |
1493 if (!browserAccessibility_) | 1512 if (!browserAccessibility_) |
1494 return; | 1513 return; |
1495 | 1514 |
1496 if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) { | 1515 if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) { |
1497 NSNumber* focusedNumber = value; | 1516 NSNumber* focusedNumber = value; |
1498 BOOL focused = [focusedNumber intValue]; | 1517 BOOL focused = [focusedNumber intValue]; |
1499 [delegate_ setAccessibilityFocus:focused | 1518 if (focused) |
1500 accessibilityId:browserAccessibility_->GetId()]; | 1519 [self delegate]->AccessibilitySetFocus(browserAccessibility_->GetId()); |
1501 } | 1520 } |
1502 if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { | 1521 if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { |
1503 NSRange range = [(NSValue*)value rangeValue]; | 1522 NSRange range = [(NSValue*)value rangeValue]; |
1504 [delegate_ | 1523 [self delegate]->AccessibilitySetTextSelection( |
1505 accessibilitySetTextSelection:browserAccessibility_->GetId() | 1524 browserAccessibility_->GetId(), |
1506 startOffset:range.location | 1525 range.location, range.location + range.length); |
1507 endOffset:range.location + range.length]; | |
1508 } | 1526 } |
1509 } | 1527 } |
1510 | 1528 |
1511 // Returns the deepest accessibility child that should not be ignored. | 1529 // Returns the deepest accessibility child that should not be ignored. |
1512 // It is assumed that the hit test has been narrowed down to this object | 1530 // It is assumed that the hit test has been narrowed down to this object |
1513 // or one of its children, so this will never return nil unless this | 1531 // or one of its children, so this will never return nil unless this |
1514 // object is invalid. | 1532 // object is invalid. |
1515 - (id)accessibilityHitTest:(NSPoint)point { | 1533 - (id)accessibilityHitTest:(NSPoint)point { |
1516 if (!browserAccessibility_) | 1534 if (!browserAccessibility_) |
1517 return nil; | 1535 return nil; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 return [super hash]; | 1567 return [super hash]; |
1550 return browserAccessibility_->GetId(); | 1568 return browserAccessibility_->GetId(); |
1551 } | 1569 } |
1552 | 1570 |
1553 - (BOOL)accessibilityShouldUseUniqueId { | 1571 - (BOOL)accessibilityShouldUseUniqueId { |
1554 return YES; | 1572 return YES; |
1555 } | 1573 } |
1556 | 1574 |
1557 @end | 1575 @end |
1558 | 1576 |
OLD | NEW |