2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "AccessibilityUIElement.h"
29 #include <JavaScriptCore/JSStringRef.h>
35 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
40 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
41 : m_element(other.m_element)
45 AccessibilityUIElement::~AccessibilityUIElement()
49 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>&)
53 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
57 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
60 if (FAILED(m_element->get_accChildCount(&childCount)))
62 for (long i = 0; i < childCount; ++i)
63 children.append(getChildAtIndex(i));
66 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length)
69 unsigned appendedCount = 0;
70 if (FAILED(m_element->get_accChildCount(&childCount)))
72 for (long i = location; i < childCount && appendedCount < length; ++i, ++appendedCount)
73 elementVector.append(getChildAtIndex(i));
76 int AccessibilityUIElement::childrenCount()
79 m_element->get_accChildCount(&childCount);
83 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
88 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
90 COMPtr<IDispatch> child;
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)))
98 return COMPtr<IAccessible>(Query, child);
101 JSStringRef AccessibilityUIElement::allAttributes()
103 return JSStringCreateWithCharacters(0, 0);
106 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
108 return JSStringCreateWithCharacters(0, 0);
111 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
113 return JSStringCreateWithCharacters(0, 0);
116 AccessibilityUIElement AccessibilityUIElement::titleUIElement()
121 AccessibilityUIElement AccessibilityUIElement::parentElement()
126 JSStringRef AccessibilityUIElement::attributesOfChildren()
128 return JSStringCreateWithCharacters(0, 0);
131 JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
133 return JSStringCreateWithCharacters(0, 0);
136 static VARIANT& self()
138 static VARIANT vSelf;
139 static bool haveInitialized;
141 if (!haveInitialized) {
142 ::VariantInit(&vSelf);
143 V_VT(&vSelf) = VT_I4;
144 V_I4(&vSelf) = CHILDID_SELF;
149 JSStringRef AccessibilityUIElement::role()
152 if (FAILED(m_element->get_accRole(self(), &vRole)))
153 return JSStringCreateWithCharacters(0, 0);
155 ASSERT(V_VT(&vRole) == VT_I4 || V_VT(&vRole) == VT_BSTR);
158 if (V_VT(&vRole) == VT_I4) {
159 unsigned roleTextLength = ::GetRoleText(V_I4(&vRole), 0, 0) + 1;
161 Vector<TCHAR> roleText(roleTextLength);
163 ::GetRoleText(V_I4(&vRole), roleText.data(), roleTextLength);
165 result = roleText.data();
166 } else if (V_VT(&vRole) == VT_BSTR)
167 result = wstring(V_BSTR(&vRole), ::SysStringLen(V_BSTR(&vRole)));
169 ::VariantClear(&vRole);
171 return JSStringCreateWithCharacters(result.data(), result.length());
174 JSStringRef AccessibilityUIElement::subrole()
179 JSStringRef AccessibilityUIElement::title()
182 if (FAILED(m_element->get_accName(self(), &titleBSTR)) || !titleBSTR)
183 return JSStringCreateWithCharacters(0, 0);
184 wstring title(titleBSTR, SysStringLen(titleBSTR));
185 ::SysFreeString(titleBSTR);
186 return JSStringCreateWithCharacters(title.data(), title.length());
189 JSStringRef AccessibilityUIElement::description()
191 BSTR descriptionBSTR;
192 if (FAILED(m_element->get_accDescription(self(), &descriptionBSTR)) || !descriptionBSTR)
193 return JSStringCreateWithCharacters(0, 0);
194 wstring description(descriptionBSTR, SysStringLen(descriptionBSTR));
195 ::SysFreeString(descriptionBSTR);
196 return JSStringCreateWithCharacters(description.data(), description.length());
199 JSStringRef AccessibilityUIElement::stringValue()
201 return JSStringCreateWithCharacters(0, 0);
204 JSStringRef AccessibilityUIElement::language()
206 return JSStringCreateWithCharacters(0, 0);
209 double AccessibilityUIElement::x()
211 long x, y, width, height;
212 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
217 double AccessibilityUIElement::y()
219 long x, y, width, height;
220 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
225 double AccessibilityUIElement::width()
227 long x, y, width, height;
228 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
233 double AccessibilityUIElement::height()
235 long x, y, width, height;
236 if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
241 double AccessibilityUIElement::clickPointX()
246 double AccessibilityUIElement::clickPointY()
251 JSStringRef AccessibilityUIElement::valueDescription()
255 bool AccessibilityUIElement::isSelected() const
260 int AccessibilityUIElement::hierarchicalLevel() const
265 bool AccessibilityUIElement::isExpanded() const
270 double AccessibilityUIElement::intValue()
273 if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
275 wstring value(valueBSTR, SysStringLen(valueBSTR));
276 ::SysFreeString(valueBSTR);
278 return _tcstod(value.data(), &ignored);
281 double AccessibilityUIElement::minValue()
286 double AccessibilityUIElement::maxValue()
291 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
296 bool AccessibilityUIElement::isEnabled()
301 bool AccessibilityUIElement::isRequired() const
307 int AccessibilityUIElement::insertionPointLineNumber()
312 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
314 return JSStringCreateWithCharacters(0, 0);
317 JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
319 return JSStringCreateWithCharacters(0, 0);
322 JSStringRef AccessibilityUIElement::attributesOfColumns()
324 return JSStringCreateWithCharacters(0, 0);
327 JSStringRef AccessibilityUIElement::attributesOfRows()
329 return JSStringCreateWithCharacters(0, 0);
332 JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
334 return JSStringCreateWithCharacters(0, 0);
337 JSStringRef AccessibilityUIElement::attributesOfHeader()
339 return JSStringCreateWithCharacters(0, 0);
342 int AccessibilityUIElement::indexInTable()
347 JSStringRef AccessibilityUIElement::rowIndexRange()
349 return JSStringCreateWithCharacters(0, 0);
352 JSStringRef AccessibilityUIElement::columnIndexRange()
354 return JSStringCreateWithCharacters(0, 0);
357 int AccessibilityUIElement::lineForIndex(int)
362 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
364 return JSStringCreateWithCharacters(0, 0);
367 JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned)
369 return JSStringCreateWithCharacters(0, 0);
372 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
377 JSStringRef AccessibilityUIElement::selectedTextRange()
379 return JSStringCreateWithCharacters(0, 0);
382 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
386 JSStringRef AccessibilityUIElement::attributeValue(JSStringRef attribute)
388 return JSStringCreateWithCharacters(0, 0);
391 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
396 void AccessibilityUIElement::increment()
400 void AccessibilityUIElement::decrement()
404 void AccessibilityUIElement::showMenu()
408 AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
413 AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
418 AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
423 JSStringRef AccessibilityUIElement::accessibilityValue() const
426 if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
427 return JSStringCreateWithCharacters(0, 0);
429 wstring value(valueBSTR, SysStringLen(valueBSTR));
430 ::SysFreeString(valueBSTR);
432 return JSStringCreateWithCharacters(value.data(), value.length());
436 JSStringRef AccessibilityUIElement::documentEncoding()
438 return JSStringCreateWithCharacters(0, 0);
441 JSStringRef AccessibilityUIElement::documentURI()
443 return JSStringCreateWithCharacters(0, 0);