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().expanded) {
105 if (accessible->state().expandable) {
106 if (
auto provider = providerForAccessible(accessible)) {
107 long expandedState = accessible->state().expanded ? ExpandCollapseState_Expanded : ExpandCollapseState_Collapsed;
110 QComVariant newVal{expandedState};
111 UiaRaiseAutomationPropertyChangedEvent(
112 provider.Get(), UIA_ExpandCollapseExpandCollapseStatePropertyId, oldVal.get(), newVal.get());
116 if (event->changedStates().active) {
117 if (accessible->role() == QAccessible::Window) {
119 if (
auto provider = providerForAccessible(accessible)) {
120 if (accessible->state().active) {
121 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowOpenedEventId);
122 if (QAccessibleInterface *focused = accessible->focusChild()) {
123 if (
auto focusedProvider = providerForAccessible(focused)) {
124 UiaRaiseAutomationEvent(focusedProvider.Get(),
125 UIA_AutomationFocusChangedEventId);
129 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowClosedEventId);
137void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event)
139 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
140 if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) {
141 QAccessibleInterface *listacc = accessible->child(0);
142 if (listacc && listacc->role() == QAccessible::List) {
143 int count = listacc->childCount();
144 for (
int i = 0; i < count; ++i) {
145 QAccessibleInterface *item = listacc->child(i);
146 if (item && item->isValid() && item->text(QAccessible::Name) == event->value()) {
147 if (!item->state().selected) {
148 if (QAccessibleActionInterface *actionInterface = item->actionInterface())
149 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
156 if (event->value().typeId() == QMetaType::QString) {
157 if (
auto provider = providerForAccessible(accessible)) {
159 const QComVariant oldVal;
160 const QComVariant newVal{ event->value().toString() };
161 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ValueValuePropertyId,
162 oldVal.get(), newVal.get());
164 }
else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
165 if (
auto provider = providerForAccessible(accessible)) {
167 const QComVariant oldVal;
168 const QComVariant newVal{ valueInterface->currentValue().toDouble() };
169 UiaRaiseAutomationPropertyChangedEvent(
170 provider.Get(), UIA_RangeValueValuePropertyId, oldVal.get(), newVal.get());
176void QWindowsUiaMainProvider::notifyNameChange(QAccessibleEvent *event)
178 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
181 if (accessible->role() == QAccessible::ComboBox || accessible->state().focused) {
182 if (
auto provider = providerForAccessible(accessible)) {
184 QComVariant newVal{ accessible->text(QAccessible::Name) };
185 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_NamePropertyId,
186 oldVal.get(), newVal.get());
192void QWindowsUiaMainProvider::notifyRoleChange(QAccessibleEvent *event)
194 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
195 if (
auto provider = providerForAccessible(accessible)) {
197 QComVariant newVal{ roleToControlTypeId(accessible->role()) };
198 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ControlTypePropertyId,
199 oldVal.get(), newVal.get());
204void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event)
206 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
207 if (
auto provider = providerForAccessible(accessible))
208 UiaRaiseAutomationEvent(provider.Get(), UIA_SelectionItem_ElementSelectedEventId);
213void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event)
215 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
216 if (accessible->textInterface()) {
217 if (
auto provider = providerForAccessible(accessible)) {
218 if (event->type() == QAccessible::TextSelectionChanged) {
219 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextSelectionChangedEventId);
220 }
else if (event->type() == QAccessible::TextCaretMoved) {
221 if (!accessible->state().readOnly) {
222 UiaRaiseAutomationEvent(provider.Get(),
223 UIA_Text_TextSelectionChangedEventId);
226 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextChangedEventId);
233void QWindowsUiaMainProvider::raiseNotification(QAccessibleAnnouncementEvent *event)
235 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
236 if (
auto provider = providerForAccessible(accessible)) {
237 QBStr message{ event->message() };
238 QAccessible::AnnouncementPoliteness prio = event->politeness();
239 NotificationProcessing processing = (prio == QAccessible::AnnouncementPoliteness::Assertive)
240 ? NotificationProcessing_ImportantAll
241 : NotificationProcessing_All;
242 QBStr activityId{ QString::fromLatin1(
"") };
243#if !defined(Q_CC_MSVC) || !defined(QT_WIN_SERVER_2016_COMPAT)
244 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
247 HMODULE uiautomationcore = GetModuleHandleW(L"UIAutomationCore.dll");
248 if (uiautomationcore != NULL) {
249 typedef HRESULT (WINAPI *EVENTFUNC)(IRawElementProviderSimple *, NotificationKind,
250 NotificationProcessing, BSTR, BSTR);
252 EVENTFUNC uiaRaiseNotificationEvent =
253 (EVENTFUNC)GetProcAddress(uiautomationcore,
"UiaRaiseNotificationEvent");
254 if (uiaRaiseNotificationEvent != NULL) {
255 uiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing,
256 message.bstr(), activityId.bstr());
264HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
266 HRESULT result = QComObject::QueryInterface(iid, iface);
268 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
269 QAccessibleInterface *accessible = accessibleInterface();
270 if (accessible && hwndForAccessible(accessible)) {
274 result = E_NOINTERFACE;
282HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
287 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
292HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
294 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
300 QAccessibleInterface *accessible = accessibleInterface();
302 return UIA_E_ELEMENTNOTAVAILABLE;
305 case UIA_WindowPatternId:
306 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
307 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
310 case UIA_TextPatternId:
311 case UIA_TextPattern2Id:
313 if (accessible->textInterface()) {
314 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
317 case UIA_ValuePatternId:
319 if (accessible->role() != QAccessible::StaticText)
320 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
322 case UIA_RangeValuePatternId:
324 if (accessible->valueInterface()) {
325 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
328 case UIA_TogglePatternId:
330 if (accessible->state().checkable)
331 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
333 case UIA_SelectionPatternId:
334 case UIA_SelectionPattern2Id:
336 if (accessible->selectionInterface()
337 || accessible->role() == QAccessible::List
338 || accessible->role() == QAccessible::PageTabList) {
339 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
342 case UIA_SelectionItemPatternId:
344 if ((accessible->parent() && accessible->parent()->selectionInterface())
345 || (accessible->role() == QAccessible::RadioButton)
346 || (accessible->role() == QAccessible::ListItem)
347 || (accessible->role() == QAccessible::PageTab)) {
348 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
351 case UIA_TablePatternId:
353 if (accessible->tableInterface()
354 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
355 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
358 case UIA_TableItemPatternId:
360 if (accessible->tableCellInterface()
361 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
362 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
365 case UIA_GridPatternId:
367 if (accessible->tableInterface()
368 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
369 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
372 case UIA_GridItemPatternId:
374 if (accessible->tableCellInterface()
375 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
376 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
379 case UIA_InvokePatternId:
381 if (accessible->actionInterface()) {
382 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
385 case UIA_ExpandCollapsePatternId:
387 if ((accessible->role() == QAccessible::MenuItem
388 && accessible->childCount() > 0
389 && accessible->child(0)->role() == QAccessible::PopupMenu)
390 || accessible->role() == QAccessible::ComboBox
391 || accessible->state().expandable) {
392 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
402void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
404 Q_ASSERT(accessible);
406 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
407 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
408 if (relationInterfaces.empty())
412 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
416 pRetVal->vt = VT_UNKNOWN;
417 pRetVal->punkVal = provider.Detach();
420void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
421 QAccessible::Relation relation, VARIANT *pRetVal)
423 Q_ASSERT(accessible);
425 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
426 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
427 if (relationInterfaces.empty())
430 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
431 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
432 if (ComPtr<IRawElementProviderSimple> provider =
433 providerForAccessible(relationInterfaces.at(i).first)) {
434 SafeArrayPutElement(elements, &i, provider.Get());
438 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
439 pRetVal->parray = elements;
442void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
444 Q_ASSERT(accessible);
446 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
447 if (!attributesIface)
451 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
452 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
454 ariaString += QStringLiteral(
";");
455 const QAccessible::Attribute key = attrKeys.at(i);
456 const QVariant value = attributesIface->attributeValue(key);
459 case QAccessible::Attribute::Custom:
462 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
463 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
464 for (
auto [name, val] : attrMap.asKeyValueRange()) {
465 if (name != *attrMap.keyBegin())
466 ariaString += QStringLiteral(
";");
467 ariaString += name + QStringLiteral(
"=") + val;
471 case QAccessible::Attribute::Level:
472 Q_ASSERT(value.canConvert<
int>());
473 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
475 case QAccessible::Attribute::PositionInSet:
476 Q_ASSERT(value.canConvert<
int>());
477 ariaString += QStringLiteral(
"posinset=") + QString::number(value.toInt());
479 case QAccessible::Attribute::SizeOfSet:
480 Q_ASSERT(value.canConvert<
int>());
481 ariaString += QStringLiteral(
"setsize=") + QString::number(value.toInt());
488 *pRetVal = QComVariant{ ariaString }.release();
491void QWindowsUiaMainProvider::setIntAttribute(QAccessibleInterface *accessible,
492 QAccessible::Attribute attribute,
495 Q_ASSERT(accessible);
497 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
498 if (!attributesIface)
501 const QVariant valueVariant = attributesIface->attributeValue(attribute);
502 if (!valueVariant.isValid())
505 Q_ASSERT(valueVariant.canConvert<
int>());
506 *pRetVal = QComVariant{
long(valueVariant.toInt()) }.release();
509void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
511 Q_ASSERT(accessible);
513 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
514 if (!attributesIface)
518 if (accessible->role() != QAccessible::Role::Heading)
521 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
522 if (!levelVariant.isValid())
525 Q_ASSERT(levelVariant.canConvert<
int>());
527 const int level = levelVariant.toInt();
528 if (level < 1 || level > 9)
531 const long styleId = styleIdForHeadingLevel(level);
532 *pRetVal = QComVariant{ styleId }.release();
535int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
538 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
540 static constexpr int styles[] = {
552 return styles[headingLevel - 1];
555HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
557 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
561 clearVariant(pRetVal);
563 QAccessibleInterface *accessible = accessibleInterface();
565 return UIA_E_ELEMENTNOTAVAILABLE;
567 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
570 case UIA_ProcessIdPropertyId:
572 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
574 case UIA_AccessKeyPropertyId:
576 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
578 case UIA_AriaRolePropertyId:
579 if (accessible->role() == QAccessible::Heading)
580 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
582 case UIA_AriaPropertiesPropertyId:
583 setAriaProperties(accessible, pRetVal);
585 case UIA_AutomationIdPropertyId:
587 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
589 case UIA_ClassNamePropertyId:
591 if (QObject *o = accessible->object()) {
592 QString className = QLatin1StringView(o->metaObject()->className());
593 *pRetVal = QComVariant{ className }.release();
596 case UIA_CulturePropertyId:
599 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
600 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
601 if (localeVariant.isValid()) {
602 Q_ASSERT(localeVariant.canConvert<QLocale>());
603 locale = localeVariant.toLocale();
606 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
607 *pRetVal = QComVariant{
long(lcid) }.release();
610 case UIA_LevelPropertyId:
614 if (accessible->role() != QAccessible::Role::Heading)
615 setIntAttribute(accessible, QAccessible::Attribute::Level, pRetVal);
617 case UIA_PositionInSetPropertyId:
618 setIntAttribute(accessible, QAccessible::Attribute::PositionInSet, pRetVal);
620 case UIA_SizeOfSetPropertyId:
621 setIntAttribute(accessible, QAccessible::Attribute::SizeOfSet, pRetVal);
623 case UIA_DescribedByPropertyId:
624 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
626 case UIA_FlowsFromPropertyId:
627 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
629 case UIA_FlowsToPropertyId:
630 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
632 case UIA_LabeledByPropertyId:
633 setLabelledBy(accessible, pRetVal);
635 case UIA_FrameworkIdPropertyId:
636 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
638 case UIA_ControlTypePropertyId:
639 if (topLevelWindow) {
641 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
644 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
647 case UIA_HelpTextPropertyId:
648 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
650 case UIA_HasKeyboardFocusPropertyId:
654 if (topLevelWindow) {
655 QAccessibleInterface *focusacc = accessible->focusChild();
657 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
661 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
663 case UIA_IsKeyboardFocusablePropertyId:
664 if (topLevelWindow) {
666 *pRetVal = QComVariant{
true }.release();
668 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
671 case UIA_IsOffscreenPropertyId:
672 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
674 case UIA_IsContentElementPropertyId:
675 *pRetVal = QComVariant{
true }.release();
677 case UIA_IsControlElementPropertyId:
678 *pRetVal = QComVariant{
true }.release();
680 case UIA_IsEnabledPropertyId:
681 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
683 case UIA_IsPasswordPropertyId:
684 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
685 && accessible->state().passwordEdit }
688 case UIA_IsPeripheralPropertyId:
690 if (QWindow *window = windowForAccessible(accessible)) {
691 const Qt::WindowType wt = window->type();
692 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
696 case UIA_IsDialogPropertyId:
697 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
698 || accessible->role() == QAccessible::AlertMessage }
701 case UIA_FullDescriptionPropertyId:
702 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
704 case UIA_LocalizedControlTypePropertyId:
707 if (accessible->role() == QAccessible::BlockQuote)
708 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
710 case UIA_NamePropertyId: {
711 QString name = accessible->text(QAccessible::Name);
712 if (name.isEmpty() && topLevelWindow)
713 name = QCoreApplication::applicationName();
714 *pRetVal = QComVariant{ name }.release();
717 case UIA_OrientationPropertyId: {
718 OrientationType orientationType = OrientationType_None;
719 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
720 const QVariant orientationVariant =
721 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
722 if (orientationVariant.isValid()) {
723 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
724 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
725 orientationType = orientation == Qt::Horizontal ? OrientationType_Horizontal
726 : OrientationType_Vertical;
729 *pRetVal = QComVariant{
long(orientationType) }.release();
732 case UIA_StyleIdAttributeId:
733 setStyle(accessible, pRetVal);
741HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
743 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
750 if (QAccessibleInterface *accessible = accessibleInterface()) {
751 if (HWND hwnd = hwndForAccessible(accessible)) {
752 return UiaHostProviderFromHwnd(hwnd, pRetVal);
759HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
761 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
767 QAccessibleInterface *accessible = accessibleInterface();
769 return UIA_E_ELEMENTNOTAVAILABLE;
771 QAccessibleInterface *targetacc =
nullptr;
773 if (direction == NavigateDirection_Parent) {
774 if (QAccessibleInterface *parent = accessible->parent()) {
776 if (parent->isValid() && parent->role() != QAccessible::Application) {
781 QAccessibleInterface *parent =
nullptr;
785 case NavigateDirection_FirstChild:
790 case NavigateDirection_LastChild:
792 index = accessible->childCount() - 1;
795 case NavigateDirection_NextSibling:
796 if ((parent = accessible->parent()))
797 index = parent->indexOfChild(accessible) + 1;
800 case NavigateDirection_PreviousSibling:
801 if ((parent = accessible->parent()))
802 index = parent->indexOfChild(accessible) - 1;
810 if (parent && parent->isValid()) {
811 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
812 if (QAccessibleInterface *child = parent->child(index)) {
813 if (child->isValid() && !child->state().invisible) {
823 *pRetVal = providerForAccessible(targetacc).Detach();
828HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
830 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
836 QAccessibleInterface *accessible = accessibleInterface();
838 return UIA_E_ELEMENTNOTAVAILABLE;
842 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
844 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
845 for (LONG i = 0; i < 2; ++i)
846 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
852HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
854 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
859 QAccessibleInterface *accessible = accessibleInterface();
861 return UIA_E_ELEMENTNOTAVAILABLE;
863 QWindow *window = windowForAccessible(accessible);
865 return UIA_E_ELEMENTNOTAVAILABLE;
867 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
871HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
873 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
883HRESULT QWindowsUiaMainProvider::SetFocus()
885 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
887 QAccessibleInterface *accessible = accessibleInterface();
889 return UIA_E_ELEMENTNOTAVAILABLE;
891 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
892 if (!actionInterface)
893 return UIA_E_ELEMENTNOTAVAILABLE;
895 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
899HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
901 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
909 if (QAccessibleInterface *accessible = accessibleInterface()) {
910 if (QWindow *window = windowForAccessible(accessible)) {
911 if (QAccessibleInterface *rootacc = window->accessibleRoot())
912 *pRetVal = providerForAccessible(rootacc).Detach();
919HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
921 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
928 QAccessibleInterface *accessible = accessibleInterface();
930 return UIA_E_ELEMENTNOTAVAILABLE;
932 QWindow *window = windowForAccessible(accessible);
934 return UIA_E_ELEMENTNOTAVAILABLE;
937 UiaPoint uiaPoint = {x, y};
939 nativeUiaPointToPoint(uiaPoint, window, &point);
941 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
944 QAccessibleInterface *acc = targetacc;
949 if (targetacc->textInterface())
break;
950 acc = acc->childAt(point.x(), point.y());
952 *pRetVal = providerForAccessible(targetacc).Detach();
958HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
960 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
966 if (QAccessibleInterface *accessible = accessibleInterface()) {
967 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
968 *pRetVal = providerForAccessible(focusacc).Detach();