| 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 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 5 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 6 | 6 |
| 7 #include <execinfo.h> | 7 #include <execinfo.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "base/mac/foundation_util.h" | 16 #include "base/mac/foundation_util.h" |
| 17 #include "base/mac/scoped_cftyperef.h" | 17 #include "base/mac/scoped_cftyperef.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "content/app/strings/grit/content_strings.h" | 21 #include "content/app/strings/grit/content_strings.h" |
| 22 #include "content/browser/accessibility/ax_platform_position.h" | 22 #include "content/browser/accessibility/ax_platform_position.h" |
| 23 #include "content/browser/accessibility/browser_accessibility_mac.h" | 23 #include "content/browser/accessibility/browser_accessibility_mac.h" |
| 24 #include "content/browser/accessibility/browser_accessibility_manager.h" | 24 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 26 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" | 26 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" |
| 27 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/accessibility/ax_range.h" | 29 #include "ui/accessibility/ax_range.h" |
| 30 #include "ui/accessibility/ax_role_properties.h" |
| 31 |
| 30 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 32 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
| 31 | 33 |
| 32 using AXPlatformPositionInstance = | 34 using AXPlatformPositionInstance = |
| 33 content::AXPlatformPosition::AXPositionInstance; | 35 content::AXPlatformPosition::AXPositionInstance; |
| 34 using AXPlatformRange = ui::AXRange<AXPlatformPositionInstance::element_type>; | 36 using AXPlatformRange = ui::AXRange<AXPlatformPositionInstance::element_type>; |
| 35 using AXTextMarkerRangeRef = CFTypeRef; | 37 using AXTextMarkerRangeRef = CFTypeRef; |
| 36 using AXTextMarkerRef = CFTypeRef; | 38 using AXTextMarkerRef = CFTypeRef; |
| 37 using StringAttribute = ui::AXStringAttribute; | 39 using StringAttribute = ui::AXStringAttribute; |
| 38 using content::AXPlatformPosition; | 40 using content::AXPlatformPosition; |
| 39 using content::AccessibilityMatchPredicate; | 41 using content::AccessibilityMatchPredicate; |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 } | 652 } |
| 651 | 653 |
| 652 - (NSNumber*)ariaBusy { | 654 - (NSNumber*)ariaBusy { |
| 653 if (![self instanceActive]) | 655 if (![self instanceActive]) |
| 654 return nil; | 656 return nil; |
| 655 return [NSNumber numberWithBool: | 657 return [NSNumber numberWithBool: |
| 656 GetState(browserAccessibility_, ui::AX_STATE_BUSY)]; | 658 GetState(browserAccessibility_, ui::AX_STATE_BUSY)]; |
| 657 } | 659 } |
| 658 | 660 |
| 659 - (NSNumber*)ariaColumnCount { | 661 - (NSNumber*)ariaColumnCount { |
| 660 if (!browserAccessibility_->IsTableLikeRole()) | 662 if (!ui::IsTableLikeRole(browserAccessibility_->GetRole())) |
| 661 return nil; | 663 return nil; |
| 662 int count = -1; | 664 int count = -1; |
| 663 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_COLUMN_COUNT, | 665 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_COLUMN_COUNT, |
| 664 &count)) { | 666 &count)) { |
| 665 return nil; | 667 return nil; |
| 666 } | 668 } |
| 667 return [NSNumber numberWithInt:count]; | 669 return [NSNumber numberWithInt:count]; |
| 668 } | 670 } |
| 669 | 671 |
| 670 - (NSNumber*)ariaColumnIndex { | 672 - (NSNumber*)ariaColumnIndex { |
| 671 if (!browserAccessibility_->IsCellOrTableHeaderRole()) | 673 if (!ui::IsCellOrTableHeaderRole(browserAccessibility_->GetRole())) |
| 672 return nil; | 674 return nil; |
| 673 int index = -1; | 675 int index = -1; |
| 674 if (!browserAccessibility_->GetIntAttribute( | 676 if (!browserAccessibility_->GetIntAttribute( |
| 675 ui::AX_ATTR_ARIA_CELL_COLUMN_INDEX, &index)) { | 677 ui::AX_ATTR_ARIA_CELL_COLUMN_INDEX, &index)) { |
| 676 return nil; | 678 return nil; |
| 677 } | 679 } |
| 678 return [NSNumber numberWithInt:index]; | 680 return [NSNumber numberWithInt:index]; |
| 679 } | 681 } |
| 680 | 682 |
| 681 - (NSString*)ariaLive { | 683 - (NSString*)ariaLive { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 693 } | 695 } |
| 694 | 696 |
| 695 - (NSString*)ariaRelevant { | 697 - (NSString*)ariaRelevant { |
| 696 if (![self instanceActive]) | 698 if (![self instanceActive]) |
| 697 return nil; | 699 return nil; |
| 698 return NSStringForStringAttribute(browserAccessibility_, | 700 return NSStringForStringAttribute(browserAccessibility_, |
| 699 ui::AX_ATTR_LIVE_RELEVANT); | 701 ui::AX_ATTR_LIVE_RELEVANT); |
| 700 } | 702 } |
| 701 | 703 |
| 702 - (NSNumber*)ariaRowCount { | 704 - (NSNumber*)ariaRowCount { |
| 703 if (!browserAccessibility_->IsTableLikeRole()) | 705 if (!ui::IsTableLikeRole(browserAccessibility_->GetRole())) |
| 704 return nil; | 706 return nil; |
| 705 int count = -1; | 707 int count = -1; |
| 706 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_ROW_COUNT, | 708 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_ROW_COUNT, |
| 707 &count)) { | 709 &count)) { |
| 708 return nil; | 710 return nil; |
| 709 } | 711 } |
| 710 return [NSNumber numberWithInt:count]; | 712 return [NSNumber numberWithInt:count]; |
| 711 } | 713 } |
| 712 | 714 |
| 713 - (NSNumber*)ariaRowIndex { | 715 - (NSNumber*)ariaRowIndex { |
| 714 if (!browserAccessibility_->IsCellOrTableHeaderRole()) | 716 if (!ui::IsCellOrTableHeaderRole(browserAccessibility_->GetRole())) |
| 715 return nil; | 717 return nil; |
| 716 int index = -1; | 718 int index = -1; |
| 717 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_CELL_ROW_INDEX, | 719 if (!browserAccessibility_->GetIntAttribute(ui::AX_ATTR_ARIA_CELL_ROW_INDEX, |
| 718 &index)) { | 720 &index)) { |
| 719 return nil; | 721 return nil; |
| 720 } | 722 } |
| 721 return [NSNumber numberWithInt:index]; | 723 return [NSNumber numberWithInt:index]; |
| 722 } | 724 } |
| 723 | 725 |
| 724 - (NSNumber*)ariaSetSize { | 726 - (NSNumber*)ariaSetSize { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 children_.reset(); | 776 children_.reset(); |
| 775 } else { | 777 } else { |
| 776 [ToBrowserAccessibilityCocoa(browserAccessibility_->PlatformGetParent()) | 778 [ToBrowserAccessibilityCocoa(browserAccessibility_->PlatformGetParent()) |
| 777 childrenChanged]; | 779 childrenChanged]; |
| 778 } | 780 } |
| 779 } | 781 } |
| 780 | 782 |
| 781 - (NSArray*)columnHeaders { | 783 - (NSArray*)columnHeaders { |
| 782 if (![self instanceActive]) | 784 if (![self instanceActive]) |
| 783 return nil; | 785 return nil; |
| 784 if (!browserAccessibility_->IsTableLikeRole()) { | 786 if (!ui::IsTableLikeRole(browserAccessibility_->GetRole())) { |
| 785 return nil; | 787 return nil; |
| 786 } | 788 } |
| 787 | 789 |
| 788 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 790 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 789 const std::vector<int32_t>& uniqueCellIds = | 791 const std::vector<int32_t>& uniqueCellIds = |
| 790 browserAccessibility_->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | 792 browserAccessibility_->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); |
| 791 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { | 793 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { |
| 792 int id = uniqueCellIds[i]; | 794 int id = uniqueCellIds[i]; |
| 793 BrowserAccessibility* cell = | 795 BrowserAccessibility* cell = |
| 794 browserAccessibility_->manager()->GetFromID(id); | 796 browserAccessibility_->manager()->GetFromID(id); |
| 795 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) | 797 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) |
| 796 [ret addObject:ToBrowserAccessibilityCocoa(cell)]; | 798 [ret addObject:ToBrowserAccessibilityCocoa(cell)]; |
| 797 } | 799 } |
| 798 return ret; | 800 return ret; |
| 799 } | 801 } |
| 800 | 802 |
| 801 - (NSValue*)columnIndexRange { | 803 - (NSValue*)columnIndexRange { |
| 802 if (![self instanceActive]) | 804 if (![self instanceActive]) |
| 803 return nil; | 805 return nil; |
| 804 if (!browserAccessibility_->IsCellOrTableHeaderRole()) | 806 if (!ui::IsCellOrTableHeaderRole(browserAccessibility_->GetRole())) |
| 805 return nil; | 807 return nil; |
| 806 | 808 |
| 807 int column = -1; | 809 int column = -1; |
| 808 int colspan = -1; | 810 int colspan = -1; |
| 809 browserAccessibility_->GetIntAttribute( | 811 browserAccessibility_->GetIntAttribute( |
| 810 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX, &column); | 812 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX, &column); |
| 811 browserAccessibility_->GetIntAttribute( | 813 browserAccessibility_->GetIntAttribute( |
| 812 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &colspan); | 814 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &colspan); |
| 813 if (column >= 0 && colspan >= 1) | 815 if (column >= 0 && colspan >= 1) |
| 814 return [NSValue valueWithRange:NSMakeRange(column, colspan)]; | 816 return [NSValue valueWithRange:NSMakeRange(column, colspan)]; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 grabbed == "true") | 1004 grabbed == "true") |
| 1003 return [NSNumber numberWithBool:YES]; | 1005 return [NSNumber numberWithBool:YES]; |
| 1004 | 1006 |
| 1005 return [NSNumber numberWithBool:NO]; | 1007 return [NSNumber numberWithBool:NO]; |
| 1006 } | 1008 } |
| 1007 | 1009 |
| 1008 - (id)header { | 1010 - (id)header { |
| 1009 if (![self instanceActive]) | 1011 if (![self instanceActive]) |
| 1010 return nil; | 1012 return nil; |
| 1011 int headerElementId = -1; | 1013 int headerElementId = -1; |
| 1012 if (browserAccessibility_->IsTableLikeRole()) { | 1014 if (ui::IsTableLikeRole(browserAccessibility_->GetRole())) { |
| 1013 browserAccessibility_->GetIntAttribute( | 1015 browserAccessibility_->GetIntAttribute( |
| 1014 ui::AX_ATTR_TABLE_HEADER_ID, &headerElementId); | 1016 ui::AX_ATTR_TABLE_HEADER_ID, &headerElementId); |
| 1015 } else if ([self internalRole] == ui::AX_ROLE_COLUMN) { | 1017 } else if ([self internalRole] == ui::AX_ROLE_COLUMN) { |
| 1016 browserAccessibility_->GetIntAttribute( | 1018 browserAccessibility_->GetIntAttribute( |
| 1017 ui::AX_ATTR_TABLE_COLUMN_HEADER_ID, &headerElementId); | 1019 ui::AX_ATTR_TABLE_COLUMN_HEADER_ID, &headerElementId); |
| 1018 } else if ([self internalRole] == ui::AX_ROLE_ROW) { | 1020 } else if ([self internalRole] == ui::AX_ROLE_ROW) { |
| 1019 browserAccessibility_->GetIntAttribute( | 1021 browserAccessibility_->GetIntAttribute( |
| 1020 ui::AX_ATTR_TABLE_ROW_HEADER_ID, &headerElementId); | 1022 ui::AX_ATTR_TABLE_ROW_HEADER_ID, &headerElementId); |
| 1021 } | 1023 } |
| 1022 | 1024 |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 default: | 1502 default: |
| 1501 break; | 1503 break; |
| 1502 } | 1504 } |
| 1503 | 1505 |
| 1504 return NSAccessibilityRoleDescription(role, nil); | 1506 return NSAccessibilityRoleDescription(role, nil); |
| 1505 } | 1507 } |
| 1506 | 1508 |
| 1507 - (NSArray*)rowHeaders { | 1509 - (NSArray*)rowHeaders { |
| 1508 if (![self instanceActive]) | 1510 if (![self instanceActive]) |
| 1509 return nil; | 1511 return nil; |
| 1510 if (!browserAccessibility_->IsTableLikeRole()) { | 1512 if (!ui::IsTableLikeRole(browserAccessibility_->GetRole())) { |
| 1511 return nil; | 1513 return nil; |
| 1512 } | 1514 } |
| 1513 | 1515 |
| 1514 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 1516 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 1515 const std::vector<int32_t>& uniqueCellIds = | 1517 const std::vector<int32_t>& uniqueCellIds = |
| 1516 browserAccessibility_->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | 1518 browserAccessibility_->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); |
| 1517 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { | 1519 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { |
| 1518 int id = uniqueCellIds[i]; | 1520 int id = uniqueCellIds[i]; |
| 1519 BrowserAccessibility* cell = | 1521 BrowserAccessibility* cell = |
| 1520 browserAccessibility_->manager()->GetFromID(id); | 1522 browserAccessibility_->manager()->GetFromID(id); |
| 1521 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER) | 1523 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER) |
| 1522 [ret addObject:ToBrowserAccessibilityCocoa(cell)]; | 1524 [ret addObject:ToBrowserAccessibilityCocoa(cell)]; |
| 1523 } | 1525 } |
| 1524 return ret; | 1526 return ret; |
| 1525 } | 1527 } |
| 1526 | 1528 |
| 1527 - (NSValue*)rowIndexRange { | 1529 - (NSValue*)rowIndexRange { |
| 1528 if (![self instanceActive]) | 1530 if (![self instanceActive]) |
| 1529 return nil; | 1531 return nil; |
| 1530 if (!browserAccessibility_->IsCellOrTableHeaderRole()) | 1532 if (!ui::IsCellOrTableHeaderRole(browserAccessibility_->GetRole())) |
| 1531 return nil; | 1533 return nil; |
| 1532 | 1534 |
| 1533 int row = -1; | 1535 int row = -1; |
| 1534 int rowspan = -1; | 1536 int rowspan = -1; |
| 1535 browserAccessibility_->GetIntAttribute( | 1537 browserAccessibility_->GetIntAttribute( |
| 1536 ui::AX_ATTR_TABLE_CELL_ROW_INDEX, &row); | 1538 ui::AX_ATTR_TABLE_CELL_ROW_INDEX, &row); |
| 1537 browserAccessibility_->GetIntAttribute( | 1539 browserAccessibility_->GetIntAttribute( |
| 1538 ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &rowspan); | 1540 ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &rowspan); |
| 1539 if (row >= 0 && rowspan >= 1) | 1541 if (row >= 0 && rowspan >= 1) |
| 1540 return [NSValue valueWithRange:NSMakeRange(row, rowspan)]; | 1542 return [NSValue valueWithRange:NSMakeRange(row, rowspan)]; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2105 continue; | 2107 continue; |
| 2106 } | 2108 } |
| 2107 if (rowIndex < row) | 2109 if (rowIndex < row) |
| 2108 continue; | 2110 continue; |
| 2109 if (rowIndex > row) | 2111 if (rowIndex > row) |
| 2110 break; | 2112 break; |
| 2111 for (size_t j = 0; | 2113 for (size_t j = 0; |
| 2112 j < child->PlatformChildCount(); | 2114 j < child->PlatformChildCount(); |
| 2113 ++j) { | 2115 ++j) { |
| 2114 BrowserAccessibility* cell = child->PlatformGetChild(j); | 2116 BrowserAccessibility* cell = child->PlatformGetChild(j); |
| 2115 if (!cell->IsCellOrTableHeaderRole()) | 2117 if (!ui::IsCellOrTableHeaderRole(cell->GetRole())) |
| 2116 continue; | 2118 continue; |
| 2117 int colIndex; | 2119 int colIndex; |
| 2118 if (!cell->GetIntAttribute( | 2120 if (!cell->GetIntAttribute( |
| 2119 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX, | 2121 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX, |
| 2120 &colIndex)) { | 2122 &colIndex)) { |
| 2121 continue; | 2123 continue; |
| 2122 } | 2124 } |
| 2123 if (colIndex == column) | 2125 if (colIndex == column) |
| 2124 return ToBrowserAccessibilityCocoa(cell); | 2126 return ToBrowserAccessibilityCocoa(cell); |
| 2125 if (colIndex > column) | 2127 if (colIndex > column) |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 } | 2880 } |
| 2879 | 2881 |
| 2880 - (BOOL)accessibilityNotifiesWhenDestroyed { | 2882 - (BOOL)accessibilityNotifiesWhenDestroyed { |
| 2881 // Indicate that BrowserAccessibilityCocoa will post a notification when it's | 2883 // Indicate that BrowserAccessibilityCocoa will post a notification when it's |
| 2882 // destroyed (see -detach). This allows VoiceOver to do some internal things | 2884 // destroyed (see -detach). This allows VoiceOver to do some internal things |
| 2883 // more efficiently. | 2885 // more efficiently. |
| 2884 return YES; | 2886 return YES; |
| 2885 } | 2887 } |
| 2886 | 2888 |
| 2887 @end | 2889 @end |
| OLD | NEW |