Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/dom/AccessibleNode.h" | |
| 6 | |
| 7 #include "core/dom/AXObjectCache.h" | |
| 8 #include "core/dom/Element.h" | |
| 9 #include "core/dom/QualifiedName.h" | |
| 10 #include "core/frame/Settings.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 AccessibleNode::AccessibleNode(Element* element) : m_element(element) { | |
| 15 DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); | |
| 16 } | |
| 17 | |
| 18 AccessibleNode::~AccessibleNode() {} | |
| 19 | |
| 20 // static | |
| 21 const AtomicString& AccessibleNode::getProperty(Element* element, | |
| 22 AOMStringProperty property) { | |
| 23 DCHECK_GE(property, AOMStringProperty::kFirst); | |
| 24 DCHECK_LT(property, AOMStringProperty::kCount); | |
|
esprehn
2017/03/28 21:39:58
Remove this and just static_assert somewhere?
dmazzoni
2017/03/29 07:00:42
Good point, actually those were really only needed
| |
| 25 | |
| 26 if (!element) | |
| 27 return nullAtom; | |
| 28 | |
| 29 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { | |
| 30 for (const auto& item : accessibleNode->m_stringProperties) { | |
| 31 if (item.first == property) | |
| 32 return item.second; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 // Fall back on the equivalent ARIA attribute. | |
| 37 switch (property) { | |
| 38 case AOMStringProperty::kRole: | |
| 39 return element->getAttribute(HTMLNames::roleAttr); | |
| 40 case AOMStringProperty::kLabel: | |
| 41 return element->getAttribute(HTMLNames::aria_labelAttr); | |
| 42 default: | |
| 43 NOTREACHED(); | |
| 44 return nullAtom; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 AtomicString AccessibleNode::role() const { | |
| 49 return getProperty(m_element, AOMStringProperty::kRole); | |
| 50 } | |
| 51 | |
| 52 void AccessibleNode::setRole(const AtomicString& role) { | |
| 53 if (!m_element) | |
| 54 return; | |
| 55 | |
| 56 setStringProperty(AOMStringProperty::kRole, role); | |
| 57 | |
| 58 // TODO(dmazzoni): Make a cleaner API for this rather than pretending | |
| 59 // the DOM attribute changed. | |
| 60 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 61 cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); | |
| 62 } | |
| 63 | |
| 64 AtomicString AccessibleNode::label() const { | |
| 65 return getProperty(m_element, AOMStringProperty::kLabel); | |
| 66 } | |
| 67 | |
| 68 void AccessibleNode::setLabel(const AtomicString& label) { | |
| 69 if (!m_element) | |
| 70 return; | |
| 71 | |
| 72 setStringProperty(AOMStringProperty::kLabel, label); | |
| 73 | |
| 74 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 75 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); | |
| 76 } | |
| 77 | |
| 78 void AccessibleNode::setStringProperty(AOMStringProperty property, | |
| 79 const AtomicString& value) { | |
| 80 for (auto& item : m_stringProperties) { | |
| 81 if (item.first == property) { | |
| 82 item.second = value; | |
| 83 return; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 m_stringProperties.push_back(std::make_pair(property, value)); | |
| 88 } | |
| 89 | |
| 90 DEFINE_TRACE(AccessibleNode) { | |
| 91 visitor->trace(m_element); | |
| 92 } | |
| 93 | |
| 94 } // namespace blink | |
| OLD | NEW |