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

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

Issue 2120523002: The children of non-editable combo boxes, search boxes and text fields should not be hidden (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Windows browser test. Created 4 years, 5 months 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/i18n/break_iterator.h" 7 #include "base/i18n/break_iterator.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // Headings with text can drop their children. 118 // Headings with text can drop their children.
119 base::string16 name = GetText(); 119 base::string16 name = GetText();
120 if (GetRole() == ui::AX_ROLE_HEADING && !name.empty()) 120 if (GetRole() == ui::AX_ROLE_HEADING && !name.empty())
121 return true; 121 return true;
122 122
123 // Focusable nodes with text can drop their children. 123 // Focusable nodes with text can drop their children.
124 if (HasState(ui::AX_STATE_FOCUSABLE) && !name.empty()) 124 if (HasState(ui::AX_STATE_FOCUSABLE) && !name.empty())
125 return true; 125 return true;
126 126
127 // Nodes with only static text as children can drop their children. 127 // Nodes with only static text as children can drop their children.
128 if (HasOnlyStaticTextChildren()) 128 if (HasOnlyTextChildren())
129 return true; 129 return true;
130 } 130 }
131 131
132 return false; 132 return false;
133 } 133 }
134 134
135 bool BrowserAccessibilityAndroid::IsCheckable() const { 135 bool BrowserAccessibilityAndroid::IsCheckable() const {
136 bool checkable = false; 136 bool checkable = false;
137 bool is_aria_pressed_defined; 137 bool is_aria_pressed_defined;
138 bool is_mixed; 138 bool is_mixed;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 352 }
353 353
354 // In accordance with ARIA, some elements use their contents as an 354 // In accordance with ARIA, some elements use their contents as an
355 // accessibility name, so some elements will have the same name as their 355 // accessibility name, so some elements will have the same name as their
356 // child. While most platforms expect this, it causes Android to speak the 356 // child. While most platforms expect this, it causes Android to speak the
357 // name twice. So in this case we should remove the name from the parent. 357 // name twice. So in this case we should remove the name from the parent.
358 if (GetRole() == ui::AX_ROLE_LIST_ITEM && 358 if (GetRole() == ui::AX_ROLE_LIST_ITEM &&
359 GetIntAttribute(ui::AX_ATTR_NAME_FROM) == ui::AX_NAME_FROM_CONTENTS) { 359 GetIntAttribute(ui::AX_ATTR_NAME_FROM) == ui::AX_NAME_FROM_CONTENTS) {
360 // This is an approximation of "PlatformChildCount() > 0" because we can't 360 // This is an approximation of "PlatformChildCount() > 0" because we can't
361 // call PlatformChildCount from here. 361 // call PlatformChildCount from here.
362 if (InternalChildCount() > 0 && !HasOnlyStaticTextChildren()) 362 if (InternalChildCount() > 0 && !HasOnlyTextChildren())
363 return base::string16(); 363 return base::string16();
364 } 364 }
365 365
366 // We can only expose one accessible name on Android, 366 // We can only expose one accessible name on Android,
367 // not 2 or 3 like on Windows or Mac. 367 // not 2 or 3 like on Windows or Mac.
368 368
369 // First, always return the |value| attribute if this is an 369 // First, always return the |value| attribute if this is an
370 // input field. 370 // input field.
371 base::string16 value = GetValue(); 371 base::string16 value = GetValue();
372 if (!value.empty()) { 372 if (!value.empty()) {
(...skipping 26 matching lines...) Expand all
399 if (!text.empty()) 399 if (!text.empty())
400 text += base::ASCIIToUTF16(" "); 400 text += base::ASCIIToUTF16(" ");
401 text += description; 401 text += description;
402 } 402 }
403 403
404 if (text.empty()) 404 if (text.empty())
405 text = value; 405 text = value;
406 406
407 // This is called from PlatformIsLeaf, so don't call PlatformChildCount 407 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
408 // from within this! 408 // from within this!
409 if (text.empty() && 409 if (text.empty() && (HasOnlyTextChildren() ||
410 (HasOnlyStaticTextChildren() || 410 (IsFocusable() && HasOnlyTextAndImageChildren()))) {
411 (IsFocusable() && HasOnlyTextAndImageChildren()))) {
412 for (uint32_t i = 0; i < InternalChildCount(); i++) { 411 for (uint32_t i = 0; i < InternalChildCount(); i++) {
413 BrowserAccessibility* child = InternalGetChild(i); 412 BrowserAccessibility* child = InternalGetChild(i);
414 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); 413 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText();
415 } 414 }
416 } 415 }
417 416
418 if (text.empty() && (IsLink() || GetRole() == ui::AX_ROLE_IMAGE)) { 417 if (text.empty() && (IsLink() || GetRole() == ui::AX_ROLE_IMAGE)) {
419 base::string16 url = GetString16Attribute(ui::AX_ATTR_URL); 418 base::string16 url = GetString16Attribute(ui::AX_ATTR_URL);
420 // Given a url like http://foo.com/bar/baz.png, just return the 419 // Given a url like http://foo.com/bar/baz.png, just return the
421 // base text, e.g., "baz". 420 // base text, e.g., "baz".
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 for (uint32_t i = 0; i < InternalChildCount(); i++) { 1328 for (uint32_t i = 0; i < InternalChildCount(); i++) {
1330 BrowserAccessibility* child = InternalGetChild(i); 1329 BrowserAccessibility* child = InternalGetChild(i);
1331 if (child->HasState(ui::AX_STATE_FOCUSABLE)) 1330 if (child->HasState(ui::AX_STATE_FOCUSABLE))
1332 return true; 1331 return true;
1333 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) 1332 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild())
1334 return true; 1333 return true;
1335 } 1334 }
1336 return false; 1335 return false;
1337 } 1336 }
1338 1337
1339 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { 1338 bool BrowserAccessibilityAndroid::HasOnlyTextChildren() const {
1340 // This is called from PlatformIsLeaf, so don't call PlatformChildCount 1339 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
1341 // from within this! 1340 // from within this!
1342 for (uint32_t i = 0; i < InternalChildCount(); i++) { 1341 for (uint32_t i = 0; i < InternalChildCount(); i++) {
1343 BrowserAccessibility* child = InternalGetChild(i); 1342 BrowserAccessibility* child = InternalGetChild(i);
1344 if (child->GetRole() != ui::AX_ROLE_STATIC_TEXT) 1343 if (!child->IsTextOnlyObject())
1345 return false; 1344 return false;
1346 } 1345 }
1347 return true; 1346 return true;
1348 } 1347 }
1349 1348
1350 bool BrowserAccessibilityAndroid::HasOnlyTextAndImageChildren() const { 1349 bool BrowserAccessibilityAndroid::HasOnlyTextAndImageChildren() const {
1351 // This is called from PlatformIsLeaf, so don't call PlatformChildCount 1350 // This is called from PlatformIsLeaf, so don't call PlatformChildCount
1352 // from within this! 1351 // from within this!
1353 for (uint32_t i = 0; i < InternalChildCount(); i++) { 1352 for (uint32_t i = 0; i < InternalChildCount(); i++) {
1354 BrowserAccessibility* child = InternalGetChild(i); 1353 BrowserAccessibility* child = InternalGetChild(i);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { 1412 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const {
1414 int count = 0; 1413 int count = 0;
1415 for (uint32_t i = 0; i < PlatformChildCount(); i++) { 1414 for (uint32_t i = 0; i < PlatformChildCount(); i++) {
1416 if (PlatformGetChild(i)->GetRole() == role) 1415 if (PlatformGetChild(i)->GetRole() == role)
1417 count++; 1416 count++;
1418 } 1417 }
1419 return count; 1418 return count;
1420 } 1419 }
1421 1420
1422 } // namespace content 1421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698