AX: Support solution to handle invalid ax text marker
[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> boundsForRange(unsigned location, unsigned length);
198     void setSelectedTextRange(unsigned location, unsigned length);
199     JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
200     JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
201     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
202     PassRefPtr<AccessibilityUIElement> uiElementForSearchPredicate(AccessibilityUIElement* startElement, bool isDirectionNext, JSStringRef searchKey, JSStringRef searchText);
203     
204     // Table-specific
205     PassRefPtr<AccessibilityUIElement> cellForColumnAndRow(unsigned column, unsigned row);
206
207     // Scrollarea-specific
208     PassRefPtr<AccessibilityUIElement> horizontalScrollbar() const;
209     PassRefPtr<AccessibilityUIElement> verticalScrollbar() const;
210
211     // Text markers.
212     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);    
213     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
214     PassRefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
215     PassRefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
216     PassRefPtr<AccessibilityTextMarker> textMarkerForPoint(int x, int y);
217     PassRefPtr<AccessibilityTextMarker> previousTextMarker(AccessibilityTextMarker*);
218     PassRefPtr<AccessibilityTextMarker> nextTextMarker(AccessibilityTextMarker*);
219     PassRefPtr<AccessibilityUIElement> accessibilityElementForTextMarker(AccessibilityTextMarker*);
220     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
221     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
222     bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
223     int indexForTextMarker(AccessibilityTextMarker*);
224     bool isTextMarkerValid(AccessibilityTextMarker*);
225     PassRefPtr<AccessibilityTextMarker> textMarkerForIndex(int);
226
227     // Notifications
228     // Function callback should take one argument, the name of the notification.
229     bool addNotificationListener(JSValueRef functionCallback);
230     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
231     bool removeNotificationListener();
232     
233 private:
234     AccessibilityUIElement(PlatformUIElement);
235     AccessibilityUIElement(const AccessibilityUIElement&);
236
237     PlatformUIElement m_element;
238     
239     // A retained, platform specific object used to help manage notifications for this object.
240 #if PLATFORM(MAC)
241     NotificationHandler m_notificationHandler;
242
243     void getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >&);
244     void getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >&);
245     void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
246     void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
247 #endif
248 };
249     
250 } // namespace WTR
251     
252 #endif // AccessibilityUIElement_h