c1bf07d0b06cd800b6f4e8a3f608935fd0c09828
[WebKit-https.git] / WebKitTools / DumpRenderTree / gtk / AccessibilityUIElementGtk.cpp
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  * Copyright (C) 2009 Jan Michael Alonzo
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #include "config.h"
28 #include "AccessibilityUIElement.h"
29
30 #include <JavaScriptCore/JSStringRef.h>
31 #include <wtf/Assertions.h>
32
33 #include <atk/atk.h>
34 #include <gtk/gtk.h>
35
36
37 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
38     : m_element(element)
39 {
40 }
41
42 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
43     : m_element(other.m_element)
44 {
45 }
46
47 AccessibilityUIElement::~AccessibilityUIElement()
48 {
49 }
50
51 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>& elements)
52 {
53     // FIXME: implement
54 }
55
56 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
57 {
58     // FIXME: implement
59 }
60
61 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
62 {
63     int count = childrenCount();
64     for (int i = 0; i < count; i++) {
65         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
66         children.append(AccessibilityUIElement(child));
67     }
68 }
69
70 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned start, unsigned end)
71 {
72     for (unsigned i = start; i < end; i++) {
73         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
74         elementVector.append(AccessibilityUIElement(child));
75     }
76 }
77
78 int AccessibilityUIElement::childrenCount()
79 {
80     if (!m_element)
81         return 0;
82
83     ASSERT(ATK_IS_OBJECT(m_element));
84
85     return atk_object_get_n_accessible_children(ATK_OBJECT(m_element));
86 }
87
88 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
89 {
90     // FIXME: implement
91     return 0;
92 }
93
94 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
95 {
96     Vector<AccessibilityUIElement> children;
97     getChildrenWithRange(children, index, index + 1);
98
99     if (children.size() == 1)
100         return children.at(0);
101
102     return 0;
103 }
104
105 JSStringRef AccessibilityUIElement::allAttributes()
106 {
107     // FIXME: implement
108     return JSStringCreateWithCharacters(0, 0);
109 }
110
111 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
112 {
113     // FIXME: implement
114     return JSStringCreateWithCharacters(0, 0);
115 }
116
117 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
118 {
119     // FIXME: implement
120     return JSStringCreateWithCharacters(0, 0);
121 }
122
123 AccessibilityUIElement AccessibilityUIElement::titleUIElement()
124 {
125     // FIXME: implement
126     return 0;
127 }
128
129 AccessibilityUIElement AccessibilityUIElement::parentElement()
130 {
131     ASSERT(m_element);
132     AtkObject* parent =  atk_object_get_parent(ATK_OBJECT(m_element));
133
134     return parent ? AccessibilityUIElement(parent) : 0;
135 }
136
137 JSStringRef AccessibilityUIElement::attributesOfChildren()
138 {
139     // FIXME: implement
140     return JSStringCreateWithCharacters(0, 0);
141 }
142
143 JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
144 {
145     // FIXME: implement
146     return JSStringCreateWithCharacters(0, 0);
147 }
148
149 JSStringRef AccessibilityUIElement::role()
150 {
151     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
152
153     if (!role)
154         return JSStringCreateWithCharacters(0, 0);
155
156     return JSStringCreateWithUTF8CString(atk_role_get_name(role));
157 }
158
159 JSStringRef AccessibilityUIElement::subrole()
160 {
161     return 0;
162 }
163
164 JSStringRef AccessibilityUIElement::title()
165 {
166     const gchar* name = atk_object_get_name(ATK_OBJECT(m_element));
167
168     if (!name)
169         return JSStringCreateWithCharacters(0, 0);
170
171     return JSStringCreateWithUTF8CString(name);
172 }
173
174 JSStringRef AccessibilityUIElement::description()
175 {
176     const gchar* description = atk_object_get_description(ATK_OBJECT(m_element));
177
178     if (!description)
179         return JSStringCreateWithCharacters(0, 0);
180
181     return JSStringCreateWithUTF8CString(description);
182 }
183
184 JSStringRef AccessibilityUIElement::stringValue()
185 {
186     // FIXME: implement
187     return JSStringCreateWithCharacters(0, 0);
188 }
189
190 JSStringRef AccessibilityUIElement::language()
191 {
192     // FIXME: implement
193     return JSStringCreateWithCharacters(0, 0);
194 }
195
196 double AccessibilityUIElement::x()
197 {
198     int x, y;
199
200     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
201
202     return x;
203 }
204
205 double AccessibilityUIElement::y()
206 {
207     int x, y;
208
209     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
210
211     return y;
212 }
213
214 double AccessibilityUIElement::width()
215 {
216     int width, height;
217
218     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
219
220     return width;
221 }
222
223 double AccessibilityUIElement::height()
224 {
225     int width, height;
226
227     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
228
229     return height;
230 }
231
232 double AccessibilityUIElement::clickPointX()
233 {
234     return 0.f;
235 }
236
237 double AccessibilityUIElement::clickPointY()
238 {
239     return 0.f;
240 }
241
242
243 double AccessibilityUIElement::intValue()
244 {
245     GValue value = { 0, { { 0 } } };
246
247     if (!ATK_IS_VALUE(m_element))
248         return 0.0f;
249
250     atk_value_get_current_value(ATK_VALUE(m_element), &value);
251
252     if (G_VALUE_HOLDS_DOUBLE(&value))
253         return g_value_get_double(&value);
254     else if (G_VALUE_HOLDS_INT(&value))
255         return static_cast<double>(g_value_get_int(&value));
256     else
257         return 0.0f;
258 }
259
260 double AccessibilityUIElement::minValue()
261 {
262     GValue value = { 0, { { 0 } } };
263
264     if (!ATK_IS_VALUE(m_element))
265         return 0.0f;
266
267     atk_value_get_minimum_value(ATK_VALUE(m_element), &value);
268
269     if (G_VALUE_HOLDS_DOUBLE(&value))
270         return g_value_get_double(&value);
271     else if (G_VALUE_HOLDS_INT(&value))
272         return static_cast<double>(g_value_get_int(&value));
273     else
274         return 0.0f;
275 }
276
277 double AccessibilityUIElement::maxValue()
278 {
279     GValue value = { 0, { { 0 } } };
280
281     if (!ATK_IS_VALUE(m_element))
282         return 0.0f;
283
284     atk_value_get_maximum_value(ATK_VALUE(m_element), &value);
285
286     if (G_VALUE_HOLDS_DOUBLE(&value))
287         return g_value_get_double(&value);
288     else if (G_VALUE_HOLDS_INT(&value))
289         return static_cast<double>(g_value_get_int(&value));
290     else
291         return 0.0f;
292 }
293
294 JSStringRef AccessibilityUIElement::valueDescription()
295 {
296     // FIXME: implement
297     return JSStringCreateWithCharacters(0, 0);
298 }
299
300 bool AccessibilityUIElement::isEnabled()
301 {
302     // FIXME: implement
303     return false;
304 }
305
306
307 int AccessibilityUIElement::insertionPointLineNumber()
308 {
309     // FIXME: implement
310     return 0;
311 }
312
313 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
314 {
315     // FIXME: implement
316     return false;
317 }
318
319 bool AccessibilityUIElement::isRequired() const
320 {
321     // FIXME: implement
322     return false;
323 }
324
325 bool AccessibilityUIElement::isSelected() const
326 {
327     // FIXME: implement
328     return false;
329 }
330
331 int AccessibilityUIElement::hierarchicalLevel() const
332 {
333     // FIXME: implement
334     return 0;
335 }
336
337 bool AccessibilityUIElement::isExpanded() const
338 {
339     // FIXME: implement
340     return false;
341 }
342
343 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
344 {
345     // FIXME: implement
346     return JSStringCreateWithCharacters(0, 0);
347 }
348
349 JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
350 {
351     // FIXME: implement
352     return JSStringCreateWithCharacters(0, 0);
353 }
354
355 JSStringRef AccessibilityUIElement::attributesOfColumns()
356 {
357     // FIXME: implement
358     return JSStringCreateWithCharacters(0, 0);
359 }
360
361 JSStringRef AccessibilityUIElement::attributesOfRows()
362 {
363     // FIXME: implement
364     return JSStringCreateWithCharacters(0, 0);
365 }
366
367 JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
368 {
369     // FIXME: implement
370     return JSStringCreateWithCharacters(0, 0);
371 }
372
373 JSStringRef AccessibilityUIElement::attributesOfHeader()
374 {
375     // FIXME: implement
376     return JSStringCreateWithCharacters(0, 0);
377 }
378
379 int AccessibilityUIElement::indexInTable()
380 {
381     // FIXME: implement
382     return 0;
383 }
384
385 JSStringRef AccessibilityUIElement::rowIndexRange()
386 {
387     // FIXME: implement
388     return JSStringCreateWithCharacters(0, 0);
389 }
390
391 JSStringRef AccessibilityUIElement::columnIndexRange()
392 {
393     // FIXME: implement
394     return JSStringCreateWithCharacters(0, 0);
395 }
396
397 int AccessibilityUIElement::lineForIndex(int)
398 {
399     // FIXME: implement
400     return 0;
401 }
402
403 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
404 {
405     // FIXME: implement
406     return JSStringCreateWithCharacters(0, 0);
407 }
408
409 JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned) 
410 {
411     // FIXME: implement
412     return JSStringCreateWithCharacters(0, 0);
413
414
415 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
416 {
417     // FIXME: implement
418     return 0;
419 }
420
421 JSStringRef AccessibilityUIElement::selectedTextRange()
422 {
423     // FIXME: implement
424     return JSStringCreateWithCharacters(0, 0);
425 }
426
427 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
428 {
429     // FIXME: implement
430 }
431
432 JSStringRef AccessibilityUIElement::attributeValue(JSStringRef attribute)
433 {
434     // FIXME: implement
435     return JSStringCreateWithCharacters(0, 0);
436 }
437
438 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
439 {
440     // FIXME: implement
441     return false;
442 }
443
444 void AccessibilityUIElement::increment()
445 {
446     // FIXME: implement
447 }
448
449 void AccessibilityUIElement::decrement()
450 {
451     // FIXME: implement
452 }
453
454 void AccessibilityUIElement::showMenu()
455 {
456     // FIXME: implement
457 }
458
459 AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
460 {
461     return 0;
462 }
463
464 AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
465 {
466     return 0;
467 }
468
469 AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
470 {
471     return 0;
472 }
473
474 JSStringRef AccessibilityUIElement::accessibilityValue() const
475 {
476     // FIXME: implement
477     return JSStringCreateWithCharacters(0, 0);
478 }