OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/AccessibleNode.h" | 5 #include "core/dom/AccessibleNode.h" |
6 | 6 |
7 #include "core/dom/AXObjectCache.h" | 7 #include "core/dom/AXObjectCache.h" |
8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
9 #include "core/dom/QualifiedName.h" | 9 #include "core/dom/QualifiedName.h" |
10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
| 14 using namespace HTMLNames; |
| 15 |
14 AccessibleNode::AccessibleNode(Element* element) : m_element(element) { | 16 AccessibleNode::AccessibleNode(Element* element) : m_element(element) { |
15 DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); | 17 DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); |
16 } | 18 } |
17 | 19 |
18 AccessibleNode::~AccessibleNode() {} | 20 AccessibleNode::~AccessibleNode() {} |
19 | 21 |
20 // static | 22 // static |
21 const AtomicString& AccessibleNode::getProperty(Element* element, | 23 const AtomicString& AccessibleNode::getProperty(Element* element, |
22 AOMStringProperty property) { | 24 AOMStringProperty property) { |
23 if (!element) | 25 if (!element) |
24 return nullAtom; | 26 return nullAtom; |
25 | 27 |
26 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { | 28 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { |
27 for (const auto& item : accessibleNode->m_stringProperties) { | 29 for (const auto& item : accessibleNode->m_stringProperties) { |
28 if (item.first == property) | 30 if (item.first == property) |
29 return item.second; | 31 return item.second; |
30 } | 32 } |
31 } | 33 } |
32 | 34 |
33 // Fall back on the equivalent ARIA attribute. | 35 // Fall back on the equivalent ARIA attribute. |
34 switch (property) { | 36 switch (property) { |
| 37 case AOMStringProperty::kAutocomplete: |
| 38 return element->getAttribute(aria_autocompleteAttr); |
| 39 case AOMStringProperty::kChecked: |
| 40 return element->getAttribute(aria_checkedAttr); |
| 41 case AOMStringProperty::kCurrent: |
| 42 return element->getAttribute(aria_currentAttr); |
| 43 case AOMStringProperty::kInvalid: |
| 44 return element->getAttribute(aria_invalidAttr); |
| 45 case AOMStringProperty::kKeyShortcuts: |
| 46 return element->getAttribute(aria_keyshortcutsAttr); |
| 47 case AOMStringProperty::kLabel: |
| 48 return element->getAttribute(aria_labelAttr); |
| 49 case AOMStringProperty::kLive: |
| 50 return element->getAttribute(aria_liveAttr); |
| 51 case AOMStringProperty::kOrientation: |
| 52 return element->getAttribute(aria_orientationAttr); |
| 53 case AOMStringProperty::kPlaceholder: |
| 54 return element->getAttribute(aria_placeholderAttr); |
| 55 case AOMStringProperty::kRelevant: |
| 56 return element->getAttribute(aria_relevantAttr); |
35 case AOMStringProperty::kRole: | 57 case AOMStringProperty::kRole: |
36 return element->getAttribute(HTMLNames::roleAttr); | 58 return element->getAttribute(roleAttr); |
37 case AOMStringProperty::kLabel: | 59 case AOMStringProperty::kRoleDescription: |
38 return element->getAttribute(HTMLNames::aria_labelAttr); | 60 return element->getAttribute(aria_roledescriptionAttr); |
39 default: | 61 case AOMStringProperty::kSort: |
40 NOTREACHED(); | 62 return element->getAttribute(aria_sortAttr); |
41 return nullAtom; | 63 case AOMStringProperty::kValueText: |
| 64 return element->getAttribute(aria_valuetextAttr); |
42 } | 65 } |
| 66 |
| 67 NOTREACHED(); |
| 68 return nullAtom; |
43 } | 69 } |
44 | 70 |
45 AtomicString AccessibleNode::role() const { | 71 AtomicString AccessibleNode::autocomplete() const { |
46 return getProperty(m_element, AOMStringProperty::kRole); | 72 return getProperty(m_element, AOMStringProperty::kAutocomplete); |
47 } | 73 } |
48 | 74 |
49 void AccessibleNode::setRole(const AtomicString& role) { | 75 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) { |
50 setStringProperty(AOMStringProperty::kRole, role); | 76 setStringProperty(AOMStringProperty::kAutocomplete, autocomplete); |
| 77 notifyAttributeChanged(aria_autocompleteAttr); |
| 78 } |
51 | 79 |
52 // TODO(dmazzoni): Make a cleaner API for this rather than pretending | 80 AtomicString AccessibleNode::checked() const { |
53 // the DOM attribute changed. | 81 return getProperty(m_element, AOMStringProperty::kChecked); |
54 if (AXObjectCache* cache = m_element->document().axObjectCache()) | 82 } |
55 cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); | 83 |
| 84 void AccessibleNode::setChecked(const AtomicString& checked) { |
| 85 setStringProperty(AOMStringProperty::kChecked, checked); |
| 86 notifyAttributeChanged(aria_checkedAttr); |
| 87 } |
| 88 |
| 89 AtomicString AccessibleNode::current() const { |
| 90 return getProperty(m_element, AOMStringProperty::kCurrent); |
| 91 } |
| 92 |
| 93 void AccessibleNode::setCurrent(const AtomicString& current) { |
| 94 setStringProperty(AOMStringProperty::kCurrent, current); |
| 95 |
| 96 if (AXObjectCache* cache = m_element->document().existingAXObjectCache()) |
| 97 cache->handleAttributeChanged(aria_currentAttr, m_element); |
| 98 } |
| 99 |
| 100 AtomicString AccessibleNode::invalid() const { |
| 101 return getProperty(m_element, AOMStringProperty::kInvalid); |
| 102 } |
| 103 |
| 104 void AccessibleNode::setInvalid(const AtomicString& invalid) { |
| 105 setStringProperty(AOMStringProperty::kInvalid, invalid); |
| 106 notifyAttributeChanged(aria_invalidAttr); |
| 107 } |
| 108 |
| 109 AtomicString AccessibleNode::keyShortcuts() const { |
| 110 return getProperty(m_element, AOMStringProperty::kKeyShortcuts); |
| 111 } |
| 112 |
| 113 void AccessibleNode::setKeyShortcuts(const AtomicString& keyShortcuts) { |
| 114 setStringProperty(AOMStringProperty::kKeyShortcuts, keyShortcuts); |
| 115 notifyAttributeChanged(aria_keyshortcutsAttr); |
56 } | 116 } |
57 | 117 |
58 AtomicString AccessibleNode::label() const { | 118 AtomicString AccessibleNode::label() const { |
59 return getProperty(m_element, AOMStringProperty::kLabel); | 119 return getProperty(m_element, AOMStringProperty::kLabel); |
60 } | 120 } |
61 | 121 |
62 void AccessibleNode::setLabel(const AtomicString& label) { | 122 void AccessibleNode::setLabel(const AtomicString& label) { |
63 setStringProperty(AOMStringProperty::kLabel, label); | 123 setStringProperty(AOMStringProperty::kLabel, label); |
| 124 notifyAttributeChanged(aria_labelAttr); |
| 125 } |
64 | 126 |
65 if (AXObjectCache* cache = m_element->document().axObjectCache()) | 127 AtomicString AccessibleNode::live() const { |
66 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); | 128 return getProperty(m_element, AOMStringProperty::kLive); |
| 129 } |
| 130 |
| 131 void AccessibleNode::setLive(const AtomicString& live) { |
| 132 setStringProperty(AOMStringProperty::kLive, live); |
| 133 notifyAttributeChanged(aria_liveAttr); |
| 134 } |
| 135 |
| 136 AtomicString AccessibleNode::orientation() const { |
| 137 return getProperty(m_element, AOMStringProperty::kOrientation); |
| 138 } |
| 139 |
| 140 void AccessibleNode::setOrientation(const AtomicString& orientation) { |
| 141 setStringProperty(AOMStringProperty::kOrientation, orientation); |
| 142 notifyAttributeChanged(aria_orientationAttr); |
| 143 } |
| 144 |
| 145 AtomicString AccessibleNode::placeholder() const { |
| 146 return getProperty(m_element, AOMStringProperty::kPlaceholder); |
| 147 } |
| 148 |
| 149 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { |
| 150 setStringProperty(AOMStringProperty::kPlaceholder, placeholder); |
| 151 notifyAttributeChanged(aria_placeholderAttr); |
| 152 } |
| 153 |
| 154 AtomicString AccessibleNode::relevant() const { |
| 155 return getProperty(m_element, AOMStringProperty::kRelevant); |
| 156 } |
| 157 |
| 158 void AccessibleNode::setRelevant(const AtomicString& relevant) { |
| 159 setStringProperty(AOMStringProperty::kRelevant, relevant); |
| 160 notifyAttributeChanged(aria_relevantAttr); |
| 161 } |
| 162 |
| 163 AtomicString AccessibleNode::role() const { |
| 164 return getProperty(m_element, AOMStringProperty::kRole); |
| 165 } |
| 166 |
| 167 void AccessibleNode::setRole(const AtomicString& role) { |
| 168 setStringProperty(AOMStringProperty::kRole, role); |
| 169 notifyAttributeChanged(roleAttr); |
| 170 } |
| 171 |
| 172 AtomicString AccessibleNode::roleDescription() const { |
| 173 return getProperty(m_element, AOMStringProperty::kRoleDescription); |
| 174 } |
| 175 |
| 176 void AccessibleNode::setRoleDescription(const AtomicString& roleDescription) { |
| 177 setStringProperty(AOMStringProperty::kRoleDescription, roleDescription); |
| 178 notifyAttributeChanged(aria_roledescriptionAttr); |
| 179 } |
| 180 |
| 181 AtomicString AccessibleNode::sort() const { |
| 182 return getProperty(m_element, AOMStringProperty::kSort); |
| 183 } |
| 184 |
| 185 void AccessibleNode::setSort(const AtomicString& sort) { |
| 186 setStringProperty(AOMStringProperty::kSort, sort); |
| 187 notifyAttributeChanged(aria_sortAttr); |
| 188 } |
| 189 |
| 190 AtomicString AccessibleNode::valueText() const { |
| 191 return getProperty(m_element, AOMStringProperty::kValueText); |
| 192 } |
| 193 |
| 194 void AccessibleNode::setValueText(const AtomicString& valueText) { |
| 195 setStringProperty(AOMStringProperty::kValueText, valueText); |
| 196 notifyAttributeChanged(aria_valuetextAttr); |
67 } | 197 } |
68 | 198 |
69 void AccessibleNode::setStringProperty(AOMStringProperty property, | 199 void AccessibleNode::setStringProperty(AOMStringProperty property, |
70 const AtomicString& value) { | 200 const AtomicString& value) { |
71 for (auto& item : m_stringProperties) { | 201 for (auto& item : m_stringProperties) { |
72 if (item.first == property) { | 202 if (item.first == property) { |
73 item.second = value; | 203 item.second = value; |
74 return; | 204 return; |
75 } | 205 } |
76 } | 206 } |
77 | 207 |
78 m_stringProperties.push_back(std::make_pair(property, value)); | 208 m_stringProperties.push_back(std::make_pair(property, value)); |
79 } | 209 } |
80 | 210 |
| 211 void AccessibleNode::notifyAttributeChanged( |
| 212 const blink::QualifiedName& attribute) { |
| 213 // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| 214 // the DOM attribute changed. |
| 215 if (AXObjectCache* cache = getAXObjectCache()) |
| 216 cache->handleAttributeChanged(attribute, m_element); |
| 217 } |
| 218 |
| 219 AXObjectCache* AccessibleNode::getAXObjectCache() { |
| 220 return m_element->document().existingAXObjectCache(); |
| 221 } |
| 222 |
81 DEFINE_TRACE(AccessibleNode) { | 223 DEFINE_TRACE(AccessibleNode) { |
82 visitor->trace(m_element); | 224 visitor->trace(m_element); |
83 } | 225 } |
84 | 226 |
85 } // namespace blink | 227 } // namespace blink |
OLD | NEW |