• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008, 2009 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 #include "config.h"
27 #include "AccessibilityUIElement.h"
28 
29 #include <JavaScriptCore/JSRetainPtr.h>
30 
31 // Static Functions
32 
toAXElement(JSObjectRef object)33 static inline AccessibilityUIElement* toAXElement(JSObjectRef object)
34 {
35     // FIXME: We should ASSERT that it is the right class here.
36     return static_cast<AccessibilityUIElement*>(JSObjectGetPrivate(object));
37 }
38 
allAttributesCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)39 static JSValueRef allAttributesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
40 {
41     JSRetainPtr<JSStringRef> attributes(Adopt, toAXElement(thisObject)->allAttributes());
42     return JSValueMakeString(context, attributes.get());
43 }
44 
attributesOfLinkedUIElementsCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)45 static JSValueRef attributesOfLinkedUIElementsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
46 {
47     JSRetainPtr<JSStringRef> linkedUIDescription(Adopt, toAXElement(thisObject)->attributesOfLinkedUIElements());
48     return JSValueMakeString(context, linkedUIDescription.get());
49 }
50 
attributesOfDocumentLinksCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)51 static JSValueRef attributesOfDocumentLinksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
52 {
53     JSRetainPtr<JSStringRef> linkedUIDescription(Adopt, toAXElement(thisObject)->attributesOfDocumentLinks());
54     return JSValueMakeString(context, linkedUIDescription.get());
55 }
56 
attributesOfChildrenCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)57 static JSValueRef attributesOfChildrenCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
58 {
59     JSRetainPtr<JSStringRef> childrenDescription(Adopt, toAXElement(thisObject)->attributesOfChildren());
60     return JSValueMakeString(context, childrenDescription.get());
61 }
62 
parameterizedAttributeNamesCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)63 static JSValueRef parameterizedAttributeNamesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
64 {
65     JSRetainPtr<JSStringRef> parameterizedAttributeNames(Adopt, toAXElement(thisObject)->parameterizedAttributeNames());
66     return JSValueMakeString(context, parameterizedAttributeNames.get());
67 }
68 
attributesOfColumnHeadersCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)69 static JSValueRef attributesOfColumnHeadersCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
70 {
71     JSRetainPtr<JSStringRef> attributesOfColumnHeaders(Adopt, toAXElement(thisObject)->attributesOfColumnHeaders());
72     return JSValueMakeString(context, attributesOfColumnHeaders.get());
73 }
74 
attributesOfRowHeadersCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)75 static JSValueRef attributesOfRowHeadersCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
76 {
77     JSRetainPtr<JSStringRef> attributesOfRowHeaders(Adopt, toAXElement(thisObject)->attributesOfRowHeaders());
78     return JSValueMakeString(context, attributesOfRowHeaders.get());
79 }
80 
attributesOfColumnsCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)81 static JSValueRef attributesOfColumnsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
82 {
83     JSRetainPtr<JSStringRef> attributesOfColumns(Adopt, toAXElement(thisObject)->attributesOfColumns());
84     return JSValueMakeString(context, attributesOfColumns.get());
85 }
86 
attributesOfRowsCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)87 static JSValueRef attributesOfRowsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
88 {
89     JSRetainPtr<JSStringRef> attributesOfRows(Adopt, toAXElement(thisObject)->attributesOfRows());
90     return JSValueMakeString(context, attributesOfRows.get());
91 }
92 
attributesOfVisibleCellsCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)93 static JSValueRef attributesOfVisibleCellsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
94 {
95     JSRetainPtr<JSStringRef> attributesOfVisibleCells(Adopt, toAXElement(thisObject)->attributesOfVisibleCells());
96     return JSValueMakeString(context, attributesOfVisibleCells.get());
97 }
98 
attributesOfHeaderCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)99 static JSValueRef attributesOfHeaderCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
100 {
101     JSRetainPtr<JSStringRef> attributesOfHeader(Adopt, toAXElement(thisObject)->attributesOfHeader());
102     return JSValueMakeString(context, attributesOfHeader.get());
103 }
104 
indexInTableCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)105 static JSValueRef indexInTableCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
106 {
107     return JSValueMakeNumber(context, toAXElement(thisObject)->indexInTable());
108 }
109 
rowIndexRangeCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)110 static JSValueRef rowIndexRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
111 {
112     JSRetainPtr<JSStringRef> rowIndexRange(Adopt, toAXElement(thisObject)->rowIndexRange());
113     return JSValueMakeString(context, rowIndexRange.get());
114 }
115 
columnIndexRangeCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)116 static JSValueRef columnIndexRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
117 {
118     JSRetainPtr<JSStringRef> columnIndexRange(Adopt, toAXElement(thisObject)->columnIndexRange());
119     return JSValueMakeString(context, columnIndexRange.get());
120 }
121 
lineForIndexCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)122 static JSValueRef lineForIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
123 {
124     int indexNumber = -1;
125     if (argumentCount == 1)
126         indexNumber = JSValueToNumber(context, arguments[0], exception);
127 
128     return JSValueMakeNumber(context, toAXElement(thisObject)->lineForIndex(indexNumber));
129 }
130 
boundsForRangeCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)131 static JSValueRef boundsForRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
132 {
133     unsigned location = UINT_MAX, length = 0;
134     if (argumentCount == 2) {
135         location = JSValueToNumber(context, arguments[0], exception);
136         length = JSValueToNumber(context, arguments[1], exception);
137     }
138 
139     JSRetainPtr<JSStringRef> boundsDescription(Adopt, toAXElement(thisObject)->boundsForRange(location, length));
140     return JSValueMakeString(context, boundsDescription.get());
141 }
142 
childAtIndexCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)143 static JSValueRef childAtIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
144 {
145     int indexNumber = -1;
146     if (argumentCount == 1)
147         indexNumber = JSValueToNumber(context, arguments[0], exception);
148 
149     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->getChildAtIndex(indexNumber));
150 }
151 
elementAtPointCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)152 static JSValueRef elementAtPointCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
153 {
154     int x = 0;
155     int y = 0;
156     if (argumentCount == 2) {
157         x = JSValueToNumber(context, arguments[0], exception);
158         y = JSValueToNumber(context, arguments[1], exception);
159     }
160 
161     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->elementAtPoint(x, y));
162 }
163 
164 
isAttributeSettableCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)165 static JSValueRef isAttributeSettableCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
166 {
167     JSStringRef attribute = NULL;
168     if (argumentCount == 1)
169         attribute = JSValueToStringCopy(context, arguments[0], exception);
170     JSValueRef result = JSValueMakeNumber(context, toAXElement(thisObject)->isAttributeSettable(attribute));
171     if (attribute)
172         JSStringRelease(attribute);
173     return result;
174 }
175 
176 
isActionSupportedCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)177 static JSValueRef isActionSupportedCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
178 {
179     JSStringRef action = 0;
180     if (argumentCount == 1)
181         action = JSValueToStringCopy(context, arguments[0], exception);
182     JSValueRef result = JSValueMakeNumber(context, toAXElement(thisObject)->isActionSupported(action));
183     if (action)
184         JSStringRelease(action);
185     return result;
186 }
187 
attributeValueCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)188 static JSValueRef attributeValueCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
189 {
190     JSStringRef attribute = NULL;
191     if (argumentCount == 1)
192         attribute = JSValueToStringCopy(context, arguments[0], exception);
193     JSValueRef result = JSValueMakeString(context, toAXElement(thisObject)->attributeValue(attribute));
194     if (attribute)
195         JSStringRelease(attribute);
196     return result;
197 }
198 
cellForColumnAndRowCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)199 static JSValueRef cellForColumnAndRowCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
200 {
201     unsigned column = 0, row = 0;
202     if (argumentCount == 2) {
203         column = JSValueToNumber(context, arguments[0], exception);
204         row = JSValueToNumber(context, arguments[1], exception);
205     }
206 
207     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->cellForColumnAndRow(column, row));
208 }
209 
titleUIElementCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)210 static JSValueRef titleUIElementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
211 {
212     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->titleUIElement());
213 }
214 
parentElementCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)215 static JSValueRef parentElementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
216 {
217     return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->parentElement());
218 }
219 
setSelectedTextRangeCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)220 static JSValueRef setSelectedTextRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
221 {
222     unsigned location = UINT_MAX, length = 0;
223     if (argumentCount == 2) {
224         location = JSValueToNumber(context, arguments[0], exception);
225         length = JSValueToNumber(context, arguments[1], exception);
226     }
227 
228     toAXElement(thisObject)->setSelectedTextRange(location, length);
229     return 0;
230 }
231 
incrementCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)232 static JSValueRef incrementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
233 {
234     toAXElement(thisObject)->increment();
235     return 0;
236 }
237 
decrementCallback(JSContextRef context,JSObjectRef function,JSObjectRef thisObject,size_t argumentCount,const JSValueRef arguments[],JSValueRef * exception)238 static JSValueRef decrementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
239 {
240     toAXElement(thisObject)->decrement();
241     return 0;
242 }
243 
244 
245 // Static Value Getters
246 
getRoleCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)247 static JSValueRef getRoleCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
248 {
249     JSRetainPtr<JSStringRef> role(Adopt, toAXElement(thisObject)->role());
250     return JSValueMakeString(context, role.get());
251 }
252 
getTitleCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)253 static JSValueRef getTitleCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
254 {
255     JSRetainPtr<JSStringRef> title(Adopt, toAXElement(thisObject)->title());
256     return JSValueMakeString(context, title.get());
257 }
258 
getDescriptionCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)259 static JSValueRef getDescriptionCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
260 {
261     JSRetainPtr<JSStringRef> description(Adopt, toAXElement(thisObject)->description());
262     return JSValueMakeString(context, description.get());
263 }
264 
getLanguageCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)265 static JSValueRef getLanguageCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
266 {
267     JSRetainPtr<JSStringRef> language(Adopt, toAXElement(thisObject)->language());
268     return JSValueMakeString(context, language.get());
269 }
270 
getChildrenCountCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)271 static JSValueRef getChildrenCountCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
272 {
273     return JSValueMakeNumber(context, toAXElement(thisObject)->childrenCount());
274 }
275 
getXCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)276 static JSValueRef getXCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
277 {
278     return JSValueMakeNumber(context, toAXElement(thisObject)->x());
279 }
280 
getYCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)281 static JSValueRef getYCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
282 {
283     return JSValueMakeNumber(context, toAXElement(thisObject)->y());
284 }
285 
getWidthCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)286 static JSValueRef getWidthCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
287 {
288     return JSValueMakeNumber(context, toAXElement(thisObject)->width());
289 }
290 
getHeightCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)291 static JSValueRef getHeightCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
292 {
293     return JSValueMakeNumber(context, toAXElement(thisObject)->height());
294 }
295 
getClickPointXCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)296 static JSValueRef getClickPointXCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
297 {
298     return JSValueMakeNumber(context, toAXElement(thisObject)->clickPointX());
299 }
300 
getClickPointYCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)301 static JSValueRef getClickPointYCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
302 {
303     return JSValueMakeNumber(context, toAXElement(thisObject)->clickPointY());
304 }
305 
getIntValueCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)306 static JSValueRef getIntValueCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
307 {
308     return JSValueMakeNumber(context, toAXElement(thisObject)->intValue());
309 }
310 
getMinValueCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)311 static JSValueRef getMinValueCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
312 {
313     return JSValueMakeNumber(context, toAXElement(thisObject)->minValue());
314 }
315 
getMaxValueCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)316 static JSValueRef getMaxValueCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
317 {
318     return JSValueMakeNumber(context, toAXElement(thisObject)->maxValue());
319 }
320 
getInsertionPointLineNumberCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)321 static JSValueRef getInsertionPointLineNumberCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
322 {
323     return JSValueMakeNumber(context, toAXElement(thisObject)->insertionPointLineNumber());
324 }
325 
getSelectedTextRangeCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)326 static JSValueRef getSelectedTextRangeCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
327 {
328     JSRetainPtr<JSStringRef> selectedTextRange(Adopt, toAXElement(thisObject)->selectedTextRange());
329     return JSValueMakeString(context, selectedTextRange.get());
330 }
331 
getIsEnabledCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)332 static JSValueRef getIsEnabledCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
333 {
334     return JSValueMakeBoolean(context, toAXElement(thisObject)->isEnabled());
335 }
336 
getIsRequiredCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef,JSValueRef *)337 static JSValueRef getIsRequiredCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef, JSValueRef*)
338 {
339     return JSValueMakeBoolean(context, toAXElement(thisObject)->isRequired());
340 }
341 
getValueDescriptionCallback(JSContextRef context,JSObjectRef thisObject,JSStringRef propertyName,JSValueRef * exception)342 static JSValueRef getValueDescriptionCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
343 {
344     JSRetainPtr<JSStringRef> valueDescription(Adopt, toAXElement(thisObject)->valueDescription());
345     return JSValueMakeString(context, valueDescription.get());
346 }
347 
348 // Destruction
349 
finalize(JSObjectRef thisObject)350 static void finalize(JSObjectRef thisObject)
351 {
352     delete toAXElement(thisObject);
353 }
354 
355 // Object Creation
356 
makeJSAccessibilityUIElement(JSContextRef context,const AccessibilityUIElement & element)357 JSObjectRef AccessibilityUIElement::makeJSAccessibilityUIElement(JSContextRef context, const AccessibilityUIElement& element)
358 {
359     return JSObjectMake(context, AccessibilityUIElement::getJSClass(), new AccessibilityUIElement(element));
360 }
361 
getJSClass()362 JSClassRef AccessibilityUIElement::getJSClass()
363 {
364     static JSStaticValue staticValues[] = {
365         { "role", getRoleCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
366         { "title", getTitleCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
367         { "description", getDescriptionCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
368         { "language", getLanguageCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
369         { "x", getXCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
370         { "y", getYCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
371         { "width", getWidthCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
372         { "height", getHeightCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
373         { "clickPointX", getClickPointXCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
374         { "clickPointY", getClickPointYCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
375         { "intValue", getIntValueCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
376         { "minValue", getMinValueCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
377         { "maxValue", getMaxValueCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
378         { "childrenCount", getChildrenCountCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
379         { "insertionPointLineNumber", getInsertionPointLineNumberCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
380         { "selectedTextRange", getSelectedTextRangeCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
381         { "isEnabled", getIsEnabledCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
382         { "isRequired", getIsRequiredCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
383         { "valueDescription", getValueDescriptionCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
384         { 0, 0, 0, 0 }
385     };
386 
387     static JSStaticFunction staticFunctions[] = {
388         { "allAttributes", allAttributesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
389         { "attributesOfLinkedUIElements", attributesOfLinkedUIElementsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
390         { "attributesOfDocumentLinks", attributesOfDocumentLinksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
391         { "attributesOfChildren", attributesOfChildrenCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
392         { "parameterizedAttributeNames", parameterizedAttributeNamesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
393         { "lineForIndex", lineForIndexCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
394         { "boundsForRange", boundsForRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
395         { "childAtIndex", childAtIndexCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
396         { "elementAtPoint", elementAtPointCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
397         { "attributesOfColumnHeaders", attributesOfColumnHeadersCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
398         { "attributesOfRowHeaders", attributesOfRowHeadersCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
399         { "attributesOfColumns", attributesOfColumnsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
400         { "attributesOfRows", attributesOfRowsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
401         { "attributesOfVisibleCells", attributesOfVisibleCellsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
402         { "attributesOfHeader", attributesOfHeaderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
403         { "indexInTable", indexInTableCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
404         { "rowIndexRange", rowIndexRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
405         { "columnIndexRange", columnIndexRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
406         { "cellForColumnAndRow", cellForColumnAndRowCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
407         { "titleUIElement", titleUIElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
408         { "setSelectedTextRange", setSelectedTextRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
409         { "attributeValue", attributeValueCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
410         { "isAttributeSettable", isAttributeSettableCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
411         { "isActionSupported", isActionSupportedCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
412         { "parentElement", parentElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
413         { "increment", incrementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
414         { "decrement", decrementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
415         { 0, 0, 0 }
416     };
417 
418     static JSClassDefinition classDefinition = {
419         0, kJSClassAttributeNone, "AccessibilityUIElement", 0, staticValues, staticFunctions,
420         0, finalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
421     };
422 
423     static JSClassRef accessibilityUIElementClass = JSClassCreate(&classDefinition);
424     return accessibilityUIElementClass;
425 }
426