5#include <QtGui/qtguiglobal.h>
6#if QT_CONFIG(accessibility)
8#include "qwindowsuiamainprovider.h"
9#include "qwindowsuiavalueprovider.h"
10#include "qwindowsuiarangevalueprovider.h"
11#include "qwindowsuiatextprovider.h"
12#include "qwindowsuiatoggleprovider.h"
13#include "qwindowsuiainvokeprovider.h"
14#include "qwindowsuiaselectionprovider.h"
15#include "qwindowsuiaselectionitemprovider.h"
16#include "qwindowsuiatableprovider.h"
17#include "qwindowsuiatableitemprovider.h"
18#include "qwindowsuiagridprovider.h"
19#include "qwindowsuiagriditemprovider.h"
20#include "qwindowsuiawindowprovider.h"
21#include "qwindowsuiaexpandcollapseprovider.h"
22#include "qwindowscontext.h"
23#include "qwindowsuiautils.h"
24#include "qwindowsuiaprovidercache.h"
26#include <QtCore/qloggingcategory.h>
27#include <QtGui/private/qaccessiblebridgeutils_p.h>
28#include <QtGui/qaccessible.h>
29#include <QtGui/qguiapplication.h>
30#include <QtGui/qwindow.h>
31#include <QtCore/private/qcomvariant_p.h>
33#if !defined(Q_CC_BOR) && !defined (Q_CC_GNU)
37#include <QtCore/qt_windows.h>
41using namespace QWindowsUiAutomation;
44ComPtr<QWindowsUiaMainProvider> QWindowsUiaMainProvider::providerForAccessible(QAccessibleInterface *accessible)
49 QAccessible::Id id = QAccessible::uniqueId(accessible);
50 QWindowsUiaProviderCache *providerCache = QWindowsUiaProviderCache::instance();
51 ComPtr<QWindowsUiaMainProvider> provider = providerCache->providerForId(id);
54 provider = makeComObject<QWindowsUiaMainProvider>(accessible);
55 providerCache->insert(id, provider.Get());
60QWindowsUiaMainProvider::QWindowsUiaMainProvider(QAccessibleInterface *a)
61 : QWindowsUiaBaseProvider(QAccessible::uniqueId(a))
65QWindowsUiaMainProvider::~QWindowsUiaMainProvider()
69void QWindowsUiaMainProvider::notifyFocusChange(QAccessibleEvent *event)
71 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
73 if (accessible->childCount()) {
74 if (QAccessibleInterface *child = accessible->focusChild())
77 if (
auto provider = providerForAccessible(accessible))
78 UiaRaiseAutomationEvent(provider.Get(), UIA_AutomationFocusChangedEventId);
82void QWindowsUiaMainProvider::notifyStateChange(QAccessibleStateChangeEvent *event)
84 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
85 if (event->changedStates().checked || event->changedStates().checkStateMixed) {
87 if (accessible->role() == QAccessible::CheckBox
88 || accessible->role() == QAccessible::Switch
89 || accessible->role() == QAccessible::Cell
90 || accessible->role() == QAccessible::ListItem
91 || accessible->role() == QAccessible::TreeItem) {
92 if (
auto provider = providerForAccessible(accessible)) {
93 long toggleState = ToggleState_Off;
94 if (accessible->state().checked)
95 toggleState = accessible->state().checkStateMixed ? ToggleState_Indeterminate : ToggleState_On;
98 QComVariant newVal{toggleState};
99 UiaRaiseAutomationPropertyChangedEvent(
100 provider.Get(), UIA_ToggleToggleStatePropertyId, oldVal.get(), newVal.get());
104 if (event->changedStates().active) {
105 if (accessible->role() == QAccessible::Window) {
107 if (
auto provider = providerForAccessible(accessible)) {
108 if (accessible->state().active) {
109 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowOpenedEventId);
110 if (QAccessibleInterface *focused = accessible->focusChild()) {
111 if (
auto focusedProvider = providerForAccessible(focused)) {
112 UiaRaiseAutomationEvent(focusedProvider.Get(),
113 UIA_AutomationFocusChangedEventId);
117 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowClosedEventId);
125void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event)
127 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
128 if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) {
129 QAccessibleInterface *listacc = accessible->child(0);
130 if (listacc && listacc->role() == QAccessible::List) {
131 int count = listacc->childCount();
132 for (
int i = 0; i < count; ++i) {
133 QAccessibleInterface *item = listacc->child(i);
134 if (item && item->isValid() && item->text(QAccessible::Name) == event->value()) {
135 if (!item->state().selected) {
136 if (QAccessibleActionInterface *actionInterface = item->actionInterface())
137 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
144 if (event->value().typeId() == QMetaType::QString) {
145 if (
auto provider = providerForAccessible(accessible)) {
147 const QComVariant oldVal;
148 const QComVariant newVal{ event->value().toString() };
149 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ValueValuePropertyId,
150 oldVal.get(), newVal.get());
152 }
else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
153 if (
auto provider = providerForAccessible(accessible)) {
155 const QComVariant oldVal;
156 const QComVariant newVal{ valueInterface->currentValue().toDouble() };
157 UiaRaiseAutomationPropertyChangedEvent(
158 provider.Get(), UIA_RangeValueValuePropertyId, oldVal.get(), newVal.get());
164void QWindowsUiaMainProvider::notifyNameChange(QAccessibleEvent *event)
166 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
169 if (accessible->role() == QAccessible::ComboBox || accessible->state().focused) {
170 if (
auto provider = providerForAccessible(accessible)) {
172 QComVariant newVal{ accessible->text(QAccessible::Name) };
173 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_NamePropertyId,
174 oldVal.get(), newVal.get());
180void QWindowsUiaMainProvider::notifyRoleChange(QAccessibleEvent *event)
182 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
183 if (
auto provider = providerForAccessible(accessible)) {
185 QComVariant newVal{ roleToControlTypeId(accessible->role()) };
186 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ControlTypePropertyId,
187 oldVal.get(), newVal.get());
192void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event)
194 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
195 if (
auto provider = providerForAccessible(accessible))
196 UiaRaiseAutomationEvent(provider.Get(), UIA_SelectionItem_ElementSelectedEventId);
201void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event)
203 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
204 if (accessible->textInterface()) {
205 if (
auto provider = providerForAccessible(accessible)) {
206 if (event->type() == QAccessible::TextSelectionChanged) {
207 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextSelectionChangedEventId);
208 }
else if (event->type() == QAccessible::TextCaretMoved) {
209 if (!accessible->state().readOnly) {
210 UiaRaiseAutomationEvent(provider.Get(),
211 UIA_Text_TextSelectionChangedEventId);
214 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextChangedEventId);
221void QWindowsUiaMainProvider::raiseNotification(QAccessibleAnnouncementEvent *event)
223 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
224 if (
auto provider = providerForAccessible(accessible)) {
225 QBStr message{ event->message() };
226 QAccessible::AnnouncementPoliteness prio = event->politeness();
227 NotificationProcessing processing = (prio == QAccessible::AnnouncementPoliteness::Assertive)
228 ? NotificationProcessing_ImportantAll
229 : NotificationProcessing_All;
230 QBStr activityId{ QString::fromLatin1(
"") };
231#if !defined(Q_CC_MSVC) || !defined(QT_WIN_SERVER_2016_COMPAT)
232 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
235 HMODULE uiautomationcore = GetModuleHandleW(L"UIAutomationCore.dll");
236 if (uiautomationcore != NULL) {
237 typedef HRESULT (WINAPI *EVENTFUNC)(IRawElementProviderSimple *, NotificationKind,
238 NotificationProcessing, BSTR, BSTR);
240 EVENTFUNC uiaRaiseNotificationEvent =
241 (EVENTFUNC)GetProcAddress(uiautomationcore,
"UiaRaiseNotificationEvent");
242 if (uiaRaiseNotificationEvent != NULL) {
243 uiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing,
244 message.bstr(), activityId.bstr());
252HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
254 HRESULT result = QComObject::QueryInterface(iid, iface);
256 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
257 QAccessibleInterface *accessible = accessibleInterface();
258 if (accessible && hwndForAccessible(accessible)) {
262 result = E_NOINTERFACE;
270HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
275 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
280HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
282 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
288 QAccessibleInterface *accessible = accessibleInterface();
290 return UIA_E_ELEMENTNOTAVAILABLE;
293 case UIA_WindowPatternId:
294 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
295 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
298 case UIA_TextPatternId:
299 case UIA_TextPattern2Id:
301 if (accessible->textInterface()) {
302 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
305 case UIA_ValuePatternId:
307 if (accessible->role() != QAccessible::StaticText)
308 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
310 case UIA_RangeValuePatternId:
312 if (accessible->valueInterface()) {
313 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
316 case UIA_TogglePatternId:
318 if (accessible->state().checkable)
319 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
321 case UIA_SelectionPatternId:
322 case UIA_SelectionPattern2Id:
324 if (accessible->selectionInterface()
325 || accessible->role() == QAccessible::List
326 || accessible->role() == QAccessible::PageTabList) {
327 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
330 case UIA_SelectionItemPatternId:
332 if ((accessible->parent() && accessible->parent()->selectionInterface())
333 || (accessible->role() == QAccessible::RadioButton)
334 || (accessible->role() == QAccessible::ListItem)
335 || (accessible->role() == QAccessible::PageTab)) {
336 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
339 case UIA_TablePatternId:
341 if (accessible->tableInterface()
342 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
343 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
346 case UIA_TableItemPatternId:
348 if (accessible->tableCellInterface()
349 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
350 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
353 case UIA_GridPatternId:
355 if (accessible->tableInterface()
356 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
357 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
360 case UIA_GridItemPatternId:
362 if (accessible->tableCellInterface()
363 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
364 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
367 case UIA_InvokePatternId:
369 if (accessible->actionInterface()) {
370 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
373 case UIA_ExpandCollapsePatternId:
375 if ((accessible->role() == QAccessible::MenuItem
376 && accessible->childCount() > 0
377 && accessible->child(0)->role() == QAccessible::PopupMenu)
378 || accessible->role() == QAccessible::ComboBox
379 || (accessible->role() == QAccessible::TreeItem && accessible->state().expandable)) {
380 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
390void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
392 Q_ASSERT(accessible);
394 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
395 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
396 if (relationInterfaces.empty())
400 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
404 pRetVal->vt = VT_UNKNOWN;
405 pRetVal->punkVal = provider.Detach();
408void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
409 QAccessible::Relation relation, VARIANT *pRetVal)
411 Q_ASSERT(accessible);
413 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
414 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
415 if (relationInterfaces.empty())
418 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
419 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
420 if (ComPtr<IRawElementProviderSimple> provider =
421 providerForAccessible(relationInterfaces.at(i).first)) {
422 SafeArrayPutElement(elements, &i, provider.Get());
426 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
427 pRetVal->parray = elements;
430void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
432 Q_ASSERT(accessible);
434 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
435 if (!attributesIface)
439 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
440 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
442 ariaString += QStringLiteral(
";");
443 const QAccessible::Attribute key = attrKeys.at(i);
444 const QVariant value = attributesIface->attributeValue(key);
447 case QAccessible::Attribute::Custom:
450 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
451 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
452 for (
auto [name, val] : attrMap.asKeyValueRange()) {
453 if (name != *attrMap.keyBegin())
454 ariaString += QStringLiteral(
";");
455 ariaString += name + QStringLiteral(
"=") + val;
459 case QAccessible::Attribute::Level:
460 Q_ASSERT(value.canConvert<
int>());
461 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
468 *pRetVal = QComVariant{ ariaString }.release();
471void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
473 Q_ASSERT(accessible);
475 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
476 if (!attributesIface)
480 if (accessible->role() != QAccessible::Role::Heading)
483 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
484 if (!levelVariant.isValid())
487 Q_ASSERT(levelVariant.canConvert<
int>());
489 const int level = levelVariant.toInt();
490 if (level < 1 || level > 9)
493 const long styleId = styleIdForHeadingLevel(level);
494 *pRetVal = QComVariant{ styleId }.release();
497int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
500 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
502 static constexpr int styles[] = {
514 return styles[headingLevel - 1];
517HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
519 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
523 clearVariant(pRetVal);
525 QAccessibleInterface *accessible = accessibleInterface();
527 return UIA_E_ELEMENTNOTAVAILABLE;
529 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
532 case UIA_ProcessIdPropertyId:
534 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
536 case UIA_AccessKeyPropertyId:
538 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
540 case UIA_AriaRolePropertyId:
541 if (accessible->role() == QAccessible::Heading)
542 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
544 case UIA_AriaPropertiesPropertyId:
545 setAriaProperties(accessible, pRetVal);
547 case UIA_AutomationIdPropertyId:
549 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
551 case UIA_ClassNamePropertyId:
553 if (QObject *o = accessible->object()) {
554 QString className = QLatin1StringView(o->metaObject()->className());
555 *pRetVal = QComVariant{ className }.release();
558 case UIA_CulturePropertyId:
561 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
562 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
563 if (localeVariant.isValid()) {
564 Q_ASSERT(localeVariant.canConvert<QLocale>());
565 locale = localeVariant.toLocale();
568 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
569 *pRetVal = QComVariant{
long(lcid) }.release();
572 case UIA_DescribedByPropertyId:
573 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
575 case UIA_FlowsFromPropertyId:
576 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
578 case UIA_FlowsToPropertyId:
579 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
581 case UIA_LabeledByPropertyId:
582 setLabelledBy(accessible, pRetVal);
584 case UIA_FrameworkIdPropertyId:
585 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
587 case UIA_ControlTypePropertyId:
588 if (topLevelWindow) {
590 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
593 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
596 case UIA_HelpTextPropertyId:
597 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
599 case UIA_HasKeyboardFocusPropertyId:
603 if (topLevelWindow) {
604 QAccessibleInterface *focusacc = accessible->focusChild();
606 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
610 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
612 case UIA_IsKeyboardFocusablePropertyId:
613 if (topLevelWindow) {
615 *pRetVal = QComVariant{
true }.release();
617 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
620 case UIA_IsOffscreenPropertyId:
621 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
623 case UIA_IsContentElementPropertyId:
624 *pRetVal = QComVariant{
true }.release();
626 case UIA_IsControlElementPropertyId:
627 *pRetVal = QComVariant{
true }.release();
629 case UIA_IsEnabledPropertyId:
630 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
632 case UIA_IsPasswordPropertyId:
633 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
634 && accessible->state().passwordEdit }
637 case UIA_IsPeripheralPropertyId:
639 if (QWindow *window = windowForAccessible(accessible)) {
640 const Qt::WindowType wt = window->type();
641 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
645 case UIA_IsDialogPropertyId:
646 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
647 || accessible->role() == QAccessible::AlertMessage }
650 case UIA_FullDescriptionPropertyId:
651 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
653 case UIA_LocalizedControlTypePropertyId:
656 if (accessible->role() == QAccessible::BlockQuote)
657 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
659 case UIA_NamePropertyId: {
660 QString name = accessible->text(QAccessible::Name);
661 if (name.isEmpty() && topLevelWindow)
662 name = QCoreApplication::applicationName();
663 *pRetVal = QComVariant{ name }.release();
666 case UIA_OrientationPropertyId: {
667 OrientationType orientationType = OrientationType_None;
668 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
669 const QVariant orientationVariant =
670 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
671 if (orientationVariant.isValid()) {
672 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
673 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
674 orientationType = orientation == Qt::Horizontal ? OrientationType_Horizontal
675 : OrientationType_Vertical;
678 *pRetVal = QComVariant{
long(orientationType) }.release();
681 case UIA_StyleIdAttributeId:
682 setStyle(accessible, pRetVal);
690HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
692 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
699 if (QAccessibleInterface *accessible = accessibleInterface()) {
700 if (HWND hwnd = hwndForAccessible(accessible)) {
701 return UiaHostProviderFromHwnd(hwnd, pRetVal);
708HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
710 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
716 QAccessibleInterface *accessible = accessibleInterface();
718 return UIA_E_ELEMENTNOTAVAILABLE;
720 QAccessibleInterface *targetacc =
nullptr;
722 if (direction == NavigateDirection_Parent) {
723 if (QAccessibleInterface *parent = accessible->parent()) {
725 if (parent->isValid() && parent->role() != QAccessible::Application) {
730 QAccessibleInterface *parent =
nullptr;
734 case NavigateDirection_FirstChild:
739 case NavigateDirection_LastChild:
741 index = accessible->childCount() - 1;
744 case NavigateDirection_NextSibling:
745 if ((parent = accessible->parent()))
746 index = parent->indexOfChild(accessible) + 1;
749 case NavigateDirection_PreviousSibling:
750 if ((parent = accessible->parent()))
751 index = parent->indexOfChild(accessible) - 1;
759 if (parent && parent->isValid()) {
760 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
761 if (QAccessibleInterface *child = parent->child(index)) {
762 if (child->isValid() && !child->state().invisible) {
772 *pRetVal = providerForAccessible(targetacc).Detach();
777HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
779 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
785 QAccessibleInterface *accessible = accessibleInterface();
787 return UIA_E_ELEMENTNOTAVAILABLE;
791 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
793 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
794 for (LONG i = 0; i < 2; ++i)
795 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
801HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
803 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
808 QAccessibleInterface *accessible = accessibleInterface();
810 return UIA_E_ELEMENTNOTAVAILABLE;
812 QWindow *window = windowForAccessible(accessible);
814 return UIA_E_ELEMENTNOTAVAILABLE;
816 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
820HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
822 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
832HRESULT QWindowsUiaMainProvider::SetFocus()
834 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
836 QAccessibleInterface *accessible = accessibleInterface();
838 return UIA_E_ELEMENTNOTAVAILABLE;
840 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
841 if (!actionInterface)
842 return UIA_E_ELEMENTNOTAVAILABLE;
844 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
848HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
850 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
858 if (QAccessibleInterface *accessible = accessibleInterface()) {
859 if (QWindow *window = windowForAccessible(accessible)) {
860 if (QAccessibleInterface *rootacc = window->accessibleRoot())
861 *pRetVal = providerForAccessible(rootacc).Detach();
868HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
870 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
877 QAccessibleInterface *accessible = accessibleInterface();
879 return UIA_E_ELEMENTNOTAVAILABLE;
881 QWindow *window = windowForAccessible(accessible);
883 return UIA_E_ELEMENTNOTAVAILABLE;
886 UiaPoint uiaPoint = {x, y};
888 nativeUiaPointToPoint(uiaPoint, window, &point);
890 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
893 QAccessibleInterface *acc = targetacc;
898 if (targetacc->textInterface())
break;
899 acc = acc->childAt(point.x(), point.y());
901 *pRetVal = providerForAccessible(targetacc).Detach();
907HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
909 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
915 if (QAccessibleInterface *accessible = accessibleInterface()) {
916 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
917 *pRetVal = providerForAccessible(focusacc).Detach();