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. | |
281 base::string16 description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); | 271 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); | |
285 base::string16 text; | 272 base::string16 text; |
286 if (!description.empty()) | 273 if (!name().empty()) |
| 274 text = base::UTF8ToUTF16(name()); |
| 275 else if (!description.empty()) |
287 text = description; | 276 text = description; |
288 else if (title_elem_id && !name().empty()) | |
289 text = base::UTF8ToUTF16(name()); | |
290 else if (!help.empty()) | |
291 text = help; | |
292 else if (!name().empty()) | |
293 text = base::UTF8ToUTF16(name()); | |
294 else if (!value().empty()) | 277 else if (!value().empty()) |
295 text = base::UTF8ToUTF16(value()); | 278 text = base::UTF8ToUTF16(value()); |
296 | 279 |
297 // This is called from PlatformIsLeaf, so don't call PlatformChildCount | 280 // This is called from PlatformIsLeaf, so don't call PlatformChildCount |
298 // from within this! | 281 // from within this! |
299 if (text.empty() && HasOnlyStaticTextChildren()) { | 282 if (text.empty() && HasOnlyStaticTextChildren()) { |
300 for (uint32 i = 0; i < InternalChildCount(); i++) { | 283 for (uint32 i = 0; i < InternalChildCount(); i++) { |
301 BrowserAccessibility* child = InternalGetChild(i); | 284 BrowserAccessibility* child = InternalGetChild(i); |
302 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); | 285 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); |
303 } | 286 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { | 626 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { |
644 int count = 0; | 627 int count = 0; |
645 for (uint32 i = 0; i < PlatformChildCount(); i++) { | 628 for (uint32 i = 0; i < PlatformChildCount(); i++) { |
646 if (PlatformGetChild(i)->GetRole() == role) | 629 if (PlatformGetChild(i)->GetRole() == role) |
647 count++; | 630 count++; |
648 } | 631 } |
649 return count; | 632 return count; |
650 } | 633 } |
651 | 634 |
652 } // namespace content | 635 } // namespace content |
OLD | NEW |