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 || accessible->role() == QAccessible::Cell
89 || accessible->role() == QAccessible::ListItem
90 || accessible->role() == QAccessible::TreeItem) {
91 if (
auto provider = providerForAccessible(accessible)) {
92 long toggleState = ToggleState_Off;
93 if (accessible->state().checked)
94 toggleState = accessible->state().checkStateMixed ? ToggleState_Indeterminate : ToggleState_On;
97 QComVariant newVal{toggleState};
98 UiaRaiseAutomationPropertyChangedEvent(
99 provider.Get(), UIA_ToggleToggleStatePropertyId, oldVal.get(), newVal.get());
103 if (event->changedStates().active) {
104 if (accessible->role() == QAccessible::Window) {
106 if (
auto provider = providerForAccessible(accessible)) {
107 if (accessible->state().active) {
108 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowOpenedEventId);
109 if (QAccessibleInterface *focused = accessible->focusChild()) {
110 if (
auto focusedProvider = providerForAccessible(focused)) {
111 UiaRaiseAutomationEvent(focusedProvider.Get(),
112 UIA_AutomationFocusChangedEventId);
116 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowClosedEventId);
124void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event)
126 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
127 if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) {
128 QAccessibleInterface *listacc = accessible->child(0);
129 if (listacc && listacc->role() == QAccessible::List) {
130 int count = listacc->childCount();
131 for (
int i = 0; i < count; ++i) {
132 QAccessibleInterface *item = listacc->child(i);
133 if (item && item->isValid() && item->text(QAccessible::Name) == event->value()) {
134 if (!item->state().selected) {
135 if (QAccessibleActionInterface *actionInterface = item->actionInterface())
136 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
143 if (event->value().typeId() == QMetaType::QString) {
144 if (
auto provider = providerForAccessible(accessible)) {
146 const QComVariant oldVal;
147 const QComVariant newVal{ event->value().toString() };
148 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ValueValuePropertyId,
149 oldVal.get(), newVal.get());
151 }
else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
152 if (
auto provider = providerForAccessible(accessible)) {
154 const QComVariant oldVal;
155 const QComVariant newVal{ valueInterface->currentValue().toDouble() };
156 UiaRaiseAutomationPropertyChangedEvent(
157 provider.Get(), UIA_RangeValueValuePropertyId, oldVal.get(), newVal.get());
163void QWindowsUiaMainProvider::notifyNameChange(QAccessibleEvent *event)
165 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
168 if (accessible->role() == QAccessible::ComboBox || accessible->state().focused) {
169 if (
auto provider = providerForAccessible(accessible)) {
171 QComVariant newVal{ accessible->text(QAccessible::Name) };
172 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_NamePropertyId,
173 oldVal.get(), newVal.get());
179void QWindowsUiaMainProvider::notifyRoleChange(QAccessibleEvent *event)
181 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
182 if (
auto provider = providerForAccessible(accessible)) {
184 QComVariant newVal{ roleToControlTypeId(accessible->role()) };
185 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ControlTypePropertyId,
186 oldVal.get(), newVal.get());
191void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event)
193 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
194 if (
auto provider = providerForAccessible(accessible))
195 UiaRaiseAutomationEvent(provider.Get(), UIA_SelectionItem_ElementSelectedEventId);
200void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event)
202 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
203 if (accessible->textInterface()) {
204 if (
auto provider = providerForAccessible(accessible)) {
205 if (event->type() == QAccessible::TextSelectionChanged) {
206 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextSelectionChangedEventId);
207 }
else if (event->type() == QAccessible::TextCaretMoved) {
208 if (!accessible->state().readOnly) {
209 UiaRaiseAutomationEvent(provider.Get(),
210 UIA_Text_TextSelectionChangedEventId);
213 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextChangedEventId);
220void QWindowsUiaMainProvider::raiseNotification(QAccessibleAnnouncementEvent *event)
222 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
223 if (
auto provider = providerForAccessible(accessible)) {
224 QBStr message{ event->message() };
225 QAccessible::AnnouncementPoliteness prio = event->politeness();
226 NotificationProcessing processing = (prio == QAccessible::AnnouncementPoliteness::Assertive)
227 ? NotificationProcessing_ImportantAll
228 : NotificationProcessing_All;
229 QBStr activityId{ QString::fromLatin1(
"") };
230#if !defined(Q_CC_MSVC) || !defined(QT_WIN_SERVER_2016_COMPAT)
231 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
234 HMODULE uiautomationcore = GetModuleHandleW(L"UIAutomationCore.dll");
235 if (uiautomationcore != NULL) {
236 typedef HRESULT (WINAPI *EVENTFUNC)(IRawElementProviderSimple *, NotificationKind,
237 NotificationProcessing, BSTR, BSTR);
239 EVENTFUNC uiaRaiseNotificationEvent =
240 (EVENTFUNC)GetProcAddress(uiautomationcore,
"UiaRaiseNotificationEvent");
241 if (uiaRaiseNotificationEvent != NULL) {
242 uiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing,
243 message.bstr(), activityId.bstr());
251HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
253 HRESULT result = QComObject::QueryInterface(iid, iface);
255 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
256 QAccessibleInterface *accessible = accessibleInterface();
257 if (accessible && hwndForAccessible(accessible)) {
261 result = E_NOINTERFACE;
269HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
274 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
279HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
281 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
287 QAccessibleInterface *accessible = accessibleInterface();
289 return UIA_E_ELEMENTNOTAVAILABLE;
292 case UIA_WindowPatternId:
293 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
294 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
297 case UIA_TextPatternId:
298 case UIA_TextPattern2Id:
300 if (accessible->textInterface()) {
301 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
304 case UIA_ValuePatternId:
306 if (accessible->role() != QAccessible::StaticText)
307 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
309 case UIA_RangeValuePatternId:
311 if (accessible->valueInterface()) {
312 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
315 case UIA_TogglePatternId:
317 if (accessible->state().checkable)
318 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
320 case UIA_SelectionPatternId:
321 case UIA_SelectionPattern2Id:
323 if (accessible->selectionInterface()
324 || accessible->role() == QAccessible::List
325 || accessible->role() == QAccessible::PageTabList) {
326 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
329 case UIA_SelectionItemPatternId:
331 if ((accessible->parent() && accessible->parent()->selectionInterface())
332 || (accessible->role() == QAccessible::RadioButton)
333 || (accessible->role() == QAccessible::ListItem)
334 || (accessible->role() == QAccessible::PageTab)) {
335 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
338 case UIA_TablePatternId:
340 if (accessible->tableInterface()
341 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
342 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
345 case UIA_TableItemPatternId:
347 if (accessible->tableCellInterface()
348 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
349 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
352 case UIA_GridPatternId:
354 if (accessible->tableInterface()
355 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
356 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
359 case UIA_GridItemPatternId:
361 if (accessible->tableCellInterface()
362 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
363 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
366 case UIA_InvokePatternId:
368 if (accessible->actionInterface()) {
369 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
372 case UIA_ExpandCollapsePatternId:
374 if ((accessible->role() == QAccessible::MenuItem
375 && accessible->childCount() > 0
376 && accessible->child(0)->role() == QAccessible::PopupMenu)
377 || accessible->role() == QAccessible::ComboBox
378 || (accessible->role() == QAccessible::TreeItem && accessible->state().expandable)) {
379 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
389void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
391 Q_ASSERT(accessible);
393 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
394 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
395 if (relationInterfaces.empty())
399 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
403 pRetVal->vt = VT_UNKNOWN;
404 pRetVal->punkVal = provider.Detach();
407void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
408 QAccessible::Relation relation, VARIANT *pRetVal)
410 Q_ASSERT(accessible);
412 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
413 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
414 if (relationInterfaces.empty())
417 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
418 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
419 if (ComPtr<IRawElementProviderSimple> provider =
420 providerForAccessible(relationInterfaces.at(i).first)) {
421 SafeArrayPutElement(elements, &i, provider.Get());
425 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
426 pRetVal->parray = elements;
429void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
431 Q_ASSERT(accessible);
433 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
434 if (!attributesIface)
438 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
439 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
441 ariaString += QStringLiteral(
";");
442 const QAccessible::Attribute key = attrKeys.at(i);
443 const QVariant value = attributesIface->attributeValue(key);
446 case QAccessible::Attribute::Custom:
449 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
450 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
451 for (
auto [name, val] : attrMap.asKeyValueRange()) {
452 if (name != *attrMap.keyBegin())
453 ariaString += QStringLiteral(
";");
454 ariaString += name + QStringLiteral(
"=") + val;
458 case QAccessible::Attribute::Level:
459 Q_ASSERT(value.canConvert<
int>());
460 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
467 *pRetVal = QComVariant{ ariaString }.release();
470void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
472 Q_ASSERT(accessible);
474 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
475 if (!attributesIface)
479 if (accessible->role() != QAccessible::Role::Heading)
482 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
483 if (!levelVariant.isValid())
486 Q_ASSERT(levelVariant.canConvert<
int>());
488 const int level = levelVariant.toInt();
489 if (level < 1 || level > 9)
492 const long styleId = styleIdForHeadingLevel(level);
493 *pRetVal = QComVariant{ styleId }.release();
496int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
499 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
501 static constexpr int styles[] = {
513 return styles[headingLevel - 1];
516HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
518 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
522 clearVariant(pRetVal);
524 QAccessibleInterface *accessible = accessibleInterface();
526 return UIA_E_ELEMENTNOTAVAILABLE;
528 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
531 case UIA_ProcessIdPropertyId:
533 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
535 case UIA_AccessKeyPropertyId:
537 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
539 case UIA_AriaRolePropertyId:
540 if (accessible->role() == QAccessible::Heading)
541 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
543 case UIA_AriaPropertiesPropertyId:
544 setAriaProperties(accessible, pRetVal);
546 case UIA_AutomationIdPropertyId:
548 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
550 case UIA_ClassNamePropertyId:
552 if (QObject *o = accessible->object()) {
553 QString className = QLatin1StringView(o->metaObject()->className());
554 *pRetVal = QComVariant{ className }.release();
557 case UIA_CulturePropertyId:
560 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
561 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
562 if (localeVariant.isValid()) {
563 Q_ASSERT(localeVariant.canConvert<QLocale>());
564 locale = localeVariant.toLocale();
567 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
568 *pRetVal = QComVariant{
long(lcid) }.release();
571 case UIA_DescribedByPropertyId:
572 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
574 case UIA_FlowsFromPropertyId:
575 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
577 case UIA_FlowsToPropertyId:
578 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
580 case UIA_LabeledByPropertyId:
581 setLabelledBy(accessible, pRetVal);
583 case UIA_FrameworkIdPropertyId:
584 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
586 case UIA_ControlTypePropertyId:
587 if (topLevelWindow) {
589 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
592 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
595 case UIA_HelpTextPropertyId:
596 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
598 case UIA_HasKeyboardFocusPropertyId:
602 if (topLevelWindow) {
603 QAccessibleInterface *focusacc = accessible->focusChild();
605 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
609 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
611 case UIA_IsKeyboardFocusablePropertyId:
612 if (topLevelWindow) {
614 *pRetVal = QComVariant{
true }.release();
616 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
619 case UIA_IsOffscreenPropertyId:
620 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
622 case UIA_IsContentElementPropertyId:
623 *pRetVal = QComVariant{
true }.release();
625 case UIA_IsControlElementPropertyId:
626 *pRetVal = QComVariant{
true }.release();
628 case UIA_IsEnabledPropertyId:
629 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
631 case UIA_IsPasswordPropertyId:
632 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
633 && accessible->state().passwordEdit }
636 case UIA_IsPeripheralPropertyId:
638 if (QWindow *window = windowForAccessible(accessible)) {
639 const Qt::WindowType wt = window->type();
640 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
644 case UIA_IsDialogPropertyId:
645 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
646 || accessible->role() == QAccessible::AlertMessage }
649 case UIA_FullDescriptionPropertyId:
650 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
652 case UIA_LocalizedControlTypePropertyId:
655 if (accessible->role() == QAccessible::BlockQuote)
656 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
658 case UIA_NamePropertyId: {
659 QString name = accessible->text(QAccessible::Name);
660 if (name.isEmpty() && topLevelWindow)
661 name = QCoreApplication::applicationName();
662 *pRetVal = QComVariant{ name }.release();
665 case UIA_OrientationPropertyId: {
666 OrientationType orientationType = OrientationType_None;
667 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
668 const QVariant orientationVariant =
669 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
670 if (orientationVariant.isValid()) {
671 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
672 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
673 orientationType = orientation == Qt::Horizontal ? OrientationType_Horizontal
674 : OrientationType_Vertical;
677 *pRetVal = QComVariant{
long(orientationType) }.release();
680 case UIA_StyleIdAttributeId:
681 setStyle(accessible, pRetVal);
689HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
691 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
698 if (QAccessibleInterface *accessible = accessibleInterface()) {
699 if (HWND hwnd = hwndForAccessible(accessible)) {
700 return UiaHostProviderFromHwnd(hwnd, pRetVal);
707HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
709 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
715 QAccessibleInterface *accessible = accessibleInterface();
717 return UIA_E_ELEMENTNOTAVAILABLE;
719 QAccessibleInterface *targetacc =
nullptr;
721 if (direction == NavigateDirection_Parent) {
722 if (QAccessibleInterface *parent = accessible->parent()) {
724 if (parent->isValid() && parent->role() != QAccessible::Application) {
729 QAccessibleInterface *parent =
nullptr;
733 case NavigateDirection_FirstChild:
738 case NavigateDirection_LastChild:
740 index = accessible->childCount() - 1;
743 case NavigateDirection_NextSibling:
744 if ((parent = accessible->parent()))
745 index = parent->indexOfChild(accessible) + 1;
748 case NavigateDirection_PreviousSibling:
749 if ((parent = accessible->parent()))
750 index = parent->indexOfChild(accessible) - 1;
758 if (parent && parent->isValid()) {
759 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
760 if (QAccessibleInterface *child = parent->child(index)) {
761 if (child->isValid() && !child->state().invisible) {
771 *pRetVal = providerForAccessible(targetacc).Detach();
776HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
778 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
784 QAccessibleInterface *accessible = accessibleInterface();
786 return UIA_E_ELEMENTNOTAVAILABLE;
790 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
792 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
793 for (LONG i = 0; i < 2; ++i)
794 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
800HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
802 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
807 QAccessibleInterface *accessible = accessibleInterface();
809 return UIA_E_ELEMENTNOTAVAILABLE;
811 QWindow *window = windowForAccessible(accessible);
813 return UIA_E_ELEMENTNOTAVAILABLE;
815 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
819HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
821 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
831HRESULT QWindowsUiaMainProvider::SetFocus()
833 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
835 QAccessibleInterface *accessible = accessibleInterface();
837 return UIA_E_ELEMENTNOTAVAILABLE;
839 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
840 if (!actionInterface)
841 return UIA_E_ELEMENTNOTAVAILABLE;
843 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
847HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
849 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
857 if (QAccessibleInterface *accessible = accessibleInterface()) {
858 if (QWindow *window = windowForAccessible(accessible)) {
859 if (QAccessibleInterface *rootacc = window->accessibleRoot())
860 *pRetVal = providerForAccessible(rootacc).Detach();
867HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
869 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
876 QAccessibleInterface *accessible = accessibleInterface();
878 return UIA_E_ELEMENTNOTAVAILABLE;
880 QWindow *window = windowForAccessible(accessible);
882 return UIA_E_ELEMENTNOTAVAILABLE;
885 UiaPoint uiaPoint = {x, y};
887 nativeUiaPointToPoint(uiaPoint, window, &point);
889 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
892 QAccessibleInterface *acc = targetacc;
897 if (targetacc->textInterface())
break;
898 acc = acc->childAt(point.x(), point.y());
900 *pRetVal = providerForAccessible(targetacc).Detach();
906HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
908 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
914 if (QAccessibleInterface *accessible = accessibleInterface()) {
915 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
916 *pRetVal = providerForAccessible(focusacc).Detach();