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