Chromium Code Reviews| Index: third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
| diff --git a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
| index 36bad05fdae17eb1258e795cf047b3e1843b27bf..d0fdeed6c13ad0ea308ff8e9fd6f168b94d0ed5d 100644 |
| --- a/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
| +++ b/third_party/WebKit/Source/modules/accessibility/AXObject.cpp |
| @@ -30,6 +30,7 @@ |
| #include "SkMatrix44.h" |
| #include "core/css/resolver/StyleResolver.h" |
| +#include "core/dom/AccessibleNode.h" |
| #include "core/dom/DocumentUserGestureToken.h" |
| #include "core/editing/EditingUtilities.h" |
| #include "core/editing/VisibleUnits.h" |
| @@ -378,6 +379,49 @@ bool AXObject::isDetached() const { |
| return !m_axObjectCache; |
| } |
| +using AOMStringPropertyToAriaMap = HashMap<AOMStringProperty, |
| + QualifiedName, |
| + WTF::IntHash<AOMStringProperty>, |
| + AOMStringPropertyHashTraits>; |
| + |
| +static AOMStringPropertyToAriaMap& getAOMStringPropertyToAriaMap() { |
| + DEFINE_STATIC_LOCAL(AOMStringPropertyToAriaMap, map, ()); |
| + if (map.isEmpty()) { |
| + map.set(AOMStringProperty::Role, roleAttr); |
|
esprehn
2017/03/22 03:40:32
Can we just use roleAttr as the key into the AOM m
dmazzoni
2017/03/23 03:36:41
I got rid of this HashMap, instead now we can just
|
| + map.set(AOMStringProperty::Label, aria_labelAttr); |
|
esprehn
2017/03/22 03:40:32
calling set() repeatedly inlines the hash function
|
| + } |
| + return map; |
| +} |
| + |
| +AccessibleNode* AXObject::getAccessibleNode() const { |
| + if (!RuntimeEnabledFeatures::accessibilityObjectModelEnabled()) |
| + return nullptr; |
| + |
| + Node* node = getNode(); |
| + if (!node || !node->isElementNode()) |
| + return nullptr; |
| + |
| + Element* element = toElement(node); |
| + return element->accessibleNode(); |
| +} |
| + |
| +const AtomicString& AXObject::getAriaAttributeOrAOMProperty( |
| + AOMStringProperty property) const { |
| + AOMStringPropertyToAriaMap& ariaMap = getAOMStringPropertyToAriaMap(); |
| + QualifiedName attrName = ariaMap.at(property); |
| + if (attrName != QualifiedName::null()) { |
| + const AtomicString& result = getAttribute(attrName); |
| + if (!result.isNull()) |
| + return result; |
| + } |
| + |
| + AccessibleNode* aomNode = getAccessibleNode(); |
| + if (aomNode) |
|
esprehn
2017/03/22 03:40:32
We often combines these like:
if (auto* node = ge
dmazzoni
2017/03/23 03:36:41
Done.
|
| + return aomNode->getProperty(property); |
| + |
| + return nullAtom; |
| +} |
| + |
| bool AXObject::isARIATextControl() const { |
| return ariaRoleAttribute() == TextFieldRole || |
| ariaRoleAttribute() == SearchBoxRole || |
| @@ -803,7 +847,8 @@ String AXObject::ariaTextAlternative(bool recursive, |
| nameSources->push_back(NameSource(*foundTextAlternative, aria_labelAttr)); |
| nameSources->back().type = nameFrom; |
| } |
| - const AtomicString& ariaLabel = getAttribute(aria_labelAttr); |
| + const AtomicString& ariaLabel = |
| + getAriaAttributeOrAOMProperty(AOMStringProperty::Label); |
| if (!ariaLabel.isEmpty()) { |
| textAlternative = ariaLabel; |