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..bec83582aa859ed06c572693d90c16cf5ea02d6e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| @@ -0,0 +1,72 @@ |
| +// 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/AXUtils.h" |
| +#include "core/dom/Element.h" |
| +#include "core/frame/Settings.h" |
| + |
| +namespace blink { |
| + |
| +AccessibleNode::AccessibleNode(Element* element) : m_element(element) { |
| + DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); |
| +} |
| + |
| +AccessibleNode::~AccessibleNode() {} |
| + |
| +const AtomicString& AccessibleNode::getProperty( |
| + AOMStringProperty property) const { |
| + if (!m_element) |
| + return nullAtom; |
| + |
| + const AtomicString& result = m_stringProperties.at(property); |
| + if (result.isNull()) |
| + return nullAtom; |
| + |
| + switch (property) { |
| + case AOMStringProperty::Role: |
| + if (!AXUtils::getInstance()->isValidRoleAttribute(result)) |
| + return nullAtom; |
| + break; |
| + case AOMStringProperty::Label: |
| + // No validation needed. |
| + break; |
| + case AOMStringProperty::None: |
| + NOTREACHED(); |
| + return nullAtom; |
| + } |
| + |
| + return result; |
| +} |
| + |
| +String AccessibleNode::role() const { |
| + return getProperty(AOMStringProperty::Role); |
| +} |
| + |
| +void AccessibleNode::setRole(const String& role) { |
| + if (!m_element) |
| + return; |
| + |
| + m_stringProperties.set(AOMStringProperty::Role, AtomicString(role)); |
| + if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| + cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); |
|
aboxhall
2017/03/20 04:22:51
Hm, this is a bit icky - maybe add a TODO here for
dmazzoni
2017/03/21 21:45:06
Done.
|
| +} |
| + |
| +String AccessibleNode::label() const { |
| + return getProperty(AOMStringProperty::Label); |
| +} |
| + |
| +void AccessibleNode::setLabel(const String& label) { |
| + m_stringProperties.set(AOMStringProperty::Label, AtomicString(label)); |
| + if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| + cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); |
| +} |
| + |
| +DEFINE_TRACE(AccessibleNode) { |
| + visitor->trace(m_element); |
| +} |
| + |
| +} // namespace blink |