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/AXUtils.h" | |
| 9 #include "core/dom/Element.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 const AtomicString& AccessibleNode::getProperty( | |
| 21 AOMStringProperty property) const { | |
| 22 if (!m_element) | |
| 23 return nullAtom; | |
| 24 | |
| 25 const AtomicString& result = m_stringProperties.at(property); | |
| 26 if (result.isNull()) | |
| 27 return nullAtom; | |
| 28 | |
| 29 switch (property) { | |
| 30 case AOMStringProperty::Role: | |
| 31 if (!AXUtils::getInstance()->isValidRoleAttribute(result)) | |
| 32 return nullAtom; | |
| 33 break; | |
| 34 case AOMStringProperty::Label: | |
| 35 // No validation needed. | |
| 36 break; | |
| 37 case AOMStringProperty::None: | |
| 38 NOTREACHED(); | |
| 39 return nullAtom; | |
| 40 } | |
| 41 | |
| 42 return result; | |
| 43 } | |
| 44 | |
| 45 String AccessibleNode::role() const { | |
| 46 return getProperty(AOMStringProperty::Role); | |
| 47 } | |
| 48 | |
| 49 void AccessibleNode::setRole(const String& role) { | |
| 50 if (!m_element) | |
| 51 return; | |
| 52 | |
| 53 m_stringProperties.set(AOMStringProperty::Role, AtomicString(role)); | |
| 54 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 55 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.
| |
| 56 } | |
| 57 | |
| 58 String AccessibleNode::label() const { | |
| 59 return getProperty(AOMStringProperty::Label); | |
| 60 } | |
| 61 | |
| 62 void AccessibleNode::setLabel(const String& label) { | |
| 63 m_stringProperties.set(AOMStringProperty::Label, AtomicString(label)); | |
| 64 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 65 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); | |
| 66 } | |
| 67 | |
| 68 DEFINE_TRACE(AccessibleNode) { | |
| 69 visitor->trace(m_element); | |
| 70 } | |
| 71 | |
| 72 } // namespace blink | |
| OLD | NEW |