3f39a1781a1dd4ab51f1beb4f8b260935fd76cd8
[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(COCOA)
39 #ifdef __OBJC__
40 typedef id PlatformUIElement;
41 #else
42 typedef struct objc_object* PlatformUIElement;
43 #endif
44 #elif HAVE(ACCESSIBILITY) && (PLATFORM(GTK) || PLATFORM(EFL))
45 #include "AccessibilityNotificationHandlerAtk.h"
46 #include <atk/atk.h>
47 #include <wtf/glib/GRefPtr.h>
48 typedef GRefPtr<AtkObject> PlatformUIElement;
49 #else
50 typedef void* PlatformUIElement;
51 #endif
52
53 #if PLATFORM(COCOA)
54 #ifdef __OBJC__
55 typedef id NotificationHandler;
56 #else
57 typedef struct objc_object* NotificationHandler;
58 #endif
59 #endif
60
61 namespace WTR {
62
63 class AccessibilityUIElement : public JSWrappable {
64 public:
65     static PassRefPtr<AccessibilityUIElement> create(PlatformUIElement);
66     static PassRefPtr<AccessibilityUIElement> create(const AccessibilityUIElement&);
67
68     ~AccessibilityUIElement();
69
70     PlatformUIElement platformUIElement() { return m_element; }
71     virtual JSClassRef wrapperClass();
72
73     static JSObjectRef makeJSAccessibilityUIElement(JSContextRef, const AccessibilityUIElement&);
74
75     bool isEqual(AccessibilityUIElement* otherElement);
76     
77     PassRefPtr<AccessibilityUIElement> elementAtPoint(int x, int y);
78     PassRefPtr<AccessibilityUIElement> childAtIndex(unsigned);
79     unsigned indexOfChild(AccessibilityUIElement*);
80     int childrenCount();
81     PassRefPtr<AccessibilityUIElement> titleUIElement();
82     PassRefPtr<AccessibilityUIElement> parentElement();
83
84     void takeFocus();
85     void takeSelection();
86     void addSelection();
87     void removeSelection();
88
89     // Methods - platform-independent implementations
90     JSRetainPtr<JSStringRef> allAttributes();
91     JSRetainPtr<JSStringRef> attributesOfLinkedUIElements();
92     PassRefPtr<AccessibilityUIElement> linkedUIElementAtIndex(unsigned);
93     
94     JSRetainPtr<JSStringRef> attributesOfDocumentLinks();
95     JSRetainPtr<JSStringRef> attributesOfChildren();
96     JSRetainPtr<JSStringRef> parameterizedAttributeNames();
97     void increment();
98     void decrement();
99     void showMenu();
100     void press();
101
102     // Attributes - platform-independent implementations
103     JSRetainPtr<JSStringRef> stringAttributeValue(JSStringRef attribute);
104     double numberAttributeValue(JSStringRef attribute);
105     JSValueRef uiElementArrayAttributeValue(JSStringRef attribute) const;
106     PassRefPtr<AccessibilityUIElement> uiElementAttributeValue(JSStringRef attribute) const;
107     bool boolAttributeValue(JSStringRef attribute);
108     void setBoolAttributeValue(JSStringRef attribute, bool value);
109     bool isAttributeSupported(JSStringRef attribute);
110     bool isAttributeSettable(JSStringRef attribute);
111     bool isPressActionSupported();
112     bool isIncrementActionSupported();
113     bool isDecrementActionSupported();
114     JSRetainPtr<JSStringRef> role();
115     JSRetainPtr<JSStringRef> subrole();
116     JSRetainPtr<JSStringRef> roleDescription();
117     JSRetainPtr<JSStringRef> computedRoleString();
118     JSRetainPtr<JSStringRef> title();
119     JSRetainPtr<JSStringRef> description();
120     JSRetainPtr<JSStringRef> language();
121     JSRetainPtr<JSStringRef> stringValue();
122     JSRetainPtr<JSStringRef> accessibilityValue() const;
123     JSRetainPtr<JSStringRef> helpText() const;
124     JSRetainPtr<JSStringRef> orientation() const;
125     double x();
126     double y();
127     double width();
128     double height();
129     double intValue() const;
130     double minValue();
131     double maxValue();
132     JSRetainPtr<JSStringRef> valueDescription();
133     int insertionPointLineNumber();
134     JSRetainPtr<JSStringRef> selectedTextRange();
135     bool isEnabled();
136     bool isRequired() const;
137     
138     bool isFocused() const;
139     bool isFocusable() const;
140     bool isSelected() const;
141     bool isSelectedOptionActive() const;
142     bool isSelectable() const;
143     bool isMultiSelectable() const;
144     void setSelectedChild(AccessibilityUIElement*) const;
145     void setSelectedChildAtIndex(unsigned) const;
146     void removeSelectionAtIndex(unsigned) const;
147     unsigned selectedChildrenCount() const;
148     PassRefPtr<AccessibilityUIElement> selectedChildAtIndex(unsigned) const;
149     
150     bool isValid() const;
151     bool isExpanded() const;
152     bool isChecked() const;
153     bool isIndeterminate() 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     JSValueRef rowHeaders() const;
183     JSValueRef columnHeaders() const;
184
185     // Tree/Outline specific attributes
186     PassRefPtr<AccessibilityUIElement> selectedRowAtIndex(unsigned);
187     PassRefPtr<AccessibilityUIElement> disclosedByRow();
188     PassRefPtr<AccessibilityUIElement> disclosedRowAtIndex(unsigned);
189     PassRefPtr<AccessibilityUIElement> rowAtIndex(unsigned);
190
191     // ARIA specific
192     PassRefPtr<AccessibilityUIElement> ariaOwnsElementAtIndex(unsigned);
193     PassRefPtr<AccessibilityUIElement> ariaFlowToElementAtIndex(unsigned);
194     PassRefPtr<AccessibilityUIElement> ariaControlsElementAtIndex(unsigned);
195
196     // ARIA Drag and Drop
197     bool ariaIsGrabbed() const;
198     // A space concatentated string of all the drop effects.
199     JSRetainPtr<JSStringRef> ariaDropEffects() const;
200     
201     // Parameterized attributes
202     int lineForIndex(int);
203     JSRetainPtr<JSStringRef> rangeForLine(int);
204     JSRetainPtr<JSStringRef> rangeForPosition(int x, int y);
205     JSRetainPtr<JSStringRef> boundsForRange(unsigned location, unsigned length);
206     bool setSelectedTextRange(unsigned location, unsigned length);
207     JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
208     JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
209     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
210     unsigned uiElementCountForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
211     PassRefPtr<AccessibilityUIElement> uiElementForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
212     JSRetainPtr<JSStringRef> selectTextWithCriteria(JSContextRef, JSStringRef ambiguityResolution, JSValueRef searchStrings, JSStringRef replacementString, JSStringRef activity);
213
214     // Text-specific
215     JSRetainPtr<JSStringRef> characterAtOffset(int offset);
216     JSRetainPtr<JSStringRef> wordAtOffset(int offset);
217     JSRetainPtr<JSStringRef> lineAtOffset(int offset);
218     JSRetainPtr<JSStringRef> sentenceAtOffset(int offset);
219     
220     // Table-specific
221     PassRefPtr<AccessibilityUIElement> cellForColumnAndRow(unsigned column, unsigned row);
222
223     // Scrollarea-specific
224     PassRefPtr<AccessibilityUIElement> horizontalScrollbar() const;
225     PassRefPtr<AccessibilityUIElement> verticalScrollbar() const;
226
227     void scrollToMakeVisible();
228     void scrollToGlobalPoint(int x, int y);
229     void scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height);
230     
231     // Text markers.
232     PassRefPtr<AccessibilityTextMarkerRange> lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
233     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);    
234     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
235     PassRefPtr<AccessibilityTextMarkerRange> selectedTextMarkerRange();
236     void resetSelectedTextMarkerRange();
237     PassRefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
238     PassRefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
239     PassRefPtr<AccessibilityTextMarker> endTextMarkerForBounds(int x, int y, int width, int height);
240     PassRefPtr<AccessibilityTextMarker> startTextMarkerForBounds(int x, int y, int width, int height);
241     PassRefPtr<AccessibilityTextMarker> textMarkerForPoint(int x, int y);
242     PassRefPtr<AccessibilityTextMarker> previousTextMarker(AccessibilityTextMarker*);
243     PassRefPtr<AccessibilityTextMarker> nextTextMarker(AccessibilityTextMarker*);
244     PassRefPtr<AccessibilityUIElement> accessibilityElementForTextMarker(AccessibilityTextMarker*);
245     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
246     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
247     bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
248     int indexForTextMarker(AccessibilityTextMarker*);
249     bool isTextMarkerValid(AccessibilityTextMarker*);
250     PassRefPtr<AccessibilityTextMarker> textMarkerForIndex(int);
251     PassRefPtr<AccessibilityTextMarker> startTextMarker();
252     PassRefPtr<AccessibilityTextMarker> endTextMarker();
253     bool setSelectedVisibleTextRange(AccessibilityTextMarkerRange*);
254     PassRefPtr<AccessibilityTextMarkerRange> leftWordTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
255     PassRefPtr<AccessibilityTextMarkerRange> rightWordTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
256     PassRefPtr<AccessibilityTextMarker> previousWordStartTextMarkerForTextMarker(AccessibilityTextMarker*);
257     PassRefPtr<AccessibilityTextMarker> nextWordEndTextMarkerForTextMarker(AccessibilityTextMarker*);
258     PassRefPtr<AccessibilityTextMarkerRange> paragraphTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
259     PassRefPtr<AccessibilityTextMarker> nextParagraphEndTextMarkerForTextMarker(AccessibilityTextMarker*);
260     PassRefPtr<AccessibilityTextMarker> previousParagraphStartTextMarkerForTextMarker(AccessibilityTextMarker*);
261     PassRefPtr<AccessibilityTextMarkerRange> sentenceTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
262     PassRefPtr<AccessibilityTextMarker> nextSentenceEndTextMarkerForTextMarker(AccessibilityTextMarker*);
263     PassRefPtr<AccessibilityTextMarker> previousSentenceStartTextMarkerForTextMarker(AccessibilityTextMarker*);
264
265     // Returns an ordered list of supported actions for an element.
266     JSRetainPtr<JSStringRef> supportedActions() const;
267     JSRetainPtr<JSStringRef> mathPostscriptsDescription() const;
268     JSRetainPtr<JSStringRef> mathPrescriptsDescription() const;
269
270     JSRetainPtr<JSStringRef> pathDescription() const;
271     
272     // Notifications
273     // Function callback should take one argument, the name of the notification.
274     bool addNotificationListener(JSValueRef functionCallback);
275     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
276     bool removeNotificationListener();
277     
278     JSRetainPtr<JSStringRef> identifier();
279     JSRetainPtr<JSStringRef> traits();
280     int elementTextPosition();
281     int elementTextLength();
282     JSRetainPtr<JSStringRef> stringForSelection();
283     JSValueRef elementsForRange(unsigned location, unsigned length);
284     void increaseTextSelection();
285     void decreaseTextSelection();
286     PassRefPtr<AccessibilityUIElement> linkedElement();
287     PassRefPtr<AccessibilityUIElement> headerElementAtIndex(unsigned index);
288     void assistiveTechnologySimulatedFocus();
289     bool isSearchField() const;
290     bool isTextArea() const;
291     
292     bool scrollPageUp();
293     bool scrollPageDown();
294     bool scrollPageLeft();
295     bool scrollPageRight();
296     
297     // Fieldset
298     bool hasContainedByFieldsetTrait();
299     PassRefPtr<AccessibilityUIElement> fieldsetAncestorElement();
300     
301 private:
302     AccessibilityUIElement(PlatformUIElement);
303     AccessibilityUIElement(const AccessibilityUIElement&);
304
305     PlatformUIElement m_element;
306     
307     // A retained, platform specific object used to help manage notifications for this object.
308 #if HAVE(ACCESSIBILITY)
309 #if PLATFORM(COCOA)
310     NotificationHandler m_notificationHandler;
311
312     void getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >&);
313     void getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >&);
314     
315     void getUIElementsWithAttribute(JSStringRef, Vector<RefPtr<AccessibilityUIElement> >&) const;
316 #endif
317
318 #if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(EFL)
319     void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
320     void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
321 #endif
322
323 #if PLATFORM(GTK) || PLATFORM(EFL)
324     RefPtr<AccessibilityNotificationHandler> m_notificationHandler;
325 #endif
326 #endif
327 };
328     
329 } // namespace WTR
330     
331 #endif // AccessibilityUIElement_h