Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/WebKit/Source/core/dom/AccessibleNode.cpp

Issue 2750533006: Initial skeleton of Accessibility Object Model Phase 1 (Closed)
Patch Set: Address feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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])
esprehn 2017/03/24 01:59:39 value = accessibleNode->m_stringProperties[index];
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)
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
50 return;
51
52 const unsigned kRoleIndex = static_cast<unsigned>(AOMStringProperty::kRole);
53 m_stringProperties[kRoleIndex] = role;
54 m_stringPropertyDirty[kRoleIndex] = true;
esprehn 2017/03/24 01:59:39 remove
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;
esprehn 2017/03/24 01:59:39 ditto
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698