|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Andy Locascio <alocascio@slack-corp.com> |
| 3 | +Date: Mon, 24 Feb 2020 13:50:29 -0800 |
| 4 | +Subject: Expose ARIA trees as tables for macOS accessibility |
| 5 | + |
| 6 | +ARIA trees were previously un-navigable with VoiceOver on macOS. This |
| 7 | +was because it didn't properly fulfill the NSAccessibilityRowsAttribute |
| 8 | +attribute. |
| 9 | + |
| 10 | +In webkit, this attribute is fulfilled by diving on the row's children |
| 11 | +and surfacing any TreeItem elements. This CL represents a port of their |
| 12 | +implementation. |
| 13 | + |
| 14 | +Additionally, I noticed a confusing spot where the subrole is being |
| 15 | +compared in a long line of role comparisons. I moved this around to be |
| 16 | +less foot-gunny/confusing and added more attributes for the OutlineRow |
| 17 | +subrole that macOS accessibility suggests are necessary (and exist in |
| 18 | +the webkit implementation). |
| 19 | + |
| 20 | +Link to webkit impl: |
| 21 | +https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm#L2836 |
| 22 | +https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/accessibility/AccessibilityObject.cpp#L1804 |
| 23 | + |
| 24 | +Bug: 868480 |
| 25 | +Test: Use VoiceOver to navigate the table at https://cookiecrook.com/test/aria/tree/ariatree2.html. Note that the table is no longer announced as empty. |
| 26 | +Change-Id: Ibb86049efa23e12875aa9aeda541e0145242e3b5 |
| 27 | + |
| 28 | +diff --git a/content/browser/accessibility/browser_accessibility_cocoa.h b/content/browser/accessibility/browser_accessibility_cocoa.h |
| 29 | +index 0216501dda1dc8b8fb4307785a0dab868bc3315a..f9730f71c122965f7ce7815a1b9a7b32f8a224f0 100644 |
| 30 | +--- a/content/browser/accessibility/browser_accessibility_cocoa.h |
| 31 | ++++ b/content/browser/accessibility/browser_accessibility_cocoa.h |
| 32 | +@@ -6,6 +6,7 @@ |
| 33 | + #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_COCOA_H_ |
| 34 | + |
| 35 | + #import <Cocoa/Cocoa.h> |
| 36 | ++#include <vector> |
| 37 | + |
| 38 | + #import "base/mac/scoped_nsobject.h" |
| 39 | + #include "base/strings/string16.h" |
| 40 | +@@ -75,6 +76,8 @@ struct AXTextEdit { |
| 41 | + // left). |
| 42 | + - (NSRect)rectInScreen:(gfx::Rect)rect; |
| 43 | + |
| 44 | ++- (void)getTreeItemDescendantNodeIds:(std::vector<int32_t>*)tree_item_ids; |
| 45 | ++ |
| 46 | + // Return the method name for the given attribute. For testing only. |
| 47 | + - (NSString*)methodNameForAttribute:(NSString*)attribute; |
| 48 | + |
| 49 | +diff --git a/content/browser/accessibility/browser_accessibility_cocoa.mm b/content/browser/accessibility/browser_accessibility_cocoa.mm |
| 50 | +index 1381a64458dd37d07c72c3265e46166935012cad..5a9ab09b5214f9a8c38756fb627d32b52b028539 100644 |
| 51 | +--- a/content/browser/accessibility/browser_accessibility_cocoa.mm |
| 52 | ++++ b/content/browser/accessibility/browser_accessibility_cocoa.mm |
| 53 | +@@ -2110,7 +2110,9 @@ - (NSArray*)rows { |
| 54 | + NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 55 | + |
| 56 | + std::vector<int32_t> node_id_list; |
| 57 | +- if (ui::IsTableLike(_owner->GetRole())) |
| 58 | ++ if (_owner->GetRole() == ax::mojom::Role::kTree) |
| 59 | ++ [self getTreeItemDescendantNodeIds:&node_id_list]; |
| 60 | ++ else if (ui::IsTableLike(_owner->GetRole())) |
| 61 | + node_id_list = _owner->node()->GetTableRowNodeIds(); |
| 62 | + // Rows attribute for a column is the list of all the elements in that column |
| 63 | + // at each row. |
| 64 | +@@ -2543,6 +2545,19 @@ - (id)window { |
| 65 | + return manager->GetWindow(); |
| 66 | + } |
| 67 | + |
| 68 | ++- (void)getTreeItemDescendantNodeIds:(std::vector<int32_t>*)tree_item_ids { |
| 69 | ++ for (auto it = _owner->PlatformChildrenBegin(); |
| 70 | ++ it != _owner->PlatformChildrenEnd(); ++it) { |
| 71 | ++ const BrowserAccessibilityCocoa* child = |
| 72 | ++ ToBrowserAccessibilityCocoa(it.get()); |
| 73 | ++ |
| 74 | ++ if ([child internalRole] == ax::mojom::Role::kTreeItem) { |
| 75 | ++ tree_item_ids->push_back([child hash]); |
| 76 | ++ } |
| 77 | ++ [child getTreeItemDescendantNodeIds:tree_item_ids]; |
| 78 | ++ } |
| 79 | ++} |
| 80 | ++ |
| 81 | + - (NSString*)methodNameForAttribute:(NSString*)attribute { |
| 82 | + return [attributeToMethodNameMap objectForKey:attribute]; |
| 83 | + } |
| 84 | +@@ -3361,18 +3376,12 @@ - (NSArray*)accessibilityAttributeNames { |
| 85 | + NSAccessibilityMaxValueAttribute, NSAccessibilityMinValueAttribute, |
| 86 | + NSAccessibilityValueDescriptionAttribute |
| 87 | + ]]; |
| 88 | +- } else if ([subrole isEqualToString:NSAccessibilityOutlineRowSubrole]) { |
| 89 | +- [ret addObjectsFromArray:@[ |
| 90 | +- NSAccessibilityDisclosingAttribute, |
| 91 | +- NSAccessibilityDisclosedByRowAttribute, |
| 92 | +- NSAccessibilityDisclosureLevelAttribute, |
| 93 | +- NSAccessibilityDisclosedRowsAttribute |
| 94 | +- ]]; |
| 95 | + } else if ([role isEqualToString:NSAccessibilityRowRole]) { |
| 96 | + BrowserAccessibility* container = _owner->PlatformGetParent(); |
| 97 | + if (container && container->GetRole() == ax::mojom::Role::kRowGroup) |
| 98 | + container = container->PlatformGetParent(); |
| 99 | +- if (container && container->GetRole() == ax::mojom::Role::kTreeGrid) { |
| 100 | ++ if ([subrole isEqualToString:NSAccessibilityOutlineRowSubrole] || |
| 101 | ++ (container && container->GetRole() == ax::mojom::Role::kTreeGrid)) { |
| 102 | + [ret addObjectsFromArray:@[ |
| 103 | + NSAccessibilityDisclosingAttribute, |
| 104 | + NSAccessibilityDisclosedByRowAttribute, |
| 105 | +@@ -3387,6 +3396,13 @@ - (NSArray*)accessibilityAttributeNames { |
| 106 | + NSAccessibilitySelectedChildrenAttribute, |
| 107 | + NSAccessibilityVisibleChildrenAttribute |
| 108 | + ]]; |
| 109 | ++ } else if ([role isEqualToString:NSAccessibilityOutlineRole]) { |
| 110 | ++ [ret addObjectsFromArray:@[ |
| 111 | ++ NSAccessibilitySelectedRowsAttribute, |
| 112 | ++ NSAccessibilityRowsAttribute, |
| 113 | ++ NSAccessibilityColumnsAttribute, |
| 114 | ++ NSAccessibilityOrientationAttribute |
| 115 | ++ ]]; |
| 116 | + } |
| 117 | + |
| 118 | + // Caret navigation and text selection attributes. |
0 commit comments