Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/AccessibleNode.cpp b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e00438127748bf8f6c34fbc98a219b06755b1d45 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/dom/AccessibleNode.h" |
| + |
| +#include "core/dom/AXObjectCache.h" |
| +#include "core/dom/Element.h" |
| +#include "core/dom/QualifiedName.h" |
| +#include "core/frame/Settings.h" |
| + |
| +namespace blink { |
| + |
| +AccessibleNode::AccessibleNode(Element* element) : m_element(element) { |
| + DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); |
| +} |
| + |
| +AccessibleNode::~AccessibleNode() {} |
| + |
| +// static |
| +const AtomicString& AccessibleNode::getProperty(Element* element, |
| + AOMStringProperty property) { |
| + DCHECK_GE(property, AOMStringProperty::kFirst); |
| + DCHECK_LT(property, AOMStringProperty::kCount); |
| + |
| + if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { |
| + unsigned propertyIndex = static_cast<unsigned>(property); |
| + if (accessibleNode->m_stringPropertyDirty[propertyIndex]) |
|
esprehn
2017/03/24 01:59:39
value = accessibleNode->m_stringProperties[index];
|
| + return accessibleNode->m_stringProperties[propertyIndex]; |
| + } |
| + |
| + // Fall back on the equivalent ARIA attribute. |
| + switch (property) { |
| + case AOMStringProperty::kRole: |
| + return element->getAttribute(HTMLNames::roleAttr); |
| + case AOMStringProperty::kLabel: |
| + return element->getAttribute(HTMLNames::aria_labelAttr); |
| + default: |
| + NOTREACHED(); |
| + return nullAtom; |
| + } |
| +} |
| + |
| +AtomicString AccessibleNode::role() const { |
| + return getProperty(m_element, AOMStringProperty::kRole); |
| +} |
| + |
| +void AccessibleNode::setRole(const AtomicString& role) { |
| + if (!m_element) |
|
esprehn
2017/03/24 01:59:39
How does the node still exist but the accessibleNo
dmazzoni
2017/03/24 17:51:12
Did you mean that backwards? The case we're guardi
|
| + return; |
| + |
| + const unsigned kRoleIndex = static_cast<unsigned>(AOMStringProperty::kRole); |
| + m_stringProperties[kRoleIndex] = role; |
| + m_stringPropertyDirty[kRoleIndex] = true; |
|
esprehn
2017/03/24 01:59:39
remove
|
| + |
| + // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| + // the DOM attribute changed. |
| + if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| + cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); |
| +} |
| + |
| +AtomicString AccessibleNode::label() const { |
| + return getProperty(m_element, AOMStringProperty::kLabel); |
| +} |
| + |
| +void AccessibleNode::setLabel(const AtomicString& label) { |
| + const unsigned kLabelIndex = static_cast<unsigned>(AOMStringProperty::kLabel); |
| + m_stringProperties[kLabelIndex] = label; |
| + m_stringPropertyDirty[kLabelIndex] = true; |
|
esprehn
2017/03/24 01:59:39
ditto
|
| + |
| + if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| + cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); |
| +} |
| + |
| +DEFINE_TRACE(AccessibleNode) { |
| + visitor->trace(m_element); |
| +} |
| + |
| +} // namespace blink |