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