Commit 375fd5fe authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Android: Talkback fix nesting level for single-level lists

Talkback would previously report nesting level for single-level lists,
which was considered unnecessary. Added functionality in the
IsHierarchical() method to determine if a list contains other lists,
or if it is contained within a list, to help determine if it is
hierarchical. Also modified DumpAccessibilityTree test expected output
files to check for new desired behavior.


R=dmazzoni@chromium.org

Bug: 591255
Change-Id: Idd995c5fae426b191825996cf02ee51bd6753607
Reviewed-on: https://chromium-review.googlesource.com/c/1300076
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603624}
parent 5674301c
...@@ -51,6 +51,53 @@ enum { ...@@ -51,6 +51,53 @@ enum {
ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT = 1 ANDROID_VIEW_ACCESSIBILITY_RANGE_TYPE_FLOAT = 1
}; };
static bool HasListAncestor(const content::BrowserAccessibility* node) {
if (node == nullptr)
return false; // Base case
if (ui::IsStaticList(node->GetRole()))
return true;
return HasListAncestor(node->InternalGetParent());
}
static bool HasListDescendant(const content::BrowserAccessibility* current,
const content::BrowserAccessibility* root) {
// Only check role of descendants
if (current != root) {
if (ui::IsStaticList(current->GetRole()))
return true;
}
int num_children = current->InternalChildCount();
for (int i = 0; i < num_children; ++i) {
if (HasListDescendant(current->InternalGetChild(i), root))
return true;
}
return false;
}
/*
Determines:
1. If this is an ancestor of any lists
2. If this list is a descendant of any lists
Talkback uses this information to report if the list has levels, and if so,
which level is currently selected
*/
static bool IsHierarchicalList(const content::BrowserAccessibility* node) {
// Only makes sense to run if |node| is already a list
DCHECK(ui::IsStaticList(node->GetRole()));
if (node == nullptr)
return false;
bool found_list_in_descendants = HasListDescendant(node, node);
bool found_list_in_ancestors = HasListAncestor(node->InternalGetParent());
return (found_list_in_descendants || found_list_in_ancestors);
}
} // namespace } // namespace
namespace content { namespace content {
...@@ -256,9 +303,8 @@ bool BrowserAccessibilityAndroid::IsHeading() const { ...@@ -256,9 +303,8 @@ bool BrowserAccessibilityAndroid::IsHeading() const {
} }
bool BrowserAccessibilityAndroid::IsHierarchical() const { bool BrowserAccessibilityAndroid::IsHierarchical() const {
return (GetRole() == ax::mojom::Role::kList || return (GetRole() == ax::mojom::Role::kTree ||
GetRole() == ax::mojom::Role::kDescriptionList || (ui::IsStaticList(GetRole()) && IsHierarchicalList(this)));
GetRole() == ax::mojom::Role::kTree);
} }
bool BrowserAccessibilityAndroid::IsLink() const { bool BrowserAccessibilityAndroid::IsLink() const {
......
...@@ -1874,6 +1874,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, ...@@ -1874,6 +1874,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
RunHtmlTest(FILE_PATH_LITERAL("label-with-presentational-child.html")); RunHtmlTest(FILE_PATH_LITERAL("label-with-presentational-child.html"));
} }
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityNestedList) {
RunHtmlTest(FILE_PATH_LITERAL("nestedlist.html"));
}
// //
// Regression tests. These don't test a specific web platform feature, // Regression tests. These don't test a specific web platform feature,
// they test a specific web page that crashed or had some bad behavior // they test a specific web page that crashed or had some bad behavior
......
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical ++android.widget.ListView collection
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=7 row_count=7 ++android.widget.ListView collection item_count=7 row_count=7
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='copy' ++++++android.view.View name='copy'
...@@ -20,4 +20,4 @@ android.webkit.WebView focusable focused scrollable ...@@ -20,4 +20,4 @@ android.webkit.WebView focusable focused scrollable
++++++android.view.View name='none(default)' ++++++android.view.View name='none(default)'
++++android.view.View collection_item item_index=6 row_index=6 ++++android.view.View collection_item item_index=6 row_index=6
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='link' ++++++android.view.View name='link'
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='grabbed-true ' ++++++android.view.View name='grabbed-true '
...@@ -11,4 +11,4 @@ android.webkit.WebView focusable focused scrollable ...@@ -11,4 +11,4 @@ android.webkit.WebView focusable focused scrollable
++++android.view.View collection_item item_index=2 row_index=2 ++++android.view.View collection_item item_index=2 row_index=2
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='grabbed-undefined ' ++++++android.view.View name='grabbed-undefined '
++++++android.widget.Image role_description='graphic' name='blue' ++++++android.widget.Image role_description='graphic' name='blue'
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item name='1' ++++android.view.View collection_item name='1'
++++android.view.View collection_item name='2' item_index=1 row_index=1 ++++android.view.View collection_item name='2' item_index=1 row_index=1
++++android.view.View collection_item name='3' item_index=2 row_index=2 ++++android.view.View collection_item name='3' item_index=2 row_index=2
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=2 row_count=2 ++android.widget.ListView collection item_count=2 row_count=2
++++android.view.View collection_item name='1' ++++android.view.View collection_item name='1'
++++android.view.View collection_item name='2' item_index=1 row_index=1 ++++android.view.View collection_item name='2' item_index=1 row_index=1
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=2 row_count=2 ++android.widget.ListView collection item_count=2 row_count=2
++++android.view.View collection_item name='Coffee' ++++android.view.View collection_item name='Coffee'
++++android.view.View role_description='definition' name='Black hot drink' ++++android.view.View role_description='definition' name='Black hot drink'
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=2 row_count=2 ++android.widget.ListView collection item_count=2 row_count=2
++++android.view.View collection_item name='Term' ++++android.view.View collection_item name='Term'
++++android.view.View role_description='definition' name='Description' ++++android.view.View role_description='definition' name='Description'
++android.view.View role_description='definition' name='Definition' ++android.view.View role_description='definition' name='Definition'
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=2 row_count=2 ++android.widget.ListView collection item_count=2 row_count=2
++++android.view.View collection_item name='Coffee' ++++android.view.View collection_item name='Coffee'
++++android.view.View role_description='definition' name='Black hot drink' ++++android.view.View role_description='definition' name='Black hot drink'
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='Item 1' ++++++android.view.View name='Item 1'
......
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='tic' ++++++android.view.View name='tic'
...@@ -9,7 +9,7 @@ android.webkit.WebView focusable focused scrollable ...@@ -9,7 +9,7 @@ android.webkit.WebView focusable focused scrollable
++++android.view.View collection_item item_index=2 row_index=2 ++++android.view.View collection_item item_index=2 row_index=2
++++++android.view.View name='• ' ++++++android.view.View name='• '
++++++android.view.View name='toe' ++++++android.view.View name='toe'
++android.widget.ListView collection hierarchical item_count=5 row_count=5 ++android.widget.ListView collection item_count=5 row_count=5
++++android.view.View collection_item name='tic' ++++android.view.View collection_item name='tic'
++++android.view.View name=' ' ++++android.view.View name=' '
++++android.view.View collection_item name='tac' item_index=1 row_index=2 ++++android.view.View collection_item name='tac' item_index=1 row_index=2
......
android.webkit.WebView focusable focused scrollable
++android.view.View name='This is a multi-leveled list'
++android.widget.ListView collection hierarchical item_count=4 row_count=4
++++android.view.View collection_item
++++++android.view.View name='1. '
++++++android.view.View name='Sports'
++++++android.widget.ListView collection hierarchical item_count=2 row_count=2
++++++++android.view.View collection_item
++++++++++android.view.View name='1. '
++++++++++android.view.View name='Tennis'
++++++++android.view.View collection_item item_index=1 row_index=1
++++++++++android.view.View name='2. '
++++++++++android.view.View name='basketball'
++++android.view.View collection_item item_index=1 row_index=1
++++++android.view.View name='2. '
++++++android.view.View name='Books'
++++++android.widget.ListView collection hierarchical item_count=3 row_count=3
++++++++android.view.View collection_item
++++++++++android.view.View name='1. '
++++++++++android.view.View name='Oliver Twist'
++++++++android.view.View collection_item item_index=1 row_index=1
++++++++++android.view.View name='2. '
++++++++++android.view.View name='Kindred'
++++++++android.view.View collection_item item_index=2 row_index=2
++++++++++android.view.View name='3. '
++++++++++android.view.View name='The Promise of Sleep'
++++android.view.View collection_item item_index=2 row_index=2
++++++android.view.View name='3. '
++++++android.view.View name='Recipes'
++++android.widget.ListView collection hierarchical
<p> This is a multi-leveled list </p>
<ol>
<li> Sports
<ol>
<li> Tennis </li>
<li> basketball </li>
</ol>
</li>
<li> Books
<ol>
<li> Oliver Twist </li>
<li> Kindred </li>
<li> The Promise of Sleep </li>
</ol>
</li>
<li> Recipes </li>
<ol>
</ol>
</ol>
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='1. ' ++++++android.view.View name='1. '
++++++android.view.View name='Chrome' ++++++android.view.View name='Chrome'
...@@ -9,7 +9,7 @@ android.webkit.WebView focusable focused scrollable ...@@ -9,7 +9,7 @@ android.webkit.WebView focusable focused scrollable
++++android.view.View collection_item item_index=2 row_index=2 ++++android.view.View collection_item item_index=2 row_index=2
++++++android.view.View name='3. ' ++++++android.view.View name='3. '
++++++android.view.View name='IE' ++++++android.view.View name='IE'
++android.widget.ListView collection hierarchical item_count=3 row_count=3 ++android.widget.ListView collection item_count=3 row_count=3
++++android.view.View collection_item ++++android.view.View collection_item
++++++android.view.View name='10. ' ++++++android.view.View name='10. '
++++++android.view.View name='Android' ++++++android.view.View name='Android'
......
...@@ -333,4 +333,14 @@ bool IsUIASelectable(const ax::mojom::Role role) { ...@@ -333,4 +333,14 @@ bool IsUIASelectable(const ax::mojom::Role role) {
} }
} }
bool IsStaticList(const ax::mojom::Role role) {
switch (role) {
case ax::mojom::Role::kList:
case ax::mojom::Role::kDescriptionList:
return true;
default:
return false;
}
}
} // namespace ui } // namespace ui
...@@ -83,6 +83,8 @@ AX_EXPORT bool SupportsToggle(const ax::mojom::Role role); ...@@ -83,6 +83,8 @@ AX_EXPORT bool SupportsToggle(const ax::mojom::Role role);
// Automation. // Automation.
AX_EXPORT bool IsUIASelectable(const ax::mojom::Role role); AX_EXPORT bool IsUIASelectable(const ax::mojom::Role role);
AX_EXPORT bool IsStaticList(const ax::mojom::Role role);
} // namespace ui } // namespace ui
#endif // UI_ACCESSIBILITY_AX_ROLE_PROPERTIES_H_ #endif // UI_ACCESSIBILITY_AX_ROLE_PROPERTIES_H_
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