Android native accessibility: Decorate link nodes with URLSpans.

This makes talkback recognize the accessibility node as containing a link.

R=dmazzoni@chromium.org
BUG=348184

Review URL: https://codereview.chromium.org/184553009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255854 0039d316-1c4b-4281-b951-d872f2087c98
parent 7f256e09
...@@ -164,6 +164,10 @@ bool BrowserAccessibilityAndroid::IsHierarchical() const { ...@@ -164,6 +164,10 @@ bool BrowserAccessibilityAndroid::IsHierarchical() const {
role() == ui::AX_ROLE_TREE); role() == ui::AX_ROLE_TREE);
} }
bool BrowserAccessibilityAndroid::IsLink() const {
return role() == ui::AX_ROLE_LINK || role() == ui::AX_ROLE_IMAGE_MAP_LINK;
}
bool BrowserAccessibilityAndroid::IsMultiLine() const { bool BrowserAccessibilityAndroid::IsMultiLine() const {
return role() == ui::AX_ROLE_TEXT_AREA; return role() == ui::AX_ROLE_TEXT_AREA;
} }
...@@ -280,12 +284,6 @@ base::string16 BrowserAccessibilityAndroid::GetText() const { ...@@ -280,12 +284,6 @@ base::string16 BrowserAccessibilityAndroid::GetText() const {
} }
switch(role()) { switch(role()) {
case ui::AX_ROLE_IMAGE_MAP_LINK:
case ui::AX_ROLE_LINK:
if (!text.empty())
text += base::ASCIIToUTF16(" ");
text += base::ASCIIToUTF16("Link");
break;
case ui::AX_ROLE_HEADING: case ui::AX_ROLE_HEADING:
// Only append "heading" if this node already has text. // Only append "heading" if this node already has text.
if (!text.empty()) if (!text.empty())
......
...@@ -30,6 +30,7 @@ class BrowserAccessibilityAndroid : public BrowserAccessibility { ...@@ -30,6 +30,7 @@ class BrowserAccessibilityAndroid : public BrowserAccessibility {
bool IsFocused() const; bool IsFocused() const;
bool IsHeading() const; bool IsHeading() const;
bool IsHierarchical() const; bool IsHierarchical() const;
bool IsLink() const;
bool IsMultiLine() const; bool IsMultiLine() const;
bool IsPassword() const; bool IsPassword() const;
bool IsRangeType() const; bool IsRangeType() const;
......
...@@ -222,10 +222,13 @@ jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityNodeInfo( ...@@ -222,10 +222,13 @@ jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityNodeInfo(
node->IsScrollable(), node->IsScrollable(),
node->IsSelected(), node->IsSelected(),
node->IsVisibleToUser()); node->IsVisibleToUser());
Java_BrowserAccessibilityManager_setAccessibilityNodeInfoStringAttributes( Java_BrowserAccessibilityManager_setAccessibilityNodeInfoClassName(
env, obj, info, env, obj, info,
base::android::ConvertUTF8ToJavaString(env, node->GetClassName()).obj(), base::android::ConvertUTF8ToJavaString(env, node->GetClassName()).obj());
base::android::ConvertUTF16ToJavaString(env, node->GetText()).obj()); Java_BrowserAccessibilityManager_setAccessibilityNodeInfoContentDescription(
env, obj, info,
base::android::ConvertUTF16ToJavaString(env, node->GetText()).obj(),
node->IsLink());
gfx::Rect absolute_rect = node->GetLocalBoundsRect(); gfx::Rect absolute_rect = node->GetLocalBoundsRect();
gfx::Rect parent_relative_rect = absolute_rect; gfx::Rect parent_relative_rect = absolute_rect;
......
...@@ -8,6 +8,8 @@ import android.content.Context; ...@@ -8,6 +8,8 @@ import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.URLSpan;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewParent; import android.view.ViewParent;
...@@ -447,11 +449,22 @@ public class BrowserAccessibilityManager { ...@@ -447,11 +449,22 @@ public class BrowserAccessibilityManager {
} }
@CalledByNative @CalledByNative
private void setAccessibilityNodeInfoStringAttributes(AccessibilityNodeInfo node, private void setAccessibilityNodeInfoClassName(AccessibilityNodeInfo node,
String className, String contentDescription) { String className) {
node.setClassName(className); node.setClassName(className);
}
@CalledByNative
private void setAccessibilityNodeInfoContentDescription(
AccessibilityNodeInfo node, String contentDescription, boolean annotateAsLink) {
if (annotateAsLink) {
SpannableString spannable = new SpannableString(contentDescription);
spannable.setSpan(new URLSpan(""), 0, spannable.length(), 0);
node.setContentDescription(spannable);
} else {
node.setContentDescription(contentDescription); node.setContentDescription(contentDescription);
} }
}
@CalledByNative @CalledByNative
private void setAccessibilityNodeInfoLocation(AccessibilityNodeInfo node, private void setAccessibilityNodeInfoLocation(AccessibilityNodeInfo node,
......
android.view.View focusable focused scrollable android.view.View focusable focused scrollable
android.view.View android.view.View
android.view.View clickable focusable name='normal link Link' android.view.View clickable focusable name='normal link'
android.view.View focusable focused scrollable android.view.View focusable focused scrollable
android.view.View clickable name='named anchor' android.view.View clickable name='named anchor'
android.view.View clickable focusable name='both a named anchor and a link Link' android.view.View clickable focusable name='both a named anchor and a link'
android.view.View focusable focused scrollable android.view.View focusable focused scrollable
android.view.View clickable name='link with no href but onclick Link' android.view.View clickable name='link with no href but onclick'
android.view.View clickable name='link with no href and click handler added via script Link' android.view.View clickable name='link with no href and click handler added via script'
android.view.View focusable focused scrollable android.view.View focusable focused scrollable
android.view.View android.view.View
android.view.View clickable focusable name='Linkwith image at start. Link' android.view.View clickable focusable name='Linkwith image at start.'
android.view.View clickable focusable name='Link withimagein the middle. Link' android.view.View clickable focusable name='Link withimagein the middle.'
android.view.View clickable focusable name='Link withbrokenin the middle. Link' android.view.View clickable focusable name='Link withbrokenin the middle.'
android.view.View clickable focusable name='Link with image at theend Link' android.view.View clickable focusable name='Link with image at theend'
...@@ -2,4 +2,4 @@ android.view.View focusable focused scrollable ...@@ -2,4 +2,4 @@ android.view.View focusable focused scrollable
android.view.View android.view.View
android.widget.Image clickable name='Image' android.widget.Image clickable name='Image'
android.view.View android.view.View
android.view.View clickable focusable name='Interactive fallback Link' android.view.View clickable focusable name='Interactive fallback'
...@@ -2,7 +2,7 @@ android.view.View focusable focused scrollable ...@@ -2,7 +2,7 @@ android.view.View focusable focused scrollable
android.view.View editable_text focusable android.view.View editable_text focusable
android.view.View editable_text android.view.View editable_text
android.view.View clickable editable_text name='Contentditable with' android.view.View clickable editable_text name='Contentditable with'
android.view.View clickable editable_text name='link Link' android.view.View clickable editable_text name='link'
android.view.View clickable editable_text name='and' android.view.View clickable editable_text name='and'
android.widget.Image clickable editable_text name='image' android.widget.Image clickable editable_text name='image'
android.view.View clickable editable_text name='and' android.view.View clickable editable_text name='and'
......
android.view.View focusable scrollable android.view.View focusable scrollable
android.app.Dialog android.app.Dialog
android.view.View clickable name='The dialog subtree should be the only text content in the accessibility tree. ' android.view.View clickable name='The dialog subtree should be the only text content in the accessibility tree. '
android.view.View clickable focusable focused name='Link inside the dialog. Link' android.view.View clickable focusable focused name='Link inside the dialog.'
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