Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/browser/accessibility/browser_accessibility_android.cc

Issue 639773012: On Android, unlabeled link containing image should use image url as name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@link_visible_text
Patch Set: Rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/accessibility/browser_accessibility_android.h" 5 #include "content/browser/accessibility/browser_accessibility_android.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/accessibility/browser_accessibility_manager_android.h" 8 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
9 #include "content/common/accessibility_messages.h" 9 #include "content/common/accessibility_messages.h"
10 10
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 text = help; 320 text = help;
321 else if (!name().empty()) 321 else if (!name().empty())
322 text = base::UTF8ToUTF16(name()); 322 text = base::UTF8ToUTF16(name());
323 else if (GetRole() == ui::AX_ROLE_TEXT_FIELD && !placeholder.empty()) 323 else if (GetRole() == ui::AX_ROLE_TEXT_FIELD && !placeholder.empty())
324 text = placeholder; 324 text = placeholder;
325 else if (!value().empty()) 325 else if (!value().empty())
326 text = base::UTF8ToUTF16(value()); 326 text = base::UTF8ToUTF16(value());
327 327
328 // This is called from PlatformIsLeaf, so don't call PlatformChildCount 328 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
329 // from within this! 329 // from within this!
330 if (text.empty() && HasOnlyStaticTextChildren()) { 330 if (text.empty() &&
331 (HasOnlyStaticTextChildren() ||
332 (IsFocusable() && HasOnlyTextAndImageChildren()))) {
331 for (uint32 i = 0; i < InternalChildCount(); i++) { 333 for (uint32 i = 0; i < InternalChildCount(); i++) {
332 BrowserAccessibility* child = InternalGetChild(i); 334 BrowserAccessibility* child = InternalGetChild(i);
333 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); 335 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText();
334 } 336 }
335 } 337 }
336 338
337 if (text.empty() && IsLink()) { 339 if (text.empty() && (IsLink() || GetRole() == ui::AX_ROLE_IMAGE)) {
338 base::string16 url = GetString16Attribute(ui::AX_ATTR_URL); 340 base::string16 url = GetString16Attribute(ui::AX_ATTR_URL);
339 // Given a url like http://foo.com/bar/baz.png, just return the 341 // Given a url like http://foo.com/bar/baz.png, just return the
340 // base name, e.g., "baz". 342 // base name, e.g., "baz".
341 int trailing_slashes = 0; 343 int trailing_slashes = 0;
342 while (url.size() - trailing_slashes > 0 && 344 while (url.size() - trailing_slashes > 0 &&
343 url[url.size() - trailing_slashes - 1] == '/') { 345 url[url.size() - trailing_slashes - 1] == '/') {
344 trailing_slashes++; 346 trailing_slashes++;
345 } 347 }
346 if (trailing_slashes) 348 if (trailing_slashes)
347 url = url.substr(0, url.size() - trailing_slashes); 349 url = url.substr(0, url.size() - trailing_slashes);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // This is called from PlatformIsLeaf, so don't call PlatformChildCount 616 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
615 // from within this! 617 // from within this!
616 for (uint32 i = 0; i < InternalChildCount(); i++) { 618 for (uint32 i = 0; i < InternalChildCount(); i++) {
617 BrowserAccessibility* child = InternalGetChild(i); 619 BrowserAccessibility* child = InternalGetChild(i);
618 if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT) 620 if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT)
619 return false; 621 return false;
620 } 622 }
621 return true; 623 return true;
622 } 624 }
623 625
626 bool BrowserAccessibilityAndroid::HasOnlyTextAndImageChildren() const {
627 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
628 // from within this!
629 for (uint32 i = 0; i < InternalChildCount(); i++) {
630 BrowserAccessibility* child = InternalGetChild(i);
631 if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT &&
632 child->GetRole() != ui::AX_ROLE_IMAGE) {
633 return false;
634 }
635 }
636 return true;
637 }
638
624 bool BrowserAccessibilityAndroid::IsIframe() const { 639 bool BrowserAccessibilityAndroid::IsIframe() const {
625 base::string16 html_tag = GetString16Attribute( 640 base::string16 html_tag = GetString16Attribute(
626 ui::AX_ATTR_HTML_TAG); 641 ui::AX_ATTR_HTML_TAG);
627 return html_tag == base::ASCIIToUTF16("iframe"); 642 return html_tag == base::ASCIIToUTF16("iframe");
628 } 643 }
629 644
630 void BrowserAccessibilityAndroid::OnDataChanged() { 645 void BrowserAccessibilityAndroid::OnDataChanged() {
631 BrowserAccessibility::OnDataChanged(); 646 BrowserAccessibility::OnDataChanged();
632 647
633 if (IsEditableText()) { 648 if (IsEditableText()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { 683 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const {
669 int count = 0; 684 int count = 0;
670 for (uint32 i = 0; i < PlatformChildCount(); i++) { 685 for (uint32 i = 0; i < PlatformChildCount(); i++) {
671 if (PlatformGetChild(i)->GetRole() == role) 686 if (PlatformGetChild(i)->GetRole() == role)
672 count++; 687 count++;
673 } 688 }
674 return count; 689 return count;
675 } 690 }
676 691
677 } // namespace content 692 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility_android.h ('k') | content/test/data/accessibility/a-no-text.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698