OLD | NEW |
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 return class_name; | 262 return class_name; |
263 } | 263 } |
264 | 264 |
265 base::string16 BrowserAccessibilityAndroid::GetText() const { | 265 base::string16 BrowserAccessibilityAndroid::GetText() const { |
266 if (IsIframe() || | 266 if (IsIframe() || |
267 GetRole() == ui::AX_ROLE_WEB_AREA) { | 267 GetRole() == ui::AX_ROLE_WEB_AREA) { |
268 return base::string16(); | 268 return base::string16(); |
269 } | 269 } |
270 | 270 |
| 271 // See comment in browser_accessibility_win.cc for details. |
| 272 // The difference here is that we can only expose one accessible |
| 273 // name on Android, not 2 or 3 like on Windows or Mac. |
| 274 // |
| 275 // The basic rule is: prefer description (aria-labelledby or aria-label), |
| 276 // then help (title), then name (inner text), then value (control value). |
| 277 // However, if title_elem_id is set, that means there's a label element |
| 278 // supplying the name and then name takes precedence over help. |
| 279 // TODO(dmazzoni): clean this up by providing more granular labels in |
| 280 // Blink, making the platform-specific mapping to accessible text simpler. |
271 base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); | 281 base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); |
| 282 base::string16 help = GetString16Attribute(ui::AX_ATTR_HELP); |
| 283 int title_elem_id = GetIntAttribute( |
| 284 ui::AX_ATTR_TITLE_UI_ELEMENT); |
272 base::string16 text; | 285 base::string16 text; |
273 if (!name().empty()) | 286 if (!description.empty()) |
| 287 text = description; |
| 288 else if (title_elem_id && !name().empty()) |
274 text = base::UTF8ToUTF16(name()); | 289 text = base::UTF8ToUTF16(name()); |
275 else if (!description.empty()) | 290 else if (!help.empty()) |
276 text = description; | 291 text = help; |
| 292 else if (!name().empty()) |
| 293 text = base::UTF8ToUTF16(name()); |
277 else if (!value().empty()) | 294 else if (!value().empty()) |
278 text = base::UTF8ToUTF16(value()); | 295 text = base::UTF8ToUTF16(value()); |
279 | 296 |
280 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 297 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
281 // from within this! | 298 // from within this! |
282 if (text.empty() && HasOnlyStaticTextChildren()) { | 299 if (text.empty() && HasOnlyStaticTextChildren()) { |
283 for (uint32 i = 0; i < InternalChildCount(); i++) { | 300 for (uint32 i = 0; i < InternalChildCount(); i++) { |
284 BrowserAccessibility* child = InternalGetChild(i); | 301 BrowserAccessibility* child = InternalGetChild(i); |
285 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); | 302 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); |
286 } | 303 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { | 643 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
627 int count = 0; | 644 int count = 0; |
628 for (uint32 i = 0; i < PlatformChildCount(); i++) { | 645 for (uint32 i = 0; i < PlatformChildCount(); i++) { |
629 if (PlatformGetChild(i)->GetRole() == role) | 646 if (PlatformGetChild(i)->GetRole() == role) |
630 count++; | 647 count++; |
631 } | 648 } |
632 return count; | 649 return count; |
633 } | 650 } |
634 | 651 |
635 } // namespace content | 652 } // namespace content |
OLD | NEW |