Introduce makeBlockPtr for lambdas
[WebKit-https.git] / Tools / DumpRenderTree / AccessibilityUIElement.h
1 /*
2  * Copyright (C) 2008 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 #pragma once
27
28 #include "AccessibilityTextMarker.h"
29 #include <JavaScriptCore/JSObjectRef.h>
30 #include <JavaScriptCore/JSRetainPtr.h>
31 #include <wtf/Platform.h>
32 #include <wtf/Vector.h>
33
34 #if PLATFORM(COCOA)
35 #ifdef __OBJC__
36 typedef id PlatformUIElement;
37 #else
38 typedef struct objc_object* PlatformUIElement;
39 #endif
40 #elif PLATFORM(WIN)
41 #undef _WINSOCKAPI_
42 #define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h
43
44 #include <WebCore/COMPtr.h>
45 #include <oleacc.h>
46
47 typedef COMPtr<IAccessible> PlatformUIElement;
48 #elif HAVE(ACCESSIBILITY) && PLATFORM(GTK)
49 #include "AccessibilityNotificationHandlerAtk.h"
50 #include <atk/atk.h>
51 typedef AtkObject* PlatformUIElement;
52 #else
53 typedef void* PlatformUIElement;
54 #endif
55
56 #if PLATFORM(COCOA)
57 #ifdef __OBJC__
58 typedef id NotificationHandler;
59 #else
60 typedef struct objc_object* NotificationHandler;
61 #endif
62 #endif
63
64 class AccessibilityUIElement {
65 public:
66     AccessibilityUIElement(PlatformUIElement);
67     AccessibilityUIElement(const AccessibilityUIElement&);
68     ~AccessibilityUIElement();
69
70     PlatformUIElement platformUIElement() const { return m_element; }
71
72     static JSObjectRef makeJSAccessibilityUIElement(JSContextRef, const AccessibilityUIElement&);
73
74     bool isEqual(AccessibilityUIElement* otherElement);
75
76     void getLinkedUIElements(Vector<AccessibilityUIElement>&);
77     void getDocumentLinks(Vector<AccessibilityUIElement>&);
78     void getChildren(Vector<AccessibilityUIElement>&);
79     void getChildrenWithRange(Vector<AccessibilityUIElement>&, unsigned location, unsigned length);
80     
81     AccessibilityUIElement elementAtPoint(int x, int y);
82     AccessibilityUIElement getChildAtIndex(unsigned);
83     unsigned indexOfChild(AccessibilityUIElement*);
84     int childrenCount();
85     AccessibilityUIElement titleUIElement();
86     AccessibilityUIElement parentElement();
87
88     void takeFocus();
89     void takeSelection();
90     void addSelection();
91     void removeSelection();
92
93     // Methods - platform-independent implementations
94     JSRetainPtr<JSStringRef> allAttributes();
95     JSRetainPtr<JSStringRef> attributesOfLinkedUIElements();
96     AccessibilityUIElement linkedUIElementAtIndex(unsigned);
97     
98     JSRetainPtr<JSStringRef> attributesOfDocumentLinks();
99     JSRetainPtr<JSStringRef> attributesOfChildren();
100     JSRetainPtr<JSStringRef> parameterizedAttributeNames();
101     void increment();
102     void decrement();
103     void showMenu();
104     void press();
105
106     // Attributes - platform-independent implementations
107     JSRetainPtr<JSStringRef> stringAttributeValue(JSStringRef attribute);
108     double numberAttributeValue(JSStringRef attribute);
109     void uiElementArrayAttributeValue(JSStringRef attribute, Vector<AccessibilityUIElement>& elements) const;
110     AccessibilityUIElement uiElementAttributeValue(JSStringRef attribute) const;    
111     bool boolAttributeValue(JSStringRef attribute);
112     void setBoolAttributeValue(JSStringRef attribute, bool value);
113     bool isAttributeSupported(JSStringRef attribute);
114     bool isAttributeSettable(JSStringRef attribute);
115     bool isPressActionSupported();
116     bool isIncrementActionSupported();
117     bool isDecrementActionSupported();
118     JSRetainPtr<JSStringRef> role();
119     JSRetainPtr<JSStringRef> subrole();
120     JSRetainPtr<JSStringRef> roleDescription();
121     JSRetainPtr<JSStringRef> computedRoleString();
122     JSRetainPtr<JSStringRef> title();
123     JSRetainPtr<JSStringRef> description();
124     JSRetainPtr<JSStringRef> language();
125     JSRetainPtr<JSStringRef> stringValue();
126     JSRetainPtr<JSStringRef> accessibilityValue() const;
127     void setValue(JSStringRef);
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> pathDescription() const;
138     JSRetainPtr<JSStringRef> valueDescription();
139     int insertionPointLineNumber();
140     JSRetainPtr<JSStringRef> selectedTextRange();
141     bool isEnabled();
142     bool isRequired() const;
143     
144     bool isFocused() const;
145     bool isFocusable() const;
146     bool isSelected() const;
147     bool isSelectable() const;
148     bool isMultiSelectable() const;
149     bool isSelectedOptionActive() const;
150     void setSelectedChild(AccessibilityUIElement*) const;
151     unsigned selectedChildrenCount() const;
152     AccessibilityUIElement selectedChildAtIndex(unsigned) const;
153     void setSelectedChildAtIndex(unsigned) const;
154     void removeSelectionAtIndex(unsigned) const;
155     void clearSelectedChildren() const;
156     
157     bool isExpanded() const;
158     bool isChecked() const;
159     bool isVisible() const;
160     bool isOffScreen() const;
161     bool isCollapsed() const;
162     bool isIgnored() const;
163     bool isSingleLine() const;
164     bool isMultiLine() const;
165     bool isIndeterminate() const;
166     bool hasPopup() const;
167     int hierarchicalLevel() const;
168     double clickPointX();
169     double clickPointY();
170     JSRetainPtr<JSStringRef> documentEncoding();
171     JSRetainPtr<JSStringRef> documentURI();
172     JSRetainPtr<JSStringRef> url();
173     JSRetainPtr<JSStringRef> classList() const;
174
175     // CSS3-speech properties.
176     JSRetainPtr<JSStringRef> speakAs();
177     
178     // Table-specific attributes
179     JSRetainPtr<JSStringRef> attributesOfColumnHeaders();
180     JSRetainPtr<JSStringRef> attributesOfRowHeaders();
181     JSRetainPtr<JSStringRef> attributesOfColumns();
182     JSRetainPtr<JSStringRef> attributesOfRows();
183     JSRetainPtr<JSStringRef> attributesOfVisibleCells();
184     JSRetainPtr<JSStringRef> attributesOfHeader();
185     int indexInTable();
186     JSRetainPtr<JSStringRef> rowIndexRange();
187     JSRetainPtr<JSStringRef> columnIndexRange();
188     int rowCount();
189     int columnCount();
190     void rowHeaders(Vector<AccessibilityUIElement>& elements) const;
191     void columnHeaders(Vector<AccessibilityUIElement>& elements) const;
192     
193     // Tree/Outline specific attributes
194     AccessibilityUIElement selectedRowAtIndex(unsigned);
195     AccessibilityUIElement disclosedByRow();
196     AccessibilityUIElement disclosedRowAtIndex(unsigned);
197     AccessibilityUIElement rowAtIndex(unsigned);
198
199     // ARIA specific
200     AccessibilityUIElement ariaOwnsElementAtIndex(unsigned);
201     AccessibilityUIElement ariaFlowToElementAtIndex(unsigned);
202     AccessibilityUIElement ariaControlsElementAtIndex(unsigned);
203
204     // ARIA Drag and Drop
205     bool ariaIsGrabbed() const;
206     // A space concatentated string of all the drop effects.
207     JSRetainPtr<JSStringRef> ariaDropEffects() const;
208     
209     // Parameterized attributes
210     int lineForIndex(int);
211     JSRetainPtr<JSStringRef> rangeForLine(int);
212     JSRetainPtr<JSStringRef> rangeForPosition(int x, int y);
213     JSRetainPtr<JSStringRef> boundsForRange(unsigned location, unsigned length);
214     void setSelectedTextRange(unsigned location, unsigned length);
215     JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
216     JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
217     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
218     unsigned uiElementCountForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
219     AccessibilityUIElement uiElementForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
220     JSRetainPtr<JSStringRef> selectTextWithCriteria(JSContextRef, JSStringRef ambiguityResolution, JSValueRef searchStrings, JSStringRef replacementString, JSStringRef activity);
221 #if PLATFORM(IOS_FAMILY)
222     void elementsForRange(unsigned location, unsigned length, Vector<AccessibilityUIElement>& elements);
223     JSRetainPtr<JSStringRef> stringForSelection();
224     void increaseTextSelection();
225     void decreaseTextSelection();
226     AccessibilityUIElement linkedElement();
227     
228     bool scrollPageUp();
229     bool scrollPageDown();
230     bool scrollPageLeft();
231     bool scrollPageRight();
232     
233     bool hasContainedByFieldsetTrait();
234     AccessibilityUIElement fieldsetAncestorElement();
235     JSRetainPtr<JSStringRef> attributedStringForElement();
236 #endif
237
238 #if PLATFORM(GTK)
239     // Text-specific
240     JSRetainPtr<JSStringRef> characterAtOffset(int offset);
241     JSRetainPtr<JSStringRef> wordAtOffset(int offset);
242     JSRetainPtr<JSStringRef> lineAtOffset(int offset);
243     JSRetainPtr<JSStringRef> sentenceAtOffset(int offset);
244 #endif
245
246     // Table-specific
247     AccessibilityUIElement cellForColumnAndRow(unsigned column, unsigned row);
248
249     // Scrollarea-specific
250     AccessibilityUIElement horizontalScrollbar() const;
251     AccessibilityUIElement verticalScrollbar() const;
252
253     // Text markers.
254     AccessibilityTextMarkerRange lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
255     AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement*);    
256     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
257     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
258     AccessibilityTextMarker endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
259     AccessibilityTextMarker endTextMarkerForBounds(int x, int y, int width, int height);
260     AccessibilityTextMarker startTextMarkerForBounds(int x, int y, int width, int height);
261     AccessibilityTextMarker textMarkerForPoint(int x, int y);
262     AccessibilityTextMarker previousTextMarker(AccessibilityTextMarker*);
263     AccessibilityTextMarker nextTextMarker(AccessibilityTextMarker*);
264     AccessibilityUIElement accessibilityElementForTextMarker(AccessibilityTextMarker*);
265     AccessibilityTextMarker startTextMarker();
266     AccessibilityTextMarker endTextMarker();
267     AccessibilityTextMarkerRange leftWordTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
268     AccessibilityTextMarkerRange rightWordTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
269     AccessibilityTextMarker previousWordStartTextMarkerForTextMarker(AccessibilityTextMarker*);
270     AccessibilityTextMarker nextWordEndTextMarkerForTextMarker(AccessibilityTextMarker*);
271     AccessibilityTextMarkerRange paragraphTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
272     AccessibilityTextMarker previousParagraphStartTextMarkerForTextMarker(AccessibilityTextMarker*);
273     AccessibilityTextMarker nextParagraphEndTextMarkerForTextMarker(AccessibilityTextMarker*);
274     AccessibilityTextMarkerRange sentenceTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
275     AccessibilityTextMarker previousSentenceStartTextMarkerForTextMarker(AccessibilityTextMarker*);
276     AccessibilityTextMarker nextSentenceEndTextMarkerForTextMarker(AccessibilityTextMarker*);
277     AccessibilityTextMarkerRange selectedTextMarkerRange();
278     void resetSelectedTextMarkerRange();
279     bool setSelectedVisibleTextRange(AccessibilityTextMarkerRange*);
280     
281     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
282     JSRetainPtr<JSStringRef> attributedStringForTextMarkerRange(AccessibilityTextMarkerRange*);
283     JSRetainPtr<JSStringRef> attributedStringForTextMarkerRangeWithOptions(AccessibilityTextMarkerRange*, bool includeSpellCheck);
284     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
285     bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
286     int indexForTextMarker(AccessibilityTextMarker*);
287     bool isTextMarkerValid(AccessibilityTextMarker*);
288     AccessibilityTextMarker textMarkerForIndex(int);
289     
290     void scrollToMakeVisible();
291     void scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height);
292     void scrollToGlobalPoint(int x, int y);
293
294     // Notifications
295     // Function callback should take one argument, the name of the notification.
296     bool addNotificationListener(JSObjectRef functionCallback);
297     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
298     void removeNotificationListener();
299     
300 #if PLATFORM(IOS_FAMILY)
301     JSRetainPtr<JSStringRef> traits();
302     JSRetainPtr<JSStringRef> identifier();
303     int elementTextPosition();
304     int elementTextLength();
305     AccessibilityUIElement headerElementAtIndex(unsigned);
306     // This will simulate the accessibilityDidBecomeFocused API in UIKit.
307     void assistiveTechnologySimulatedFocus();
308     
309     bool isTextArea() const;
310     bool isSearchField() const;
311     
312     AccessibilityTextMarkerRange textMarkerRangeMatchesTextNearMarkers(JSStringRef, AccessibilityTextMarker*, AccessibilityTextMarker*);
313     
314 #endif // PLATFORM(IOS_FAMILY)
315
316 #if PLATFORM(MAC) && !PLATFORM(IOS_FAMILY)
317     // Returns an ordered list of supported actions for an element.
318     JSRetainPtr<JSStringRef> supportedActions();
319     
320     // A general description of the elements making up multiscript pre/post objects.
321     JSRetainPtr<JSStringRef> mathPostscriptsDescription() const;
322     JSRetainPtr<JSStringRef> mathPrescriptsDescription() const;
323 #endif
324     
325 private:
326     static JSClassRef getJSClass();
327     PlatformUIElement m_element;
328     
329 #if PLATFORM(COCOA)
330     // A retained, platform specific object used to help manage notifications for this object.
331     NotificationHandler m_notificationHandler;
332 #endif
333
334 #if HAVE(ACCESSIBILITY) && PLATFORM(GTK)
335     RefPtr<AccessibilityNotificationHandler> m_notificationHandler;
336 #endif
337 };