Chromium Code Reviews| 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { | 26 if (AccessibleNode* accessibleNode = element->existingAccessibleNode()) { |
| 27 for (const auto& item : accessibleNode->m_stringProperties) { | 27 for (const auto& item : accessibleNode->m_stringProperties) { |
| 28 if (item.first == property) | 28 if (item.first == property) |
| 29 return item.second; | 29 return item.second; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Fall back on the equivalent ARIA attribute. | 33 // Fall back on the equivalent ARIA attribute. |
| 34 switch (property) { | 34 switch (property) { |
| 35 case AOMStringProperty::kAutocomplete: | |
| 36 return element->getAttribute(HTMLNames::aria_autocompleteAttr); | |
| 37 case AOMStringProperty::kChecked: | |
| 38 return element->getAttribute(HTMLNames::aria_checkedAttr); | |
| 39 case AOMStringProperty::kCurrent: | |
| 40 return element->getAttribute(HTMLNames::aria_currentAttr); | |
| 41 case AOMStringProperty::kInvalid: | |
| 42 return element->getAttribute(HTMLNames::aria_invalidAttr); | |
| 43 case AOMStringProperty::kKeyShortcuts: | |
| 44 return element->getAttribute(HTMLNames::aria_keyshortcutsAttr); | |
| 45 case AOMStringProperty::kLabel: | |
| 46 return element->getAttribute(HTMLNames::aria_labelAttr); | |
| 47 case AOMStringProperty::kLive: | |
| 48 return element->getAttribute(HTMLNames::aria_liveAttr); | |
| 49 case AOMStringProperty::kOrientation: | |
| 50 return element->getAttribute(HTMLNames::aria_orientationAttr); | |
| 51 case AOMStringProperty::kPlaceholder: | |
| 52 return element->getAttribute(HTMLNames::aria_placeholderAttr); | |
| 53 case AOMStringProperty::kRelevant: | |
| 54 return element->getAttribute(HTMLNames::aria_relevantAttr); | |
| 35 case AOMStringProperty::kRole: | 55 case AOMStringProperty::kRole: |
| 36 return element->getAttribute(HTMLNames::roleAttr); | 56 return element->getAttribute(HTMLNames::roleAttr); |
| 37 case AOMStringProperty::kLabel: | 57 case AOMStringProperty::kRoleDescription: |
| 38 return element->getAttribute(HTMLNames::aria_labelAttr); | 58 return element->getAttribute(HTMLNames::aria_roledescriptionAttr); |
| 59 case AOMStringProperty::kSort: | |
| 60 return element->getAttribute(HTMLNames::aria_sortAttr); | |
| 61 case AOMStringProperty::kValueText: | |
| 62 return element->getAttribute(HTMLNames::aria_valuetextAttr); | |
| 39 default: | 63 default: |
|
esprehn
2017/04/04 06:22:30
If you remove the default it'll fail to compile if
dmazzoni
2017/04/04 18:59:17
Done.
| |
| 40 NOTREACHED(); | 64 NOTREACHED(); |
| 41 return nullAtom; | 65 return nullAtom; |
| 42 } | 66 } |
| 43 } | 67 } |
| 44 | 68 |
| 69 AtomicString AccessibleNode::autocomplete() const { | |
| 70 return getProperty(m_element, AOMStringProperty::kAutocomplete); | |
| 71 } | |
| 72 | |
| 73 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) { | |
| 74 setStringProperty(AOMStringProperty::kAutocomplete, autocomplete); | |
| 75 | |
| 76 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
|
esprehn
2017/04/04 06:22:30
You do this same thing everywhere, maybe you want
dmazzoni
2017/04/04 18:59:17
Done.
Actually, glad I looked at this. We should
| |
| 77 cache->handleAttributeChanged(HTMLNames::aria_autocompleteAttr, m_element); | |
| 78 } | |
| 79 | |
| 80 AtomicString AccessibleNode::checked() const { | |
| 81 return getProperty(m_element, AOMStringProperty::kChecked); | |
| 82 } | |
| 83 | |
| 84 void AccessibleNode::setChecked(const AtomicString& checked) { | |
| 85 setStringProperty(AOMStringProperty::kChecked, checked); | |
| 86 | |
| 87 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 88 cache->handleAttributeChanged(HTMLNames::aria_checkedAttr, m_element); | |
| 89 } | |
| 90 | |
| 91 AtomicString AccessibleNode::current() const { | |
| 92 return getProperty(m_element, AOMStringProperty::kCurrent); | |
| 93 } | |
| 94 | |
| 95 void AccessibleNode::setCurrent(const AtomicString& current) { | |
| 96 setStringProperty(AOMStringProperty::kCurrent, current); | |
| 97 | |
| 98 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 99 cache->handleAttributeChanged(HTMLNames::aria_currentAttr, m_element); | |
| 100 } | |
| 101 | |
| 102 AtomicString AccessibleNode::invalid() const { | |
| 103 return getProperty(m_element, AOMStringProperty::kInvalid); | |
| 104 } | |
| 105 | |
| 106 void AccessibleNode::setInvalid(const AtomicString& invalid) { | |
| 107 setStringProperty(AOMStringProperty::kInvalid, invalid); | |
| 108 | |
| 109 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 110 cache->handleAttributeChanged(HTMLNames::aria_invalidAttr, m_element); | |
| 111 } | |
| 112 | |
| 113 AtomicString AccessibleNode::keyShortcuts() const { | |
| 114 return getProperty(m_element, AOMStringProperty::kKeyShortcuts); | |
| 115 } | |
| 116 | |
| 117 void AccessibleNode::setKeyShortcuts(const AtomicString& keyShortcuts) { | |
| 118 setStringProperty(AOMStringProperty::kKeyShortcuts, keyShortcuts); | |
| 119 | |
| 120 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 121 cache->handleAttributeChanged(HTMLNames::aria_keyshortcutsAttr, m_element); | |
| 122 } | |
| 123 | |
| 124 AtomicString AccessibleNode::label() const { | |
| 125 return getProperty(m_element, AOMStringProperty::kLabel); | |
| 126 } | |
| 127 | |
| 128 void AccessibleNode::setLabel(const AtomicString& label) { | |
| 129 setStringProperty(AOMStringProperty::kLabel, label); | |
| 130 | |
| 131 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 132 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); | |
| 133 } | |
| 134 | |
| 135 AtomicString AccessibleNode::live() const { | |
| 136 return getProperty(m_element, AOMStringProperty::kLive); | |
| 137 } | |
| 138 | |
| 139 void AccessibleNode::setLive(const AtomicString& live) { | |
| 140 setStringProperty(AOMStringProperty::kLive, live); | |
| 141 | |
| 142 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 143 cache->handleAttributeChanged(HTMLNames::aria_liveAttr, m_element); | |
| 144 } | |
| 145 | |
| 146 AtomicString AccessibleNode::orientation() const { | |
| 147 return getProperty(m_element, AOMStringProperty::kOrientation); | |
| 148 } | |
| 149 | |
| 150 void AccessibleNode::setOrientation(const AtomicString& orientation) { | |
| 151 setStringProperty(AOMStringProperty::kOrientation, orientation); | |
| 152 | |
| 153 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 154 cache->handleAttributeChanged(HTMLNames::aria_orientationAttr, m_element); | |
| 155 } | |
| 156 | |
| 157 AtomicString AccessibleNode::placeholder() const { | |
| 158 return getProperty(m_element, AOMStringProperty::kPlaceholder); | |
| 159 } | |
| 160 | |
| 161 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { | |
| 162 setStringProperty(AOMStringProperty::kPlaceholder, placeholder); | |
| 163 | |
| 164 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 165 cache->handleAttributeChanged(HTMLNames::aria_placeholderAttr, m_element); | |
| 166 } | |
| 167 | |
| 168 AtomicString AccessibleNode::relevant() const { | |
| 169 return getProperty(m_element, AOMStringProperty::kRelevant); | |
| 170 } | |
| 171 | |
| 172 void AccessibleNode::setRelevant(const AtomicString& relevant) { | |
| 173 setStringProperty(AOMStringProperty::kRelevant, relevant); | |
| 174 | |
| 175 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 176 cache->handleAttributeChanged(HTMLNames::aria_relevantAttr, m_element); | |
| 177 } | |
| 178 | |
| 45 AtomicString AccessibleNode::role() const { | 179 AtomicString AccessibleNode::role() const { |
| 46 return getProperty(m_element, AOMStringProperty::kRole); | 180 return getProperty(m_element, AOMStringProperty::kRole); |
| 47 } | 181 } |
| 48 | 182 |
| 49 void AccessibleNode::setRole(const AtomicString& role) { | 183 void AccessibleNode::setRole(const AtomicString& role) { |
| 50 setStringProperty(AOMStringProperty::kRole, role); | 184 setStringProperty(AOMStringProperty::kRole, role); |
| 51 | 185 |
| 52 // TODO(dmazzoni): Make a cleaner API for this rather than pretending | 186 // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| 53 // the DOM attribute changed. | 187 // the DOM attribute changed. |
| 54 if (AXObjectCache* cache = m_element->document().axObjectCache()) | 188 if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| 55 cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); | 189 cache->handleAttributeChanged(HTMLNames::roleAttr, m_element); |
| 56 } | 190 } |
| 57 | 191 |
| 58 AtomicString AccessibleNode::label() const { | 192 AtomicString AccessibleNode::roleDescription() const { |
| 59 return getProperty(m_element, AOMStringProperty::kLabel); | 193 return getProperty(m_element, AOMStringProperty::kRoleDescription); |
| 60 } | 194 } |
| 61 | 195 |
| 62 void AccessibleNode::setLabel(const AtomicString& label) { | 196 void AccessibleNode::setRoleDescription(const AtomicString& roleDescription) { |
| 63 setStringProperty(AOMStringProperty::kLabel, label); | 197 setStringProperty(AOMStringProperty::kRoleDescription, roleDescription); |
| 198 | |
| 199 if (AXObjectCache* cache = m_element->document().axObjectCache()) { | |
| 200 cache->handleAttributeChanged(HTMLNames::aria_roledescriptionAttr, | |
| 201 m_element); | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 AtomicString AccessibleNode::sort() const { | |
| 206 return getProperty(m_element, AOMStringProperty::kSort); | |
| 207 } | |
| 208 | |
| 209 void AccessibleNode::setSort(const AtomicString& sort) { | |
| 210 setStringProperty(AOMStringProperty::kSort, sort); | |
| 64 | 211 |
| 65 if (AXObjectCache* cache = m_element->document().axObjectCache()) | 212 if (AXObjectCache* cache = m_element->document().axObjectCache()) |
| 66 cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element); | 213 cache->handleAttributeChanged(HTMLNames::aria_sortAttr, m_element); |
| 214 } | |
| 215 | |
| 216 AtomicString AccessibleNode::valueText() const { | |
| 217 return getProperty(m_element, AOMStringProperty::kValueText); | |
| 218 } | |
| 219 | |
| 220 void AccessibleNode::setValueText(const AtomicString& valueText) { | |
| 221 setStringProperty(AOMStringProperty::kValueText, valueText); | |
| 222 | |
| 223 if (AXObjectCache* cache = m_element->document().axObjectCache()) | |
| 224 cache->handleAttributeChanged(HTMLNames::aria_valuetextAttr, m_element); | |
| 67 } | 225 } |
| 68 | 226 |
| 69 void AccessibleNode::setStringProperty(AOMStringProperty property, | 227 void AccessibleNode::setStringProperty(AOMStringProperty property, |
| 70 const AtomicString& value) { | 228 const AtomicString& value) { |
| 71 for (auto& item : m_stringProperties) { | 229 for (auto& item : m_stringProperties) { |
| 72 if (item.first == property) { | 230 if (item.first == property) { |
| 73 item.second = value; | 231 item.second = value; |
| 74 return; | 232 return; |
| 75 } | 233 } |
| 76 } | 234 } |
| 77 | 235 |
| 78 m_stringProperties.push_back(std::make_pair(property, value)); | 236 m_stringProperties.push_back(std::make_pair(property, value)); |
| 79 } | 237 } |
| 80 | 238 |
| 81 DEFINE_TRACE(AccessibleNode) { | 239 DEFINE_TRACE(AccessibleNode) { |
| 82 visitor->trace(m_element); | 240 visitor->trace(m_element); |
| 83 } | 241 } |
| 84 | 242 |
| 85 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |