OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/accessibility/accessibility_node_serializer.h" | 5 #include "content/renderer/accessibility/accessibility_node_serializer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 WebAXObject parent = child.parentObject(); | 44 WebAXObject parent = child.parentObject(); |
45 while (!parent.isDetached() && parent.accessibilityIsIgnored()) | 45 while (!parent.isDetached() && parent.accessibilityIsIgnored()) |
46 parent = parent.parentObject(); | 46 parent = parent.parentObject(); |
47 return parent.equals(ancestor); | 47 return parent.equals(ancestor); |
48 } | 48 } |
49 | 49 |
50 bool IsTrue(std::string html_value) { | 50 bool IsTrue(std::string html_value) { |
51 return LowerCaseEqualsASCII(html_value, "true"); | 51 return LowerCaseEqualsASCII(html_value, "true"); |
52 } | 52 } |
53 | 53 |
| 54 std::string GetEquivalentAriaRoleString(const ui::AXRole role) { |
| 55 switch (role) { |
| 56 case ui::AX_ROLE_ARTICLE: |
| 57 return "article"; |
| 58 case ui::AX_ROLE_BANNER: |
| 59 return "banner"; |
| 60 case ui::AX_ROLE_COMPLEMENTARY: |
| 61 return "complementary"; |
| 62 case ui::AX_ROLE_CONTENT_INFO: |
| 63 case ui::AX_ROLE_FOOTER: |
| 64 return "contentinfo"; |
| 65 case ui::AX_ROLE_MAIN: |
| 66 return "main"; |
| 67 case ui::AX_ROLE_NAVIGATION: |
| 68 return "navigation"; |
| 69 case ui::AX_ROLE_REGION: |
| 70 return "region"; |
| 71 default: |
| 72 break; |
| 73 } |
| 74 |
| 75 return std::string(); |
| 76 } |
| 77 |
54 } // Anonymous namespace | 78 } // Anonymous namespace |
55 | 79 |
56 void SerializeAccessibilityNode( | 80 void SerializeAccessibilityNode( |
57 const WebAXObject& src, | 81 const WebAXObject& src, |
58 ui::AXNodeData* dst) { | 82 ui::AXNodeData* dst) { |
59 dst->role = AXRoleFromBlink(src.role()); | 83 dst->role = AXRoleFromBlink(src.role()); |
60 dst->state = AXStateFromBlink(src); | 84 dst->state = AXStateFromBlink(src); |
61 dst->location = src.boundingBoxRect(); | 85 dst->location = src.boundingBoxRect(); |
62 dst->id = src.axID(); | 86 dst->id = src.axID(); |
63 std::string name = base::UTF16ToUTF8(src.title()); | 87 std::string name = base::UTF16ToUTF8(src.title()); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 for (size_t i = 0; i < src_line_breaks.size(); ++i) | 219 for (size_t i = 0; i < src_line_breaks.size(); ++i) |
196 line_breaks.push_back(src_line_breaks[i]); | 220 line_breaks.push_back(src_line_breaks[i]); |
197 dst->AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS, line_breaks); | 221 dst->AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS, line_breaks); |
198 } | 222 } |
199 } | 223 } |
200 | 224 |
201 // ARIA role. | 225 // ARIA role. |
202 if (element.hasAttribute("role")) { | 226 if (element.hasAttribute("role")) { |
203 dst->AddStringAttribute(ui::AX_ATTR_ROLE, | 227 dst->AddStringAttribute(ui::AX_ATTR_ROLE, |
204 UTF16ToUTF8(element.getAttribute("role"))); | 228 UTF16ToUTF8(element.getAttribute("role"))); |
| 229 } else { |
| 230 std::string role = GetEquivalentAriaRoleString(dst->role); |
| 231 if (!role.empty()) |
| 232 dst->AddStringAttribute(ui::AX_ATTR_ROLE, role); |
205 } | 233 } |
206 | 234 |
207 // Live region attributes | 235 // Live region attributes |
208 live_atomic = base::UTF16ToUTF8(element.getAttribute("aria-atomic")); | 236 live_atomic = base::UTF16ToUTF8(element.getAttribute("aria-atomic")); |
209 live_busy = base::UTF16ToUTF8(element.getAttribute("aria-busy")); | 237 live_busy = base::UTF16ToUTF8(element.getAttribute("aria-busy")); |
210 live_status = base::UTF16ToUTF8(element.getAttribute("aria-live")); | 238 live_status = base::UTF16ToUTF8(element.getAttribute("aria-live")); |
211 live_relevant = base::UTF16ToUTF8(element.getAttribute("aria-relevant")); | 239 live_relevant = base::UTF16ToUTF8(element.getAttribute("aria-relevant")); |
212 } | 240 } |
213 | 241 |
214 // Walk up the parent chain to set live region attributes of containers | 242 // Walk up the parent chain to set live region attributes of containers |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 WebNode node = parent.node(); | 436 WebNode node = parent.node(); |
409 if (!node.isNull() && node.isElementNode()) { | 437 if (!node.isNull() && node.isElementNode()) { |
410 WebElement element = node.to<WebElement>(); | 438 WebElement element = node.to<WebElement>(); |
411 is_iframe = (element.tagName() == base::ASCIIToUTF16("IFRAME")); | 439 is_iframe = (element.tagName() == base::ASCIIToUTF16("IFRAME")); |
412 } | 440 } |
413 | 441 |
414 return (is_iframe || IsParentUnignoredOf(parent, child)); | 442 return (is_iframe || IsParentUnignoredOf(parent, child)); |
415 } | 443 } |
416 | 444 |
417 } // namespace content | 445 } // namespace content |
OLD | NEW |