Commit f7644527 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Add support for links, headings, and list items in native arc accessibility

Bug: 751264, 751263, 751259, 745865
Change-Id: Ia354c13d609e80d0f068040f9888fd278e30c417
Reviewed-on: https://chromium-review.googlesource.com/639322
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#500030}
parent c886e182
......@@ -144,8 +144,68 @@ bool GetStringListProperty(arc::mojom::AccessibilityNodeInfoData* node,
return true;
}
bool HasCoveringSpan(arc::mojom::AccessibilityNodeInfoData* data,
arc::mojom::AccessibilityStringProperty prop,
arc::mojom::SpanType span_type) {
if (!data->spannable_string_properties)
return false;
std::string text;
GetStringProperty(data, prop, &text);
if (text.empty())
return false;
auto span_entries_it = data->spannable_string_properties->find(prop);
if (span_entries_it == data->spannable_string_properties->end())
return false;
for (size_t i = 0; i < span_entries_it->second.size(); ++i) {
if (span_entries_it->second[i]->span_type != span_type)
continue;
size_t span_size =
span_entries_it->second[i]->end - span_entries_it->second[i]->start;
if (span_size == text.size())
return true;
}
return false;
}
void PopulateAXRole(arc::mojom::AccessibilityNodeInfoData* node,
ui::AXNodeData* out_data) {
if (HasCoveringSpan(node, arc::mojom::AccessibilityStringProperty::TEXT,
arc::mojom::SpanType::URL) ||
HasCoveringSpan(
node, arc::mojom::AccessibilityStringProperty::CONTENT_DESCRIPTION,
arc::mojom::SpanType::URL)) {
out_data->role = ui::AX_ROLE_LINK;
return;
}
arc::mojom::AccessibilityCollectionItemInfoData* collection_item_info =
node->collection_item_info.get();
if (collection_item_info) {
if (collection_item_info->is_heading) {
out_data->role = ui::AX_ROLE_HEADING;
} else {
out_data->role = ui::AX_ROLE_LIST_ITEM;
out_data->AddIntAttribute(ui::AX_ATTR_POS_IN_SET,
collection_item_info->row_index);
}
return;
}
std::string chrome_role;
if (GetStringProperty(node,
arc::mojom::AccessibilityStringProperty::CHROME_ROLE,
&chrome_role)) {
ui::AXRole role_value = ui::ParseAXRole(chrome_role);
if (role_value != ui::AX_ROLE_NONE) {
out_data->role = role_value;
return;
}
}
std::string class_name;
GetStringProperty(node, arc::mojom::AccessibilityStringProperty::CLASS_NAME,
&class_name);
......@@ -431,6 +491,12 @@ void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node,
else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION,
&text))
out_data->SetName(text);
std::string role_description;
if (GetStringProperty(node, AXStringProperty::ROLE_DESCRIPTION,
&role_description)) {
out_data->AddStringAttribute(ui::AX_ATTR_ROLE_DESCRIPTION,
role_description);
}
// Boolean properties.
PopulateAXState(node, out_data);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 5
// Next MinVersion: 6
module arc.mojom;
......@@ -12,6 +12,9 @@ import "screen_rect.mojom";
// from their equivalents in the Android source. Keep them in the
// order given below and add as needed. The initial order matches the
// order they appear in source files.
//
// If not explicitly called out, the structs and enums below come from:
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html
// AccessibilityEventType lists the possible accessibility events on Android.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html
......@@ -44,8 +47,7 @@ enum AccessibilityEventType {
ASSIST_READING_CONTEXT,
};
// AccessibilityActionType lists possible accessibility actions on Android.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html
// Possible actions that can be performed on an AccessibilityNodeInfo.
[Extensible]
enum AccessibilityActionType {
FOCUS,
......@@ -82,7 +84,6 @@ enum AccessibilityActionType {
};
// Possible boolean properties set on an AccessibilityNodeInfo.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html
// The enum values appear in the same order as they do within
// AccessibilityNodeInfo.java.
[Extensible]
......@@ -116,7 +117,9 @@ enum AccessibilityStringProperty {
CLASS_NAME,
TEXT,
CONTENT_DESCRIPTION,
VIEW_ID_RESOURCE_NAME
VIEW_ID_RESOURCE_NAME,
CHROME_ROLE, // Chrome only
ROLE_DESCRIPTION // Chrome only
};
// These fields are taken from int instance members of
......@@ -142,14 +145,71 @@ enum AccessibilityIntListProperty {
CUSTOM_ACTION_IDS
};
// These fields are taken from List<String> instance members of
// AccessibilityNodeInfo.
[Extensible]
enum AccessibilityStringListProperty {
CUSTOM_ACTION_DESCRIPTIONS
};
// This type is a subset of spans available under android.text.style.
[Extensible]
enum SpanType {
URL,
CLICKABLE
};
// Groups data about a Spannable.
struct SpanEntry {
int32 start;
int32 end;
SpanType span_type;
};
// These fields are taken from AccessibilityNodeInfo.CollectionItemInfo.
[Extensible]
enum AccessibilitySelectionMode {
NONE,
SINGLE,
MULTIPLE
};
// These fields are taken from AccessibilityNodeInfo.CollectionInfo.
struct AccessibilityCollectionInfoData {
int32 row_count;
int32 column_count;
bool is_hierarchical;
AccessibilitySelectionMode selection_mode;
};
// These fields are taken from AccessibilityNodeInfo.CollectionItemInfo.
struct AccessibilityCollectionItemInfoData {
int32 row_index;
int32 column_index;
int32 row_span;
int32 column_span;
bool is_heading;
bool is_selected;
};
// These fields are taken from AccessibilityNodeInfo.RangeInfo.
[Extensible]
enum AccessibilityRangeType {
INT,
FLOAT,
PERCENT
};
// These fields are taken from AccessibilityNodeInfo.RangeInfo.
struct AccessibilityRangeInfoData {
AccessibilityRangeType range_type;
float min;
float max;
float current;
};
// AccessibilityNodeInfoData is a struct to contain info of
// AccessibilityNodeInfo in Android.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html
struct AccessibilityNodeInfoData {
ScreenRect bounds_in_screen;
[MinVersion=1]int32 id;
......@@ -160,6 +220,11 @@ struct AccessibilityNodeInfoData {
map<AccessibilityIntListProperty, array<int32>>? int_list_properties;
[MinVersion=3]map<AccessibilityStringListProperty, array<string>>?
string_list_properties;
[MinVersion=5]map<AccessibilityStringProperty, array<SpanEntry>>?
spannable_string_properties;
[MinVersion=5]AccessibilityCollectionInfoData? collection_info;
[MinVersion=5]AccessibilityCollectionItemInfoData? collection_item_info;
[MinVersion=5]AccessibilityRangeInfoData? range_info;
};
// Filters the event type (and implicitly the data) sent by the ARC
......
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