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 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 && !item.second.IsNull()) | 30 if (item.first == property && !item.second.IsNull()) |
| 31 return item.second; | 31 return item.second; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 return g_null_atom; | 35 return g_null_atom; |
| 36 } | 36 } |
| 37 | 37 |
| 38 template <typename P, typename T> | |
| 39 static T FindPropertyValue(P property, | |
| 40 bool& is_null, | |
| 41 Vector<std::pair<P, T>>& properties, | |
| 42 T default_value) { | |
| 43 for (const auto& item : properties) { | |
| 44 if (item.first == property) { | |
| 45 is_null = false; | |
| 46 return item.second; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 return default_value; | |
| 51 } | |
| 52 | |
| 38 // static | 53 // static |
| 39 bool AccessibleNode::GetProperty(Element* element, | 54 bool AccessibleNode::GetProperty(Element* element, |
| 40 AOMBooleanProperty property, | 55 AOMBooleanProperty property, |
| 41 bool& is_null) { | 56 bool& is_null) { |
| 42 is_null = true; | 57 is_null = true; |
| 43 if (!element) | |
| 44 return false; | |
| 45 | 58 |
| 46 if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) { | 59 bool default_value = false; |
| 47 for (const auto& item : accessible_node->boolean_properties_) { | 60 if (!element || !element->ExistingAccessibleNode()) |
| 48 if (item.first == property) { | 61 return default_value; |
| 49 is_null = false; | |
| 50 return item.second; | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | 62 |
| 55 return false; | 63 return FindPropertyValue( |
| 64 property, is_null, element->ExistingAccessibleNode()->boolean_properties_, | |
| 65 default_value); | |
| 56 } | 66 } |
| 57 | 67 |
| 58 // static | 68 // static |
| 69 float AccessibleNode::GetProperty(Element* element, | |
| 70 AOMFloatProperty property, | |
| 71 bool& is_null) { | |
| 72 is_null = true; | |
| 73 | |
| 74 float default_value = 0.0; | |
| 75 if (!element || !element->ExistingAccessibleNode()) | |
| 76 return default_value; | |
| 77 | |
| 78 return FindPropertyValue(property, is_null, | |
| 79 element->ExistingAccessibleNode()->float_properties_, | |
| 80 default_value); | |
| 81 } | |
| 82 | |
| 83 // static | |
| 84 int32_t AccessibleNode::GetProperty(Element* element, | |
| 85 AOMIntProperty property, | |
| 86 bool& is_null) { | |
| 87 is_null = true; | |
| 88 | |
| 89 int32_t default_value = 0; | |
| 90 if (!element || !element->ExistingAccessibleNode()) | |
| 91 return default_value; | |
| 92 | |
| 93 return FindPropertyValue(property, is_null, | |
| 94 element->ExistingAccessibleNode()->int_properties_, | |
| 95 default_value); | |
| 96 } | |
| 97 | |
| 98 // static | |
| 99 uint32_t AccessibleNode::GetProperty(Element* element, | |
| 100 AOMUIntProperty property, | |
| 101 bool& is_null) { | |
| 102 is_null = true; | |
| 103 | |
| 104 uint32_t default_value = 0; | |
| 105 if (!element || !element->ExistingAccessibleNode()) | |
| 106 return default_value; | |
| 107 | |
| 108 return FindPropertyValue(property, is_null, | |
| 109 element->ExistingAccessibleNode()->uint_properties_, | |
| 110 default_value); | |
| 111 } | |
| 112 | |
| 113 // static | |
| 59 const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute( | 114 const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute( |
| 60 Element* element, | 115 Element* element, |
| 61 AOMStringProperty property) { | 116 AOMStringProperty property) { |
| 62 if (!element) | 117 if (!element) |
| 63 return g_null_atom; | 118 return g_null_atom; |
| 64 | 119 |
| 65 const AtomicString& result = GetProperty(element, property); | 120 const AtomicString& result = GetProperty(element, property); |
| 66 if (!result.IsNull()) | 121 if (!result.IsNull()) |
| 67 return result; | 122 return result; |
| 68 | 123 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 break; | 204 break; |
| 150 case AOMBooleanProperty::kSelected: | 205 case AOMBooleanProperty::kSelected: |
| 151 attr_value = element->FastGetAttribute(aria_selectedAttr); | 206 attr_value = element->FastGetAttribute(aria_selectedAttr); |
| 152 break; | 207 break; |
| 153 } | 208 } |
| 154 | 209 |
| 155 is_null = attr_value.IsNull(); | 210 is_null = attr_value.IsNull(); |
| 156 return EqualIgnoringASCIICase(attr_value, "true"); | 211 return EqualIgnoringASCIICase(attr_value, "true"); |
| 157 } | 212 } |
| 158 | 213 |
| 214 // static | |
| 215 float AccessibleNode::GetPropertyOrARIAAttribute(Element* element, | |
| 216 AOMFloatProperty property, | |
| 217 bool& is_null) { | |
| 218 is_null = true; | |
| 219 if (!element) | |
| 220 return 0.0; | |
| 221 | |
| 222 float result = GetProperty(element, property, is_null); | |
| 223 if (!is_null) | |
| 224 return result; | |
| 225 | |
| 226 // Fall back on the equivalent ARIA attribute. | |
| 227 AtomicString attr_value; | |
| 228 switch (property) { | |
| 229 case AOMFloatProperty::kValueMax: | |
| 230 attr_value = element->FastGetAttribute(aria_valuemaxAttr); | |
| 231 break; | |
| 232 case AOMFloatProperty::kValueMin: | |
| 233 attr_value = element->FastGetAttribute(aria_valueminAttr); | |
| 234 break; | |
| 235 case AOMFloatProperty::kValueNow: | |
| 236 attr_value = element->FastGetAttribute(aria_valuenowAttr); | |
| 237 break; | |
| 238 } | |
| 239 | |
| 240 is_null = attr_value.IsNull(); | |
| 241 return attr_value.ToFloat(); | |
| 242 } | |
| 243 | |
| 244 // static | |
| 245 uint32_t AccessibleNode::GetPropertyOrARIAAttribute(Element* element, | |
| 246 AOMUIntProperty property, | |
| 247 bool& is_null) { | |
| 248 is_null = true; | |
| 249 if (!element) | |
| 250 return 0; | |
| 251 | |
| 252 int32_t result = GetProperty(element, property, is_null); | |
| 253 if (!is_null) | |
| 254 return result; | |
| 255 | |
| 256 // Fall back on the equivalent ARIA attribute. | |
| 257 AtomicString attr_value; | |
| 258 switch (property) { | |
| 259 case AOMUIntProperty::kColIndex: | |
| 260 attr_value = element->FastGetAttribute(aria_colindexAttr); | |
| 261 break; | |
| 262 case AOMUIntProperty::kColSpan: | |
| 263 attr_value = element->FastGetAttribute(aria_colspanAttr); | |
| 264 break; | |
| 265 case AOMUIntProperty::kLevel: | |
| 266 attr_value = element->FastGetAttribute(aria_levelAttr); | |
| 267 break; | |
| 268 case AOMUIntProperty::kPosInSet: | |
| 269 attr_value = element->FastGetAttribute(aria_posinsetAttr); | |
| 270 break; | |
| 271 case AOMUIntProperty::kRowIndex: | |
| 272 attr_value = element->FastGetAttribute(aria_rowindexAttr); | |
| 273 break; | |
| 274 case AOMUIntProperty::kRowSpan: | |
| 275 attr_value = element->FastGetAttribute(aria_rowspanAttr); | |
| 276 break; | |
| 277 } | |
| 278 | |
| 279 is_null = attr_value.IsNull(); | |
| 280 return attr_value.GetString().ToUInt(); | |
|
tkent
2017/07/28 02:31:14
Is String::ToUInt() correct for aria attribute par
| |
| 281 } | |
| 282 | |
| 283 // static | |
| 284 int32_t AccessibleNode::GetPropertyOrARIAAttribute(Element* element, | |
| 285 AOMIntProperty property, | |
| 286 bool& is_null) { | |
| 287 is_null = true; | |
| 288 if (!element) | |
| 289 return 0; | |
| 290 | |
| 291 int32_t result = GetProperty(element, property, is_null); | |
| 292 if (!is_null) | |
| 293 return result; | |
| 294 | |
| 295 // Fall back on the equivalent ARIA attribute. | |
| 296 AtomicString attr_value; | |
| 297 switch (property) { | |
| 298 case AOMIntProperty::kColCount: | |
| 299 attr_value = element->FastGetAttribute(aria_colcountAttr); | |
| 300 break; | |
| 301 case AOMIntProperty::kRowCount: | |
| 302 attr_value = element->FastGetAttribute(aria_rowcountAttr); | |
| 303 break; | |
| 304 case AOMIntProperty::kSetSize: | |
| 305 attr_value = element->FastGetAttribute(aria_setsizeAttr); | |
| 306 break; | |
| 307 } | |
| 308 | |
| 309 is_null = attr_value.IsNull(); | |
| 310 return attr_value.ToInt(); | |
|
tkent
2017/07/28 02:31:14
Ditto.
| |
| 311 } | |
| 312 | |
| 159 bool AccessibleNode::atomic(bool& is_null) const { | 313 bool AccessibleNode::atomic(bool& is_null) const { |
| 160 return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null); | 314 return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null); |
| 161 } | 315 } |
| 162 | 316 |
| 163 void AccessibleNode::setAtomic(bool atomic, bool is_null) { | 317 void AccessibleNode::setAtomic(bool atomic, bool is_null) { |
| 164 SetBooleanProperty(AOMBooleanProperty::kAtomic, atomic, is_null); | 318 SetBooleanProperty(AOMBooleanProperty::kAtomic, atomic, is_null); |
| 165 NotifyAttributeChanged(aria_atomicAttr); | 319 NotifyAttributeChanged(aria_atomicAttr); |
| 166 } | 320 } |
| 167 | 321 |
| 168 AtomicString AccessibleNode::autocomplete() const { | 322 AtomicString AccessibleNode::autocomplete() const { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 185 | 339 |
| 186 AtomicString AccessibleNode::checked() const { | 340 AtomicString AccessibleNode::checked() const { |
| 187 return GetProperty(element_, AOMStringProperty::kChecked); | 341 return GetProperty(element_, AOMStringProperty::kChecked); |
| 188 } | 342 } |
| 189 | 343 |
| 190 void AccessibleNode::setChecked(const AtomicString& checked) { | 344 void AccessibleNode::setChecked(const AtomicString& checked) { |
| 191 SetStringProperty(AOMStringProperty::kChecked, checked); | 345 SetStringProperty(AOMStringProperty::kChecked, checked); |
| 192 NotifyAttributeChanged(aria_checkedAttr); | 346 NotifyAttributeChanged(aria_checkedAttr); |
| 193 } | 347 } |
| 194 | 348 |
| 349 int32_t AccessibleNode::colCount(bool& is_null) const { | |
| 350 return GetProperty(element_, AOMIntProperty::kColCount, is_null); | |
| 351 } | |
| 352 | |
| 353 void AccessibleNode::setColCount(int32_t col_count, bool is_null) { | |
| 354 SetIntProperty(AOMIntProperty::kColCount, col_count, is_null); | |
| 355 NotifyAttributeChanged(aria_colcountAttr); | |
| 356 } | |
| 357 | |
| 358 uint32_t AccessibleNode::colIndex(bool& is_null) const { | |
| 359 return GetProperty(element_, AOMUIntProperty::kColIndex, is_null); | |
| 360 } | |
| 361 | |
| 362 void AccessibleNode::setColIndex(uint32_t col_index, bool is_null) { | |
| 363 SetUIntProperty(AOMUIntProperty::kColIndex, col_index, is_null); | |
| 364 NotifyAttributeChanged(aria_colindexAttr); | |
| 365 } | |
| 366 | |
| 367 uint32_t AccessibleNode::colSpan(bool& is_null) const { | |
| 368 return GetProperty(element_, AOMUIntProperty::kColSpan, is_null); | |
| 369 } | |
| 370 | |
| 371 void AccessibleNode::setColSpan(uint32_t col_span, bool is_null) { | |
| 372 SetUIntProperty(AOMUIntProperty::kColSpan, col_span, is_null); | |
| 373 NotifyAttributeChanged(aria_colspanAttr); | |
| 374 } | |
| 375 | |
| 195 AtomicString AccessibleNode::current() const { | 376 AtomicString AccessibleNode::current() const { |
| 196 return GetProperty(element_, AOMStringProperty::kCurrent); | 377 return GetProperty(element_, AOMStringProperty::kCurrent); |
| 197 } | 378 } |
| 198 | 379 |
| 199 void AccessibleNode::setCurrent(const AtomicString& current) { | 380 void AccessibleNode::setCurrent(const AtomicString& current) { |
| 200 SetStringProperty(AOMStringProperty::kCurrent, current); | 381 SetStringProperty(AOMStringProperty::kCurrent, current); |
| 201 | 382 |
| 202 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache()) | 383 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache()) |
| 203 cache->HandleAttributeChanged(aria_currentAttr, element_); | 384 cache->HandleAttributeChanged(aria_currentAttr, element_); |
| 204 } | 385 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 431 |
| 251 AtomicString AccessibleNode::label() const { | 432 AtomicString AccessibleNode::label() const { |
| 252 return GetProperty(element_, AOMStringProperty::kLabel); | 433 return GetProperty(element_, AOMStringProperty::kLabel); |
| 253 } | 434 } |
| 254 | 435 |
| 255 void AccessibleNode::setLabel(const AtomicString& label) { | 436 void AccessibleNode::setLabel(const AtomicString& label) { |
| 256 SetStringProperty(AOMStringProperty::kLabel, label); | 437 SetStringProperty(AOMStringProperty::kLabel, label); |
| 257 NotifyAttributeChanged(aria_labelAttr); | 438 NotifyAttributeChanged(aria_labelAttr); |
| 258 } | 439 } |
| 259 | 440 |
| 441 uint32_t AccessibleNode::level(bool& is_null) const { | |
| 442 return GetProperty(element_, AOMUIntProperty::kLevel, is_null); | |
| 443 } | |
| 444 | |
| 445 void AccessibleNode::setLevel(uint32_t level, bool is_null) { | |
| 446 SetUIntProperty(AOMUIntProperty::kLevel, level, is_null); | |
| 447 NotifyAttributeChanged(aria_levelAttr); | |
| 448 } | |
| 449 | |
| 260 AtomicString AccessibleNode::live() const { | 450 AtomicString AccessibleNode::live() const { |
| 261 return GetProperty(element_, AOMStringProperty::kLive); | 451 return GetProperty(element_, AOMStringProperty::kLive); |
| 262 } | 452 } |
| 263 | 453 |
| 264 void AccessibleNode::setLive(const AtomicString& live) { | 454 void AccessibleNode::setLive(const AtomicString& live) { |
| 265 SetStringProperty(AOMStringProperty::kLive, live); | 455 SetStringProperty(AOMStringProperty::kLive, live); |
| 266 NotifyAttributeChanged(aria_liveAttr); | 456 NotifyAttributeChanged(aria_liveAttr); |
| 267 } | 457 } |
| 268 | 458 |
| 269 bool AccessibleNode::modal(bool& is_null) const { | 459 bool AccessibleNode::modal(bool& is_null) const { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 | 495 |
| 306 AtomicString AccessibleNode::placeholder() const { | 496 AtomicString AccessibleNode::placeholder() const { |
| 307 return GetProperty(element_, AOMStringProperty::kPlaceholder); | 497 return GetProperty(element_, AOMStringProperty::kPlaceholder); |
| 308 } | 498 } |
| 309 | 499 |
| 310 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { | 500 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { |
| 311 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder); | 501 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder); |
| 312 NotifyAttributeChanged(aria_placeholderAttr); | 502 NotifyAttributeChanged(aria_placeholderAttr); |
| 313 } | 503 } |
| 314 | 504 |
| 505 uint32_t AccessibleNode::posInSet(bool& is_null) const { | |
| 506 return GetProperty(element_, AOMUIntProperty::kPosInSet, is_null); | |
| 507 } | |
| 508 | |
| 509 void AccessibleNode::setPosInSet(uint32_t pos_in_set, bool is_null) { | |
| 510 SetUIntProperty(AOMUIntProperty::kPosInSet, pos_in_set, is_null); | |
| 511 NotifyAttributeChanged(aria_posinsetAttr); | |
| 512 } | |
| 513 | |
| 315 bool AccessibleNode::readOnly(bool& is_null) const { | 514 bool AccessibleNode::readOnly(bool& is_null) const { |
| 316 return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null); | 515 return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null); |
| 317 } | 516 } |
| 318 | 517 |
| 319 void AccessibleNode::setReadOnly(bool read_only, bool is_null) { | 518 void AccessibleNode::setReadOnly(bool read_only, bool is_null) { |
| 320 SetBooleanProperty(AOMBooleanProperty::kReadOnly, read_only, is_null); | 519 SetBooleanProperty(AOMBooleanProperty::kReadOnly, read_only, is_null); |
| 321 NotifyAttributeChanged(aria_readonlyAttr); | 520 NotifyAttributeChanged(aria_readonlyAttr); |
| 322 } | 521 } |
| 323 | 522 |
| 324 AtomicString AccessibleNode::relevant() const { | 523 AtomicString AccessibleNode::relevant() const { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 350 | 549 |
| 351 AtomicString AccessibleNode::roleDescription() const { | 550 AtomicString AccessibleNode::roleDescription() const { |
| 352 return GetProperty(element_, AOMStringProperty::kRoleDescription); | 551 return GetProperty(element_, AOMStringProperty::kRoleDescription); |
| 353 } | 552 } |
| 354 | 553 |
| 355 void AccessibleNode::setRoleDescription(const AtomicString& role_description) { | 554 void AccessibleNode::setRoleDescription(const AtomicString& role_description) { |
| 356 SetStringProperty(AOMStringProperty::kRoleDescription, role_description); | 555 SetStringProperty(AOMStringProperty::kRoleDescription, role_description); |
| 357 NotifyAttributeChanged(aria_roledescriptionAttr); | 556 NotifyAttributeChanged(aria_roledescriptionAttr); |
| 358 } | 557 } |
| 359 | 558 |
| 559 int32_t AccessibleNode::rowCount(bool& is_null) const { | |
| 560 return GetProperty(element_, AOMIntProperty::kRowCount, is_null); | |
| 561 } | |
| 562 | |
| 563 void AccessibleNode::setRowCount(int32_t row_count, bool is_null) { | |
| 564 SetIntProperty(AOMIntProperty::kRowCount, row_count, is_null); | |
| 565 NotifyAttributeChanged(aria_rowcountAttr); | |
| 566 } | |
| 567 | |
| 568 uint32_t AccessibleNode::rowIndex(bool& is_null) const { | |
| 569 return GetProperty(element_, AOMUIntProperty::kRowIndex, is_null); | |
| 570 } | |
| 571 | |
| 572 void AccessibleNode::setRowIndex(uint32_t row_index, bool is_null) { | |
| 573 SetUIntProperty(AOMUIntProperty::kRowIndex, row_index, is_null); | |
| 574 NotifyAttributeChanged(aria_rowindexAttr); | |
| 575 } | |
| 576 | |
| 577 uint32_t AccessibleNode::rowSpan(bool& is_null) const { | |
| 578 return GetProperty(element_, AOMUIntProperty::kRowSpan, is_null); | |
| 579 } | |
| 580 | |
| 581 void AccessibleNode::setRowSpan(uint32_t row_span, bool is_null) { | |
| 582 SetUIntProperty(AOMUIntProperty::kRowSpan, row_span, is_null); | |
| 583 NotifyAttributeChanged(aria_rowspanAttr); | |
| 584 } | |
| 585 | |
| 360 bool AccessibleNode::selected(bool& is_null) const { | 586 bool AccessibleNode::selected(bool& is_null) const { |
| 361 return GetProperty(element_, AOMBooleanProperty::kSelected, is_null); | 587 return GetProperty(element_, AOMBooleanProperty::kSelected, is_null); |
| 362 } | 588 } |
| 363 | 589 |
| 364 void AccessibleNode::setSelected(bool selected, bool is_null) { | 590 void AccessibleNode::setSelected(bool selected, bool is_null) { |
| 365 SetBooleanProperty(AOMBooleanProperty::kSelected, selected, is_null); | 591 SetBooleanProperty(AOMBooleanProperty::kSelected, selected, is_null); |
| 366 NotifyAttributeChanged(aria_selectedAttr); | 592 NotifyAttributeChanged(aria_selectedAttr); |
| 367 } | 593 } |
| 368 | 594 |
| 595 int32_t AccessibleNode::setSize(bool& is_null) const { | |
| 596 return GetProperty(element_, AOMIntProperty::kSetSize, is_null); | |
| 597 } | |
| 598 | |
| 599 void AccessibleNode::setSetSize(int32_t set_size, bool is_null) { | |
| 600 SetIntProperty(AOMIntProperty::kSetSize, set_size, is_null); | |
| 601 NotifyAttributeChanged(aria_setsizeAttr); | |
| 602 } | |
| 603 | |
| 369 AtomicString AccessibleNode::sort() const { | 604 AtomicString AccessibleNode::sort() const { |
| 370 return GetProperty(element_, AOMStringProperty::kSort); | 605 return GetProperty(element_, AOMStringProperty::kSort); |
| 371 } | 606 } |
| 372 | 607 |
| 373 void AccessibleNode::setSort(const AtomicString& sort) { | 608 void AccessibleNode::setSort(const AtomicString& sort) { |
| 374 SetStringProperty(AOMStringProperty::kSort, sort); | 609 SetStringProperty(AOMStringProperty::kSort, sort); |
| 375 NotifyAttributeChanged(aria_sortAttr); | 610 NotifyAttributeChanged(aria_sortAttr); |
| 376 } | 611 } |
| 377 | 612 |
| 613 float AccessibleNode::valueMax(bool& is_null) const { | |
| 614 return GetProperty(element_, AOMFloatProperty::kValueMax, is_null); | |
| 615 } | |
| 616 | |
| 617 void AccessibleNode::setValueMax(float value_max, bool is_null) { | |
| 618 SetFloatProperty(AOMFloatProperty::kValueMax, value_max, is_null); | |
| 619 NotifyAttributeChanged(aria_valuemaxAttr); | |
| 620 } | |
| 621 | |
| 622 float AccessibleNode::valueMin(bool& is_null) const { | |
| 623 return GetProperty(element_, AOMFloatProperty::kValueMin, is_null); | |
| 624 } | |
| 625 | |
| 626 void AccessibleNode::setValueMin(float value_min, bool is_null) { | |
| 627 SetFloatProperty(AOMFloatProperty::kValueMin, value_min, is_null); | |
| 628 NotifyAttributeChanged(aria_valueminAttr); | |
| 629 } | |
| 630 | |
| 631 float AccessibleNode::valueNow(bool& is_null) const { | |
| 632 return GetProperty(element_, AOMFloatProperty::kValueNow, is_null); | |
| 633 } | |
| 634 | |
| 635 void AccessibleNode::setValueNow(float value_now, bool is_null) { | |
| 636 SetFloatProperty(AOMFloatProperty::kValueNow, value_now, is_null); | |
| 637 NotifyAttributeChanged(aria_valuenowAttr); | |
| 638 } | |
| 639 | |
| 378 AtomicString AccessibleNode::valueText() const { | 640 AtomicString AccessibleNode::valueText() const { |
| 379 return GetProperty(element_, AOMStringProperty::kValueText); | 641 return GetProperty(element_, AOMStringProperty::kValueText); |
| 380 } | 642 } |
| 381 | 643 |
| 382 void AccessibleNode::setValueText(const AtomicString& value_text) { | 644 void AccessibleNode::setValueText(const AtomicString& value_text) { |
| 383 SetStringProperty(AOMStringProperty::kValueText, value_text); | 645 SetStringProperty(AOMStringProperty::kValueText, value_text); |
| 384 NotifyAttributeChanged(aria_valuetextAttr); | 646 NotifyAttributeChanged(aria_valuetextAttr); |
| 385 } | 647 } |
| 386 | 648 |
| 387 void AccessibleNode::SetStringProperty(AOMStringProperty property, | 649 void AccessibleNode::SetStringProperty(AOMStringProperty property, |
| 388 const AtomicString& value) { | 650 const AtomicString& value) { |
| 389 for (auto& item : string_properties_) { | 651 for (auto& item : string_properties_) { |
| 390 if (item.first == property) { | 652 if (item.first == property) { |
| 391 item.second = value; | 653 item.second = value; |
| 392 return; | 654 return; |
| 393 } | 655 } |
| 394 } | 656 } |
| 395 | 657 |
| 396 string_properties_.push_back(std::make_pair(property, value)); | 658 string_properties_.push_back(std::make_pair(property, value)); |
| 397 } | 659 } |
| 398 | 660 |
| 399 void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property, | 661 template <typename P, typename T> |
| 400 bool value, | 662 static void SetProperty(P property, |
| 401 bool is_null) { | 663 T value, |
| 402 for (size_t i = 0; i < boolean_properties_.size(); i++) { | 664 bool is_null, |
| 403 auto& item = boolean_properties_[i]; | 665 Vector<std::pair<P, T>>& properties) { |
| 666 for (size_t i = 0; i < properties.size(); i++) { | |
| 667 auto& item = properties[i]; | |
| 404 if (item.first == property) { | 668 if (item.first == property) { |
| 405 if (is_null) | 669 if (is_null) |
| 406 boolean_properties_.erase(i); | 670 properties.erase(i); |
| 407 else | 671 else |
| 408 item.second = value; | 672 item.second = value; |
| 409 return; | 673 return; |
| 410 } | 674 } |
| 411 } | 675 } |
| 412 | 676 |
| 413 boolean_properties_.push_back(std::make_pair(property, value)); | 677 properties.push_back(std::make_pair(property, value)); |
| 678 } | |
| 679 | |
| 680 void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property, | |
| 681 bool value, | |
| 682 bool is_null) { | |
| 683 SetProperty(property, value, is_null, boolean_properties_); | |
| 684 } | |
| 685 | |
| 686 void AccessibleNode::SetIntProperty(AOMIntProperty property, | |
| 687 int32_t value, | |
| 688 bool is_null) { | |
| 689 SetProperty(property, value, is_null, int_properties_); | |
| 690 } | |
| 691 | |
| 692 void AccessibleNode::SetUIntProperty(AOMUIntProperty property, | |
| 693 uint32_t value, | |
| 694 bool is_null) { | |
| 695 SetProperty(property, value, is_null, uint_properties_); | |
| 696 } | |
| 697 | |
| 698 void AccessibleNode::SetFloatProperty(AOMFloatProperty property, | |
| 699 float value, | |
| 700 bool is_null) { | |
| 701 SetProperty(property, value, is_null, float_properties_); | |
| 414 } | 702 } |
| 415 | 703 |
| 416 void AccessibleNode::NotifyAttributeChanged( | 704 void AccessibleNode::NotifyAttributeChanged( |
| 417 const blink::QualifiedName& attribute) { | 705 const blink::QualifiedName& attribute) { |
| 418 // TODO(dmazzoni): Make a cleaner API for this rather than pretending | 706 // TODO(dmazzoni): Make a cleaner API for this rather than pretending |
| 419 // the DOM attribute changed. | 707 // the DOM attribute changed. |
| 420 if (AXObjectCache* cache = GetAXObjectCache()) | 708 if (AXObjectCache* cache = GetAXObjectCache()) |
| 421 cache->HandleAttributeChanged(attribute, element_); | 709 cache->HandleAttributeChanged(attribute, element_); |
| 422 } | 710 } |
| 423 | 711 |
| 424 AXObjectCache* AccessibleNode::GetAXObjectCache() { | 712 AXObjectCache* AccessibleNode::GetAXObjectCache() { |
| 425 return element_->GetDocument().ExistingAXObjectCache(); | 713 return element_->GetDocument().ExistingAXObjectCache(); |
| 426 } | 714 } |
| 427 | 715 |
| 428 DEFINE_TRACE(AccessibleNode) { | 716 DEFINE_TRACE(AccessibleNode) { |
| 429 visitor->Trace(element_); | 717 visitor->Trace(element_); |
| 430 } | 718 } |
| 431 | 719 |
| 432 } // namespace blink | 720 } // namespace blink |
| OLD | NEW |