| 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 base::string16 BrowserAccessibilityAndroid::GetText() const { | 274 base::string16 BrowserAccessibilityAndroid::GetText() const { |
| 275 if (IsIframe() || | 275 if (IsIframe() || |
| 276 GetRole() == ui::AX_ROLE_WEB_AREA) { | 276 GetRole() == ui::AX_ROLE_WEB_AREA) { |
| 277 return base::string16(); | 277 return base::string16(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // See comment in browser_accessibility_win.cc for details. | 280 // See comment in browser_accessibility_win.cc for details. |
| 281 // The difference here is that we can only expose one accessible | 281 // The difference here is that we can only expose one accessible |
| 282 // name on Android, not 2 or 3 like on Windows or Mac. | 282 // name on Android, not 2 or 3 like on Windows or Mac. |
| 283 // | 283 |
| 284 // The basic rule is: prefer description (aria-labelledby or aria-label), | 284 // First, always return the |value| attribute if this is an |
| 285 // then help (title), then name (inner text), then value (control value). | 285 // accessible text. |
| 286 // However, if title_elem_id is set, that means there's a label element | 286 if (!value().empty() && |
| 287 (GetRole() == ui::AX_ROLE_EDITABLE_TEXT || |
| 288 GetRole() == ui::AX_ROLE_TEXT_AREA || |
| 289 GetRole() == ui::AX_ROLE_TEXT_FIELD || |
| 290 HasState(ui::AX_STATE_EDITABLE))) { |
| 291 return base::UTF8ToUTF16(value()); |
| 292 } |
| 293 |
| 294 // If there's no text value, the basic rule is: prefer description |
| 295 // (aria-labelledby or aria-label), then help (title), then name |
| 296 // (inner text), then value (control value). However, if |
| 297 // title_elem_id is set, that means there's a label element |
| 287 // supplying the name and then name takes precedence over help. | 298 // supplying the name and then name takes precedence over help. |
| 288 // TODO(dmazzoni): clean this up by providing more granular labels in | 299 // TODO(dmazzoni): clean this up by providing more granular labels in |
| 289 // Blink, making the platform-specific mapping to accessible text simpler. | 300 // Blink, making the platform-specific mapping to accessible text simpler. |
| 290 base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); | 301 base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); |
| 291 base::string16 help = GetString16Attribute(ui::AX_ATTR_HELP); | 302 base::string16 help = GetString16Attribute(ui::AX_ATTR_HELP); |
| 292 int title_elem_id = GetIntAttribute( | 303 int title_elem_id = GetIntAttribute( |
| 293 ui::AX_ATTR_TITLE_UI_ELEMENT); | 304 ui::AX_ATTR_TITLE_UI_ELEMENT); |
| 294 base::string16 text; | 305 base::string16 text; |
| 295 if (!description.empty()) | 306 if (!description.empty()) |
| 296 text = description; | 307 text = description; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { | 657 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
| 647 int count = 0; | 658 int count = 0; |
| 648 for (uint32 i = 0; i < PlatformChildCount(); i++) { | 659 for (uint32 i = 0; i < PlatformChildCount(); i++) { |
| 649 if (PlatformGetChild(i)->GetRole() == role) | 660 if (PlatformGetChild(i)->GetRole() == role) |
| 650 count++; | 661 count++; |
| 651 } | 662 } |
| 652 return count; | 663 return count; |
| 653 } | 664 } |
| 654 | 665 |
| 655 } // namespace content | 666 } // namespace content |
| OLD | NEW |