static COMPtr<IAccessible> findAccessibleObjectById(AccessibilityUIElement parentObject, BSTR idAttribute) { COMPtr<IAccessible> parentIAccessible = parentObject.platformUIElement(); COMPtr<IServiceProvider> serviceProvider(Query, parentIAccessible); if (!serviceProvider) return 0; COMPtr<IAccessibleComparable> comparable = comparableObject(serviceProvider); if (!comparable) return 0; _variant_t value; _bstr_t elementIdAttributeKey(L"AXDRTElementIdAttribute"); if (SUCCEEDED(comparable->get_attribute(elementIdAttributeKey, &value.GetVARIANT()))) { ASSERT(V_VT(&value) == VT_BSTR); if (VARCMP_EQ == ::VarBstrCmp(value.bstrVal, idAttribute, LOCALE_USER_DEFAULT, 0)) return parentIAccessible; } long childCount = parentObject.childrenCount(); if (!childCount) return nullptr; COMPtr<IAccessible> result; for (long i = 0; i < childCount; ++i) { AccessibilityUIElement childAtIndex = parentObject.getChildAtIndex(i); result = findAccessibleObjectById(childAtIndex, idAttribute); if (result) return result; } return nullptr; }
AccessibilityUIElement AccessibilityUIElement::titleUIElement() { COMPtr<IAccessible> platformElement = platformUIElement(); COMPtr<IAccessibleComparable> comparable = comparableObject(platformElement.get()); if (!comparable) return 0; _variant_t value; _bstr_t titleUIElementAttributeKey(L"AXTitleUIElementAttribute"); if (FAILED(comparable->get_attribute(titleUIElementAttributeKey, &value.GetVARIANT()))) return nullptr; if (V_VT(&value) == VT_EMPTY) return nullptr; ASSERT(V_VT(&value) == VT_UNKNOWN); if (V_VT(&value) != VT_UNKNOWN) return nullptr; COMPtr<IAccessible> titleElement(Query, value.punkVal); if (value.punkVal) value.punkVal->Release(); return titleElement; }
JSStringRef AccessibilityUIElement::selectedTextRange() { COMPtr<IAccessibleComparable> comparable = comparableObject(platformUIElement().get()); if (!comparable) return JSStringCreateWithCharacters(0, 0); _variant_t value; if (FAILED(comparable->get_attribute(_bstr_t(L"AXSelectedTextRangeAttribute"), &value.GetVARIANT()))) return JSStringCreateWithCharacters(0, 0); ASSERT(V_VT(&value) == VT_BSTR); return JSStringCreateWithBSTR(value.bstrVal); }
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; }