| 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 17 matching lines...) Expand all Loading... |
| 28 if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) { | 28 if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) { |
| 29 for (const auto& item : accessible_node->string_properties_) { | 29 for (const auto& item : accessible_node->string_properties_) { |
| 30 if (item.first == property) | 30 if (item.first == property) |
| 31 return item.second; | 31 return item.second; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Fall back on the equivalent ARIA attribute. | 35 // Fall back on the equivalent ARIA attribute. |
| 36 switch (property) { | 36 switch (property) { |
| 37 case AOMStringProperty::kAutocomplete: | 37 case AOMStringProperty::kAutocomplete: |
| 38 return element->getAttribute(aria_autocompleteAttr); | 38 return element->FastGetAttribute(aria_autocompleteAttr); |
| 39 case AOMStringProperty::kChecked: | 39 case AOMStringProperty::kChecked: |
| 40 return element->getAttribute(aria_checkedAttr); | 40 return element->FastGetAttribute(aria_checkedAttr); |
| 41 case AOMStringProperty::kCurrent: | 41 case AOMStringProperty::kCurrent: |
| 42 return element->getAttribute(aria_currentAttr); | 42 return element->FastGetAttribute(aria_currentAttr); |
| 43 case AOMStringProperty::kInvalid: | 43 case AOMStringProperty::kInvalid: |
| 44 return element->getAttribute(aria_invalidAttr); | 44 return element->FastGetAttribute(aria_invalidAttr); |
| 45 case AOMStringProperty::kKeyShortcuts: | 45 case AOMStringProperty::kKeyShortcuts: |
| 46 return element->getAttribute(aria_keyshortcutsAttr); | 46 return element->FastGetAttribute(aria_keyshortcutsAttr); |
| 47 case AOMStringProperty::kLabel: | 47 case AOMStringProperty::kLabel: |
| 48 return element->getAttribute(aria_labelAttr); | 48 return element->FastGetAttribute(aria_labelAttr); |
| 49 case AOMStringProperty::kLive: | 49 case AOMStringProperty::kLive: |
| 50 return element->getAttribute(aria_liveAttr); | 50 return element->FastGetAttribute(aria_liveAttr); |
| 51 case AOMStringProperty::kOrientation: | 51 case AOMStringProperty::kOrientation: |
| 52 return element->getAttribute(aria_orientationAttr); | 52 return element->FastGetAttribute(aria_orientationAttr); |
| 53 case AOMStringProperty::kPlaceholder: | 53 case AOMStringProperty::kPlaceholder: |
| 54 return element->getAttribute(aria_placeholderAttr); | 54 return element->FastGetAttribute(aria_placeholderAttr); |
| 55 case AOMStringProperty::kRelevant: | 55 case AOMStringProperty::kRelevant: |
| 56 return element->getAttribute(aria_relevantAttr); | 56 return element->FastGetAttribute(aria_relevantAttr); |
| 57 case AOMStringProperty::kRole: | 57 case AOMStringProperty::kRole: |
| 58 return element->getAttribute(roleAttr); | 58 return element->FastGetAttribute(roleAttr); |
| 59 case AOMStringProperty::kRoleDescription: | 59 case AOMStringProperty::kRoleDescription: |
| 60 return element->getAttribute(aria_roledescriptionAttr); | 60 return element->FastGetAttribute(aria_roledescriptionAttr); |
| 61 case AOMStringProperty::kSort: | 61 case AOMStringProperty::kSort: |
| 62 return element->getAttribute(aria_sortAttr); | 62 return element->FastGetAttribute(aria_sortAttr); |
| 63 case AOMStringProperty::kValueText: | 63 case AOMStringProperty::kValueText: |
| 64 return element->getAttribute(aria_valuetextAttr); | 64 return element->FastGetAttribute(aria_valuetextAttr); |
| 65 } | 65 } |
| 66 | 66 |
| 67 NOTREACHED(); | 67 NOTREACHED(); |
| 68 return g_null_atom; | 68 return g_null_atom; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // static |
| 72 bool AccessibleNode::GetProperty(Element* element, |
| 73 AOMBooleanProperty property, |
| 74 bool& is_null) { |
| 75 is_null = true; |
| 76 if (!element) |
| 77 return false; |
| 78 |
| 79 if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) { |
| 80 for (const auto& item : accessible_node->boolean_properties_) { |
| 81 if (item.first == property) { |
| 82 is_null = false; |
| 83 return item.second; |
| 84 } |
| 85 } |
| 86 } |
| 87 |
| 88 // Fall back on the equivalent ARIA attribute. |
| 89 AtomicString attr_value; |
| 90 switch (property) { |
| 91 case AOMBooleanProperty::kAtomic: |
| 92 attr_value = element->FastGetAttribute(aria_atomicAttr); |
| 93 break; |
| 94 case AOMBooleanProperty::kBusy: |
| 95 attr_value = element->FastGetAttribute(aria_busyAttr); |
| 96 break; |
| 97 case AOMBooleanProperty::kDisabled: |
| 98 attr_value = element->FastGetAttribute(aria_disabledAttr); |
| 99 break; |
| 100 case AOMBooleanProperty::kExpanded: |
| 101 attr_value = element->FastGetAttribute(aria_expandedAttr); |
| 102 break; |
| 103 case AOMBooleanProperty::kHidden: |
| 104 attr_value = element->FastGetAttribute(aria_hiddenAttr); |
| 105 break; |
| 106 case AOMBooleanProperty::kModal: |
| 107 attr_value = element->FastGetAttribute(aria_modalAttr); |
| 108 break; |
| 109 case AOMBooleanProperty::kMultiline: |
| 110 attr_value = element->FastGetAttribute(aria_multilineAttr); |
| 111 break; |
| 112 case AOMBooleanProperty::kMultiselectable: |
| 113 attr_value = element->FastGetAttribute(aria_multiselectableAttr); |
| 114 break; |
| 115 case AOMBooleanProperty::kReadOnly: |
| 116 attr_value = element->FastGetAttribute(aria_readonlyAttr); |
| 117 break; |
| 118 case AOMBooleanProperty::kRequired: |
| 119 attr_value = element->FastGetAttribute(aria_requiredAttr); |
| 120 break; |
| 121 case AOMBooleanProperty::kSelected: |
| 122 attr_value = element->FastGetAttribute(aria_selectedAttr); |
| 123 break; |
| 124 } |
| 125 |
| 126 is_null = attr_value.IsNull(); |
| 127 return EqualIgnoringASCIICase(attr_value, "true"); |
| 128 } |
| 129 |
| 130 bool AccessibleNode::atomic(bool& is_null) const { |
| 131 return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null); |
| 132 } |
| 133 |
| 134 void AccessibleNode::setAtomic(bool atomic, bool is_null) { |
| 135 SetBooleanProperty(AOMBooleanProperty::kAtomic, atomic); |
| 136 NotifyAttributeChanged(aria_atomicAttr); |
| 137 } |
| 138 |
| 71 AtomicString AccessibleNode::autocomplete() const { | 139 AtomicString AccessibleNode::autocomplete() const { |
| 72 return GetProperty(element_, AOMStringProperty::kAutocomplete); | 140 return GetProperty(element_, AOMStringProperty::kAutocomplete); |
| 73 } | 141 } |
| 74 | 142 |
| 75 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) { | 143 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) { |
| 76 SetStringProperty(AOMStringProperty::kAutocomplete, autocomplete); | 144 SetStringProperty(AOMStringProperty::kAutocomplete, autocomplete); |
| 77 NotifyAttributeChanged(aria_autocompleteAttr); | 145 NotifyAttributeChanged(aria_autocompleteAttr); |
| 78 } | 146 } |
| 79 | 147 |
| 148 bool AccessibleNode::busy(bool& is_null) const { |
| 149 return GetProperty(element_, AOMBooleanProperty::kBusy, is_null); |
| 150 } |
| 151 |
| 152 void AccessibleNode::setBusy(bool busy, bool is_null) { |
| 153 SetBooleanProperty(AOMBooleanProperty::kBusy, busy); |
| 154 NotifyAttributeChanged(aria_busyAttr); |
| 155 } |
| 156 |
| 80 AtomicString AccessibleNode::checked() const { | 157 AtomicString AccessibleNode::checked() const { |
| 81 return GetProperty(element_, AOMStringProperty::kChecked); | 158 return GetProperty(element_, AOMStringProperty::kChecked); |
| 82 } | 159 } |
| 83 | 160 |
| 84 void AccessibleNode::setChecked(const AtomicString& checked) { | 161 void AccessibleNode::setChecked(const AtomicString& checked) { |
| 85 SetStringProperty(AOMStringProperty::kChecked, checked); | 162 SetStringProperty(AOMStringProperty::kChecked, checked); |
| 86 NotifyAttributeChanged(aria_checkedAttr); | 163 NotifyAttributeChanged(aria_checkedAttr); |
| 87 } | 164 } |
| 88 | 165 |
| 89 AtomicString AccessibleNode::current() const { | 166 AtomicString AccessibleNode::current() const { |
| 90 return GetProperty(element_, AOMStringProperty::kCurrent); | 167 return GetProperty(element_, AOMStringProperty::kCurrent); |
| 91 } | 168 } |
| 92 | 169 |
| 93 void AccessibleNode::setCurrent(const AtomicString& current) { | 170 void AccessibleNode::setCurrent(const AtomicString& current) { |
| 94 SetStringProperty(AOMStringProperty::kCurrent, current); | 171 SetStringProperty(AOMStringProperty::kCurrent, current); |
| 95 | 172 |
| 96 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache()) | 173 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache()) |
| 97 cache->HandleAttributeChanged(aria_currentAttr, element_); | 174 cache->HandleAttributeChanged(aria_currentAttr, element_); |
| 98 } | 175 } |
| 99 | 176 |
| 177 bool AccessibleNode::disabled(bool& is_null) const { |
| 178 return GetProperty(element_, AOMBooleanProperty::kDisabled, is_null); |
| 179 } |
| 180 |
| 181 void AccessibleNode::setDisabled(bool disabled, bool is_null) { |
| 182 SetBooleanProperty(AOMBooleanProperty::kDisabled, disabled); |
| 183 NotifyAttributeChanged(aria_disabledAttr); |
| 184 } |
| 185 |
| 186 bool AccessibleNode::expanded(bool& is_null) const { |
| 187 return GetProperty(element_, AOMBooleanProperty::kExpanded, is_null); |
| 188 } |
| 189 |
| 190 void AccessibleNode::setExpanded(bool expanded, bool is_null) { |
| 191 SetBooleanProperty(AOMBooleanProperty::kExpanded, expanded); |
| 192 NotifyAttributeChanged(aria_expandedAttr); |
| 193 } |
| 194 |
| 195 bool AccessibleNode::hidden(bool& is_null) const { |
| 196 return GetProperty(element_, AOMBooleanProperty::kHidden, is_null); |
| 197 } |
| 198 |
| 199 void AccessibleNode::setHidden(bool hidden, bool is_null) { |
| 200 SetBooleanProperty(AOMBooleanProperty::kHidden, hidden); |
| 201 NotifyAttributeChanged(aria_hiddenAttr); |
| 202 } |
| 203 |
| 100 AtomicString AccessibleNode::invalid() const { | 204 AtomicString AccessibleNode::invalid() const { |
| 101 return GetProperty(element_, AOMStringProperty::kInvalid); | 205 return GetProperty(element_, AOMStringProperty::kInvalid); |
| 102 } | 206 } |
| 103 | 207 |
| 104 void AccessibleNode::setInvalid(const AtomicString& invalid) { | 208 void AccessibleNode::setInvalid(const AtomicString& invalid) { |
| 105 SetStringProperty(AOMStringProperty::kInvalid, invalid); | 209 SetStringProperty(AOMStringProperty::kInvalid, invalid); |
| 106 NotifyAttributeChanged(aria_invalidAttr); | 210 NotifyAttributeChanged(aria_invalidAttr); |
| 107 } | 211 } |
| 108 | 212 |
| 109 AtomicString AccessibleNode::keyShortcuts() const { | 213 AtomicString AccessibleNode::keyShortcuts() const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 126 | 230 |
| 127 AtomicString AccessibleNode::live() const { | 231 AtomicString AccessibleNode::live() const { |
| 128 return GetProperty(element_, AOMStringProperty::kLive); | 232 return GetProperty(element_, AOMStringProperty::kLive); |
| 129 } | 233 } |
| 130 | 234 |
| 131 void AccessibleNode::setLive(const AtomicString& live) { | 235 void AccessibleNode::setLive(const AtomicString& live) { |
| 132 SetStringProperty(AOMStringProperty::kLive, live); | 236 SetStringProperty(AOMStringProperty::kLive, live); |
| 133 NotifyAttributeChanged(aria_liveAttr); | 237 NotifyAttributeChanged(aria_liveAttr); |
| 134 } | 238 } |
| 135 | 239 |
| 240 bool AccessibleNode::modal(bool& is_null) const { |
| 241 return GetProperty(element_, AOMBooleanProperty::kModal, is_null); |
| 242 } |
| 243 |
| 244 void AccessibleNode::setModal(bool modal, bool is_null) { |
| 245 SetBooleanProperty(AOMBooleanProperty::kModal, modal); |
| 246 NotifyAttributeChanged(aria_modalAttr); |
| 247 } |
| 248 |
| 249 bool AccessibleNode::multiline(bool& is_null) const { |
| 250 return GetProperty(element_, AOMBooleanProperty::kMultiline, is_null); |
| 251 } |
| 252 |
| 253 void AccessibleNode::setMultiline(bool multiline, bool is_null) { |
| 254 SetBooleanProperty(AOMBooleanProperty::kMultiline, multiline); |
| 255 NotifyAttributeChanged(aria_multilineAttr); |
| 256 } |
| 257 |
| 258 bool AccessibleNode::multiselectable(bool& is_null) const { |
| 259 return GetProperty(element_, AOMBooleanProperty::kMultiselectable, is_null); |
| 260 } |
| 261 |
| 262 void AccessibleNode::setMultiselectable(bool multiselectable, bool is_null) { |
| 263 SetBooleanProperty(AOMBooleanProperty::kMultiselectable, multiselectable); |
| 264 NotifyAttributeChanged(aria_multiselectableAttr); |
| 265 } |
| 266 |
| 136 AtomicString AccessibleNode::orientation() const { | 267 AtomicString AccessibleNode::orientation() const { |
| 137 return GetProperty(element_, AOMStringProperty::kOrientation); | 268 return GetProperty(element_, AOMStringProperty::kOrientation); |
| 138 } | 269 } |
| 139 | 270 |
| 140 void AccessibleNode::setOrientation(const AtomicString& orientation) { | 271 void AccessibleNode::setOrientation(const AtomicString& orientation) { |
| 141 SetStringProperty(AOMStringProperty::kOrientation, orientation); | 272 SetStringProperty(AOMStringProperty::kOrientation, orientation); |
| 142 NotifyAttributeChanged(aria_orientationAttr); | 273 NotifyAttributeChanged(aria_orientationAttr); |
| 143 } | 274 } |
| 144 | 275 |
| 145 AtomicString AccessibleNode::placeholder() const { | 276 AtomicString AccessibleNode::placeholder() const { |
| 146 return GetProperty(element_, AOMStringProperty::kPlaceholder); | 277 return GetProperty(element_, AOMStringProperty::kPlaceholder); |
| 147 } | 278 } |
| 148 | 279 |
| 149 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { | 280 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { |
| 150 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder); | 281 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder); |
| 151 NotifyAttributeChanged(aria_placeholderAttr); | 282 NotifyAttributeChanged(aria_placeholderAttr); |
| 152 } | 283 } |
| 153 | 284 |
| 285 bool AccessibleNode::readOnly(bool& is_null) const { |
| 286 return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null); |
| 287 } |
| 288 |
| 289 void AccessibleNode::setReadOnly(bool read_only, bool is_null) { |
| 290 SetBooleanProperty(AOMBooleanProperty::kReadOnly, read_only); |
| 291 NotifyAttributeChanged(aria_readonlyAttr); |
| 292 } |
| 293 |
| 154 AtomicString AccessibleNode::relevant() const { | 294 AtomicString AccessibleNode::relevant() const { |
| 155 return GetProperty(element_, AOMStringProperty::kRelevant); | 295 return GetProperty(element_, AOMStringProperty::kRelevant); |
| 156 } | 296 } |
| 157 | 297 |
| 158 void AccessibleNode::setRelevant(const AtomicString& relevant) { | 298 void AccessibleNode::setRelevant(const AtomicString& relevant) { |
| 159 SetStringProperty(AOMStringProperty::kRelevant, relevant); | 299 SetStringProperty(AOMStringProperty::kRelevant, relevant); |
| 160 NotifyAttributeChanged(aria_relevantAttr); | 300 NotifyAttributeChanged(aria_relevantAttr); |
| 161 } | 301 } |
| 162 | 302 |
| 303 bool AccessibleNode::required(bool& is_null) const { |
| 304 return GetProperty(element_, AOMBooleanProperty::kRequired, is_null); |
| 305 } |
| 306 |
| 307 void AccessibleNode::setRequired(bool required, bool is_null) { |
| 308 SetBooleanProperty(AOMBooleanProperty::kRequired, required); |
| 309 NotifyAttributeChanged(aria_requiredAttr); |
| 310 } |
| 311 |
| 163 AtomicString AccessibleNode::role() const { | 312 AtomicString AccessibleNode::role() const { |
| 164 return GetProperty(element_, AOMStringProperty::kRole); | 313 return GetProperty(element_, AOMStringProperty::kRole); |
| 165 } | 314 } |
| 166 | 315 |
| 167 void AccessibleNode::setRole(const AtomicString& role) { | 316 void AccessibleNode::setRole(const AtomicString& role) { |
| 168 SetStringProperty(AOMStringProperty::kRole, role); | 317 SetStringProperty(AOMStringProperty::kRole, role); |
| 169 NotifyAttributeChanged(roleAttr); | 318 NotifyAttributeChanged(roleAttr); |
| 170 } | 319 } |
| 171 | 320 |
| 172 AtomicString AccessibleNode::roleDescription() const { | 321 AtomicString AccessibleNode::roleDescription() const { |
| 173 return GetProperty(element_, AOMStringProperty::kRoleDescription); | 322 return GetProperty(element_, AOMStringProperty::kRoleDescription); |
| 174 } | 323 } |
| 175 | 324 |
| 176 void AccessibleNode::setRoleDescription(const AtomicString& role_description) { | 325 void AccessibleNode::setRoleDescription(const AtomicString& role_description) { |
| 177 SetStringProperty(AOMStringProperty::kRoleDescription, role_description); | 326 SetStringProperty(AOMStringProperty::kRoleDescription, role_description); |
| 178 NotifyAttributeChanged(aria_roledescriptionAttr); | 327 NotifyAttributeChanged(aria_roledescriptionAttr); |
| 179 } | 328 } |
| 180 | 329 |
| 330 bool AccessibleNode::selected(bool& is_null) const { |
| 331 return GetProperty(element_, AOMBooleanProperty::kSelected, is_null); |
| 332 } |
| 333 |
| 334 void AccessibleNode::setSelected(bool selected, bool is_null) { |
| 335 SetBooleanProperty(AOMBooleanProperty::kSelected, selected); |
| 336 NotifyAttributeChanged(aria_selectedAttr); |
| 337 } |
| 338 |
| 181 AtomicString AccessibleNode::sort() const { | 339 AtomicString AccessibleNode::sort() const { |
| 182 return GetProperty(element_, AOMStringProperty::kSort); | 340 return GetProperty(element_, AOMStringProperty::kSort); |
| 183 } | 341 } |
| 184 | 342 |
| 185 void AccessibleNode::setSort(const AtomicString& sort) { | 343 void AccessibleNode::setSort(const AtomicString& sort) { |
| 186 SetStringProperty(AOMStringProperty::kSort, sort); | 344 SetStringProperty(AOMStringProperty::kSort, sort); |
| 187 NotifyAttributeChanged(aria_sortAttr); | 345 NotifyAttributeChanged(aria_sortAttr); |
| 188 } | 346 } |
| 189 | 347 |
| 190 AtomicString AccessibleNode::valueText() const { | 348 AtomicString AccessibleNode::valueText() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 201 for (auto& item : string_properties_) { | 359 for (auto& item : string_properties_) { |
| 202 if (item.first == property) { | 360 if (item.first == property) { |
| 203 item.second = value; | 361 item.second = value; |
| 204 return; | 362 return; |
| 205 } | 363 } |
| 206 } | 364 } |
| 207 | 365 |
| 208 string_properties_.push_back(std::make_pair(property, value)); | 366 string_properties_.push_back(std::make_pair(property, value)); |
| 209 } | 367 } |
| 210 | 368 |
| 369 void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property, |
| 370 bool value) { |
| 371 for (auto& item : boolean_properties_) { |
| 372 if (item.first == property) { |
| 373 item.second = value; |
| 374 return; |
| 375 } |
| 376 } |
| 377 |
| 378 boolean_properties_.push_back(std::make_pair(property, value)); |
| 379 } |
| 380 |
| 211 void AccessibleNode::NotifyAttributeChanged( | 381 void AccessibleNode::NotifyAttributeChanged( |
| 212 const blink::QualifiedName& attribute) { | 382 const blink::QualifiedName& attribute) { |
| 213 // TODO(dmazzoni): Make a cleaner API for this rather than pretending | 383 // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| 214 // the DOM attribute changed. | 384 // the DOM attribute changed. |
| 215 if (AXObjectCache* cache = GetAXObjectCache()) | 385 if (AXObjectCache* cache = GetAXObjectCache()) |
| 216 cache->HandleAttributeChanged(attribute, element_); | 386 cache->HandleAttributeChanged(attribute, element_); |
| 217 } | 387 } |
| 218 | 388 |
| 219 AXObjectCache* AccessibleNode::GetAXObjectCache() { | 389 AXObjectCache* AccessibleNode::GetAXObjectCache() { |
| 220 return element_->GetDocument().ExistingAXObjectCache(); | 390 return element_->GetDocument().ExistingAXObjectCache(); |
| 221 } | 391 } |
| 222 | 392 |
| 223 DEFINE_TRACE(AccessibleNode) { | 393 DEFINE_TRACE(AccessibleNode) { |
| 224 visitor->Trace(element_); | 394 visitor->Trace(element_); |
| 225 } | 395 } |
| 226 | 396 |
| 227 } // namespace blink | 397 } // namespace blink |
| OLD | NEW |