Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: third_party/WebKit/Source/core/dom/AccessibleNode.cpp

Issue 2805493002: Boolean properties for Accessibility Object Model Phase 1 (Closed)
Patch Set: Back to previous patchset, ready to land Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 14 using namespace HTMLNames;
15 15
16 AccessibleNode::AccessibleNode(Element* element) : element_(element) { 16 AccessibleNode::AccessibleNode(Element* element) : element_(element) {
17 DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled()); 17 DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled());
18 } 18 }
19 19
20 AccessibleNode::~AccessibleNode() {} 20 AccessibleNode::~AccessibleNode() {}
21 21
22 // static 22 // static
23 const AtomicString& AccessibleNode::GetProperty(Element* element, 23 const AtomicString& AccessibleNode::GetProperty(Element* element,
24 AOMStringProperty property) { 24 AOMStringProperty property) {
25 if (!element) 25 if (!element)
26 return g_null_atom; 26 return g_null_atom;
27 27
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 && !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 // static 38 // static
39 bool AccessibleNode::GetProperty(Element* element,
40 AOMBooleanProperty property,
41 bool& is_null) {
42 is_null = true;
43 if (!element)
44 return false;
45
46 if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) {
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 }
54
55 return false;
56 }
57
58 // static
39 const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute( 59 const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute(
40 Element* element, 60 Element* element,
41 AOMStringProperty property) { 61 AOMStringProperty property) {
42 if (!element) 62 if (!element)
43 return g_null_atom; 63 return g_null_atom;
44 64
45 const AtomicString& result = GetProperty(element, property); 65 const AtomicString& result = GetProperty(element, property);
46 if (!result.IsNull()) 66 if (!result.IsNull())
47 return result; 67 return result;
48 68
49 // Fall back on the equivalent ARIA attribute. 69 // Fall back on the equivalent ARIA attribute.
50 switch (property) { 70 switch (property) {
51 case AOMStringProperty::kAutocomplete: 71 case AOMStringProperty::kAutocomplete:
52 return element->getAttribute(aria_autocompleteAttr); 72 return element->FastGetAttribute(aria_autocompleteAttr);
53 case AOMStringProperty::kChecked: 73 case AOMStringProperty::kChecked:
54 return element->getAttribute(aria_checkedAttr); 74 return element->FastGetAttribute(aria_checkedAttr);
55 case AOMStringProperty::kCurrent: 75 case AOMStringProperty::kCurrent:
56 return element->getAttribute(aria_currentAttr); 76 return element->FastGetAttribute(aria_currentAttr);
57 case AOMStringProperty::kInvalid: 77 case AOMStringProperty::kInvalid:
58 return element->getAttribute(aria_invalidAttr); 78 return element->FastGetAttribute(aria_invalidAttr);
59 case AOMStringProperty::kKeyShortcuts: 79 case AOMStringProperty::kKeyShortcuts:
60 return element->getAttribute(aria_keyshortcutsAttr); 80 return element->FastGetAttribute(aria_keyshortcutsAttr);
61 case AOMStringProperty::kLabel: 81 case AOMStringProperty::kLabel:
62 return element->getAttribute(aria_labelAttr); 82 return element->FastGetAttribute(aria_labelAttr);
63 case AOMStringProperty::kLive: 83 case AOMStringProperty::kLive:
64 return element->getAttribute(aria_liveAttr); 84 return element->FastGetAttribute(aria_liveAttr);
65 case AOMStringProperty::kOrientation: 85 case AOMStringProperty::kOrientation:
66 return element->getAttribute(aria_orientationAttr); 86 return element->FastGetAttribute(aria_orientationAttr);
67 case AOMStringProperty::kPlaceholder: 87 case AOMStringProperty::kPlaceholder:
68 return element->getAttribute(aria_placeholderAttr); 88 return element->FastGetAttribute(aria_placeholderAttr);
69 case AOMStringProperty::kRelevant: 89 case AOMStringProperty::kRelevant:
70 return element->getAttribute(aria_relevantAttr); 90 return element->FastGetAttribute(aria_relevantAttr);
71 case AOMStringProperty::kRole: 91 case AOMStringProperty::kRole:
72 return element->getAttribute(roleAttr); 92 return element->FastGetAttribute(roleAttr);
73 case AOMStringProperty::kRoleDescription: 93 case AOMStringProperty::kRoleDescription:
74 return element->getAttribute(aria_roledescriptionAttr); 94 return element->FastGetAttribute(aria_roledescriptionAttr);
75 case AOMStringProperty::kSort: 95 case AOMStringProperty::kSort:
76 return element->getAttribute(aria_sortAttr); 96 return element->FastGetAttribute(aria_sortAttr);
77 case AOMStringProperty::kValueText: 97 case AOMStringProperty::kValueText:
78 return element->getAttribute(aria_valuetextAttr); 98 return element->FastGetAttribute(aria_valuetextAttr);
79 } 99 }
80 100
81 NOTREACHED(); 101 NOTREACHED();
82 return g_null_atom; 102 return g_null_atom;
83 } 103 }
84 104
105 // static
106 bool AccessibleNode::GetPropertyOrARIAAttribute(Element* element,
107 AOMBooleanProperty property,
108 bool& is_null) {
109 is_null = true;
110 if (!element)
111 return false;
112
113 bool result = GetProperty(element, property, is_null);
114 if (!is_null)
115 return result;
116
117 // Fall back on the equivalent ARIA attribute.
118 AtomicString attr_value;
119 switch (property) {
120 case AOMBooleanProperty::kAtomic:
121 attr_value = element->FastGetAttribute(aria_atomicAttr);
122 break;
123 case AOMBooleanProperty::kBusy:
124 attr_value = element->FastGetAttribute(aria_busyAttr);
125 break;
126 case AOMBooleanProperty::kDisabled:
127 attr_value = element->FastGetAttribute(aria_disabledAttr);
128 break;
129 case AOMBooleanProperty::kExpanded:
130 attr_value = element->FastGetAttribute(aria_expandedAttr);
131 break;
132 case AOMBooleanProperty::kHidden:
133 attr_value = element->FastGetAttribute(aria_hiddenAttr);
134 break;
135 case AOMBooleanProperty::kModal:
136 attr_value = element->FastGetAttribute(aria_modalAttr);
137 break;
138 case AOMBooleanProperty::kMultiline:
139 attr_value = element->FastGetAttribute(aria_multilineAttr);
140 break;
141 case AOMBooleanProperty::kMultiselectable:
142 attr_value = element->FastGetAttribute(aria_multiselectableAttr);
143 break;
144 case AOMBooleanProperty::kReadOnly:
145 attr_value = element->FastGetAttribute(aria_readonlyAttr);
146 break;
147 case AOMBooleanProperty::kRequired:
148 attr_value = element->FastGetAttribute(aria_requiredAttr);
149 break;
150 case AOMBooleanProperty::kSelected:
151 attr_value = element->FastGetAttribute(aria_selectedAttr);
152 break;
153 }
154
155 is_null = attr_value.IsNull();
156 return EqualIgnoringASCIICase(attr_value, "true");
157 }
158
159 bool AccessibleNode::atomic(bool& is_null) const {
160 return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null);
161 }
162
163 void AccessibleNode::setAtomic(bool atomic, bool is_null) {
164 SetBooleanProperty(AOMBooleanProperty::kAtomic, atomic, is_null);
165 NotifyAttributeChanged(aria_atomicAttr);
166 }
167
85 AtomicString AccessibleNode::autocomplete() const { 168 AtomicString AccessibleNode::autocomplete() const {
86 return GetProperty(element_, AOMStringProperty::kAutocomplete); 169 return GetProperty(element_, AOMStringProperty::kAutocomplete);
87 } 170 }
88 171
89 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) { 172 void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) {
90 SetStringProperty(AOMStringProperty::kAutocomplete, autocomplete); 173 SetStringProperty(AOMStringProperty::kAutocomplete, autocomplete);
91 NotifyAttributeChanged(aria_autocompleteAttr); 174 NotifyAttributeChanged(aria_autocompleteAttr);
92 } 175 }
93 176
177 bool AccessibleNode::busy(bool& is_null) const {
178 return GetProperty(element_, AOMBooleanProperty::kBusy, is_null);
179 }
180
181 void AccessibleNode::setBusy(bool busy, bool is_null) {
182 SetBooleanProperty(AOMBooleanProperty::kBusy, busy, is_null);
183 NotifyAttributeChanged(aria_busyAttr);
184 }
185
94 AtomicString AccessibleNode::checked() const { 186 AtomicString AccessibleNode::checked() const {
95 return GetProperty(element_, AOMStringProperty::kChecked); 187 return GetProperty(element_, AOMStringProperty::kChecked);
96 } 188 }
97 189
98 void AccessibleNode::setChecked(const AtomicString& checked) { 190 void AccessibleNode::setChecked(const AtomicString& checked) {
99 SetStringProperty(AOMStringProperty::kChecked, checked); 191 SetStringProperty(AOMStringProperty::kChecked, checked);
100 NotifyAttributeChanged(aria_checkedAttr); 192 NotifyAttributeChanged(aria_checkedAttr);
101 } 193 }
102 194
103 AtomicString AccessibleNode::current() const { 195 AtomicString AccessibleNode::current() const {
104 return GetProperty(element_, AOMStringProperty::kCurrent); 196 return GetProperty(element_, AOMStringProperty::kCurrent);
105 } 197 }
106 198
107 void AccessibleNode::setCurrent(const AtomicString& current) { 199 void AccessibleNode::setCurrent(const AtomicString& current) {
108 SetStringProperty(AOMStringProperty::kCurrent, current); 200 SetStringProperty(AOMStringProperty::kCurrent, current);
109 201
110 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache()) 202 if (AXObjectCache* cache = element_->GetDocument().ExistingAXObjectCache())
111 cache->HandleAttributeChanged(aria_currentAttr, element_); 203 cache->HandleAttributeChanged(aria_currentAttr, element_);
112 } 204 }
113 205
206 bool AccessibleNode::disabled(bool& is_null) const {
207 return GetProperty(element_, AOMBooleanProperty::kDisabled, is_null);
208 }
209
210 void AccessibleNode::setDisabled(bool disabled, bool is_null) {
211 SetBooleanProperty(AOMBooleanProperty::kDisabled, disabled, is_null);
212 NotifyAttributeChanged(aria_disabledAttr);
213 }
214
215 bool AccessibleNode::expanded(bool& is_null) const {
216 return GetProperty(element_, AOMBooleanProperty::kExpanded, is_null);
217 }
218
219 void AccessibleNode::setExpanded(bool expanded, bool is_null) {
220 SetBooleanProperty(AOMBooleanProperty::kExpanded, expanded, is_null);
221 NotifyAttributeChanged(aria_expandedAttr);
222 }
223
224 bool AccessibleNode::hidden(bool& is_null) const {
225 return GetProperty(element_, AOMBooleanProperty::kHidden, is_null);
226 }
227
228 void AccessibleNode::setHidden(bool hidden, bool is_null) {
229 SetBooleanProperty(AOMBooleanProperty::kHidden, hidden, is_null);
230 NotifyAttributeChanged(aria_hiddenAttr);
231 }
232
114 AtomicString AccessibleNode::invalid() const { 233 AtomicString AccessibleNode::invalid() const {
115 return GetProperty(element_, AOMStringProperty::kInvalid); 234 return GetProperty(element_, AOMStringProperty::kInvalid);
116 } 235 }
117 236
118 void AccessibleNode::setInvalid(const AtomicString& invalid) { 237 void AccessibleNode::setInvalid(const AtomicString& invalid) {
119 SetStringProperty(AOMStringProperty::kInvalid, invalid); 238 SetStringProperty(AOMStringProperty::kInvalid, invalid);
120 NotifyAttributeChanged(aria_invalidAttr); 239 NotifyAttributeChanged(aria_invalidAttr);
121 } 240 }
122 241
123 AtomicString AccessibleNode::keyShortcuts() const { 242 AtomicString AccessibleNode::keyShortcuts() const {
(...skipping 16 matching lines...) Expand all
140 259
141 AtomicString AccessibleNode::live() const { 260 AtomicString AccessibleNode::live() const {
142 return GetProperty(element_, AOMStringProperty::kLive); 261 return GetProperty(element_, AOMStringProperty::kLive);
143 } 262 }
144 263
145 void AccessibleNode::setLive(const AtomicString& live) { 264 void AccessibleNode::setLive(const AtomicString& live) {
146 SetStringProperty(AOMStringProperty::kLive, live); 265 SetStringProperty(AOMStringProperty::kLive, live);
147 NotifyAttributeChanged(aria_liveAttr); 266 NotifyAttributeChanged(aria_liveAttr);
148 } 267 }
149 268
269 bool AccessibleNode::modal(bool& is_null) const {
270 return GetProperty(element_, AOMBooleanProperty::kModal, is_null);
271 }
272
273 void AccessibleNode::setModal(bool modal, bool is_null) {
274 SetBooleanProperty(AOMBooleanProperty::kModal, modal, is_null);
275 NotifyAttributeChanged(aria_modalAttr);
276 }
277
278 bool AccessibleNode::multiline(bool& is_null) const {
279 return GetProperty(element_, AOMBooleanProperty::kMultiline, is_null);
280 }
281
282 void AccessibleNode::setMultiline(bool multiline, bool is_null) {
283 SetBooleanProperty(AOMBooleanProperty::kMultiline, multiline, is_null);
284 NotifyAttributeChanged(aria_multilineAttr);
285 }
286
287 bool AccessibleNode::multiselectable(bool& is_null) const {
288 return GetProperty(element_, AOMBooleanProperty::kMultiselectable, is_null);
289 }
290
291 void AccessibleNode::setMultiselectable(bool multiselectable, bool is_null) {
292 SetBooleanProperty(AOMBooleanProperty::kMultiselectable, multiselectable,
293 is_null);
294 NotifyAttributeChanged(aria_multiselectableAttr);
295 }
296
150 AtomicString AccessibleNode::orientation() const { 297 AtomicString AccessibleNode::orientation() const {
151 return GetProperty(element_, AOMStringProperty::kOrientation); 298 return GetProperty(element_, AOMStringProperty::kOrientation);
152 } 299 }
153 300
154 void AccessibleNode::setOrientation(const AtomicString& orientation) { 301 void AccessibleNode::setOrientation(const AtomicString& orientation) {
155 SetStringProperty(AOMStringProperty::kOrientation, orientation); 302 SetStringProperty(AOMStringProperty::kOrientation, orientation);
156 NotifyAttributeChanged(aria_orientationAttr); 303 NotifyAttributeChanged(aria_orientationAttr);
157 } 304 }
158 305
159 AtomicString AccessibleNode::placeholder() const { 306 AtomicString AccessibleNode::placeholder() const {
160 return GetProperty(element_, AOMStringProperty::kPlaceholder); 307 return GetProperty(element_, AOMStringProperty::kPlaceholder);
161 } 308 }
162 309
163 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { 310 void AccessibleNode::setPlaceholder(const AtomicString& placeholder) {
164 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder); 311 SetStringProperty(AOMStringProperty::kPlaceholder, placeholder);
165 NotifyAttributeChanged(aria_placeholderAttr); 312 NotifyAttributeChanged(aria_placeholderAttr);
166 } 313 }
167 314
315 bool AccessibleNode::readOnly(bool& is_null) const {
316 return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null);
317 }
318
319 void AccessibleNode::setReadOnly(bool read_only, bool is_null) {
320 SetBooleanProperty(AOMBooleanProperty::kReadOnly, read_only, is_null);
321 NotifyAttributeChanged(aria_readonlyAttr);
322 }
323
168 AtomicString AccessibleNode::relevant() const { 324 AtomicString AccessibleNode::relevant() const {
169 return GetProperty(element_, AOMStringProperty::kRelevant); 325 return GetProperty(element_, AOMStringProperty::kRelevant);
170 } 326 }
171 327
172 void AccessibleNode::setRelevant(const AtomicString& relevant) { 328 void AccessibleNode::setRelevant(const AtomicString& relevant) {
173 SetStringProperty(AOMStringProperty::kRelevant, relevant); 329 SetStringProperty(AOMStringProperty::kRelevant, relevant);
174 NotifyAttributeChanged(aria_relevantAttr); 330 NotifyAttributeChanged(aria_relevantAttr);
175 } 331 }
176 332
333 bool AccessibleNode::required(bool& is_null) const {
334 return GetProperty(element_, AOMBooleanProperty::kRequired, is_null);
335 }
336
337 void AccessibleNode::setRequired(bool required, bool is_null) {
338 SetBooleanProperty(AOMBooleanProperty::kRequired, required, is_null);
339 NotifyAttributeChanged(aria_requiredAttr);
340 }
341
177 AtomicString AccessibleNode::role() const { 342 AtomicString AccessibleNode::role() const {
178 return GetProperty(element_, AOMStringProperty::kRole); 343 return GetProperty(element_, AOMStringProperty::kRole);
179 } 344 }
180 345
181 void AccessibleNode::setRole(const AtomicString& role) { 346 void AccessibleNode::setRole(const AtomicString& role) {
182 SetStringProperty(AOMStringProperty::kRole, role); 347 SetStringProperty(AOMStringProperty::kRole, role);
183 NotifyAttributeChanged(roleAttr); 348 NotifyAttributeChanged(roleAttr);
184 } 349 }
185 350
186 AtomicString AccessibleNode::roleDescription() const { 351 AtomicString AccessibleNode::roleDescription() const {
187 return GetProperty(element_, AOMStringProperty::kRoleDescription); 352 return GetProperty(element_, AOMStringProperty::kRoleDescription);
188 } 353 }
189 354
190 void AccessibleNode::setRoleDescription(const AtomicString& role_description) { 355 void AccessibleNode::setRoleDescription(const AtomicString& role_description) {
191 SetStringProperty(AOMStringProperty::kRoleDescription, role_description); 356 SetStringProperty(AOMStringProperty::kRoleDescription, role_description);
192 NotifyAttributeChanged(aria_roledescriptionAttr); 357 NotifyAttributeChanged(aria_roledescriptionAttr);
193 } 358 }
194 359
360 bool AccessibleNode::selected(bool& is_null) const {
361 return GetProperty(element_, AOMBooleanProperty::kSelected, is_null);
362 }
363
364 void AccessibleNode::setSelected(bool selected, bool is_null) {
365 SetBooleanProperty(AOMBooleanProperty::kSelected, selected, is_null);
366 NotifyAttributeChanged(aria_selectedAttr);
367 }
368
195 AtomicString AccessibleNode::sort() const { 369 AtomicString AccessibleNode::sort() const {
196 return GetProperty(element_, AOMStringProperty::kSort); 370 return GetProperty(element_, AOMStringProperty::kSort);
197 } 371 }
198 372
199 void AccessibleNode::setSort(const AtomicString& sort) { 373 void AccessibleNode::setSort(const AtomicString& sort) {
200 SetStringProperty(AOMStringProperty::kSort, sort); 374 SetStringProperty(AOMStringProperty::kSort, sort);
201 NotifyAttributeChanged(aria_sortAttr); 375 NotifyAttributeChanged(aria_sortAttr);
202 } 376 }
203 377
204 AtomicString AccessibleNode::valueText() const { 378 AtomicString AccessibleNode::valueText() const {
(...skipping 10 matching lines...) Expand all
215 for (auto& item : string_properties_) { 389 for (auto& item : string_properties_) {
216 if (item.first == property) { 390 if (item.first == property) {
217 item.second = value; 391 item.second = value;
218 return; 392 return;
219 } 393 }
220 } 394 }
221 395
222 string_properties_.push_back(std::make_pair(property, value)); 396 string_properties_.push_back(std::make_pair(property, value));
223 } 397 }
224 398
399 void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property,
400 bool value,
401 bool is_null) {
402 for (size_t i = 0; i < boolean_properties_.size(); i++) {
403 auto& item = boolean_properties_[i];
404 if (item.first == property) {
405 if (is_null)
406 boolean_properties_.erase(i);
407 else
408 item.second = value;
409 return;
410 }
411 }
412
413 boolean_properties_.push_back(std::make_pair(property, value));
414 }
415
225 void AccessibleNode::NotifyAttributeChanged( 416 void AccessibleNode::NotifyAttributeChanged(
226 const blink::QualifiedName& attribute) { 417 const blink::QualifiedName& attribute) {
227 // TODO(dmazzoni): Make a cleaner API for this rather than pretending 418 // TODO(dmazzoni): Make a cleaner API for this rather than pretending
228 // the DOM attribute changed. 419 // the DOM attribute changed.
229 if (AXObjectCache* cache = GetAXObjectCache()) 420 if (AXObjectCache* cache = GetAXObjectCache())
230 cache->HandleAttributeChanged(attribute, element_); 421 cache->HandleAttributeChanged(attribute, element_);
231 } 422 }
232 423
233 AXObjectCache* AccessibleNode::GetAXObjectCache() { 424 AXObjectCache* AccessibleNode::GetAXObjectCache() {
234 return element_->GetDocument().ExistingAXObjectCache(); 425 return element_->GetDocument().ExistingAXObjectCache();
235 } 426 }
236 427
237 DEFINE_TRACE(AccessibleNode) { 428 DEFINE_TRACE(AccessibleNode) {
238 visitor->Trace(element_); 429 visitor->Trace(element_);
239 } 430 }
240 431
241 } // namespace blink 432 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/AccessibleNode.h ('k') | third_party/WebKit/Source/core/dom/AccessibleNode.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698