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 #include "config.h"
27 #include "AccessibilityUIElement.h"
28
29 #include <JavaScriptCore/JSStringRef.h>
30 #include <tchar.h>
31 #include <string>
32
33 using std::wstring;
34
AccessibilityUIElement(PlatformUIElement element)35 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
36 : m_element(element)
37 {
38 }
39
AccessibilityUIElement(const AccessibilityUIElement & other)40 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
41 : m_element(other.m_element)
42 {
43 }
44
~AccessibilityUIElement()45 AccessibilityUIElement::~AccessibilityUIElement()
46 {
47 }
48
getLinkedUIElements(Vector<AccessibilityUIElement> &)49 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>&)
50 {
51 }
52
getDocumentLinks(Vector<AccessibilityUIElement> &)53 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
54 {
55 }
56
getChildren(Vector<AccessibilityUIElement> & children)57 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
58 {
59 long childCount;
60 if (FAILED(m_element->get_accChildCount(&childCount)))
61 return;
62 for (long i = 0; i < childCount; ++i)
63 children.append(getChildAtIndex(i));
64 }
65
getChildrenWithRange(Vector<AccessibilityUIElement> & elementVector,unsigned location,unsigned length)66 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length)
67 {
68 long childCount;
69 unsigned appendedCount = 0;
70 if (FAILED(m_element->get_accChildCount(&childCount)))
71 return;
72 for (long i = location; i < childCount && appendedCount < length; ++i, ++appendedCount)
73 elementVector.append(getChildAtIndex(i));
74 }
75
childrenCount()76 int AccessibilityUIElement::childrenCount()
77 {
78 long childCount;
79 m_element->get_accChildCount(&childCount);
80 return childCount;
81 }
82
elementAtPoint(int x,int y)83 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
84 {
85 return 0;
86 }
87
getChildAtIndex(unsigned index)88 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
89 {
90 COMPtr<IDispatch> child;
91 VARIANT vChild;
92 ::VariantInit(&vChild);
93 V_VT(&vChild) = VT_I4;
94 // In MSAA, index 0 is the object itself.
95 V_I4(&vChild) = index + 1;
96 if (FAILED(m_element->get_accChild(vChild, &child)))
97 return 0;
98 return COMPtr<IAccessible>(Query, child);
99 }
100
allAttributes()101 JSStringRef AccessibilityUIElement::allAttributes()
102 {
103 return JSStringCreateWithCharacters(0, 0);
104 }
105
attributesOfLinkedUIElements()106 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
107 {
108 return JSStringCreateWithCharacters(0, 0);
109 }
110
attributesOfDocumentLinks()111 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
112 {
113 return JSStringCreateWithCharacters(0, 0);
114 }
115
titleUIElement()116 AccessibilityUIElement AccessibilityUIElement::titleUIElement()
117 {
118 return 0;
119 }
120
parentElement()121 AccessibilityUIElement AccessibilityUIElement::parentElement()
122 {
123 return 0;
124 }
125
attributesOfChildren()126 JSStringRef AccessibilityUIElement::attributesOfChildren()
127 {
128 return JSStringCreateWithCharacters(0, 0);
129 }
130
parameterizedAttributeNames()131 JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
132 {
133 return JSStringCreateWithCharacters(0, 0);
134 }
135
self()136 static VARIANT& self()
137 {
138 static VARIANT vSelf;
139 static bool haveInitialized;
140
141 if (!haveInitialized) {
142 ::VariantInit(&vSelf);
143 V_VT(&vSelf) = VT_I4;
144 V_I4(&vSelf) = CHILDID_SELF;
145 }
146 return vSelf;
147 }
148
role()149 JSStringRef AccessibilityUIElement::role()
150 {
151 VARIANT vRole;
152 if (FAILED(m_element->get_accRole(self(), &vRole)))
153 return JSStringCreateWithCharacters(0, 0);
154 ASSERT(V_VT(&vRole) == VT_I4);
155 TCHAR roleText[64] = {0};
156 ::GetRoleText(V_I4(&vRole), roleText, ARRAYSIZE(roleText));
157 return JSStringCreateWithCharacters(roleText, _tcslen(roleText));
158 }
159
title()160 JSStringRef AccessibilityUIElement::title()
161 {
162 BSTR titleBSTR;
163 if (FAILED(m_element->get_accName(self(), &titleBSTR)) || !titleBSTR)
164 return JSStringCreateWithCharacters(0, 0);
165 wstring title(titleBSTR, SysStringLen(titleBSTR));
166 ::SysFreeString(titleBSTR);
167 return JSStringCreateWithCharacters(title.data(), title.length());
168 }
169
description()170 JSStringRef AccessibilityUIElement::description()
171 {
172 BSTR descriptionBSTR;
173 if (FAILED(m_element->get_accName(self(), &descriptionBSTR)) || !descriptionBSTR)
174 return JSStringCreateWithCharacters(0, 0);
175 wstring description(descriptionBSTR, SysStringLen(descriptionBSTR));
176 ::SysFreeString(descriptionBSTR);
177 return JSStringCreateWithCharacters(description.data(), description.length());
178 }
179
language()180 JSStringRef AccessibilityUIElement::language()
181 {
182 return JSStringCreateWithCharacters(0, 0);
183 }
184
x()185 double AccessibilityUIElement::x()
186 {
187 long x, y, width, height;
188 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
189 return 0;
190 return x;
191 }
192
y()193 double AccessibilityUIElement::y()
194 {
195 long x, y, width, height;
196 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
197 return 0;
198 return y;
199 }
200
width()201 double AccessibilityUIElement::width()
202 {
203 long x, y, width, height;
204 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
205 return 0;
206 return width;
207 }
208
height()209 double AccessibilityUIElement::height()
210 {
211 long x, y, width, height;
212 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
213 return 0;
214 return height;
215 }
216
clickPointX()217 double AccessibilityUIElement::clickPointX()
218 {
219 return 0;
220 }
221
clickPointY()222 double AccessibilityUIElement::clickPointY()
223 {
224 return 0;
225 }
226
valueDescription()227 JSStringRef AccessibilityUIElement::valueDescription()
228 {
229 return 0;
230 }
231
intValue()232 double AccessibilityUIElement::intValue()
233 {
234 BSTR valueBSTR;
235 if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
236 return 0;
237 wstring value(valueBSTR, SysStringLen(valueBSTR));
238 ::SysFreeString(valueBSTR);
239 TCHAR* ignored;
240 return _tcstod(value.data(), &ignored);
241 }
242
minValue()243 double AccessibilityUIElement::minValue()
244 {
245 return 0;
246 }
247
maxValue()248 double AccessibilityUIElement::maxValue()
249 {
250 return 0;
251 }
252
isActionSupported(JSStringRef action)253 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
254 {
255 return false;
256 }
257
isEnabled()258 bool AccessibilityUIElement::isEnabled()
259 {
260 return false;
261 }
262
isRequired() const263 bool AccessibilityUIElement::isRequired() const
264 {
265 return false;
266 }
267
insertionPointLineNumber()268 int AccessibilityUIElement::insertionPointLineNumber()
269 {
270 return 0;
271 }
272
attributesOfColumnHeaders()273 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
274 {
275 return JSStringCreateWithCharacters(0, 0);
276 }
277
attributesOfRowHeaders()278 JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
279 {
280 return JSStringCreateWithCharacters(0, 0);
281 }
282
attributesOfColumns()283 JSStringRef AccessibilityUIElement::attributesOfColumns()
284 {
285 return JSStringCreateWithCharacters(0, 0);
286 }
287
attributesOfRows()288 JSStringRef AccessibilityUIElement::attributesOfRows()
289 {
290 return JSStringCreateWithCharacters(0, 0);
291 }
292
attributesOfVisibleCells()293 JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
294 {
295 return JSStringCreateWithCharacters(0, 0);
296 }
297
attributesOfHeader()298 JSStringRef AccessibilityUIElement::attributesOfHeader()
299 {
300 return JSStringCreateWithCharacters(0, 0);
301 }
302
indexInTable()303 int AccessibilityUIElement::indexInTable()
304 {
305 return 0;
306 }
307
rowIndexRange()308 JSStringRef AccessibilityUIElement::rowIndexRange()
309 {
310 return JSStringCreateWithCharacters(0, 0);
311 }
312
columnIndexRange()313 JSStringRef AccessibilityUIElement::columnIndexRange()
314 {
315 return JSStringCreateWithCharacters(0, 0);
316 }
317
lineForIndex(int)318 int AccessibilityUIElement::lineForIndex(int)
319 {
320 return 0;
321 }
322
boundsForRange(unsigned location,unsigned length)323 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
324 {
325 return JSStringCreateWithCharacters(0, 0);
326 }
327
cellForColumnAndRow(unsigned column,unsigned row)328 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
329 {
330 return 0;
331 }
332
selectedTextRange()333 JSStringRef AccessibilityUIElement::selectedTextRange()
334 {
335 return JSStringCreateWithCharacters(0, 0);
336 }
337
setSelectedTextRange(unsigned location,unsigned length)338 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
339 {
340 }
341
attributeValue(JSStringRef attribute)342 JSStringRef AccessibilityUIElement::attributeValue(JSStringRef attribute)
343 {
344 return JSStringCreateWithCharacters(0, 0);
345 }
346
isAttributeSettable(JSStringRef attribute)347 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
348 {
349 return false;
350 }
351
increment()352 void AccessibilityUIElement::increment()
353 {
354 }
355
decrement()356 void AccessibilityUIElement::decrement()
357 {
358 }
359