AX: Implement paragraph related text marker functions using TextIterator
[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
262     // Returns an ordered list of supported actions for an element.
263     JSRetainPtr<JSStringRef> supportedActions() const;
264     JSRetainPtr<JSStringRef> mathPostscriptsDescription() const;
265     JSRetainPtr<JSStringRef> mathPrescriptsDescription() const;
266
267     JSRetainPtr<JSStringRef> pathDescription() const;
268     
269     // Notifications
270     // Function callback should take one argument, the name of the notification.
271     bool addNotificationListener(JSValueRef functionCallback);
272     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
273     bool removeNotificationListener();
274     
275     JSRetainPtr<JSStringRef> identifier();
276     JSRetainPtr<JSStringRef> traits();
277     int elementTextPosition();
278     int elementTextLength();
279     JSRetainPtr<JSStringRef> stringForSelection();
280     JSValueRef elementsForRange(unsigned location, unsigned length);
281     void increaseTextSelection();
282     void decreaseTextSelection();
283     PassRefPtr<AccessibilityUIElement> linkedElement();
284     PassRefPtr<AccessibilityUIElement> headerElementAtIndex(unsigned index);
285     void assistiveTechnologySimulatedFocus();
286     bool isSearchField() const;
287     bool isTextArea() const;
288     
289     bool scrollPageUp();
290     bool scrollPageDown();
291     bool scrollPageLeft();
292     bool scrollPageRight();
293     
294     // Fieldset
295     bool hasContainedByFieldsetTrait();
296     PassRefPtr<AccessibilityUIElement> fieldsetAncestorElement();
297     
298 private:
299     AccessibilityUIElement(PlatformUIElement);
300     AccessibilityUIElement(const AccessibilityUIElement&);
301
302     PlatformUIElement m_element;
303     
304     // A retained, platform specific object used to help manage notifications for this object.
305 #if HAVE(ACCESSIBILITY)
306 #if PLATFORM(COCOA)
307     NotificationHandler m_notificationHandler;
308
309     void getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >&);
310     void getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >&);
311     
312     void getUIElementsWithAttribute(JSStringRef, Vector<RefPtr<AccessibilityUIElement> >&) const;
313 #endif
314
315 #if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(EFL)
316     void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
317     void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
318 #endif
319
320 #if PLATFORM(GTK) || PLATFORM(EFL)
321     RefPtr<AccessibilityNotificationHandler> m_notificationHandler;
322 #endif
323 #endif
324 };
325     
326 } // namespace WTR
327     
328 #endif // AccessibilityUIElement_h