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 if (
auto provider = providerForAccessible(accessible)) {
88 long toggleState = ToggleState_Off;
89 if (accessible->state().checked)
90 toggleState = accessible->state().checkStateMixed ? ToggleState_Indeterminate : ToggleState_On;
93 QComVariant newVal{toggleState};
94 UiaRaiseAutomationPropertyChangedEvent(
95 provider.Get(), UIA_ToggleToggleStatePropertyId, oldVal.get(), newVal.get());
99 if (event->changedStates().active) {
100 if (accessible->role() == QAccessible::Window) {
102 if (
auto provider = providerForAccessible(accessible)) {
103 if (accessible->state().active) {
104 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowOpenedEventId);
105 if (QAccessibleInterface *focused = accessible->focusChild()) {
106 if (
auto focusedProvider = providerForAccessible(focused)) {
107 UiaRaiseAutomationEvent(focusedProvider.Get(),
108 UIA_AutomationFocusChangedEventId);
112 UiaRaiseAutomationEvent(provider.Get(), UIA_Window_WindowClosedEventId);
120void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event)
122 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
123 if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) {
124 QAccessibleInterface *listacc = accessible->child(0);
125 if (listacc && listacc->role() == QAccessible::List) {
126 int count = listacc->childCount();
127 for (
int i = 0; i < count; ++i) {
128 QAccessibleInterface *item = listacc->child(i);
129 if (item && item->isValid() && item->text(QAccessible::Name) == event->value()) {
130 if (!item->state().selected) {
131 if (QAccessibleActionInterface *actionInterface = item->actionInterface())
132 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
139 if (event->value().typeId() == QMetaType::QString) {
140 if (
auto provider = providerForAccessible(accessible)) {
142 const QComVariant oldVal;
143 const QComVariant newVal{ event->value().toString() };
144 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ValueValuePropertyId,
145 oldVal.get(), newVal.get());
147 }
else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
148 if (
auto provider = providerForAccessible(accessible)) {
150 const QComVariant oldVal;
151 const QComVariant newVal{ valueInterface->currentValue().toDouble() };
152 UiaRaiseAutomationPropertyChangedEvent(
153 provider.Get(), UIA_RangeValueValuePropertyId, oldVal.get(), newVal.get());
159void QWindowsUiaMainProvider::notifyNameChange(QAccessibleEvent *event)
161 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
164 if (accessible->role() == QAccessible::ComboBox || accessible->state().focused) {
165 if (
auto provider = providerForAccessible(accessible)) {
167 QComVariant newVal{ accessible->text(QAccessible::Name) };
168 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_NamePropertyId,
169 oldVal.get(), newVal.get());
175void QWindowsUiaMainProvider::notifyRoleChange(QAccessibleEvent *event)
177 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
178 if (
auto provider = providerForAccessible(accessible)) {
180 QComVariant newVal{ roleToControlTypeId(accessible->role()) };
181 UiaRaiseAutomationPropertyChangedEvent(provider.Get(), UIA_ControlTypePropertyId,
182 oldVal.get(), newVal.get());
187void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event)
189 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
190 if (
auto provider = providerForAccessible(accessible))
191 UiaRaiseAutomationEvent(provider.Get(), UIA_SelectionItem_ElementSelectedEventId);
196void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event)
198 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
199 if (accessible->textInterface()) {
200 if (
auto provider = providerForAccessible(accessible)) {
201 if (event->type() == QAccessible::TextSelectionChanged) {
202 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextSelectionChangedEventId);
203 }
else if (event->type() == QAccessible::TextCaretMoved) {
204 if (!accessible->state().readOnly) {
205 UiaRaiseAutomationEvent(provider.Get(),
206 UIA_Text_TextSelectionChangedEventId);
209 UiaRaiseAutomationEvent(provider.Get(), UIA_Text_TextChangedEventId);
216void QWindowsUiaMainProvider::raiseNotification(QAccessibleAnnouncementEvent *event)
218 if (QAccessibleInterface *accessible = event->accessibleInterface()) {
219 if (
auto provider = providerForAccessible(accessible)) {
220 QBStr message{ event->message() };
221 QAccessible::AnnouncementPoliteness prio = event->politeness();
222 NotificationProcessing processing = (prio == QAccessible::AnnouncementPoliteness::Assertive)
223 ? NotificationProcessing_ImportantAll
224 : NotificationProcessing_All;
225 QBStr activityId{ QString::fromLatin1(
"") };
226#if !defined(Q_CC_MSVC) || !defined(QT_WIN_SERVER_2016_COMPAT)
227 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
230 HMODULE uiautomationcore = GetModuleHandleW(L"UIAutomationCore.dll");
231 if (uiautomationcore != NULL) {
232 typedef HRESULT (WINAPI *EVENTFUNC)(IRawElementProviderSimple *, NotificationKind,
233 NotificationProcessing, BSTR, BSTR);
235 EVENTFUNC uiaRaiseNotificationEvent =
236 (EVENTFUNC)GetProcAddress(uiautomationcore,
"UiaRaiseNotificationEvent");
237 if (uiaRaiseNotificationEvent != NULL) {
238 uiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing,
239 message.bstr(), activityId.bstr());
247HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
249 HRESULT result = QComObject::QueryInterface(iid, iface);
251 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
252 QAccessibleInterface *accessible = accessibleInterface();
253 if (accessible && hwndForAccessible(accessible)) {
257 result = E_NOINTERFACE;
265HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
270 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
275HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
277 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
283 QAccessibleInterface *accessible = accessibleInterface();
285 return UIA_E_ELEMENTNOTAVAILABLE;
288 case UIA_WindowPatternId:
289 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
290 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
293 case UIA_TextPatternId:
294 case UIA_TextPattern2Id:
296 if (accessible->textInterface()) {
297 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
300 case UIA_ValuePatternId:
302 if (accessible->role() != QAccessible::StaticText)
303 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
305 case UIA_RangeValuePatternId:
307 if (accessible->valueInterface()) {
308 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
311 case UIA_TogglePatternId:
313 if (accessible->state().checkable)
314 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
316 case UIA_SelectionPatternId:
317 case UIA_SelectionPattern2Id:
319 if (accessible->selectionInterface()
320 || accessible->role() == QAccessible::List
321 || accessible->role() == QAccessible::PageTabList) {
322 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
325 case UIA_SelectionItemPatternId:
327 if ((accessible->parent() && accessible->parent()->selectionInterface())
328 || (accessible->role() == QAccessible::RadioButton)
329 || (accessible->role() == QAccessible::ListItem)
330 || (accessible->role() == QAccessible::PageTab)) {
331 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
334 case UIA_TablePatternId:
336 if (accessible->tableInterface()
337 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
338 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
341 case UIA_TableItemPatternId:
343 if (accessible->tableCellInterface()
344 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
345 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
348 case UIA_GridPatternId:
350 if (accessible->tableInterface()
351 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
352 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
355 case UIA_GridItemPatternId:
357 if (accessible->tableCellInterface()
358 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
359 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
362 case UIA_InvokePatternId:
364 if (accessible->actionInterface()) {
365 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
368 case UIA_ExpandCollapsePatternId:
370 if ((accessible->role() == QAccessible::MenuItem
371 && accessible->childCount() > 0
372 && accessible->child(0)->role() == QAccessible::PopupMenu)
373 || accessible->role() == QAccessible::ComboBox
374 || (accessible->role() == QAccessible::TreeItem && accessible->state().expandable)) {
375 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
385void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
387 Q_ASSERT(accessible);
389 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
390 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
391 if (relationInterfaces.empty())
395 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
399 pRetVal->vt = VT_UNKNOWN;
400 pRetVal->punkVal = provider.Detach();
403void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
404 QAccessible::Relation relation, VARIANT *pRetVal)
406 Q_ASSERT(accessible);
408 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
409 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
410 if (relationInterfaces.empty())
413 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
414 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
415 if (ComPtr<IRawElementProviderSimple> provider =
416 providerForAccessible(relationInterfaces.at(i).first)) {
417 SafeArrayPutElement(elements, &i, provider.Get());
421 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
422 pRetVal->parray = elements;
425void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
427 Q_ASSERT(accessible);
429 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
430 if (!attributesIface)
434 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
435 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
437 ariaString += QStringLiteral(
";");
438 const QAccessible::Attribute key = attrKeys.at(i);
439 const QVariant value = attributesIface->attributeValue(key);
442 case QAccessible::Attribute::Custom:
445 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
446 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
447 for (
auto [name, val] : attrMap.asKeyValueRange()) {
448 if (name != *attrMap.keyBegin())
449 ariaString += QStringLiteral(
";");
450 ariaString += name + QStringLiteral(
"=") + val;
454 case QAccessible::Attribute::Level:
455 Q_ASSERT(value.canConvert<
int>());
456 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
463 *pRetVal = QComVariant{ ariaString }.release();
466void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
468 Q_ASSERT(accessible);
470 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
471 if (!attributesIface)
475 if (accessible->role() != QAccessible::Role::Heading)
478 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
479 if (!levelVariant.isValid())
482 Q_ASSERT(levelVariant.canConvert<
int>());
484 const int level = levelVariant.toInt();
485 if (level < 1 || level > 9)
488 const long styleId = styleIdForHeadingLevel(level);
489 *pRetVal = QComVariant{ styleId }.release();
492int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
495 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
497 static constexpr int styles[] = {
509 return styles[headingLevel - 1];
512HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
514 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
518 clearVariant(pRetVal);
520 QAccessibleInterface *accessible = accessibleInterface();
522 return UIA_E_ELEMENTNOTAVAILABLE;
524 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
527 case UIA_ProcessIdPropertyId:
529 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
531 case UIA_AccessKeyPropertyId:
533 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
535 case UIA_AriaRolePropertyId:
536 if (accessible->role() == QAccessible::Heading)
537 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
539 case UIA_AriaPropertiesPropertyId:
540 setAriaProperties(accessible, pRetVal);
542 case UIA_AutomationIdPropertyId:
544 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
546 case UIA_ClassNamePropertyId:
548 if (QObject *o = accessible->object()) {
549 QString className = QLatin1StringView(o->metaObject()->className());
550 *pRetVal = QComVariant{ className }.release();
553 case UIA_CulturePropertyId:
556 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
557 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
558 if (localeVariant.isValid()) {
559 Q_ASSERT(localeVariant.canConvert<QLocale>());
560 locale = localeVariant.toLocale();
563 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
564 *pRetVal = QComVariant{
long(lcid) }.release();
567 case UIA_DescribedByPropertyId:
568 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
570 case UIA_FlowsFromPropertyId:
571 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
573 case UIA_FlowsToPropertyId:
574 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
576 case UIA_LabeledByPropertyId:
577 setLabelledBy(accessible, pRetVal);
579 case UIA_FrameworkIdPropertyId:
580 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
582 case UIA_ControlTypePropertyId:
583 if (topLevelWindow) {
585 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
588 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
591 case UIA_HelpTextPropertyId:
592 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
594 case UIA_HasKeyboardFocusPropertyId:
595 if (topLevelWindow) {
597 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
599 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
602 case UIA_IsKeyboardFocusablePropertyId:
603 if (topLevelWindow) {
605 *pRetVal = QComVariant{
true }.release();
607 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
610 case UIA_IsOffscreenPropertyId:
611 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
613 case UIA_IsContentElementPropertyId:
614 *pRetVal = QComVariant{
true }.release();
616 case UIA_IsControlElementPropertyId:
617 *pRetVal = QComVariant{
true }.release();
619 case UIA_IsEnabledPropertyId:
620 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
622 case UIA_IsPasswordPropertyId:
623 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
624 && accessible->state().passwordEdit }
627 case UIA_IsPeripheralPropertyId:
629 if (QWindow *window = windowForAccessible(accessible)) {
630 const Qt::WindowType wt = window->type();
631 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
635 case UIA_IsDialogPropertyId:
636 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
637 || accessible->role() == QAccessible::AlertMessage }
640 case UIA_FullDescriptionPropertyId:
641 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
643 case UIA_LocalizedControlTypePropertyId:
646 if (accessible->role() == QAccessible::BlockQuote)
647 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
649 case UIA_NamePropertyId: {
650 QString name = accessible->text(QAccessible::Name);
651 if (name.isEmpty() && topLevelWindow)
652 name = QCoreApplication::applicationName();
653 *pRetVal = QComVariant{ name }.release();
656 case UIA_StyleIdAttributeId:
657 setStyle(accessible, pRetVal);
665HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
667 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
674 if (QAccessibleInterface *accessible = accessibleInterface()) {
675 if (HWND hwnd = hwndForAccessible(accessible)) {
676 return UiaHostProviderFromHwnd(hwnd, pRetVal);
683HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
685 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
691 QAccessibleInterface *accessible = accessibleInterface();
693 return UIA_E_ELEMENTNOTAVAILABLE;
695 QAccessibleInterface *targetacc =
nullptr;
697 if (direction == NavigateDirection_Parent) {
698 if (QAccessibleInterface *parent = accessible->parent()) {
700 if (parent->isValid() && parent->role() != QAccessible::Application) {
705 QAccessibleInterface *parent =
nullptr;
709 case NavigateDirection_FirstChild:
714 case NavigateDirection_LastChild:
716 index = accessible->childCount() - 1;
719 case NavigateDirection_NextSibling:
720 if ((parent = accessible->parent()))
721 index = parent->indexOfChild(accessible) + 1;
724 case NavigateDirection_PreviousSibling:
725 if ((parent = accessible->parent()))
726 index = parent->indexOfChild(accessible) - 1;
734 if (parent && parent->isValid()) {
735 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
736 if (QAccessibleInterface *child = parent->child(index)) {
737 if (child->isValid() && !child->state().invisible) {
747 *pRetVal = providerForAccessible(targetacc).Detach();
752HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
754 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
760 QAccessibleInterface *accessible = accessibleInterface();
762 return UIA_E_ELEMENTNOTAVAILABLE;
766 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
768 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
769 for (LONG i = 0; i < 2; ++i)
770 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
776HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
778 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
783 QAccessibleInterface *accessible = accessibleInterface();
785 return UIA_E_ELEMENTNOTAVAILABLE;
787 QWindow *window = windowForAccessible(accessible);
789 return UIA_E_ELEMENTNOTAVAILABLE;
791 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
795HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
797 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
807HRESULT QWindowsUiaMainProvider::SetFocus()
809 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
811 QAccessibleInterface *accessible = accessibleInterface();
813 return UIA_E_ELEMENTNOTAVAILABLE;
815 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
816 if (!actionInterface)
817 return UIA_E_ELEMENTNOTAVAILABLE;
819 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
823HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
825 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
833 if (QAccessibleInterface *accessible = accessibleInterface()) {
834 if (QWindow *window = windowForAccessible(accessible)) {
835 if (QAccessibleInterface *rootacc = window->accessibleRoot())
836 *pRetVal = providerForAccessible(rootacc).Detach();
843HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
845 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
852 QAccessibleInterface *accessible = accessibleInterface();
854 return UIA_E_ELEMENTNOTAVAILABLE;
856 QWindow *window = windowForAccessible(accessible);
858 return UIA_E_ELEMENTNOTAVAILABLE;
861 UiaPoint uiaPoint = {x, y};
863 nativeUiaPointToPoint(uiaPoint, window, &point);
865 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
868 QAccessibleInterface *acc = targetacc;
873 if (targetacc->textInterface())
break;
874 acc = acc->childAt(point.x(), point.y());
876 *pRetVal = providerForAccessible(targetacc).Detach();
882HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
884 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
890 if (QAccessibleInterface *accessible = accessibleInterface()) {
891 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
892 *pRetVal = providerForAccessible(focusacc).Detach();