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