123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- /*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "config.h"
- #include "AccessibilityUIElement.h"
- #include "AccessibilityController.h"
- #include "DumpRenderTree.h"
- #include "FrameLoadDelegate.h"
- #include <JavaScriptCore/JSStringRef.h>
- #include <comutil.h>
- #include <tchar.h>
- #include <string>
- using std::wstring;
- static COMPtr<IAccessibleComparable> comparableObject(IAccessible* accessible)
- {
- COMPtr<IServiceProvider> serviceProvider(Query, accessible);
- if (!serviceProvider)
- return 0;
- COMPtr<IAccessibleComparable> comparable;
- serviceProvider->QueryService(SID_AccessibleComparable, __uuidof(IAccessibleComparable), reinterpret_cast<void**>(&comparable));
- return comparable;
- }
- AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
- : m_element(element)
- {
- }
- AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
- : m_element(other.m_element)
- {
- }
- AccessibilityUIElement::~AccessibilityUIElement()
- {
- }
- bool AccessibilityUIElement::isEqual(AccessibilityUIElement* otherElement)
- {
- COMPtr<IAccessibleComparable> comparable = comparableObject(m_element.get());
- COMPtr<IAccessibleComparable> otherComparable = comparableObject(otherElement->m_element.get());
- if (!comparable || !otherComparable)
- return false;
- BOOL isSame = FALSE;
- if (FAILED(comparable->isSameObject(otherComparable.get(), &isSame)))
- return false;
- return isSame;
- }
- void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>&)
- {
- }
- void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
- {
- }
- void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
- {
- long childCount;
- if (FAILED(m_element->get_accChildCount(&childCount)))
- return;
- for (long i = 0; i < childCount; ++i)
- children.append(getChildAtIndex(i));
- }
- void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length)
- {
- long childCount;
- unsigned appendedCount = 0;
- if (FAILED(m_element->get_accChildCount(&childCount)))
- return;
- for (long i = location; i < childCount && appendedCount < length; ++i, ++appendedCount)
- elementVector.append(getChildAtIndex(i));
- }
- int AccessibilityUIElement::childrenCount()
- {
- long childCount;
- m_element->get_accChildCount(&childCount);
- return childCount;
- }
- int AccessibilityUIElement::rowCount()
- {
- // FIXME: implement
- return 0;
- }
-
- int AccessibilityUIElement::columnCount()
- {
- // FIXME: implement
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
- {
- // FIXME: implement
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
- {
- COMPtr<IDispatch> child;
- VARIANT vChild;
- ::VariantInit(&vChild);
- V_VT(&vChild) = VT_I4;
- // In MSAA, index 0 is the object itself.
- V_I4(&vChild) = index + 1;
- if (FAILED(m_element->get_accChild(vChild, &child)))
- return 0;
- return COMPtr<IAccessible>(Query, child);
- }
- unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
- {
- // FIXME: implement
- return 0;
- }
- JSStringRef AccessibilityUIElement::allAttributes()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- AccessibilityUIElement AccessibilityUIElement::titleUIElement()
- {
- COMPtr<IAccessible> platformElement = platformUIElement();
- COMPtr<IAccessibleComparable> comparable = comparableObject(platformElement.get());
- if (!comparable)
- return 0;
- VARIANT value;
- ::VariantInit(&value);
- _bstr_t titleUIElementAttributeKey(L"AXTitleUIElementAttribute");
- if (FAILED(comparable->get_attribute(titleUIElementAttributeKey, &value))) {
- ::VariantClear(&value);
- return 0;
- }
- if (V_VT(&value) == VT_EMPTY) {
- ::VariantClear(&value);
- return 0;
- }
- ASSERT(V_VT(&value) == VT_UNKNOWN);
- if (V_VT(&value) != VT_UNKNOWN) {
- ::VariantClear(&value);
- return 0;
- }
- COMPtr<IAccessible> titleElement(Query, value.punkVal);
- if (value.punkVal)
- value.punkVal->Release();
- ::VariantClear(&value);
- return titleElement;
- }
- AccessibilityUIElement AccessibilityUIElement::parentElement()
- {
- COMPtr<IDispatch> parent;
- m_element->get_accParent(&parent);
- COMPtr<IAccessible> parentAccessible(Query, parent);
- return parentAccessible;
- }
- JSStringRef AccessibilityUIElement::attributesOfChildren()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- static VARIANT& self()
- {
- static VARIANT vSelf;
- static bool haveInitialized;
- if (!haveInitialized) {
- ::VariantInit(&vSelf);
- V_VT(&vSelf) = VT_I4;
- V_I4(&vSelf) = CHILDID_SELF;
- }
- return vSelf;
- }
- JSStringRef AccessibilityUIElement::role()
- {
- if (!m_element)
- return JSStringCreateWithCharacters(0, 0);
- VARIANT vRole;
- if (FAILED(m_element->get_accRole(self(), &vRole)))
- return JSStringCreateWithCharacters(0, 0);
- ASSERT(V_VT(&vRole) == VT_I4 || V_VT(&vRole) == VT_BSTR);
- wstring result;
- if (V_VT(&vRole) == VT_I4) {
- unsigned roleTextLength = ::GetRoleText(V_I4(&vRole), 0, 0) + 1;
- Vector<TCHAR> roleText(roleTextLength);
- ::GetRoleText(V_I4(&vRole), roleText.data(), roleTextLength);
- result = roleText.data();
- } else if (V_VT(&vRole) == VT_BSTR)
- result = wstring(V_BSTR(&vRole), ::SysStringLen(V_BSTR(&vRole)));
- ::VariantClear(&vRole);
- return JSStringCreateWithCharacters(result.data(), result.length());
- }
- JSStringRef AccessibilityUIElement::subrole()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::roleDescription()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::title()
- {
- BSTR titleBSTR;
- if (FAILED(m_element->get_accName(self(), &titleBSTR)) || !titleBSTR)
- return JSStringCreateWithCharacters(0, 0);
- wstring title(titleBSTR, SysStringLen(titleBSTR));
- ::SysFreeString(titleBSTR);
- return JSStringCreateWithCharacters(title.data(), title.length());
- }
- JSStringRef AccessibilityUIElement::description()
- {
- BSTR descriptionBSTR;
- if (FAILED(m_element->get_accDescription(self(), &descriptionBSTR)) || !descriptionBSTR)
- return JSStringCreateWithCharacters(0, 0);
- wstring description(descriptionBSTR, SysStringLen(descriptionBSTR));
- ::SysFreeString(descriptionBSTR);
- return JSStringCreateWithCharacters(description.data(), description.length());
- }
- JSStringRef AccessibilityUIElement::stringValue()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::language()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::helpText() const
- {
- return 0;
- }
- double AccessibilityUIElement::x()
- {
- long x, y, width, height;
- if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
- return 0;
- return x;
- }
- double AccessibilityUIElement::y()
- {
- long x, y, width, height;
- if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
- return 0;
- return y;
- }
- double AccessibilityUIElement::width()
- {
- long x, y, width, height;
- if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
- return 0;
- return width;
- }
- double AccessibilityUIElement::height()
- {
- long x, y, width, height;
- if (FAILED(m_element->accLocation(&x, &y, &width, &height, self())))
- return 0;
- return height;
- }
- double AccessibilityUIElement::clickPointX()
- {
- return 0;
- }
- double AccessibilityUIElement::clickPointY()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::valueDescription()
- {
- return 0;
- }
- static DWORD accessibilityState(COMPtr<IAccessible> element)
- {
- VARIANT state;
- element->get_accState(self(), &state);
- ASSERT(V_VT(&state) == VT_I4);
- DWORD result = state.lVal;
- VariantClear(&state);
- return result;
- }
- bool AccessibilityUIElement::isFocused() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isSelected() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_SELECTED) == STATE_SYSTEM_SELECTED;
- }
- int AccessibilityUIElement::hierarchicalLevel() const
- {
- return 0;
- }
- bool AccessibilityUIElement::ariaIsGrabbed() const
- {
- return false;
- }
-
- JSStringRef AccessibilityUIElement::ariaDropEffects() const
- {
- return 0;
- }
- bool AccessibilityUIElement::isExpanded() const
- {
- return false;
- }
- bool AccessibilityUIElement::isChecked() const
- {
- VARIANT vState;
- if (FAILED(m_element->get_accState(self(), &vState)))
- return false;
- return vState.lVal & STATE_SYSTEM_CHECKED;
- }
- JSStringRef AccessibilityUIElement::orientation() const
- {
- return 0;
- }
- double AccessibilityUIElement::intValue() const
- {
- BSTR valueBSTR;
- if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
- return 0;
- wstring value(valueBSTR, SysStringLen(valueBSTR));
- ::SysFreeString(valueBSTR);
- TCHAR* ignored;
- return _tcstod(value.data(), &ignored);
- }
- double AccessibilityUIElement::minValue()
- {
- return 0;
- }
- double AccessibilityUIElement::maxValue()
- {
- return 0;
- }
- bool AccessibilityUIElement::isPressActionSupported()
- {
- return false;
- }
- bool AccessibilityUIElement::isIncrementActionSupported()
- {
- return false;
- }
- bool AccessibilityUIElement::isDecrementActionSupported()
- {
- return false;
- }
- bool AccessibilityUIElement::isEnabled()
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_UNAVAILABLE) != STATE_SYSTEM_UNAVAILABLE;
- }
- bool AccessibilityUIElement::isRequired() const
- {
- return false;
- }
- int AccessibilityUIElement::insertionPointLineNumber()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfColumns()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfRows()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributesOfHeader()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- int AccessibilityUIElement::indexInTable()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::rowIndexRange()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::columnIndexRange()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- int AccessibilityUIElement::lineForIndex(int)
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned)
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::attributedStringForRange(unsigned, unsigned)
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned, unsigned)
- {
- return false;
- }
- AccessibilityUIElement AccessibilityUIElement::uiElementForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::selectedTextRange()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
- {
- }
- JSStringRef AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
- {
- // FIXME: implement
- return JSStringCreateWithCharacters(0, 0);
- }
- double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
- {
- // FIXME: implement
- return 0;
- }
- bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
- {
- return false;
- }
- bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
- {
- return false;
- }
- void AccessibilityUIElement::increment()
- {
- }
- void AccessibilityUIElement::decrement()
- {
- }
- void AccessibilityUIElement::showMenu()
- {
- ASSERT(hasPopup());
- m_element->accDoDefaultAction(self());
- }
- void AccessibilityUIElement::press()
- {
- // FIXME: implement
- }
- AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::rowAtIndex(unsigned index)
- {
- return 0;
- }
- AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
- {
- return 0;
- }
- JSStringRef AccessibilityUIElement::accessibilityValue() const
- {
- BSTR valueBSTR;
- if (FAILED(m_element->get_accValue(self(), &valueBSTR)) || !valueBSTR)
- return JSStringCreateWithCharacters(0, 0);
- wstring value(valueBSTR, SysStringLen(valueBSTR));
- ::SysFreeString(valueBSTR);
- return JSStringCreateWithCharacters(value.data(), value.length());
- }
- JSStringRef AccessibilityUIElement::documentEncoding()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::documentURI()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSStringRef AccessibilityUIElement::url()
- {
- // FIXME: implement
- return JSStringCreateWithCharacters(0, 0);
- }
- bool AccessibilityUIElement::addNotificationListener(JSObjectRef functionCallback)
- {
- if (!functionCallback)
- return false;
- sharedFrameLoadDelegate->accessibilityController()->winAddNotificationListener(m_element, functionCallback);
- return true;
- }
- void AccessibilityUIElement::removeNotificationListener()
- {
- // FIXME: implement
- }
- bool AccessibilityUIElement::isFocusable() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isSelectable() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_SELECTABLE) == STATE_SYSTEM_SELECTABLE;
- }
- bool AccessibilityUIElement::isMultiSelectable() const
- {
- DWORD multiSelectable = STATE_SYSTEM_EXTSELECTABLE | STATE_SYSTEM_MULTISELECTABLE;
- DWORD state = accessibilityState(m_element);
- return (state & multiSelectable) == multiSelectable;
- }
- bool AccessibilityUIElement::isSelectedOptionActive() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isVisible() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_INVISIBLE) != STATE_SYSTEM_INVISIBLE;
- }
- bool AccessibilityUIElement::isOffScreen() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_OFFSCREEN) == STATE_SYSTEM_OFFSCREEN;
- }
- bool AccessibilityUIElement::isCollapsed() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_COLLAPSED) == STATE_SYSTEM_COLLAPSED;
- }
- bool AccessibilityUIElement::isIgnored() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::hasPopup() const
- {
- DWORD state = accessibilityState(m_element);
- return (state & STATE_SYSTEM_HASPOPUP) == STATE_SYSTEM_HASPOPUP;
- }
- void AccessibilityUIElement::takeFocus()
- {
- m_element->accSelect(SELFLAG_TAKEFOCUS, self());
- }
- void AccessibilityUIElement::takeSelection()
- {
- m_element->accSelect(SELFLAG_TAKESELECTION, self());
- }
- void AccessibilityUIElement::addSelection()
- {
- m_element->accSelect(SELFLAG_ADDSELECTION, self());
- }
- void AccessibilityUIElement::removeSelection()
- {
- m_element->accSelect(SELFLAG_REMOVESELECTION, self());
- }
- void AccessibilityUIElement::scrollToMakeVisible()
- {
- // FIXME: implement
- }
- void AccessibilityUIElement::scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height)
- {
- // FIXME: implement
- }
- void AccessibilityUIElement::scrollToGlobalPoint(int x, int y)
- {
- // FIXME: implement
- }
|