| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "core/html/HTMLSelectElement.h" | 44 #include "core/html/HTMLSelectElement.h" |
| 45 #include "core/html/HTMLTableCellElement.h" | 45 #include "core/html/HTMLTableCellElement.h" |
| 46 #include "core/html/HTMLTableElement.h" | 46 #include "core/html/HTMLTableElement.h" |
| 47 #include "core/html/HTMLTableRowElement.h" | 47 #include "core/html/HTMLTableRowElement.h" |
| 48 #include "core/html/HTMLTableSectionElement.h" | 48 #include "core/html/HTMLTableSectionElement.h" |
| 49 #include "core/html/HTMLTextAreaElement.h" | 49 #include "core/html/HTMLTextAreaElement.h" |
| 50 #include "core/html/parser/HTMLParserIdioms.h" | 50 #include "core/html/parser/HTMLParserIdioms.h" |
| 51 #include "core/html/shadow/MediaControlElements.h" | 51 #include "core/html/shadow/MediaControlElements.h" |
| 52 #include "core/layout/LayoutObject.h" | 52 #include "core/layout/LayoutObject.h" |
| 53 #include "modules/accessibility/AXObjectCacheImpl.h" | 53 #include "modules/accessibility/AXObjectCacheImpl.h" |
| 54 #include "modules/accessibility/InspectorTypeBuilderHelper.h" |
| 54 #include "platform/UserGestureIndicator.h" | 55 #include "platform/UserGestureIndicator.h" |
| 55 #include "wtf/text/StringBuilder.h" | 56 #include "wtf/text/StringBuilder.h" |
| 56 | 57 |
| 57 | 58 |
| 58 namespace blink { | 59 namespace blink { |
| 59 | 60 |
| 60 using namespace HTMLNames; | 61 using namespace HTMLNames; |
| 61 | 62 |
| 63 using TypeBuilder::Accessibility::AXIgnoredReasons; |
| 64 |
| 62 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl* axObjectCache) | 65 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl* axObjectCache) |
| 63 : AXObject(axObjectCache) | 66 : AXObject(axObjectCache) |
| 64 , m_ariaRole(UnknownRole) | 67 , m_ariaRole(UnknownRole) |
| 65 , m_childrenDirty(false) | 68 , m_childrenDirty(false) |
| 66 #if ENABLE(ASSERT) | 69 #if ENABLE(ASSERT) |
| 67 , m_initialized(false) | 70 , m_initialized(false) |
| 68 #endif | 71 #endif |
| 69 , m_node(node) | 72 , m_node(node) |
| 70 { | 73 { |
| 71 } | 74 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 154 } |
| 152 | 155 |
| 153 | 156 |
| 154 void AXNodeObject::ariaLabeledByElements(WillBeHeapVector<RawPtrWillBeMember<Ele
ment>>& elements) const | 157 void AXNodeObject::ariaLabeledByElements(WillBeHeapVector<RawPtrWillBeMember<Ele
ment>>& elements) const |
| 155 { | 158 { |
| 156 elementsFromAttribute(elements, aria_labeledbyAttr); | 159 elementsFromAttribute(elements, aria_labeledbyAttr); |
| 157 if (!elements.size()) | 160 if (!elements.size()) |
| 158 elementsFromAttribute(elements, aria_labelledbyAttr); | 161 elementsFromAttribute(elements, aria_labelledbyAttr); |
| 159 } | 162 } |
| 160 | 163 |
| 161 bool AXNodeObject::computeAccessibilityIsIgnored() const | 164 bool AXNodeObject::computeAccessibilityIsIgnored(PassRefPtr<TypeBuilder::Array<T
ypeBuilder::Accessibility::AXProperty>> passIgnoredReasons) const |
| 162 { | 165 { |
| 163 #if ENABLE(ASSERT) | 166 #if ENABLE(ASSERT) |
| 164 // Double-check that an AXObject is never accessed before | 167 // Double-check that an AXObject is never accessed before |
| 165 // it's been initialized. | 168 // it's been initialized. |
| 166 ASSERT(m_initialized); | 169 ASSERT(m_initialized); |
| 167 #endif | 170 #endif |
| 171 RefPtr<TypeBuilder::Array<TypeBuilder::Accessibility::AXProperty>> ignoredRe
asons = passIgnoredReasons; |
| 168 | 172 |
| 169 // If this element is within a parent that cannot have children, it should n
ot be exposed. | 173 // If this element is within a parent that cannot have children, it should n
ot be exposed. |
| 170 if (isDescendantOfBarrenParent()) | 174 if (isDescendantOfLeafNode()) { |
| 175 if (ignoredReasons) |
| 176 ignoredReasons->addItem(createProperty(AXIgnoredReasons::AncestorIsL
eafNode, createRelatedNodeValue(leafNodeAncestor()))); |
| 171 return true; | 177 return true; |
| 178 } |
| 172 | 179 |
| 173 // Ignore labels that are already referenced by a control's title UI element
. | 180 // Ignore labels that are already referenced by a control's title UI element
. |
| 174 AXObject* controlObject = correspondingControlForLabelElement(); | 181 AXObject* controlObject = correspondingControlForLabelElement(); |
| 175 if (controlObject && !controlObject->deprecatedExposesTitleUIElement() && co
ntrolObject->isCheckboxOrRadio()) | 182 if (controlObject && !controlObject->deprecatedExposesTitleUIElement() && co
ntrolObject->isCheckboxOrRadio()) { |
| 183 if (ignoredReasons) { |
| 184 HTMLLabelElement* label = labelElementContainer(); |
| 185 if (label && !label->isSameNode(node())) { |
| 186 AXObject* labelAXObject = axObjectCache()->getOrCreate(label); |
| 187 ignoredReasons->addItem(createProperty(AXIgnoredReasons::LabelCo
ntainer, createRelatedNodeValue(labelAXObject))); |
| 188 } |
| 189 |
| 190 ignoredReasons->addItem(createProperty(AXIgnoredReasons::LabelFor, c
reateRelatedNodeValue(controlObject))); |
| 191 } |
| 176 return true; | 192 return true; |
| 193 } |
| 177 | 194 |
| 178 return m_role == UnknownRole; | 195 if (m_role == UnknownRole) { |
| 196 if (ignoredReasons) |
| 197 ignoredReasons->addItem(createProperty(AXIgnoredReasons::Uninteresti
ng, createBooleanValue(true))); |
| 198 return true; |
| 199 } |
| 200 return false; |
| 179 } | 201 } |
| 180 | 202 |
| 181 static bool isListElement(Node* node) | 203 static bool isListElement(Node* node) |
| 182 { | 204 { |
| 183 return isHTMLUListElement(*node) || isHTMLOListElement(*node) || isHTMLDList
Element(*node); | 205 return isHTMLUListElement(*node) || isHTMLOListElement(*node) || isHTMLDList
Element(*node); |
| 184 } | 206 } |
| 185 | 207 |
| 186 static bool isPresentationRoleInTable(AXObject* parent, Node* child) | 208 static bool isPresentationRoleInTable(AXObject* parent, Node* child) |
| 187 { | 209 { |
| 188 Node* parentNode = parent->node(); | 210 Node* parentNode = parent->node(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (isHTMLTableRowElement(childNode)) | 248 if (isHTMLTableRowElement(childNode)) |
| 227 return isHTMLTableSectionElement(*parentNode); | 249 return isHTMLTableSectionElement(*parentNode); |
| 228 | 250 |
| 229 // In case of ListboxRole and it's child, ListBoxOptionRole, | 251 // In case of ListboxRole and it's child, ListBoxOptionRole, |
| 230 // Inheritance of presentation role is handled in AXListBoxOption | 252 // Inheritance of presentation role is handled in AXListBoxOption |
| 231 // Because ListBoxOption Role doesn't have any child. | 253 // Because ListBoxOption Role doesn't have any child. |
| 232 // If it's just ignored because of presentation, we can't see any AX tree re
lated to ListBoxOption. | 254 // If it's just ignored because of presentation, we can't see any AX tree re
lated to ListBoxOption. |
| 233 return false; | 255 return false; |
| 234 } | 256 } |
| 235 | 257 |
| 236 bool AXNodeObject::computeHasInheritedPresentationalRole() const | 258 AXObject* AXNodeObject::inheritsPresentationalRoleFrom() const |
| 237 { | 259 { |
| 238 // ARIA states if an item can get focus, it should not be presentational. | 260 // ARIA states if an item can get focus, it should not be presentational. |
| 239 if (canSetFocusAttribute()) | 261 if (canSetFocusAttribute()) |
| 240 return false; | 262 return 0; |
| 241 | 263 |
| 242 if (isPresentational()) | 264 if (isPresentational()) |
| 243 return true; | 265 return 0; |
| 244 | 266 |
| 245 // http://www.w3.org/TR/wai-aria/complete#presentation | 267 // http://www.w3.org/TR/wai-aria/complete#presentation |
| 246 // ARIA spec says that the user agent MUST apply an inherited role of presen
tation | 268 // ARIA spec says that the user agent MUST apply an inherited role of presen
tation |
| 247 // to any owned elements that do not have an explicit role defined. | 269 // to any owned elements that do not have an explicit role defined. |
| 248 if (ariaRoleAttribute() != UnknownRole) | 270 if (ariaRoleAttribute() != UnknownRole) |
| 249 return false; | 271 return 0; |
| 250 | 272 |
| 251 AXObject* parent = parentObject(); | 273 AXObject* parent = parentObject(); |
| 252 if (!parent) | 274 if (!parent) |
| 253 return false; | 275 return 0; |
| 254 | 276 |
| 255 Node* curNode = node(); | 277 Node* curNode = node(); |
| 256 if (!parent->hasInheritedPresentationalRole() | 278 if (!parent->hasInheritedPresentationalRole() |
| 257 && !isPresentationRoleInTable(parent, curNode)) | 279 && !isPresentationRoleInTable(parent, curNode)) |
| 258 return false; | 280 return 0; |
| 259 | 281 |
| 260 // ARIA spec says that when a parent object is presentational and this objec
t | 282 // ARIA spec says that when a parent object is presentational and this objec
t |
| 261 // is a required owned element of that parent, then this object is also pres
entational. | 283 // is a required owned element of that parent, then this object is also pres
entational. |
| 262 return isRequiredOwnedElement(parent, roleValue(), curNode); | 284 if (isRequiredOwnedElement(parent, roleValue(), curNode)) |
| 285 return parent; |
| 286 return 0; |
| 263 } | 287 } |
| 264 | 288 |
| 265 bool AXNodeObject::isDescendantOfElementType(const HTMLQualifiedName& tagName) c
onst | 289 bool AXNodeObject::isDescendantOfElementType(const HTMLQualifiedName& tagName) c
onst |
| 266 { | 290 { |
| 267 if (!node()) | 291 if (!node()) |
| 268 return false; | 292 return false; |
| 269 | 293 |
| 270 for (Element* parent = node()->parentElement(); parent; parent = parent->par
entElement()) { | 294 for (Element* parent = node()->parentElement(); parent; parent = parent->par
entElement()) { |
| 271 if (parent->hasTagName(tagName)) | 295 if (parent->hasTagName(tagName)) |
| 272 return true; | 296 return true; |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 // it's focusable - but without making its title be the full inner text, whi
ch is | 1469 // it's focusable - but without making its title be the full inner text, whi
ch is |
| 1446 // quite long. As a heuristic, skip links, controls, and elements that are u
sually | 1470 // quite long. As a heuristic, skip links, controls, and elements that are u
sually |
| 1447 // containers with lots of children. | 1471 // containers with lots of children. |
| 1448 | 1472 |
| 1449 // Skip hidden children | 1473 // Skip hidden children |
| 1450 if (obj->isInertOrAriaHidden()) | 1474 if (obj->isInertOrAriaHidden()) |
| 1451 return false; | 1475 return false; |
| 1452 | 1476 |
| 1453 // If something doesn't expose any children, then we can always take the inn
er text content. | 1477 // If something doesn't expose any children, then we can always take the inn
er text content. |
| 1454 // This is what we want when someone puts an <a> inside a <button> for examp
le. | 1478 // This is what we want when someone puts an <a> inside a <button> for examp
le. |
| 1455 if (obj->isDescendantOfBarrenParent()) | 1479 if (obj->isDescendantOfLeafNode()) |
| 1456 return true; | 1480 return true; |
| 1457 | 1481 |
| 1458 // Skip focusable children, so we don't include the text of links and contro
ls. | 1482 // Skip focusable children, so we don't include the text of links and contro
ls. |
| 1459 if (obj->canSetFocusAttribute()) | 1483 if (obj->canSetFocusAttribute()) |
| 1460 return false; | 1484 return false; |
| 1461 | 1485 |
| 1462 // Skip big container elements like lists, tables, etc. | 1486 // Skip big container elements like lists, tables, etc. |
| 1463 if (obj->isList() || obj->isAXTable() || obj->isTree() || obj->isCanvas()) | 1487 if (obj->isList() || obj->isAXTable() || obj->isTree() || obj->isCanvas()) |
| 1464 return false; | 1488 return false; |
| 1465 | 1489 |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 ariaLabeledByElements(elements); | 2186 ariaLabeledByElements(elements); |
| 2163 | 2187 |
| 2164 for (const auto& element : elements) { | 2188 for (const auto& element : elements) { |
| 2165 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); | 2189 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); |
| 2166 textOrder.append(AccessibilityText(ariaLabeledBy, AlternativeText, a
xElement)); | 2190 textOrder.append(AccessibilityText(ariaLabeledBy, AlternativeText, a
xElement)); |
| 2167 } | 2191 } |
| 2168 } | 2192 } |
| 2169 } | 2193 } |
| 2170 | 2194 |
| 2171 } // namespace blink | 2195 } // namespace blink |
| OLD | NEW |