[EFL][GTK] Adapt accessibility feature to WebKitTestRunner.
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / atk / AccessibilityUIElementAtk.cpp
1 /*
2  * Copyright (C) 2011 Apple Inc. All Rights Reserved.
3  * Copyright (C) 2012 Igalia S.L.
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 "InjectedBundle.h"
31 #include "InjectedBundlePage.h"
32 #include <JavaScriptCore/JSStringRef.h>
33 #include <atk/atk.h>
34 #include <wtf/Assertions.h>
35 #include <wtf/gobject/GOwnPtr.h>
36 #include <wtf/gobject/GRefPtr.h>
37 #include <wtf/text/CString.h>
38 #include <wtf/text/WTFString.h>
39 #include <wtf/unicode/CharacterNames.h>
40
41 namespace WTR {
42
43 static gchar* attributeSetToString(AtkAttributeSet* attributeSet)
44 {
45     GString* str = g_string_new(0);
46     for (GSList* attributes = attributeSet; attributes; attributes = attributes->next) {
47         AtkAttribute* attribute = static_cast<AtkAttribute*>(attributes->data);
48         GOwnPtr<gchar> attributeData(g_strconcat(attribute->name, ":", attribute->value, NULL));
49         g_string_append(str, attributeData.get());
50         if (attributes->next)
51             g_string_append(str, ", ");
52     }
53
54     return g_string_free(str, FALSE);
55 }
56
57 static bool checkElementState(PlatformUIElement element, AtkStateType stateType)
58 {
59     if (!ATK_IS_OBJECT(element))
60         return false;
61
62     GRefPtr<AtkStateSet> stateSet = adoptGRef(atk_object_ref_state_set(ATK_OBJECT(element)));
63     return atk_state_set_contains_state(stateSet.get(), stateType);
64 }
65
66 static JSStringRef indexRangeInTable(PlatformUIElement element, bool isRowRange)
67 {
68     GOwnPtr<gchar> rangeString(g_strdup("{0, 0}"));
69
70     if (!element || !ATK_IS_OBJECT(element))
71         return JSStringCreateWithUTF8CString(rangeString.get());
72
73     AtkObject* axTable = atk_object_get_parent(ATK_OBJECT(element));
74     if (!axTable || !ATK_IS_TABLE(axTable))
75         return JSStringCreateWithUTF8CString(rangeString.get());
76
77     // Look for the cell in the table.
78     gint indexInParent = atk_object_get_index_in_parent(ATK_OBJECT(element));
79     if (indexInParent == -1)
80         return JSStringCreateWithUTF8CString(rangeString.get());
81
82     int row = -1;
83     int column = -1;
84     row = atk_table_get_row_at_index(ATK_TABLE(axTable), indexInParent);
85     column = atk_table_get_column_at_index(ATK_TABLE(axTable), indexInParent);
86
87     // Get the actual values, if row and columns are valid values.
88     if (row != -1 && column != -1) {
89         int base = 0;
90         int length = 0;
91         if (isRowRange) {
92             base = row;
93             length = atk_table_get_row_extent_at(ATK_TABLE(axTable), row, column);
94         } else {
95             base = column;
96             length = atk_table_get_column_extent_at(ATK_TABLE(axTable), row, column);
97         }
98         rangeString.set(g_strdup_printf("{%d, %d}", base, length));
99     }
100
101     return JSStringCreateWithUTF8CString(rangeString.get());
102 }
103
104 static void alterCurrentValue(PlatformUIElement element, int factor)
105 {
106     if (!element || !ATK_IS_VALUE(element))
107         return;
108
109     GValue currentValue = G_VALUE_INIT;
110     atk_value_get_current_value(ATK_VALUE(element), &currentValue);
111
112     GValue increment = G_VALUE_INIT;
113     atk_value_get_minimum_increment(ATK_VALUE(element), &increment);
114
115     GValue newValue = G_VALUE_INIT;
116     g_value_init(&newValue, G_TYPE_DOUBLE);
117
118     g_value_set_float(&newValue, g_value_get_float(&currentValue) + factor * g_value_get_float(&increment));
119     atk_value_set_current_value(ATK_VALUE(element), &newValue);
120
121     g_value_unset(&newValue);
122     g_value_unset(&increment);
123     g_value_unset(&currentValue);
124 }
125
126 static gchar* replaceCharactersForResults(gchar* str)
127 {
128     WTF::String uString = WTF::String::fromUTF8(str);
129
130     // The object replacement character is passed along to ATs so we need to be
131     // able to test for their presence and do so without causing test failures.
132     uString.replace(objectReplacementCharacter, "<obj>");
133
134     // The presence of newline characters in accessible text of a single object
135     // is appropriate, but it makes test results (especially the accessible tree)
136     // harder to read.
137     uString.replace("\n", "<\\n>");
138
139     return g_strdup(uString.utf8().data());
140 }
141
142 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
143     : m_element(element)
144 {
145 }
146
147 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
148     : JSWrappable()
149     , m_element(other.m_element)
150 {
151 }
152
153 AccessibilityUIElement::~AccessibilityUIElement()
154 {
155 }
156
157 bool AccessibilityUIElement::isEqual(AccessibilityUIElement* otherElement)
158 {
159     return m_element == otherElement->platformUIElement();
160 }
161
162 void AccessibilityUIElement::getChildren(Vector<RefPtr<AccessibilityUIElement> >& children)
163 {
164     if (!m_element || !ATK_IS_OBJECT(m_element))
165         return;
166
167     int count = childrenCount();
168     for (int i = 0; i < count; i++) {
169         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
170         children.append(AccessibilityUIElement::create(child));
171     }
172 }
173
174 void AccessibilityUIElement::getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >& children, unsigned location, unsigned length)
175 {
176     if (!m_element || !ATK_IS_OBJECT(m_element))
177         return;
178     unsigned end = location + length;
179     for (unsigned i = location; i < end; i++) {
180         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
181         children.append(AccessibilityUIElement::create(child));
182     }
183 }
184
185 int AccessibilityUIElement::childrenCount()
186 {
187     if (!m_element)
188         return 0;
189
190     return atk_object_get_n_accessible_children(ATK_OBJECT(m_element));
191 }
192
193 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::elementAtPoint(int x, int y)
194 {
195     // FIXME: implement
196     return 0;
197 }
198
199 unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
200 {
201     if (!m_element || !ATK_IS_OBJECT(m_element))
202         return 0;
203
204     Vector<RefPtr<AccessibilityUIElement> > children;
205     getChildren(children);
206
207     unsigned count = children.size();
208     for (unsigned i = 0; i < count; i++)
209         if (children[i]->isEqual(element))
210             return i;
211
212     return 0;
213 }
214
215 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::childAtIndex(unsigned index)
216 {
217     Vector<RefPtr<AccessibilityUIElement> > children;
218     getChildrenWithRange(children, index, 1);
219
220     if (children.size() == 1)
221         return children[0];
222
223     return 0;
224 }
225
226 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
227 {
228     // FIXME: implement
229     return 0;
230 }
231
232 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
233 {
234     // FIXME: implement
235     return 0;
236 }
237
238 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
239 {
240     // FIXME: implement
241     return 0;
242 }
243
244 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
245 {
246     // FIXME: implement
247     return 0;
248 }
249
250 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::rowAtIndex(unsigned index)
251 {
252     // FIXME: implement
253     return 0;
254 }
255
256 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedChildAtIndex(unsigned index) const
257 {
258     // FIXME: implement
259     return 0;
260 }
261
262 unsigned AccessibilityUIElement::selectedChildrenCount() const
263 {
264     // FIXME: implement
265     return 0;
266 }
267
268 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedRowAtIndex(unsigned index)
269 {
270     // FIXME: implement
271     return 0;
272 }
273
274 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::titleUIElement()
275 {
276     // FIXME: implement
277     return 0;
278 }
279
280 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::parentElement()
281 {
282     if (!m_element || !ATK_IS_OBJECT(m_element))
283         return 0;
284
285     AtkObject* parent = atk_object_get_parent(ATK_OBJECT(m_element));
286     return parent ? AccessibilityUIElement::create(parent) : 0;
287 }
288
289 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedByRow()
290 {
291     // FIXME: implement
292     return 0;
293 }
294
295 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements()
296 {
297     // FIXME: implement
298     return JSStringCreateWithCharacters(0, 0);
299 }
300
301 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks()
302 {
303     // FIXME: implement
304     return JSStringCreateWithCharacters(0, 0);
305 }
306
307 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren()
308 {
309     // FIXME: implement
310     return JSStringCreateWithCharacters(0, 0);
311 }
312
313 JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes()
314 {
315     if (!m_element || !ATK_IS_OBJECT(m_element))
316         return JSStringCreateWithCharacters(0, 0);
317
318     GOwnPtr<gchar> attributeData(attributeSetToString(atk_object_get_attributes(ATK_OBJECT(m_element))));
319     return JSStringCreateWithUTF8CString(attributeData.get());
320 }
321
322 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
323 {
324     // FIXME: implement
325     return JSStringCreateWithCharacters(0, 0);
326 }
327
328 double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
329 {
330     // FIXME: implement
331     return 0.0f;
332 }
333
334 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementAttributeValue(JSStringRef attribute) const
335 {
336     // FIXME: implement
337     return 0;
338 }
339
340 bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
341 {
342     // FIXME: implement
343     return false;
344 }
345
346 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
347 {
348     // FIXME: implement
349     return false;
350 }
351
352 bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
353 {
354     // FIXME: implement
355     return false;
356 }
357
358 JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames()
359 {
360     // FIXME: implement
361     return JSStringCreateWithCharacters(0, 0);
362 }
363
364 JSRetainPtr<JSStringRef> AccessibilityUIElement::role()
365 {
366     if (!m_element || !ATK_IS_OBJECT(m_element))
367         return JSStringCreateWithCharacters(0, 0);
368
369     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
370     if (!role)
371         return JSStringCreateWithCharacters(0, 0);
372
373     const gchar* roleName = atk_role_get_name(role);
374     GOwnPtr<gchar> axRole(g_strdup_printf("AXRole: %s", roleName));
375
376     return JSStringCreateWithUTF8CString(axRole.get());
377 }
378
379 JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole()
380 {
381     // FIXME: implement
382     return JSStringCreateWithCharacters(0, 0);
383 }
384
385 JSRetainPtr<JSStringRef> AccessibilityUIElement::roleDescription()
386 {
387     // FIXME: implement
388     return JSStringCreateWithCharacters(0, 0);
389 }
390
391 JSRetainPtr<JSStringRef> AccessibilityUIElement::title()
392 {
393     if (!m_element || !ATK_IS_OBJECT(m_element))
394         return JSStringCreateWithCharacters(0, 0);
395
396     const gchar* name = atk_object_get_name(ATK_OBJECT(m_element));
397     if (!name)
398         return JSStringCreateWithCharacters(0, 0);
399
400     GOwnPtr<gchar> axTitle(g_strdup_printf("AXTitle: %s", name));
401
402     return JSStringCreateWithUTF8CString(axTitle.get());
403 }
404
405 JSRetainPtr<JSStringRef> AccessibilityUIElement::description()
406 {
407     if (!m_element || !ATK_IS_OBJECT(m_element))
408         return JSStringCreateWithCharacters(0, 0);
409
410     const gchar* description = atk_object_get_description(ATK_OBJECT(m_element));
411     if (!description)
412         return JSStringCreateWithCharacters(0, 0);
413
414     GOwnPtr<gchar> axDesc(g_strdup_printf("AXDescription: %s", description));
415
416     return JSStringCreateWithUTF8CString(axDesc.get());
417 }
418
419 JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
420 {
421     // FIXME: implement
422     return JSStringCreateWithCharacters(0, 0);
423 }
424
425 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringValue()
426 {
427     if (!m_element || !ATK_IS_TEXT(m_element))
428         return JSStringCreateWithCharacters(0, 0);
429
430     GOwnPtr<gchar> text(atk_text_get_text(ATK_TEXT(m_element), 0, -1));
431     GOwnPtr<gchar> textWithReplacedCharacters(replaceCharactersForResults(text.get()));
432     GOwnPtr<gchar> axValue(g_strdup_printf("AXValue: %s", textWithReplacedCharacters.get()));
433
434     return JSStringCreateWithUTF8CString(axValue.get());
435 }
436
437 JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
438 {
439     // FIXME: implement
440     return JSStringCreateWithCharacters(0, 0);
441 }
442
443 JSRetainPtr<JSStringRef> AccessibilityUIElement::helpText() const
444 {
445     // FIXME: implement
446     // We need a way to call WebCore::AccessibilityObject::helpText()
447     // from here, probably a new helper class in WebProcess/WebCoreSupport.
448     return JSStringCreateWithCharacters(0, 0);
449 }
450
451 double AccessibilityUIElement::x()
452 {
453     if (!m_element || !ATK_IS_OBJECT(m_element))
454         return 0.0f;
455
456     int x, y;
457     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
458     return x;
459 }
460
461 double AccessibilityUIElement::y()
462 {
463     if (!m_element || !ATK_IS_OBJECT(m_element))
464         return 0.0f;
465
466     int x, y;
467     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
468     return y;
469 }
470
471 double AccessibilityUIElement::width()
472 {
473     if (!m_element || !ATK_IS_OBJECT(m_element))
474         return 0.0f;
475
476     int width, height;
477     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
478     return width;
479 }
480
481 double AccessibilityUIElement::height()
482 {
483     if (!m_element || !ATK_IS_OBJECT(m_element))
484         return 0.0f;
485
486     int width, height;
487     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
488     return height;
489 }
490
491 double AccessibilityUIElement::clickPointX()
492 {
493     // FIXME: implement
494     return 0.0f;
495 }
496
497 double AccessibilityUIElement::clickPointY()
498 {
499     // FIXME: implement
500     return 0.0f;
501 }
502
503 double AccessibilityUIElement::intValue() const
504 {
505     if (!m_element || !ATK_IS_OBJECT(m_element))
506         return 0.0f;
507
508     GValue value = G_VALUE_INIT;
509     atk_value_get_current_value(ATK_VALUE(m_element), &value);
510     if (!G_VALUE_HOLDS_FLOAT(&value))
511         return 0.0f;
512
513     return g_value_get_float(&value);
514 }
515
516 double AccessibilityUIElement::minValue()
517 {
518     if (!m_element || !ATK_IS_OBJECT(m_element))
519         return 0.0f;
520
521     GValue value = G_VALUE_INIT;
522     atk_value_get_minimum_value(ATK_VALUE(m_element), &value);
523     if (!G_VALUE_HOLDS_FLOAT(&value))
524         return 0.0f;
525
526     return g_value_get_float(&value);
527 }
528
529 double AccessibilityUIElement::maxValue()
530 {
531     if (!m_element || !ATK_IS_OBJECT(m_element))
532         return 0.0f;
533
534     GValue value = G_VALUE_INIT;
535     atk_value_get_maximum_value(ATK_VALUE(m_element), &value);
536     if (!G_VALUE_HOLDS_FLOAT(&value))
537         return 0.0f;
538
539     return g_value_get_float(&value);
540 }
541
542 JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
543 {
544     // FIXME: implement
545     return JSStringCreateWithCharacters(0, 0);
546 }
547
548 int AccessibilityUIElement::insertionPointLineNumber()
549 {
550     // FIXME: implement
551     return -1;
552 }
553
554 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
555 {
556     // FIXME: implement
557     return false;
558 }
559
560 bool AccessibilityUIElement::isEnabled()
561 {
562     return checkElementState(m_element, ATK_STATE_ENABLED);
563 }
564
565 bool AccessibilityUIElement::isRequired() const
566 {
567     // FIXME: implement
568     return false;
569 }
570
571 bool AccessibilityUIElement::isFocused() const
572 {
573     return checkElementState(m_element, ATK_STATE_FOCUSED);
574 }
575
576 bool AccessibilityUIElement::isSelected() const
577 {
578     return checkElementState(m_element, ATK_STATE_SELECTED);
579 }
580
581 bool AccessibilityUIElement::isExpanded() const
582 {
583     return checkElementState(m_element, ATK_STATE_EXPANDED);
584 }
585
586 bool AccessibilityUIElement::isChecked() const
587 {
588     return checkElementState(m_element, ATK_STATE_CHECKED);
589 }
590
591 int AccessibilityUIElement::hierarchicalLevel() const
592 {
593     // FIXME: implement
594     return 0;
595 }
596
597 JSRetainPtr<JSStringRef> AccessibilityUIElement::speak()
598 {
599     // FIXME: implement
600     return JSStringCreateWithCharacters(0, 0);
601 }
602
603 bool AccessibilityUIElement::ariaIsGrabbed() const
604 {
605     // FIXME: implement
606     return false;
607 }
608
609 JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
610 {
611     // FIXME: implement
612     return JSStringCreateWithCharacters(0, 0);
613 }
614
615 // parameterized attributes
616 int AccessibilityUIElement::lineForIndex(int index)
617 {
618     // FIXME: implement
619     return 0;
620 }
621
622 JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForLine(int line)
623 {
624     // FIXME: implement
625     return JSStringCreateWithCharacters(0, 0);
626 }
627
628 JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForPosition(int x, int y)
629 {
630     // FIXME: implement
631     return JSStringCreateWithCharacters(0, 0);
632 }
633
634 JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
635 {
636     // FIXME: implement
637     return JSStringCreateWithCharacters(0, 0);
638 }
639
640 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForRange(unsigned location, unsigned length)
641 {
642     // FIXME: implement
643     return JSStringCreateWithCharacters(0, 0);
644 }
645
646 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForRange(unsigned location, unsigned length)
647 {
648     // FIXME: implement
649     return JSStringCreateWithCharacters(0, 0);
650 }
651
652 bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned location, unsigned length)
653 {
654     // FIXME: implement
655     return false;
656 }
657
658 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementForSearchPredicate(AccessibilityUIElement* startElement, bool isDirectionNext, JSStringRef searchKey, JSStringRef searchText)
659 {
660     // FIXME: implement
661     return 0;
662 }
663
664 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders()
665 {
666     // FIXME: implement
667     return JSStringCreateWithCharacters(0, 0);
668 }
669
670 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders()
671 {
672     // FIXME: implement
673     return JSStringCreateWithCharacters(0, 0);
674 }
675
676 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns()
677 {
678     // FIXME: implement
679     return JSStringCreateWithCharacters(0, 0);
680 }
681
682 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows()
683 {
684     // FIXME: implement
685     return JSStringCreateWithCharacters(0, 0);
686 }
687
688 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells()
689 {
690     // FIXME: implement
691     return JSStringCreateWithCharacters(0, 0);
692 }
693
694 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader()
695 {
696     // FIXME: implement
697     return JSStringCreateWithCharacters(0, 0);
698 }
699
700 int AccessibilityUIElement::rowCount()
701 {
702     if (!m_element || !ATK_IS_TABLE(m_element))
703         return 0;
704
705     return atk_table_get_n_rows(ATK_TABLE(m_element));
706 }
707
708 int AccessibilityUIElement::columnCount()
709 {
710     if (!m_element || !ATK_IS_TABLE(m_element))
711         return 0;
712
713     return atk_table_get_n_columns(ATK_TABLE(m_element));
714 }
715
716 int AccessibilityUIElement::indexInTable()
717 {
718     // FIXME: implement
719     return -1;
720 }
721
722 JSRetainPtr<JSStringRef> AccessibilityUIElement::rowIndexRange()
723 {
724     // Range in table for rows.
725     return indexRangeInTable(m_element, true);
726 }
727
728 JSRetainPtr<JSStringRef> AccessibilityUIElement::columnIndexRange()
729 {
730     // Range in table for columns.
731     return indexRangeInTable(m_element, false);
732 }
733
734 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::cellForColumnAndRow(unsigned col, unsigned row)
735 {
736     if (!m_element || !ATK_IS_TABLE(m_element))
737         return 0;
738
739     AtkObject* foundCell = atk_table_ref_at(ATK_TABLE(m_element), row, col);
740     return foundCell ? AccessibilityUIElement::create(foundCell) : 0;
741 }
742
743 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::horizontalScrollbar() const
744 {
745     // FIXME: implement
746     return 0;
747 }
748
749 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::verticalScrollbar() const
750 {
751     // FIXME: implement
752     return 0;
753 }
754
755 JSRetainPtr<JSStringRef> AccessibilityUIElement::selectedTextRange()
756 {
757     // FIXME: implement
758     return JSStringCreateWithCharacters(0, 0);
759 }
760
761 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
762 {
763     // FIXME: implement
764 }
765
766 void AccessibilityUIElement::increment()
767 {
768     alterCurrentValue(m_element, 1);
769 }
770
771 void AccessibilityUIElement::decrement()
772 {
773     alterCurrentValue(m_element, -1);
774 }
775
776 void AccessibilityUIElement::showMenu()
777 {
778     // FIXME: implement
779 }
780
781 void AccessibilityUIElement::press()
782 {
783     if (!m_element || !ATK_IS_OBJECT(m_element))
784         return;
785
786     if (!ATK_IS_ACTION(m_element))
787         return;
788
789     // Only one action per object is supported so far.
790     atk_action_do_action(ATK_ACTION(m_element), 0);
791 }
792
793 void AccessibilityUIElement::setSelectedChild(AccessibilityUIElement* element) const
794 {
795     // FIXME: implement
796 }
797
798 JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
799 {
800     // FIXME: implement
801     return JSStringCreateWithCharacters(0, 0);
802 }
803
804 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
805 {
806     if (!m_element || !ATK_IS_OBJECT(m_element))
807         return JSStringCreateWithCharacters(0, 0);
808
809     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
810     if (role != ATK_ROLE_DOCUMENT_FRAME)
811         return JSStringCreateWithCharacters(0, 0);
812
813     return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element), "Encoding"));
814 }
815
816 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
817 {
818     if (!m_element || !ATK_IS_OBJECT(m_element))
819         return JSStringCreateWithCharacters(0, 0);
820
821     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
822     if (role != ATK_ROLE_DOCUMENT_FRAME)
823         return JSStringCreateWithCharacters(0, 0);
824
825     return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element), "URI"));
826 }
827
828 JSRetainPtr<JSStringRef> AccessibilityUIElement::url()
829 {
830     // FIXME: implement
831     return JSStringCreateWithCharacters(0, 0);
832 }
833
834 bool AccessibilityUIElement::addNotificationListener(JSValueRef functionCallback)
835 {
836     // FIXME: implement
837     return true;
838 }
839
840 bool AccessibilityUIElement::removeNotificationListener()
841 {
842     // FIXME: implement
843     return true;
844 }
845
846 bool AccessibilityUIElement::isFocusable() const
847 {
848     return checkElementState(m_element, ATK_STATE_FOCUSABLE);
849 }
850
851 bool AccessibilityUIElement::isSelectable() const
852 {
853     return checkElementState(m_element, ATK_STATE_SELECTABLE);
854 }
855
856 bool AccessibilityUIElement::isMultiSelectable() const
857 {
858     return checkElementState(m_element, ATK_STATE_MULTISELECTABLE);
859 }
860
861 bool AccessibilityUIElement::isVisible() const
862 {
863     return checkElementState(m_element, ATK_STATE_VISIBLE);
864 }
865
866 bool AccessibilityUIElement::isOffScreen() const
867 {
868     // FIXME: implement
869     return false;
870 }
871
872 bool AccessibilityUIElement::isCollapsed() const
873 {
874     // FIXME: implement
875     return false;
876 }
877
878 bool AccessibilityUIElement::isIgnored() const
879 {
880     // FIXME: implement
881     return false;
882 }
883
884 bool AccessibilityUIElement::hasPopup() const
885 {
886     // FIXME: implement
887     return false;
888 }
889
890 void AccessibilityUIElement::takeFocus()
891 {
892     // FIXME: implement
893 }
894
895 void AccessibilityUIElement::takeSelection()
896 {
897     // FIXME: implement
898 }
899
900 void AccessibilityUIElement::addSelection()
901 {
902     // FIXME: implement
903 }
904
905 void AccessibilityUIElement::removeSelection()
906 {
907     // FIXME: implement
908 }
909
910 // Text markers
911 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
912 {
913     // FIXME: implement
914     return 0;
915 }
916
917 int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
918 {
919     // FIXME: implement
920     return 0;
921 }
922
923 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
924 {
925     // FIXME: implement
926     return 0;
927 }
928
929 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
930 {
931     // FIXME: implement
932     return 0;
933 }
934
935 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
936 {
937     // FIXME: implement
938     return JSStringCreateWithCharacters(0, 0);
939 }
940
941 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
942 {
943     // FIXME: implement
944     return 0;
945 }
946
947 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
948 {
949     // FIXME: implement
950     return 0;
951 }
952
953 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
954 {
955     // FIXME: implement
956     return 0;
957 }
958
959 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(int x, int y)
960 {
961     // FIXME: implement
962     return 0;
963 }
964
965 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
966 {
967     // FIXME: implement
968     return 0;
969 }
970
971 bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
972 {
973     // FIXME: implement
974     return false;
975 }
976
977 int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker* marker)
978 {
979     // FIXME: implement
980     return -1;
981 }
982
983 bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker* textMarker)
984 {
985     // FIXME: implement
986     return false;
987 }
988
989 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForIndex(int textIndex)
990 {
991     // FIXME: implement
992     return 0;
993 }
994
995
996 } // namespace WTR