4#include <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
7#include "qwindowsuiamainprovider.h"
8#include "qwindowsuiavalueprovider.h"
9#include "qwindowsuiarangevalueprovider.h"
10#include "qwindowsuiatextprovider.h"
11#include "qwindowsuiatoggleprovider.h"
12#include "qwindowsuiainvokeprovider.h"
13#include "qwindowsuiaselectionprovider.h"
14#include "qwindowsuiaselectionitemprovider.h"
15#include "qwindowsuiatableprovider.h"
16#include "qwindowsuiatableitemprovider.h"
17#include "qwindowsuiagridprovider.h"
18#include "qwindowsuiagriditemprovider.h"
19#include "qwindowsuiawindowprovider.h"
20#include "qwindowsuiaexpandcollapseprovider.h"
21#include "qwindowscontext.h"
22#include "qwindowsuiautils.h"
23#include "qwindowsuiaprovidercache.h"
25#include <QtCore/qloggingcategory.h>
26#include <QtGui/private/qaccessiblebridgeutils_p.h>
27#include <QtGui/qaccessible.h>
28#include <QtGui/qguiapplication.h>
29#include <QtGui/qwindow.h>
30#include <QtCore/private/qcomvariant_p.h>
32#if !defined(Q_CC_BOR) && !defined (Q_CC_GNU)
36#include <QtCore/qt_windows.h>
40using namespace QWindowsUiAutomation;
43ComPtr<QWindowsUiaMainProvider> QWindowsUiaMainProvider::providerForAccessible(QAccessibleInterface *accessible)
48 QAccessible::Id id = QAccessible::uniqueId(accessible);
49 QWindowsUiaProviderCache *providerCache = QWindowsUiaProviderCache::instance();
50 ComPtr<QWindowsUiaMainProvider> provider = providerCache->providerForId(id);
53 provider = makeComObject<QWindowsUiaMainProvider>(accessible);
54 providerCache->insert(id, provider.Get());
59QWindowsUiaMainProvider::QWindowsUiaMainProvider(QAccessibleInterface *a)
60 : QWindowsUiaBaseProvider(QAccessible::uniqueId(a))
64QWindowsUiaMainProvider::~QWindowsUiaMainProvider()
68void QWindowsUiaMainProvider::notifyFocusChange(QAccessibleEvent *event)
70 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
72 if (accessible->childCount()) {
73 if (QAccessibleInterface *child = accessible->focusChild())
76 if (
auto provider = providerForAccessible(accessible))
77 UiaRaiseAutomationEvent(provider.Get(), UIA_AutomationFocusChangedEventId);
81void QWindowsUiaMainProvider::notifyStateChange(QAccessibleStateChangeEvent *event)
83 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
84 if (event->changedStates().checked || event->changedStates().checkStateMixed) {
86 if (accessible->role() == QAccessible::CheckBox
87 || accessible->role() == QAccessible::Switch) {
88 if (
auto provider = providerForAccessible(accessible)) {
89 long toggleState = ToggleState_Off;
90 if (accessible->state().checked)
91 toggleState = accessible->state().checkStateMixed ? ToggleState_Indeterminate : ToggleState_On;
94 QComVariant newVal{toggleState};
95 UiaRaiseAutomationPropertyChangedEvent(
96 provider.Get(), UIA_ToggleToggleStatePropertyId, oldVal.get(), newVal.get());
100 if (event->changedStates().active) {
101 if (accessible->role() == QAccessible::Window) {
103 if (
auto provider = providerForAccessible(accessible)) {
104 if (accessible->state().active) {
105 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowOpenedEventId);
106 if (QAccessibleInterface *focused = accessible->focusChild()) {
107 if (
auto focusedProvider = providerForAccessible(focused)) {
108 UiaRaiseAutomationEvent(focusedProvider.Get(),
109 UIA_AutomationFocusChangedEventId);
113 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowClosedEventId);
121void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event)
123 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
124 if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) {
125 QAccessibleInterface *listacc = accessible->child(0);
126 if (listacc && listacc->role() == QAccessible::List) {
127 int count = listacc->childCount();
128 for (
int i = 0; i < count; ++i) {
129 QAccessibleInterface *item = listacc->child(i);
130 if (item && item->isValid() && item->text(QAccessible::Name) == event->value()) {
131 if (!item->state().selected) {
132 if (QAccessibleActionInterface *actionInterface = item->actionInterface())
133 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
140 if (event->value().typeId() == QMetaType::QString) {
141 if (
auto provider = providerForAccessible(accessible)) {
143 const QComVariant oldVal;
144 const QComVariant newVal{ event->value().toString() };
145 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ValueValuePropertyId,
146 oldVal.get(), newVal.get());
148 }
else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
149 if (
auto provider = providerForAccessible(accessible)) {
151 const QComVariant oldVal;
152 const QComVariant newVal{ valueInterface->currentValue().toDouble() };
153 UiaRaiseAutomationPropertyChangedEvent(
154 provider.Get(), UIA_RangeValueValuePropertyId, oldVal.get(), newVal.get());
160void QWindowsUiaMainProvider::notifyNameChange(QAccessibleEvent *event)
162 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
165 if (accessible->role() == QAccessible::ComboBox || accessible->state().focused) {
166 if (
auto provider = providerForAccessible(accessible)) {
168 QComVariant newVal{ accessible->text(QAccessible::Name) };
169 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_NamePropertyId,
170 oldVal.get(), newVal.get());
176void QWindowsUiaMainProvider::notifyRoleChange(QAccessibleEvent *event)
178 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
179 if (
auto provider = providerForAccessible(accessible)) {
181 QComVariant newVal{ roleToControlTypeId(accessible->role()) };
182 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ControlTypePropertyId,
183 oldVal.get(), newVal.get());
188void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event)
190 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
191 if (
auto provider = providerForAccessible(accessible))
192 UiaRaiseAutomationEvent(provider.Get(), UIA_SelectionItem_ElementSelectedEventId);
197void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event)
199 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
200 if (accessible->textInterface()) {
201 if (
auto provider = providerForAccessible(accessible)) {
202 if (event->type() == QAccessible::TextSelectionChanged) {
203 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextSelectionChangedEventId);
204 }
else if (event->type() == QAccessible::TextCaretMoved) {
205 if (!accessible->state().readOnly) {
206 UiaRaiseAutomationEvent(provider.Get(),
207 UIA_Text_TextSelectionChangedEventId);
210 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextChangedEventId);
217void QWindowsUiaMainProvider::raiseNotification(QAccessibleAnnouncementEvent *event)
219 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
220 if (
auto provider = providerForAccessible(accessible)) {
221 QBStr message{ event->message() };
222 QAccessible::AnnouncementPoliteness prio = event->politeness();
223 NotificationProcessing processing = (prio == QAccessible::AnnouncementPoliteness::Assertive)
224 ? NotificationProcessing_ImportantAll
225 : NotificationProcessing_All;
226 QBStr activityId{ QString::fromLatin1(
"") };
227#if !defined(Q_CC_MSVC) || !defined(QT_WIN_SERVER_2016_COMPAT)
228 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
231 HMODULE uiautomationcore = GetModuleHandleW(L"UIAutomationCore.dll");
232 if (uiautomationcore != NULL) {
233 typedef HRESULT (WINAPI *EVENTFUNC)(IRawElementProviderSimple *, NotificationKind,
234 NotificationProcessing, BSTR, BSTR);
236 EVENTFUNC uiaRaiseNotificationEvent =
237 (EVENTFUNC)GetProcAddress(uiautomationcore,
"UiaRaiseNotificationEvent");
238 if (uiaRaiseNotificationEvent != NULL) {
239 uiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing,
240 message.bstr(), activityId.bstr());
248HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
250 HRESULT result = QComObject::QueryInterface(iid, iface);
252 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
253 QAccessibleInterface *accessible = accessibleInterface();
254 if (accessible && hwndForAccessible(accessible)) {
258 result = E_NOINTERFACE;
266HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
271 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
276HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
278 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
284 QAccessibleInterface *accessible = accessibleInterface();
286 return UIA_E_ELEMENTNOTAVAILABLE;
289 case UIA_WindowPatternId:
290 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
291 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
294 case UIA_TextPatternId:
295 case UIA_TextPattern2Id:
297 if (accessible->textInterface()) {
298 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
301 case UIA_ValuePatternId:
303 if (accessible->role() != QAccessible::StaticText)
304 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
306 case UIA_RangeValuePatternId:
308 if (accessible->valueInterface()) {
309 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
312 case UIA_TogglePatternId:
314 if (accessible->state().checkable)
315 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
317 case UIA_SelectionPatternId:
318 case UIA_SelectionPattern2Id:
320 if (accessible->selectionInterface()
321 || accessible->role() == QAccessible::List
322 || accessible->role() == QAccessible::PageTabList) {
323 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
326 case UIA_SelectionItemPatternId:
328 if ((accessible->parent() && accessible->parent()->selectionInterface())
329 || (accessible->role() == QAccessible::RadioButton)
330 || (accessible->role() == QAccessible::ListItem)
331 || (accessible->role() == QAccessible::PageTab)) {
332 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
335 case UIA_TablePatternId:
337 if (accessible->tableInterface()
338 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
339 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
342 case UIA_TableItemPatternId:
344 if (accessible->tableCellInterface()
345 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
346 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
349 case UIA_GridPatternId:
351 if (accessible->tableInterface()
352 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
353 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
356 case UIA_GridItemPatternId:
358 if (accessible->tableCellInterface()
359 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
360 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
363 case UIA_InvokePatternId:
365 if (accessible->actionInterface()) {
366 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
369 case UIA_ExpandCollapsePatternId:
371 if ((accessible->role() == QAccessible::MenuItem
372 && accessible->childCount() > 0
373 && accessible->child(0)->role() == QAccessible::PopupMenu)
374 || accessible->role() == QAccessible::ComboBox
375 || (accessible->role() == QAccessible::TreeItem && accessible->state().expandable)) {
376 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
386void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
388 Q_ASSERT(accessible);
390 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
391 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
392 if (relationInterfaces.empty())
396 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
400 pRetVal->vt = VT_UNKNOWN;
401 pRetVal->punkVal = provider.Detach();
404void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
405 QAccessible::Relation relation, VARIANT *pRetVal)
407 Q_ASSERT(accessible);
409 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
410 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
411 if (relationInterfaces.empty())
414 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
415 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
416 if (ComPtr<IRawElementProviderSimple> provider =
417 providerForAccessible(relationInterfaces.at(i).first)) {
418 SafeArrayPutElement(elements, &i, provider.Get());
422 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
423 pRetVal->parray = elements;
426void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
428 Q_ASSERT(accessible);
430 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
431 if (!attributesIface)
435 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
436 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
438 ariaString += QStringLiteral(
";");
439 const QAccessible::Attribute key = attrKeys.at(i);
440 const QVariant value = attributesIface->attributeValue(key);
443 case QAccessible::Attribute::Custom:
446 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
447 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
448 for (
auto [name, val] : attrMap.asKeyValueRange()) {
449 if (name != *attrMap.keyBegin())
450 ariaString += QStringLiteral(
";");
451 ariaString += name + QStringLiteral(
"=") + val;
455 case QAccessible::Attribute::Level:
456 Q_ASSERT(value.canConvert<
int>());
457 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
464 *pRetVal = QComVariant{ ariaString }.release();
467void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
469 Q_ASSERT(accessible);
471 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
472 if (!attributesIface)
476 if (accessible->role() != QAccessible::Role::Heading)
479 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
480 if (!levelVariant.isValid())
483 Q_ASSERT(levelVariant.canConvert<
int>());
485 const int level = levelVariant.toInt();
486 if (level < 1 || level > 9)
489 const long styleId = styleIdForHeadingLevel(level);
490 *pRetVal = QComVariant{ styleId }.release();
493int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
496 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
498 static constexpr int styles[] = {
510 return styles[headingLevel - 1];
513HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
515 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
519 clearVariant(pRetVal);
521 QAccessibleInterface *accessible = accessibleInterface();
523 return UIA_E_ELEMENTNOTAVAILABLE;
525 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
528 case UIA_ProcessIdPropertyId:
530 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
532 case UIA_AccessKeyPropertyId:
534 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
536 case UIA_AriaRolePropertyId:
537 if (accessible->role() == QAccessible::Heading)
538 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
540 case UIA_AriaPropertiesPropertyId:
541 setAriaProperties(accessible, pRetVal);
543 case UIA_AutomationIdPropertyId:
545 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
547 case UIA_ClassNamePropertyId:
549 if (QObject *o = accessible->object()) {
550 QString className = QLatin1StringView(o->metaObject()->className());
551 *pRetVal = QComVariant{ className }.release();
554 case UIA_CulturePropertyId:
557 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
558 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
559 if (localeVariant.isValid()) {
560 Q_ASSERT(localeVariant.canConvert<QLocale>());
561 locale = localeVariant.toLocale();
564 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
565 *pRetVal = QComVariant{
long(lcid) }.release();
568 case UIA_DescribedByPropertyId:
569 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
571 case UIA_FlowsFromPropertyId:
572 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
574 case UIA_FlowsToPropertyId:
575 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
577 case UIA_LabeledByPropertyId:
578 setLabelledBy(accessible, pRetVal);
580 case UIA_FrameworkIdPropertyId:
581 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
583 case UIA_ControlTypePropertyId:
584 if (topLevelWindow) {
586 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
589 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
592 case UIA_HelpTextPropertyId:
593 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
595 case UIA_HasKeyboardFocusPropertyId:
596 if (topLevelWindow) {
598 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
600 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
603 case UIA_IsKeyboardFocusablePropertyId:
604 if (topLevelWindow) {
606 *pRetVal = QComVariant{
true }.release();
608 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
611 case UIA_IsOffscreenPropertyId:
612 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
614 case UIA_IsContentElementPropertyId:
615 *pRetVal = QComVariant{
true }.release();
617 case UIA_IsControlElementPropertyId:
618 *pRetVal = QComVariant{
true }.release();
620 case UIA_IsEnabledPropertyId:
621 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
623 case UIA_IsPasswordPropertyId:
624 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
625 && accessible->state().passwordEdit }
628 case UIA_IsPeripheralPropertyId:
630 if (QWindow *window = windowForAccessible(accessible)) {
631 const Qt::WindowType wt = window->type();
632 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
636 case UIA_IsDialogPropertyId:
637 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
638 || accessible->role() == QAccessible::AlertMessage }
641 case UIA_FullDescriptionPropertyId:
642 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
644 case UIA_LocalizedControlTypePropertyId:
647 if (accessible->role() == QAccessible::BlockQuote)
648 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
650 case UIA_NamePropertyId: {
651 QString name = accessible->text(QAccessible::Name);
652 if (name.isEmpty() && topLevelWindow)
653 name = QCoreApplication::applicationName();
654 *pRetVal = QComVariant{ name }.release();
657 case UIA_OrientationPropertyId: {
658 OrientationType orientationType = OrientationType_None;
659 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
660 const QVariant orientationVariant =
661 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
662 if (orientationVariant.isValid()) {
663 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
664 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
665 orientationType = orientation == Qt::Horizontal ? OrientationType_Horizontal
666 : OrientationType_Vertical;
669 *pRetVal = QComVariant{
long(orientationType) }.release();
672 case UIA_StyleIdAttributeId:
673 setStyle(accessible, pRetVal);
681HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
683 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
690 if (QAccessibleInterface *accessible = accessibleInterface()) {
691 if (HWND hwnd = hwndForAccessible(accessible)) {
692 return UiaHostProviderFromHwnd(hwnd, pRetVal);
699HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
701 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
707 QAccessibleInterface *accessible = accessibleInterface();
709 return UIA_E_ELEMENTNOTAVAILABLE;
711 QAccessibleInterface *targetacc =
nullptr;
713 if (direction == NavigateDirection_Parent) {
714 if (QAccessibleInterface *parent = accessible->parent()) {
716 if (parent->isValid() && parent->role() != QAccessible::Application) {
721 QAccessibleInterface *parent =
nullptr;
725 case NavigateDirection_FirstChild:
730 case NavigateDirection_LastChild:
732 index = accessible->childCount() - 1;
735 case NavigateDirection_NextSibling:
736 if ((parent = accessible->parent()))
737 index = parent->indexOfChild(accessible) + 1;
740 case NavigateDirection_PreviousSibling:
741 if ((parent = accessible->parent()))
742 index = parent->indexOfChild(accessible) - 1;
750 if (parent && parent->isValid()) {
751 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
752 if (QAccessibleInterface *child = parent->child(index)) {
753 if (child->isValid() && !child->state().invisible) {
763 *pRetVal = providerForAccessible(targetacc).Detach();
768HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
770 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
776 QAccessibleInterface *accessible = accessibleInterface();
778 return UIA_E_ELEMENTNOTAVAILABLE;
782 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
784 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
785 for (LONG i = 0; i < 2; ++i)
786 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
792HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
794 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
799 QAccessibleInterface *accessible = accessibleInterface();
801 return UIA_E_ELEMENTNOTAVAILABLE;
803 QWindow *window = windowForAccessible(accessible);
805 return UIA_E_ELEMENTNOTAVAILABLE;
807 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
811HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
813 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
823HRESULT QWindowsUiaMainProvider::SetFocus()
825 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
827 QAccessibleInterface *accessible = accessibleInterface();
829 return UIA_E_ELEMENTNOTAVAILABLE;
831 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
832 if (!actionInterface)
833 return UIA_E_ELEMENTNOTAVAILABLE;
835 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
839HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
841 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
849 if (QAccessibleInterface *accessible = accessibleInterface()) {
850 if (QWindow *window = windowForAccessible(accessible)) {
851 if (QAccessibleInterface *rootacc = window->accessibleRoot())
852 *pRetVal = providerForAccessible(rootacc).Detach();
859HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
861 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
868 QAccessibleInterface *accessible = accessibleInterface();
870 return UIA_E_ELEMENTNOTAVAILABLE;
872 QWindow *window = windowForAccessible(accessible);
874 return UIA_E_ELEMENTNOTAVAILABLE;
877 UiaPoint uiaPoint = {x, y};
879 nativeUiaPointToPoint(uiaPoint, window, &point);
881 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
884 QAccessibleInterface *acc = targetacc;
889 if (targetacc->textInterface())
break;
890 acc = acc->childAt(point.x(), point.y());
892 *pRetVal = providerForAccessible(targetacc).Detach();
898HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
900 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
906 if (QAccessibleInterface *accessible = accessibleInterface()) {
907 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
908 *pRetVal = providerForAccessible(focusacc).Detach();