Commit 9526014c authored by dmazzoni's avatar dmazzoni Committed by Commit bot

On Android, unlabeled link containing image should use image url as name.

This is just a heuristic to handle a situation where neither the link or
image are labeled. Since we can only export a single name attribute on
Android - unlike other systems where we export several fields and let the
assistive technology decide - this tries to do the sensible thing when
there's a link containing an image.

BUG=386623

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

Cr-Commit-Position: refs/heads/master@{#301390}
parent 82992f77
...@@ -327,14 +327,16 @@ base::string16 BrowserAccessibilityAndroid::GetText() const { ...@@ -327,14 +327,16 @@ base::string16 BrowserAccessibilityAndroid::GetText() const {
// This is called from PlatformIsLeaf, so don't call PlatformChildCount // This is called from PlatformIsLeaf, so don't call PlatformChildCount
// from within this! // from within this!
if (text.empty() && HasOnlyStaticTextChildren()) { if (text.empty() &&
(HasOnlyStaticTextChildren() ||
(IsFocusable() && HasOnlyTextAndImageChildren()))) {
for (uint32 i = 0; i < InternalChildCount(); i++) { for (uint32 i = 0; i < InternalChildCount(); i++) {
BrowserAccessibility* child = InternalGetChild(i); BrowserAccessibility* child = InternalGetChild(i);
text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText();
} }
} }
if (text.empty() && IsLink()) { if (text.empty() && (IsLink() || GetRole() == ui::AX_ROLE_IMAGE)) {
base::string16 url = GetString16Attribute(ui::AX_ATTR_URL); base::string16 url = GetString16Attribute(ui::AX_ATTR_URL);
// Given a url like http://foo.com/bar/baz.png, just return the // Given a url like http://foo.com/bar/baz.png, just return the
// base name, e.g., "baz". // base name, e.g., "baz".
...@@ -621,6 +623,19 @@ bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { ...@@ -621,6 +623,19 @@ bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const {
return true; return true;
} }
bool BrowserAccessibilityAndroid::HasOnlyTextAndImageChildren() const {
// This is called from PlatformIsLeaf, so don't call PlatformChildCount
// from within this!
for (uint32 i = 0; i < InternalChildCount(); i++) {
BrowserAccessibility* child = InternalGetChild(i);
if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT &&
child->GetRole() != ui::AX_ROLE_IMAGE) {
return false;
}
}
return true;
}
bool BrowserAccessibilityAndroid::IsIframe() const { bool BrowserAccessibilityAndroid::IsIframe() const {
base::string16 html_tag = GetString16Attribute( base::string16 html_tag = GetString16Attribute(
ui::AX_ATTR_HTML_TAG); ui::AX_ATTR_HTML_TAG);
......
...@@ -86,6 +86,7 @@ class BrowserAccessibilityAndroid : public BrowserAccessibility { ...@@ -86,6 +86,7 @@ class BrowserAccessibilityAndroid : public BrowserAccessibility {
BrowserAccessibilityAndroid(); BrowserAccessibilityAndroid();
bool HasOnlyStaticTextChildren() const; bool HasOnlyStaticTextChildren() const;
bool HasOnlyTextAndImageChildren() const;
bool IsIframe() const; bool IsIframe() const;
void NotifyLiveRegionUpdate(base::string16& aria_live); void NotifyLiveRegionUpdate(base::string16& aria_live);
......
...@@ -8,3 +8,5 @@ android.webkit.WebView focusable focused scrollable ...@@ -8,3 +8,5 @@ android.webkit.WebView focusable focused scrollable
android.view.View clickable focusable name='dest6' android.view.View clickable focusable name='dest6'
android.view.View clickable focusable name='dest7' android.view.View clickable focusable name='dest7'
android.view.View clickable focusable name='dest.8' android.view.View clickable focusable name='dest.8'
android.view.View clickable focusable name='greenbox'
android.view.View clickable focusable name='greenbox'
...@@ -11,5 +11,7 @@ ...@@ -11,5 +11,7 @@
<a href="dest6.html"><img src="#"> </a> <a href="dest6.html"><img src="#"> </a>
<a href="http://example.com/dest7.html"><img src="#"> </a> <a href="http://example.com/dest7.html"><img src="#"> </a>
<a href="http://example.com/dest.8.html"><img src="#"> </a> <a href="http://example.com/dest.8.html"><img src="#"> </a>
<a href="dest9.html"><img src="greenbox.png"></a>
<a href="dest10.html"><img src="greenbox.png"> </a>
</body> </body>
</html> </html>
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