Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Unified Diff: third_party/WebKit/Source/modules/accessibility/AXObject.cpp

Issue 2750533006: Initial skeleton of Accessibility Object Model Phase 1 (Closed)
Patch Set: Add comment about ugly AXObjectCache interface Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698