2009-11-12 Joanmarie Diggs <joanmarie.diggs@gmail.com>
[WebKit-https.git] / WebKitTools / DumpRenderTree / win / AccessibilityUIElementWin.cpp
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 <JavaScriptCore/JSStringRef.h>
30 #include <tchar.h>
31 #include <string>
32
33 using std::wstring;
34
35 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
36     : m_element(element)
37 {
38 }
39
40 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
41     : m_element(other.m_element)
42 {
43 }
44
45 AccessibilityUIElement::~AccessibilityUIElement()
46 {
47 }
48
49 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>&)
50 {
51 }
52
53 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
54 {
55 }
56
57 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
58 {
59     long childCount;
60     if (FAILED(m_element->get_accChildCount(&childCount)))
61         return;
62     for (long i = 0; i < childCount; ++i)
63         children.append(getChildAtIndex(i));
64 }
65
66 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length)
67 {
68     long childCount;
69     unsigned appendedCount = 0;
70     if (FAILED(m_element->get_accChildCount(&childCount)))
71         return;
72     for (long i = location; i < childCount && appendedCount < length; ++i, ++appendedCount)
73         elementVector.append(getChildAtIndex(i));
74 }
75
76 int AccessibilityUIElement::childrenCount()
77 {
78     long childCount;
79     m_element->get_accChildCount(&childCount);
80     return childCount;
81 }
82
83 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
84 {
85     return 0;
86 }
87
88 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
89 {
90     COMPtr<IDispatch> child;
91     VARIANT vChild;
92     ::VariantInit(&vChild);
93     V_VT(&vChild) = VT_I4;
94     // In MSAA, index 0 is the object itself.
95     V_I4(&vChild) = index + 1;
96     if (FAILED(m_element->get_accChild(vChild, &child)))
97         return 0;
98     return COMPtr<IAccessible>(Query, child);
99 }
100
101 JSStringRef AccessibilityUIElement::allAttributes()
102 {
103     return JSStringCreateWithCharacters(0, 0);
104 }
105
106 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
107 {
108     return JSStringCreateWithCharacters(0, 0);
109 }
110
111 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
112 {
113     return JSStringCreateWithCharacters(0, 0);
114 }
115
116 AccessibilityUIElement AccessibilityUIElement::titleUIElement()
117 {
118     return 0;
119 }
120
121 AccessibilityUIElement AccessibilityUIElement::parentElement()
122 {
123     return 0;
124 }
125
126 JSStringRef AccessibilityUIElement::attributesOfChildren()
127 {
128     return JSStringCreateWithCharacters(0, 0);
129 }
130
131 JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
132 {
133     return JSStringCreateWithCharacters(0, 0);
134 }
135
136 static VARIANT& self()
137 {
138     static VARIANT vSelf;
139     static bool haveInitialized;
140
141     if (!haveInitialized) {
142         ::VariantInit(&vSelf);
143         V_VT(&vSelf) = VT_I4;
144         V_I4(&vSelf) = CHILDID_SELF;
145     }
146     return vSelf;
147 }
148
149 JSStringRef AccessibilityUIElement::role()
150 {
151     VARIANT vRole;
152     if (FAILED(m_element->get_accRole(self(), &vRole)))
153         return JSStringCreateWithCharacters(0, 0);
154
155     ASSERT(V_VT(&vRole) == VT_I4 || V_VT(&vRole) == VT_BSTR);
156
157     wstring result;
158     if (V_VT(&vRole) == VT_I4) {
159         unsigned roleTextLength = ::GetRoleText(V_I4(&vRole), 0, 0) + 1;
160
161         Vector<TCHAR> roleText(roleTextLength);
162
163         ::GetRoleText(V_I4(&vRole), roleText.data(), roleTextLength);
164
165         result = roleText.data();
166     } else if (V_VT(&vRole) == VT_BSTR)
167         result = wstring(V_BSTR(&vRole), ::SysStringLen(V_BSTR(&vRole)));
168
169     ::VariantClear(&vRole);
170
171     return JSStringCreateWithCharacters(result.data(), result.length());
172 }
173
174 JSStringRef AccessibilityUIElement::subrole()
175 {
176     return 0;
177 }
178
179 JSStringRef AccessibilityUIElement::title()
180 {
181     BSTR titleBSTR;
182     if (FAILED(m_element->get_accName(self(), &titleBSTR)) || !titleBSTR)
183         return JSStringCreateWithCharacters(0, 0);
184     wstring title(titleBSTR, SysStringLen(titleBSTR));
185     ::SysFreeString(titleBSTR);
186     return JSStringCreateWithCharacters(title.data(), title.length());
187 }
188
189 JSStringRef AccessibilityUIElement::description()
190 {
191     BSTR descriptionBSTR;
192     if (FAILED(m_element->get_accDescription(self(), &descriptionBSTR)) || !descriptionBSTR)
193         return JSStringCreateWithCharacters(0, 0);
194     wstring description(descriptionBSTR, SysStringLen(descriptionBSTR));
195     ::SysFreeString(descriptionBSTR);
196     return JSStringCreateWithCharacters(description.data(), description.length());
197 }
198
199 JSStringRef AccessibilityUIElement::stringValue()
200 {
201     return JSStringCreateWithCharacters(0, 0);
202 }
203
204 JSStringRef AccessibilityUIElement::language()
205 {
206     return JSStringCreateWithCharacters(0, 0);
207 }
208
209 double AccessibilityUIElement::x()
210 {
211     long x, y, width, height;
212     if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
213         return 0;
214     return x;
215 }
216
217 double AccessibilityUIElement::y()
218 {
219     long x, y, width, height;
220     if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
221         return 0;
222     return y;
223 }
224
225 double AccessibilityUIElement::width()
226 {
227     long x, y, width, height;
228     if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
229         return 0;
230     return width;
231 }
232
233 double AccessibilityUIElement::height()
234 {
235     long x, y, width, height;
236     if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
237         return 0;
238     return height;
239 }
240
241 double AccessibilityUIElement::clickPointX()
242 {
243     return 0;
244 }
245
246 double AccessibilityUIElement::clickPointY()
247 {
248     return 0;
249 }
250
251 JSStringRef AccessibilityUIElement::valueDescription()
252 {
253     return 0;
254 }
255 bool AccessibilityUIElement::isSelected() const
256 {
257     return false;
258 }
259
260 int AccessibilityUIElement::hierarchicalLevel() const
261 {
262     return 0;
263 }
264
265 bool AccessibilityUIElement::isExpanded() const
266 {
267     return false;
268 }
269
270 double AccessibilityUIElement::intValue()
271 {
272     BSTR valueBSTR;
273     if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
274         return 0;
275     wstring value(valueBSTR, SysStringLen(valueBSTR));
276     ::SysFreeString(valueBSTR);
277     TCHAR* ignored;
278     return _tcstod(value.data(), &ignored);
279 }
280
281 double AccessibilityUIElement::minValue()
282 {
283     return 0;
284 }
285
286 double AccessibilityUIElement::maxValue()
287 {
288     return 0;
289 }
290
291 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
292 {
293     return false;
294 }
295
296 bool AccessibilityUIElement::isEnabled()
297 {
298     return false;
299 }
300
301 bool AccessibilityUIElement::isRequired() const
302 {
303     return false;
304 }
305
306
307 int AccessibilityUIElement::insertionPointLineNumber()
308 {
309     return 0;
310 }
311
312 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
313 {
314     return JSStringCreateWithCharacters(0, 0);
315 }
316
317 JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
318 {
319     return JSStringCreateWithCharacters(0, 0);
320 }
321
322 JSStringRef AccessibilityUIElement::attributesOfColumns()
323 {
324     return JSStringCreateWithCharacters(0, 0);
325 }
326
327 JSStringRef AccessibilityUIElement::attributesOfRows()
328 {
329     return JSStringCreateWithCharacters(0, 0);
330 }
331
332 JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
333 {
334     return JSStringCreateWithCharacters(0, 0);
335 }
336
337 JSStringRef AccessibilityUIElement::attributesOfHeader()
338 {
339     return JSStringCreateWithCharacters(0, 0);
340 }
341
342 int AccessibilityUIElement::indexInTable()
343 {
344     return 0;
345 }
346
347 JSStringRef AccessibilityUIElement::rowIndexRange()
348 {
349     return JSStringCreateWithCharacters(0, 0);
350 }
351
352 JSStringRef AccessibilityUIElement::columnIndexRange()
353 {
354     return JSStringCreateWithCharacters(0, 0);
355 }
356
357 int AccessibilityUIElement::lineForIndex(int)
358 {
359     return 0;
360 }
361
362 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
363 {
364     return JSStringCreateWithCharacters(0, 0);
365 }
366
367 JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned)
368 {
369     return JSStringCreateWithCharacters(0, 0);
370 }
371
372 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
373 {
374     return 0;
375 }
376
377 JSStringRef AccessibilityUIElement::selectedTextRange()
378 {
379     return JSStringCreateWithCharacters(0, 0);    
380 }
381
382 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
383 {
384 }
385
386 JSStringRef AccessibilityUIElement::attributeValue(JSStringRef attribute)
387 {
388     return JSStringCreateWithCharacters(0, 0);
389 }
390
391 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
392 {
393     return false;
394 }
395
396 void AccessibilityUIElement::increment()
397 {
398 }
399
400 void AccessibilityUIElement::decrement()
401 {
402 }
403
404 void AccessibilityUIElement::showMenu()
405 {
406 }
407
408 AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
409 {
410     return 0;
411 }
412
413 AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
414 {
415     return 0;
416 }
417
418 AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
419 {
420     return 0;
421 }
422
423 JSStringRef AccessibilityUIElement::accessibilityValue() const
424 {
425     BSTR valueBSTR;
426     if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
427         return JSStringCreateWithCharacters(0, 0);
428
429     wstring value(valueBSTR, SysStringLen(valueBSTR));
430     ::SysFreeString(valueBSTR);
431
432     return JSStringCreateWithCharacters(value.data(), value.length());
433 }
434
435
436 JSStringRef AccessibilityUIElement::documentEncoding()
437 {
438     return JSStringCreateWithCharacters(0, 0);
439 }
440
441 JSStringRef AccessibilityUIElement::documentURI()
442 {
443     return JSStringCreateWithCharacters(0, 0);
444 }