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