[ATK] Missing WTR AccessibilityUIElement::addNotificationListener implementation
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / AccessibilityUIElement.h
1 /*
2  * Copyright (C) 2011 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 #ifndef AccessibilityUIElement_h
27 #define AccessibilityUIElement_h
28
29 #include "AccessibilityTextMarker.h"
30 #include "AccessibilityTextMarkerRange.h"
31 #include "JSWrappable.h"
32
33 #include <JavaScriptCore/JSObjectRef.h>
34 #include <JavaScriptCore/JSRetainPtr.h>
35 #include <wtf/Platform.h>
36 #include <wtf/Vector.h>
37
38 #if PLATFORM(MAC)
39 #ifdef __OBJC__
40 typedef id PlatformUIElement;
41 #else
42 typedef struct objc_object* PlatformUIElement;
43 #endif
44 #elif PLATFORM(WIN)
45 #undef _WINSOCKAPI_
46 #define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h
47
48 #include <WebCore/COMPtr.h>
49 #include <oleacc.h>
50
51 typedef COMPtr<IAccessible> PlatformUIElement;
52 #elif PLATFORM(GTK) || (PLATFORM(EFL) && HAVE(ACCESSIBILITY))
53 #include "AccessibilityNotificationHandlerAtk.h"
54 #include <atk/atk.h>
55 #include <wtf/gobject/GRefPtr.h>
56 typedef GRefPtr<AtkObject> PlatformUIElement;
57 #else
58 typedef void* PlatformUIElement;
59 #endif
60
61 #if PLATFORM(MAC)
62 #ifdef __OBJC__
63 typedef id NotificationHandler;
64 #else
65 typedef struct objc_object* NotificationHandler;
66 #endif
67 #endif
68
69 namespace WTR {
70
71 class AccessibilityUIElement : public JSWrappable {
72 public:
73     static PassRefPtr<AccessibilityUIElement> create(PlatformUIElement);
74     static PassRefPtr<AccessibilityUIElement> create(const AccessibilityUIElement&);
75
76     ~AccessibilityUIElement();
77
78     PlatformUIElement platformUIElement() { return m_element; }
79     virtual JSClassRef wrapperClass();
80
81     static JSObjectRef makeJSAccessibilityUIElement(JSContextRef, const AccessibilityUIElement&);
82
83     bool isEqual(AccessibilityUIElement* otherElement);
84     
85     PassRefPtr<AccessibilityUIElement> elementAtPoint(int x, int y);
86     PassRefPtr<AccessibilityUIElement> childAtIndex(unsigned);
87     unsigned indexOfChild(AccessibilityUIElement*);
88     int childrenCount();
89     PassRefPtr<AccessibilityUIElement> titleUIElement();
90     PassRefPtr<AccessibilityUIElement> parentElement();
91
92     void takeFocus();
93     void takeSelection();
94     void addSelection();
95     void removeSelection();
96
97     // Methods - platform-independent implementations
98     JSRetainPtr<JSStringRef> allAttributes();
99     JSRetainPtr<JSStringRef> attributesOfLinkedUIElements();
100     PassRefPtr<AccessibilityUIElement> linkedUIElementAtIndex(unsigned);
101     
102     JSRetainPtr<JSStringRef> attributesOfDocumentLinks();
103     JSRetainPtr<JSStringRef> attributesOfChildren();
104     JSRetainPtr<JSStringRef> parameterizedAttributeNames();
105     void increment();
106     void decrement();
107     void showMenu();
108     void press();
109
110     // Attributes - platform-independent implementations
111     JSRetainPtr<JSStringRef> stringAttributeValue(JSStringRef attribute);
112     double numberAttributeValue(JSStringRef attribute);
113     PassRefPtr<AccessibilityUIElement> uiElementAttributeValue(JSStringRef attribute) const;
114     bool boolAttributeValue(JSStringRef attribute);
115     bool isAttributeSupported(JSStringRef attribute);
116     bool isAttributeSettable(JSStringRef attribute);
117     bool isPressActionSupported();
118     bool isIncrementActionSupported();
119     bool isDecrementActionSupported();
120     JSRetainPtr<JSStringRef> role();
121     JSRetainPtr<JSStringRef> subrole();
122     JSRetainPtr<JSStringRef> roleDescription();
123     JSRetainPtr<JSStringRef> title();
124     JSRetainPtr<JSStringRef> description();
125     JSRetainPtr<JSStringRef> language();
126     JSRetainPtr<JSStringRef> stringValue();
127     JSRetainPtr<JSStringRef> accessibilityValue() const;
128     JSRetainPtr<JSStringRef> helpText() const;
129     JSRetainPtr<JSStringRef> orientation() const;
130     double x();
131     double y();
132     double width();
133     double height();
134     double intValue() const;
135     double minValue();
136     double maxValue();
137     JSRetainPtr<JSStringRef> valueDescription();
138     int insertionPointLineNumber();
139     JSRetainPtr<JSStringRef> selectedTextRange();
140     bool isEnabled();
141     bool isRequired() const;
142     
143     bool isFocused() const;
144     bool isFocusable() const;
145     bool isSelected() const;
146     bool isSelectable() const;
147     bool isMultiSelectable() const;
148     void setSelectedChild(AccessibilityUIElement*) const;
149     unsigned selectedChildrenCount() const;
150     PassRefPtr<AccessibilityUIElement> selectedChildAtIndex(unsigned) const;
151     
152     bool isValid() const;
153     bool isExpanded() const;
154     bool isChecked() const;
155     bool isVisible() const;
156     bool isOffScreen() const;
157     bool isCollapsed() const;
158     bool isIgnored() const;
159     bool hasPopup() const;
160     int hierarchicalLevel() const;
161     double clickPointX();
162     double clickPointY();
163     JSRetainPtr<JSStringRef> documentEncoding();
164     JSRetainPtr<JSStringRef> documentURI();
165     JSRetainPtr<JSStringRef> url();
166     JSRetainPtr<JSStringRef> classList() const;
167
168     // CSS3-speech properties.
169     JSRetainPtr<JSStringRef> speak();
170     
171     // Table-specific attributes
172     JSRetainPtr<JSStringRef> attributesOfColumnHeaders();
173     JSRetainPtr<JSStringRef> attributesOfRowHeaders();
174     JSRetainPtr<JSStringRef> attributesOfColumns();
175     JSRetainPtr<JSStringRef> attributesOfRows();
176     JSRetainPtr<JSStringRef> attributesOfVisibleCells();
177     JSRetainPtr<JSStringRef> attributesOfHeader();
178     int indexInTable();
179     JSRetainPtr<JSStringRef> rowIndexRange();
180     JSRetainPtr<JSStringRef> columnIndexRange();
181     int rowCount();
182     int columnCount();
183     
184     // Tree/Outline specific attributes
185     PassRefPtr<AccessibilityUIElement> selectedRowAtIndex(unsigned);
186     PassRefPtr<AccessibilityUIElement> disclosedByRow();
187     PassRefPtr<AccessibilityUIElement> disclosedRowAtIndex(unsigned);
188     PassRefPtr<AccessibilityUIElement> rowAtIndex(unsigned);
189
190     // ARIA specific
191     PassRefPtr<AccessibilityUIElement> ariaOwnsElementAtIndex(unsigned);
192     PassRefPtr<AccessibilityUIElement> ariaFlowToElementAtIndex(unsigned);
193
194     // ARIA Drag and Drop
195     bool ariaIsGrabbed() const;
196     // A space concatentated string of all the drop effects.
197     JSRetainPtr<JSStringRef> ariaDropEffects() const;
198     
199     // Parameterized attributes
200     int lineForIndex(int);
201     JSRetainPtr<JSStringRef> rangeForLine(int);
202     JSRetainPtr<JSStringRef> rangeForPosition(int x, int y);
203     JSRetainPtr<JSStringRef> boundsForRange(unsigned location, unsigned length);
204     void setSelectedTextRange(unsigned location, unsigned length);
205     JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
206     JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
207     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
208     PassRefPtr<AccessibilityUIElement> uiElementForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly);
209     
210     // Table-specific
211     PassRefPtr<AccessibilityUIElement> cellForColumnAndRow(unsigned column, unsigned row);
212
213     // Scrollarea-specific
214     PassRefPtr<AccessibilityUIElement> horizontalScrollbar() const;
215     PassRefPtr<AccessibilityUIElement> verticalScrollbar() const;
216
217     void scrollToMakeVisible();
218     
219     // Text markers.
220     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);    
221     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
222     PassRefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
223     PassRefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
224     PassRefPtr<AccessibilityTextMarker> textMarkerForPoint(int x, int y);
225     PassRefPtr<AccessibilityTextMarker> previousTextMarker(AccessibilityTextMarker*);
226     PassRefPtr<AccessibilityTextMarker> nextTextMarker(AccessibilityTextMarker*);
227     PassRefPtr<AccessibilityUIElement> accessibilityElementForTextMarker(AccessibilityTextMarker*);
228     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
229     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
230     bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
231     int indexForTextMarker(AccessibilityTextMarker*);
232     bool isTextMarkerValid(AccessibilityTextMarker*);
233     PassRefPtr<AccessibilityTextMarker> textMarkerForIndex(int);
234
235     // Returns an ordered list of supported actions for an element.
236     JSRetainPtr<JSStringRef> supportedActions() const;
237     JSRetainPtr<JSStringRef> mathPostscriptsDescription() const;
238     JSRetainPtr<JSStringRef> mathPrescriptsDescription() const;
239
240     JSRetainPtr<JSStringRef> pathDescription() const;
241     
242     // Notifications
243     // Function callback should take one argument, the name of the notification.
244     bool addNotificationListener(JSValueRef functionCallback);
245     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
246     bool removeNotificationListener();
247     
248 private:
249     AccessibilityUIElement(PlatformUIElement);
250     AccessibilityUIElement(const AccessibilityUIElement&);
251
252     PlatformUIElement m_element;
253     
254     // A retained, platform specific object used to help manage notifications for this object.
255 #if PLATFORM(MAC)
256     NotificationHandler m_notificationHandler;
257
258     void getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >&);
259     void getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >&);
260 #endif
261
262 #if PLATFORM(MAC) || PLATFORM(GTK) || (PLATFORM(EFL) && HAVE(ACCESSIBILITY))
263     void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
264     void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
265 #endif
266
267 #if PLATFORM(GTK) || (PLATFORM(EFL) && HAVE(ACCESSIBILITY))
268     RefPtr<AccessibilityNotificationHandler> m_notificationHandler;
269 #endif
270 };
271     
272 } // namespace WTR
273     
274 #endif // AccessibilityUIElement_h