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