| 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 if (!element) |
| 24 return nullAtom; |
| 25 |
| 26 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { |
| 27 for (const auto& item : accessibleNode->m_stringProperties) { |
| 28 if (item.first == property) |
| 29 return item.second; |
| 30 } |
| 31 } |
| 32 |
| 33 // Fall back on the equivalent ARIA attribute. |
| 34 switch (property) { |
| 35 case AOMStringProperty::kRole: |
| 36 return element->getAttribute(HTMLNames::roleAttr); |
| 37 case AOMStringProperty::kLabel: |
| 38 return element->getAttribute(HTMLNames::aria_labelAttr); |
| 39 default: |
| 40 NOTREACHED(); |
| 41 return nullAtom; |
| 42 } |
| 43 } |
| 44 |
| 45 AtomicString AccessibleNode::role() const { |
| 46 return getProperty(m_element, AOMStringProperty::kRole); |
| 47 } |
| 48 |
| 49 void AccessibleNode::setRole(const AtomicString& role) { |
| 50 setStringProperty(AOMStringProperty::kRole, role); |
| 51 |
| 52 // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| 53 // the DOM attribute changed. |
| 54 if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| 55 cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); |
| 56 } |
| 57 |
| 58 AtomicString AccessibleNode::label() const { |
| 59 return getProperty(m_element, AOMStringProperty::kLabel); |
| 60 } |
| 61 |
| 62 void AccessibleNode::setLabel(const AtomicString& label) { |
| 63 setStringProperty(AOMStringProperty::kLabel, label); |
| 64 |
| 65 if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| 66 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); |
| 67 } |
| 68 |
| 69 void AccessibleNode::setStringProperty(AOMStringProperty property, |
| 70 const AtomicString& value) { |
| 71 for (auto& item : m_stringProperties) { |
| 72 if (item.first == property) { |
| 73 item.second = value; |
| 74 return; |
| 75 } |
| 76 } |
| 77 |
| 78 m_stringProperties.push_back(std::make_pair(property, value)); |
| 79 } |
| 80 |
| 81 DEFINE_TRACE(AccessibleNode) { |
| 82 visitor->trace(m_element); |
| 83 } |
| 84 |
| 85 } // namespace blink |
| OLD | NEW |