Commit 5159a454 authored by Andy Locascio's avatar Andy Locascio Committed by Commit Bot

Expose ARIA trees as tables for macOS accessibility

ARIA trees were previously un-navigable with VoiceOver on macOS. This
was because it didn't properly fulfill the NSAccessibilityRowsAttribute
attribute.

In webkit, this attribute is fulfilled by diving on the row's children
and surfacing any TreeItem elements. This CL represents a port of their
implementation.

Additionally, I noticed a confusing spot where the subrole is being
compared in a long line of role comparisons. I moved this around to be
less foot-gunny/confusing and added more attributes for the OutlineRow
subrole that macOS accessibility suggests are necessary (and exist in
the webkit implementation).

Link to webkit impl:
https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm#L2836
https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/accessibility/AccessibilityObject.cpp#L1804

Bug: 868480
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.
Change-Id: Ibb86049efa23e12875aa9aeda541e0145242e3b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062913Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Auto-Submit: Andy Locascio <andy@slack-corp.com>
Cr-Commit-Position: refs/heads/master@{#744740}
parent 93812d9f
......@@ -6,6 +6,7 @@
#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_COCOA_H_
#import <Cocoa/Cocoa.h>
#include <vector>
#import "base/mac/scoped_nsobject.h"
#include "base/strings/string16.h"
......@@ -75,6 +76,8 @@ struct AXTextEdit {
// left).
- (NSRect)rectInScreen:(gfx::Rect)rect;
- (void)getTreeItemDescendantNodeIds:(std::vector<int32_t>*)tree_item_ids;
// Return the method name for the given attribute. For testing only.
- (NSString*)methodNameForAttribute:(NSString*)attribute;
......
......@@ -2097,7 +2097,9 @@ NSString* const NSAccessibilityRequiredAttributeChrome = @"AXRequired";
NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease];
std::vector<int32_t> node_id_list;
if (ui::IsTableLike(_owner->GetRole()))
if (_owner->GetRole() == ax::mojom::Role::kTree)
[self getTreeItemDescendantNodeIds:&node_id_list];
else if (ui::IsTableLike(_owner->GetRole()))
node_id_list = _owner->node()->GetTableRowNodeIds();
// Rows attribute for a column is the list of all the elements in that column
// at each row.
......@@ -2522,6 +2524,19 @@ NSString* const NSAccessibilityRequiredAttributeChrome = @"AXRequired";
return manager->GetWindow();
}
- (void)getTreeItemDescendantNodeIds:(std::vector<int32_t>*)tree_item_ids {
for (auto it = _owner->PlatformChildrenBegin();
it != _owner->PlatformChildrenEnd(); ++it) {
const BrowserAccessibilityCocoa* child =
ToBrowserAccessibilityCocoa(it.get());
if ([child internalRole] == ax::mojom::Role::kTreeItem) {
tree_item_ids->push_back([child hash]);
}
[child getTreeItemDescendantNodeIds:tree_item_ids];
}
}
- (NSString*)methodNameForAttribute:(NSString*)attribute {
return [attributeToMethodNameMap objectForKey:attribute];
}
......@@ -3336,18 +3351,12 @@ NSString* const NSAccessibilityRequiredAttributeChrome = @"AXRequired";
NSAccessibilityMaxValueAttribute, NSAccessibilityMinValueAttribute,
NSAccessibilityValueDescriptionAttribute
]];
} else if ([subrole isEqualToString:NSAccessibilityOutlineRowSubrole]) {
[ret addObjectsFromArray:@[
NSAccessibilityDisclosingAttribute,
NSAccessibilityDisclosedByRowAttribute,
NSAccessibilityDisclosureLevelAttribute,
NSAccessibilityDisclosedRowsAttribute
]];
} else if ([role isEqualToString:NSAccessibilityRowRole]) {
BrowserAccessibility* container = _owner->PlatformGetParent();
if (container && container->GetRole() == ax::mojom::Role::kRowGroup)
container = container->PlatformGetParent();
if (container && container->GetRole() == ax::mojom::Role::kTreeGrid) {
if ([subrole isEqualToString:NSAccessibilityOutlineRowSubrole] ||
(container && container->GetRole() == ax::mojom::Role::kTreeGrid)) {
[ret addObjectsFromArray:@[
NSAccessibilityDisclosingAttribute,
NSAccessibilityDisclosedByRowAttribute,
......@@ -3362,6 +3371,13 @@ NSString* const NSAccessibilityRequiredAttributeChrome = @"AXRequired";
NSAccessibilitySelectedChildrenAttribute,
NSAccessibilityVisibleChildrenAttribute
]];
} else if ([role isEqualToString:NSAccessibilityOutlineRole]) {
[ret addObjectsFromArray:@[
NSAccessibilitySelectedRowsAttribute,
NSAccessibilityRowsAttribute,
NSAccessibilityColumnsAttribute,
NSAccessibilityOrientationAttribute
]];
}
// Caret navigation and text selection attributes.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment