|
1 /* |
|
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #include "config.h" |
|
27 #include "AccessibilityUIElement.h" |
|
28 |
|
29 #include "AccessibilityController.h" |
|
30 #include "DumpRenderTree.h" |
|
31 #include "FrameLoadDelegate.h" |
|
32 #include <JavaScriptCore/JSStringRef.h> |
|
33 #include <tchar.h> |
|
34 #include <string> |
|
35 |
|
36 using std::wstring; |
|
37 |
|
38 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element) |
|
39 : m_element(element) |
|
40 { |
|
41 } |
|
42 |
|
43 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other) |
|
44 : m_element(other.m_element) |
|
45 { |
|
46 } |
|
47 |
|
48 AccessibilityUIElement::~AccessibilityUIElement() |
|
49 { |
|
50 } |
|
51 |
|
52 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>&) |
|
53 { |
|
54 } |
|
55 |
|
56 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&) |
|
57 { |
|
58 } |
|
59 |
|
60 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children) |
|
61 { |
|
62 long childCount; |
|
63 if (FAILED(m_element->get_accChildCount(&childCount))) |
|
64 return; |
|
65 for (long i = 0; i < childCount; ++i) |
|
66 children.append(getChildAtIndex(i)); |
|
67 } |
|
68 |
|
69 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length) |
|
70 { |
|
71 long childCount; |
|
72 unsigned appendedCount = 0; |
|
73 if (FAILED(m_element->get_accChildCount(&childCount))) |
|
74 return; |
|
75 for (long i = location; i < childCount && appendedCount < length; ++i, ++appendedCount) |
|
76 elementVector.append(getChildAtIndex(i)); |
|
77 } |
|
78 |
|
79 int AccessibilityUIElement::childrenCount() |
|
80 { |
|
81 long childCount; |
|
82 m_element->get_accChildCount(&childCount); |
|
83 return childCount; |
|
84 } |
|
85 |
|
86 int AccessibilityUIElement::rowCount() |
|
87 { |
|
88 // FIXME: implement |
|
89 return 0; |
|
90 } |
|
91 |
|
92 int AccessibilityUIElement::columnCount() |
|
93 { |
|
94 // FIXME: implement |
|
95 return 0; |
|
96 } |
|
97 |
|
98 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y) |
|
99 { |
|
100 return 0; |
|
101 } |
|
102 |
|
103 AccessibilityUIElement AccessibilityUIElement::linkedUIElementAtIndex(unsigned index) |
|
104 { |
|
105 // FIXME: implement |
|
106 return 0; |
|
107 } |
|
108 |
|
109 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index) |
|
110 { |
|
111 COMPtr<IDispatch> child; |
|
112 VARIANT vChild; |
|
113 ::VariantInit(&vChild); |
|
114 V_VT(&vChild) = VT_I4; |
|
115 // In MSAA, index 0 is the object itself. |
|
116 V_I4(&vChild) = index + 1; |
|
117 if (FAILED(m_element->get_accChild(vChild, &child))) |
|
118 return 0; |
|
119 return COMPtr<IAccessible>(Query, child); |
|
120 } |
|
121 |
|
122 unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element) |
|
123 { |
|
124 // FIXME: implement |
|
125 return 0; |
|
126 } |
|
127 |
|
128 JSStringRef AccessibilityUIElement::allAttributes() |
|
129 { |
|
130 return JSStringCreateWithCharacters(0, 0); |
|
131 } |
|
132 |
|
133 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements() |
|
134 { |
|
135 return JSStringCreateWithCharacters(0, 0); |
|
136 } |
|
137 |
|
138 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks() |
|
139 { |
|
140 return JSStringCreateWithCharacters(0, 0); |
|
141 } |
|
142 |
|
143 AccessibilityUIElement AccessibilityUIElement::titleUIElement() |
|
144 { |
|
145 return 0; |
|
146 } |
|
147 |
|
148 AccessibilityUIElement AccessibilityUIElement::parentElement() |
|
149 { |
|
150 COMPtr<IDispatch> parent; |
|
151 m_element->get_accParent(&parent); |
|
152 |
|
153 COMPtr<IAccessible> parentAccessible(Query, parent); |
|
154 return parentAccessible; |
|
155 } |
|
156 |
|
157 JSStringRef AccessibilityUIElement::attributesOfChildren() |
|
158 { |
|
159 return JSStringCreateWithCharacters(0, 0); |
|
160 } |
|
161 |
|
162 JSStringRef AccessibilityUIElement::parameterizedAttributeNames() |
|
163 { |
|
164 return JSStringCreateWithCharacters(0, 0); |
|
165 } |
|
166 |
|
167 static VARIANT& self() |
|
168 { |
|
169 static VARIANT vSelf; |
|
170 static bool haveInitialized; |
|
171 |
|
172 if (!haveInitialized) { |
|
173 ::VariantInit(&vSelf); |
|
174 V_VT(&vSelf) = VT_I4; |
|
175 V_I4(&vSelf) = CHILDID_SELF; |
|
176 } |
|
177 return vSelf; |
|
178 } |
|
179 |
|
180 JSStringRef AccessibilityUIElement::role() |
|
181 { |
|
182 VARIANT vRole; |
|
183 if (FAILED(m_element->get_accRole(self(), &vRole))) |
|
184 return JSStringCreateWithCharacters(0, 0); |
|
185 |
|
186 ASSERT(V_VT(&vRole) == VT_I4 || V_VT(&vRole) == VT_BSTR); |
|
187 |
|
188 wstring result; |
|
189 if (V_VT(&vRole) == VT_I4) { |
|
190 unsigned roleTextLength = ::GetRoleText(V_I4(&vRole), 0, 0) + 1; |
|
191 |
|
192 Vector<TCHAR> roleText(roleTextLength); |
|
193 |
|
194 ::GetRoleText(V_I4(&vRole), roleText.data(), roleTextLength); |
|
195 |
|
196 result = roleText.data(); |
|
197 } else if (V_VT(&vRole) == VT_BSTR) |
|
198 result = wstring(V_BSTR(&vRole), ::SysStringLen(V_BSTR(&vRole))); |
|
199 |
|
200 ::VariantClear(&vRole); |
|
201 |
|
202 return JSStringCreateWithCharacters(result.data(), result.length()); |
|
203 } |
|
204 |
|
205 JSStringRef AccessibilityUIElement::subrole() |
|
206 { |
|
207 return 0; |
|
208 } |
|
209 |
|
210 JSStringRef AccessibilityUIElement::roleDescription() |
|
211 { |
|
212 return 0; |
|
213 } |
|
214 |
|
215 JSStringRef AccessibilityUIElement::title() |
|
216 { |
|
217 BSTR titleBSTR; |
|
218 if (FAILED(m_element->get_accName(self(), &titleBSTR)) || !titleBSTR) |
|
219 return JSStringCreateWithCharacters(0, 0); |
|
220 wstring title(titleBSTR, SysStringLen(titleBSTR)); |
|
221 ::SysFreeString(titleBSTR); |
|
222 return JSStringCreateWithCharacters(title.data(), title.length()); |
|
223 } |
|
224 |
|
225 JSStringRef AccessibilityUIElement::description() |
|
226 { |
|
227 BSTR descriptionBSTR; |
|
228 if (FAILED(m_element->get_accDescription(self(), &descriptionBSTR)) || !descriptionBSTR) |
|
229 return JSStringCreateWithCharacters(0, 0); |
|
230 wstring description(descriptionBSTR, SysStringLen(descriptionBSTR)); |
|
231 ::SysFreeString(descriptionBSTR); |
|
232 return JSStringCreateWithCharacters(description.data(), description.length()); |
|
233 } |
|
234 |
|
235 JSStringRef AccessibilityUIElement::stringValue() |
|
236 { |
|
237 return JSStringCreateWithCharacters(0, 0); |
|
238 } |
|
239 |
|
240 JSStringRef AccessibilityUIElement::language() |
|
241 { |
|
242 return JSStringCreateWithCharacters(0, 0); |
|
243 } |
|
244 |
|
245 JSStringRef AccessibilityUIElement::helpText() const |
|
246 { |
|
247 return 0; |
|
248 } |
|
249 |
|
250 double AccessibilityUIElement::x() |
|
251 { |
|
252 long x, y, width, height; |
|
253 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self()))) |
|
254 return 0; |
|
255 return x; |
|
256 } |
|
257 |
|
258 double AccessibilityUIElement::y() |
|
259 { |
|
260 long x, y, width, height; |
|
261 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self()))) |
|
262 return 0; |
|
263 return y; |
|
264 } |
|
265 |
|
266 double AccessibilityUIElement::width() |
|
267 { |
|
268 long x, y, width, height; |
|
269 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self()))) |
|
270 return 0; |
|
271 return width; |
|
272 } |
|
273 |
|
274 double AccessibilityUIElement::height() |
|
275 { |
|
276 long x, y, width, height; |
|
277 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self()))) |
|
278 return 0; |
|
279 return height; |
|
280 } |
|
281 |
|
282 double AccessibilityUIElement::clickPointX() |
|
283 { |
|
284 return 0; |
|
285 } |
|
286 |
|
287 double AccessibilityUIElement::clickPointY() |
|
288 { |
|
289 return 0; |
|
290 } |
|
291 |
|
292 JSStringRef AccessibilityUIElement::valueDescription() |
|
293 { |
|
294 return 0; |
|
295 } |
|
296 |
|
297 static DWORD accessibilityState(COMPtr<IAccessible> element) |
|
298 { |
|
299 VARIANT state; |
|
300 element->get_accState(self(), &state); |
|
301 |
|
302 ASSERT(V_VT(&state) == VT_I4); |
|
303 |
|
304 DWORD result = state.lVal; |
|
305 VariantClear(&state); |
|
306 |
|
307 return result; |
|
308 } |
|
309 |
|
310 bool AccessibilityUIElement::isSelected() const |
|
311 { |
|
312 DWORD state = accessibilityState(m_element); |
|
313 return (state & STATE_SYSTEM_SELECTED) == STATE_SYSTEM_SELECTED; |
|
314 } |
|
315 |
|
316 int AccessibilityUIElement::hierarchicalLevel() const |
|
317 { |
|
318 return 0; |
|
319 } |
|
320 |
|
321 bool AccessibilityUIElement::ariaIsGrabbed() const |
|
322 { |
|
323 return false; |
|
324 } |
|
325 |
|
326 JSStringRef AccessibilityUIElement::ariaDropEffects() const |
|
327 { |
|
328 return 0; |
|
329 } |
|
330 |
|
331 bool AccessibilityUIElement::isExpanded() const |
|
332 { |
|
333 return false; |
|
334 } |
|
335 |
|
336 bool AccessibilityUIElement::isChecked() const |
|
337 { |
|
338 VARIANT vState; |
|
339 if (FAILED(m_element->get_accState(self(), &vState))) |
|
340 return false; |
|
341 |
|
342 return vState.lVal & STATE_SYSTEM_CHECKED; |
|
343 } |
|
344 |
|
345 JSStringRef AccessibilityUIElement::orientation() const |
|
346 { |
|
347 return 0; |
|
348 } |
|
349 |
|
350 double AccessibilityUIElement::intValue() const |
|
351 { |
|
352 BSTR valueBSTR; |
|
353 if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR) |
|
354 return 0; |
|
355 wstring value(valueBSTR, SysStringLen(valueBSTR)); |
|
356 ::SysFreeString(valueBSTR); |
|
357 TCHAR* ignored; |
|
358 return _tcstod(value.data(), &ignored); |
|
359 } |
|
360 |
|
361 double AccessibilityUIElement::minValue() |
|
362 { |
|
363 return 0; |
|
364 } |
|
365 |
|
366 double AccessibilityUIElement::maxValue() |
|
367 { |
|
368 return 0; |
|
369 } |
|
370 |
|
371 bool AccessibilityUIElement::isActionSupported(JSStringRef action) |
|
372 { |
|
373 return false; |
|
374 } |
|
375 |
|
376 bool AccessibilityUIElement::isEnabled() |
|
377 { |
|
378 DWORD state = accessibilityState(m_element); |
|
379 return (state & STATE_SYSTEM_UNAVAILABLE) != STATE_SYSTEM_UNAVAILABLE; |
|
380 } |
|
381 |
|
382 bool AccessibilityUIElement::isRequired() const |
|
383 { |
|
384 return false; |
|
385 } |
|
386 |
|
387 |
|
388 int AccessibilityUIElement::insertionPointLineNumber() |
|
389 { |
|
390 return 0; |
|
391 } |
|
392 |
|
393 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders() |
|
394 { |
|
395 return JSStringCreateWithCharacters(0, 0); |
|
396 } |
|
397 |
|
398 JSStringRef AccessibilityUIElement::attributesOfRowHeaders() |
|
399 { |
|
400 return JSStringCreateWithCharacters(0, 0); |
|
401 } |
|
402 |
|
403 JSStringRef AccessibilityUIElement::attributesOfColumns() |
|
404 { |
|
405 return JSStringCreateWithCharacters(0, 0); |
|
406 } |
|
407 |
|
408 JSStringRef AccessibilityUIElement::attributesOfRows() |
|
409 { |
|
410 return JSStringCreateWithCharacters(0, 0); |
|
411 } |
|
412 |
|
413 JSStringRef AccessibilityUIElement::attributesOfVisibleCells() |
|
414 { |
|
415 return JSStringCreateWithCharacters(0, 0); |
|
416 } |
|
417 |
|
418 JSStringRef AccessibilityUIElement::attributesOfHeader() |
|
419 { |
|
420 return JSStringCreateWithCharacters(0, 0); |
|
421 } |
|
422 |
|
423 int AccessibilityUIElement::indexInTable() |
|
424 { |
|
425 return 0; |
|
426 } |
|
427 |
|
428 JSStringRef AccessibilityUIElement::rowIndexRange() |
|
429 { |
|
430 return JSStringCreateWithCharacters(0, 0); |
|
431 } |
|
432 |
|
433 JSStringRef AccessibilityUIElement::columnIndexRange() |
|
434 { |
|
435 return JSStringCreateWithCharacters(0, 0); |
|
436 } |
|
437 |
|
438 int AccessibilityUIElement::lineForIndex(int) |
|
439 { |
|
440 return 0; |
|
441 } |
|
442 |
|
443 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length) |
|
444 { |
|
445 return JSStringCreateWithCharacters(0, 0); |
|
446 } |
|
447 |
|
448 JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned) |
|
449 { |
|
450 return JSStringCreateWithCharacters(0, 0); |
|
451 } |
|
452 |
|
453 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row) |
|
454 { |
|
455 return 0; |
|
456 } |
|
457 |
|
458 JSStringRef AccessibilityUIElement::selectedTextRange() |
|
459 { |
|
460 return JSStringCreateWithCharacters(0, 0); |
|
461 } |
|
462 |
|
463 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length) |
|
464 { |
|
465 } |
|
466 |
|
467 JSStringRef AccessibilityUIElement::stringAttributeValue(JSStringRef attribute) |
|
468 { |
|
469 // FIXME: implement |
|
470 return JSStringCreateWithCharacters(0, 0); |
|
471 } |
|
472 |
|
473 bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute) |
|
474 { |
|
475 // FIXME: implement |
|
476 return false; |
|
477 } |
|
478 |
|
479 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute) |
|
480 { |
|
481 return false; |
|
482 } |
|
483 |
|
484 bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute) |
|
485 { |
|
486 return false; |
|
487 } |
|
488 |
|
489 void AccessibilityUIElement::increment() |
|
490 { |
|
491 } |
|
492 |
|
493 void AccessibilityUIElement::decrement() |
|
494 { |
|
495 } |
|
496 |
|
497 void AccessibilityUIElement::showMenu() |
|
498 { |
|
499 ASSERT(hasPopup()); |
|
500 m_element->accDoDefaultAction(self()); |
|
501 } |
|
502 |
|
503 void AccessibilityUIElement::press() |
|
504 { |
|
505 // FIXME: implement |
|
506 } |
|
507 |
|
508 AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index) |
|
509 { |
|
510 return 0; |
|
511 } |
|
512 |
|
513 AccessibilityUIElement AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index) |
|
514 { |
|
515 return 0; |
|
516 } |
|
517 |
|
518 AccessibilityUIElement AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index) |
|
519 { |
|
520 return 0; |
|
521 } |
|
522 |
|
523 AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index) |
|
524 { |
|
525 return 0; |
|
526 } |
|
527 |
|
528 AccessibilityUIElement AccessibilityUIElement::disclosedByRow() |
|
529 { |
|
530 return 0; |
|
531 } |
|
532 |
|
533 JSStringRef AccessibilityUIElement::accessibilityValue() const |
|
534 { |
|
535 BSTR valueBSTR; |
|
536 if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR) |
|
537 return JSStringCreateWithCharacters(0, 0); |
|
538 |
|
539 wstring value(valueBSTR, SysStringLen(valueBSTR)); |
|
540 ::SysFreeString(valueBSTR); |
|
541 |
|
542 return JSStringCreateWithCharacters(value.data(), value.length()); |
|
543 } |
|
544 |
|
545 |
|
546 JSStringRef AccessibilityUIElement::documentEncoding() |
|
547 { |
|
548 return JSStringCreateWithCharacters(0, 0); |
|
549 } |
|
550 |
|
551 JSStringRef AccessibilityUIElement::documentURI() |
|
552 { |
|
553 return JSStringCreateWithCharacters(0, 0); |
|
554 } |
|
555 |
|
556 JSStringRef AccessibilityUIElement::url() |
|
557 { |
|
558 // FIXME: implement |
|
559 return JSStringCreateWithCharacters(0, 0); |
|
560 } |
|
561 |
|
562 bool AccessibilityUIElement::addNotificationListener(JSObjectRef functionCallback) |
|
563 { |
|
564 if (!functionCallback) |
|
565 return false; |
|
566 |
|
567 sharedFrameLoadDelegate->accessibilityController()->addNotificationListener(m_element, functionCallback); |
|
568 return true; |
|
569 } |
|
570 |
|
571 void AccessibilityUIElement::removeNotificationListener() |
|
572 { |
|
573 // FIXME: implement |
|
574 } |
|
575 |
|
576 bool AccessibilityUIElement::isSelectable() const |
|
577 { |
|
578 DWORD state = accessibilityState(m_element); |
|
579 return (state & STATE_SYSTEM_SELECTABLE) == STATE_SYSTEM_SELECTABLE; |
|
580 } |
|
581 |
|
582 bool AccessibilityUIElement::isMultiSelectable() const |
|
583 { |
|
584 DWORD multiSelectable = STATE_SYSTEM_EXTSELECTABLE | STATE_SYSTEM_MULTISELECTABLE; |
|
585 DWORD state = accessibilityState(m_element); |
|
586 return (state & multiSelectable) == multiSelectable; |
|
587 } |
|
588 |
|
589 bool AccessibilityUIElement::isVisible() const |
|
590 { |
|
591 DWORD state = accessibilityState(m_element); |
|
592 return (state & STATE_SYSTEM_INVISIBLE) != STATE_SYSTEM_INVISIBLE; |
|
593 } |
|
594 |
|
595 bool AccessibilityUIElement::isOffScreen() const |
|
596 { |
|
597 DWORD state = accessibilityState(m_element); |
|
598 return (state & STATE_SYSTEM_OFFSCREEN) == STATE_SYSTEM_OFFSCREEN; |
|
599 } |
|
600 |
|
601 bool AccessibilityUIElement::isCollapsed() const |
|
602 { |
|
603 DWORD state = accessibilityState(m_element); |
|
604 return (state & STATE_SYSTEM_COLLAPSED) == STATE_SYSTEM_COLLAPSED; |
|
605 } |
|
606 |
|
607 bool AccessibilityUIElement::hasPopup() const |
|
608 { |
|
609 DWORD state = accessibilityState(m_element); |
|
610 return (state & STATE_SYSTEM_HASPOPUP) == STATE_SYSTEM_HASPOPUP; |
|
611 } |
|
612 |
|
613 void AccessibilityUIElement::takeFocus() |
|
614 { |
|
615 m_element->accSelect(SELFLAG_TAKEFOCUS, self()); |
|
616 } |
|
617 |
|
618 void AccessibilityUIElement::takeSelection() |
|
619 { |
|
620 m_element->accSelect(SELFLAG_TAKESELECTION, self()); |
|
621 } |
|
622 |
|
623 void AccessibilityUIElement::addSelection() |
|
624 { |
|
625 m_element->accSelect(SELFLAG_ADDSELECTION, self()); |
|
626 } |
|
627 |
|
628 void AccessibilityUIElement::removeSelection() |
|
629 { |
|
630 m_element->accSelect(SELFLAG_REMOVESELECTION, self()); |
|
631 } |