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 UiaRaiseNotificationEvent(provider.Get(), NotificationKind_Other, processing, message.bstr(),
249HRESULT STDMETHODCALLTYPE QWindowsUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface)
251 HRESULT result = QComObject::QueryInterface(iid, iface);
253 if (SUCCEEDED(result) && iid == __uuidof(IRawElementProviderFragmentRoot)) {
254 QAccessibleInterface *accessible = accessibleInterface();
255 if (accessible && hwndForAccessible(accessible)) {
259 result = E_NOINTERFACE;
267HRESULT QWindowsUiaMainProvider::get_ProviderOptions(ProviderOptions *pRetVal)
272 *pRetVal =
static_cast<ProviderOptions>(ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading);
277HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknown **pRetVal)
279 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idPattern;
285 QAccessibleInterface *accessible = accessibleInterface();
287 return UIA_E_ELEMENTNOTAVAILABLE;
290 case UIA_WindowPatternId:
291 if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) {
292 *pRetVal = makeComObject<QWindowsUiaWindowProvider>(id()).Detach();
295 case UIA_TextPatternId:
296 case UIA_TextPattern2Id:
298 if (accessible->textInterface()) {
299 *pRetVal = makeComObject<QWindowsUiaTextProvider>(id()).Detach();
302 case UIA_ValuePatternId:
304 if (accessible->role() != QAccessible::StaticText)
305 *pRetVal = makeComObject<QWindowsUiaValueProvider>(id()).Detach();
307 case UIA_RangeValuePatternId:
309 if (accessible->valueInterface()) {
310 *pRetVal = makeComObject<QWindowsUiaRangeValueProvider>(id()).Detach();
313 case UIA_TogglePatternId:
315 if (accessible->state().checkable)
316 *pRetVal = makeComObject<QWindowsUiaToggleProvider>(id()).Detach();
318 case UIA_SelectionPatternId:
319 case UIA_SelectionPattern2Id:
321 if (accessible->selectionInterface()
322 || accessible->role() == QAccessible::List
323 || accessible->role() == QAccessible::PageTabList) {
324 *pRetVal = makeComObject<QWindowsUiaSelectionProvider>(id()).Detach();
327 case UIA_SelectionItemPatternId:
329 if ((accessible->parent() && accessible->parent()->selectionInterface())
330 || (accessible->role() == QAccessible::RadioButton)
331 || (accessible->role() == QAccessible::ListItem)
332 || (accessible->role() == QAccessible::PageTab)) {
333 *pRetVal = makeComObject<QWindowsUiaSelectionItemProvider>(id()).Detach();
336 case UIA_TablePatternId:
338 if (accessible->tableInterface()
339 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
340 *pRetVal = makeComObject<QWindowsUiaTableProvider>(id()).Detach();
343 case UIA_TableItemPatternId:
345 if (accessible->tableCellInterface()
346 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
347 *pRetVal = makeComObject<QWindowsUiaTableItemProvider>(id()).Detach();
350 case UIA_GridPatternId:
352 if (accessible->tableInterface()
353 && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) {
354 *pRetVal = makeComObject<QWindowsUiaGridProvider>(id()).Detach();
357 case UIA_GridItemPatternId:
359 if (accessible->tableCellInterface()
360 && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) {
361 *pRetVal = makeComObject<QWindowsUiaGridItemProvider>(id()).Detach();
364 case UIA_InvokePatternId:
366 if (accessible->actionInterface()) {
367 *pRetVal = makeComObject<QWindowsUiaInvokeProvider>(id()).Detach();
370 case UIA_ExpandCollapsePatternId:
372 if ((accessible->role() == QAccessible::MenuItem
373 && accessible->childCount() > 0
374 && accessible->child(0)->role() == QAccessible::PopupMenu)
375 || accessible->role() == QAccessible::ComboBox
376 || accessible->state().expandable) {
377 *pRetVal = makeComObject<QWindowsUiaExpandCollapseProvider>(id()).Detach();
387void QWindowsUiaMainProvider::setLabelledBy(QAccessibleInterface *accessible, VARIANT *pRetVal)
389 Q_ASSERT(accessible);
391 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
392 const QList<RelationPair> relationInterfaces = accessible->relations(QAccessible::Label);
393 if (relationInterfaces.empty())
397 ComPtr<IRawElementProviderSimple> provider = providerForAccessible(relationInterfaces.first().first);
401 pRetVal->vt = VT_UNKNOWN;
402 pRetVal->punkVal = provider.Detach();
405void QWindowsUiaMainProvider::fillVariantArrayForRelation(QAccessibleInterface* accessible,
406 QAccessible::Relation relation, VARIANT *pRetVal)
408 Q_ASSERT(accessible);
410 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
411 const QList<RelationPair> relationInterfaces = accessible->relations(relation);
412 if (relationInterfaces.empty())
415 SAFEARRAY *elements = SafeArrayCreateVector(VT_UNKNOWN, 0, relationInterfaces.size());
416 for (LONG i = 0; i < relationInterfaces.size(); ++i) {
417 if (ComPtr<IRawElementProviderSimple> provider =
418 providerForAccessible(relationInterfaces.at(i).first)) {
419 SafeArrayPutElement(elements, &i, provider.Get());
423 pRetVal->vt = VT_UNKNOWN | VT_ARRAY;
424 pRetVal->parray = elements;
427void QWindowsUiaMainProvider::setAriaProperties(QAccessibleInterface *accessible, VARIANT *pRetVal)
429 Q_ASSERT(accessible);
431 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
432 if (!attributesIface)
436 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
437 for (qsizetype i = 0; i < attrKeys.size(); ++i) {
439 ariaString += QStringLiteral(
";");
440 const QAccessible::Attribute key = attrKeys.at(i);
441 const QVariant value = attributesIface->attributeValue(key);
444 case QAccessible::Attribute::Custom:
447 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
448 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
449 for (
auto [name, val] : attrMap.asKeyValueRange()) {
450 if (name != *attrMap.keyBegin())
451 ariaString += QStringLiteral(
";");
452 ariaString += name + QStringLiteral(
"=") + val;
456 case QAccessible::Attribute::Level:
457 Q_ASSERT(value.canConvert<
int>());
458 ariaString += QStringLiteral(
"level=") + QString::number(value.toInt());
460 case QAccessible::Attribute::PositionInSet:
461 Q_ASSERT(value.canConvert<
int>());
462 ariaString += QStringLiteral(
"posinset=") + QString::number(value.toInt());
464 case QAccessible::Attribute::SizeOfSet:
465 Q_ASSERT(value.canConvert<
int>());
466 ariaString += QStringLiteral(
"setsize=") + QString::number(value.toInt());
473 *pRetVal = QComVariant{ ariaString }.release();
476void QWindowsUiaMainProvider::setIntAttribute(QAccessibleInterface *accessible,
477 QAccessible::Attribute attribute,
480 Q_ASSERT(accessible);
482 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
483 if (!attributesIface)
486 const QVariant valueVariant = attributesIface->attributeValue(attribute);
487 if (!valueVariant.isValid())
490 Q_ASSERT(valueVariant.canConvert<
int>());
491 *pRetVal = QComVariant{
long(valueVariant.toInt()) }.release();
494void QWindowsUiaMainProvider::setHeadingLevel(QAccessibleInterface *accessible, VARIANT *pRetVal)
496 Q_ASSERT(accessible);
498 if (accessible->role() != QAccessible::Heading)
501 static constexpr long levels[] = { HeadingLevel1, HeadingLevel2, HeadingLevel3,
502 HeadingLevel4, HeadingLevel5, HeadingLevel6,
503 HeadingLevel7, HeadingLevel8, HeadingLevel9 };
505 long headingLevel = HeadingLevel_None;
506 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
507 const QVariant levelVariant =
508 attributesIface->attributeValue(QAccessible::Attribute::Level);
509 if (levelVariant.isValid()) {
510 Q_ASSERT(levelVariant.canConvert<
int>());
511 const int level = levelVariant.toInt();
512 if (level <= 9 && level > 0) {
513 headingLevel = levels[level - 1];
517 *pRetVal = QComVariant{ headingLevel }.release();
520void QWindowsUiaMainProvider::setStyle(QAccessibleInterface *accessible, VARIANT *pRetVal)
522 Q_ASSERT(accessible);
524 QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface();
525 if (!attributesIface)
529 if (accessible->role() != QAccessible::Role::Heading)
532 const QVariant levelVariant = attributesIface->attributeValue(QAccessible::Attribute::Level);
533 if (!levelVariant.isValid())
536 Q_ASSERT(levelVariant.canConvert<
int>());
538 const int level = levelVariant.toInt();
539 if (level < 1 || level > 9)
542 const long styleId = styleIdForHeadingLevel(level);
543 *pRetVal = QComVariant{ styleId }.release();
546int QWindowsUiaMainProvider::styleIdForHeadingLevel(
int headingLevel)
549 Q_ASSERT(headingLevel > 0 && headingLevel <= 9);
551 static constexpr int styles[] = {
563 return styles[headingLevel - 1];
566HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pRetVal)
568 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << idProp;
572 clearVariant(pRetVal);
574 QAccessibleInterface *accessible = accessibleInterface();
576 return UIA_E_ELEMENTNOTAVAILABLE;
578 bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application);
581 case UIA_ProcessIdPropertyId:
583 *pRetVal = QComVariant{
static_cast<
long>(GetCurrentProcessId()) }.release();
585 case UIA_AccessKeyPropertyId:
587 *pRetVal = QComVariant{ accessible->text(QAccessible::Accelerator) }.release();
589 case UIA_AriaRolePropertyId:
590 if (accessible->role() == QAccessible::Heading)
591 *pRetVal = QComVariant{ QStringLiteral(
"heading") }.release();
593 case UIA_AriaPropertiesPropertyId:
594 setAriaProperties(accessible, pRetVal);
596 case UIA_AutomationIdPropertyId:
598 *pRetVal = QComVariant{ QAccessibleBridgeUtils::accessibleId(accessible) }.release();
600 case UIA_ClassNamePropertyId:
602 if (QObject *o = accessible->object()) {
603 QString className = QLatin1StringView(o->metaObject()->className());
604 *pRetVal = QComVariant{ className }.release();
607 case UIA_CulturePropertyId:
610 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
611 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
612 if (localeVariant.isValid()) {
613 Q_ASSERT(localeVariant.canConvert<QLocale>());
614 locale = localeVariant.toLocale();
617 LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
618 *pRetVal = QComVariant{
long(lcid) }.release();
621 case UIA_LevelPropertyId:
625 if (accessible->role() != QAccessible::Role::Heading)
626 setIntAttribute(accessible, QAccessible::Attribute::Level, pRetVal);
628 case UIA_PositionInSetPropertyId:
629 setIntAttribute(accessible, QAccessible::Attribute::PositionInSet, pRetVal);
631 case UIA_SizeOfSetPropertyId:
632 setIntAttribute(accessible, QAccessible::Attribute::SizeOfSet, pRetVal);
634 case UIA_DescribedByPropertyId:
635 fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
637 case UIA_FlowsFromPropertyId:
638 fillVariantArrayForRelation(accessible, QAccessible::FlowsTo, pRetVal);
640 case UIA_FlowsToPropertyId:
641 fillVariantArrayForRelation(accessible, QAccessible::FlowsFrom, pRetVal);
643 case UIA_LabeledByPropertyId:
644 setLabelledBy(accessible, pRetVal);
646 case UIA_FrameworkIdPropertyId:
647 *pRetVal = QComVariant{ QStringLiteral(
"Qt") }.release();
649 case UIA_ControlTypePropertyId:
650 if (topLevelWindow) {
652 *pRetVal = QComVariant{ UIA_WindowControlTypeId }.release();
655 *pRetVal = QComVariant{ roleToControlTypeId(accessible->role()) }.release();
658 case UIA_HelpTextPropertyId:
659 *pRetVal = QComVariant{ accessible->text(QAccessible::Help) }.release();
661 case UIA_HasKeyboardFocusPropertyId:
665 if (topLevelWindow) {
666 QAccessibleInterface *focusacc = accessible->focusChild();
668 *pRetVal = QComVariant{ accessible->state().active ?
true :
false }.release();
672 *pRetVal = QComVariant{ accessible->state().focused ?
true :
false }.release();
674 case UIA_IsKeyboardFocusablePropertyId:
675 if (topLevelWindow) {
677 *pRetVal = QComVariant{
true }.release();
679 *pRetVal = QComVariant{ accessible->state().focusable ?
true :
false }.release();
682 case UIA_IsOffscreenPropertyId:
683 *pRetVal = QComVariant{ accessible->state().offscreen ?
true :
false }.release();
685 case UIA_IsContentElementPropertyId:
686 *pRetVal = QComVariant{
true }.release();
688 case UIA_IsControlElementPropertyId:
689 *pRetVal = QComVariant{
true }.release();
691 case UIA_IsEnabledPropertyId:
692 *pRetVal = QComVariant{ !accessible->state().disabled }.release();
694 case UIA_IsPasswordPropertyId:
695 *pRetVal = QComVariant{ accessible->role() == QAccessible::EditableText
696 && accessible->state().passwordEdit }
699 case UIA_IsPeripheralPropertyId:
701 if (QWindow *window = windowForAccessible(accessible)) {
702 const Qt::WindowType wt = window->type();
703 *pRetVal = QComVariant{ wt == Qt::Popup || wt == Qt::ToolTip || wt == Qt::SplashScreen }
707 case UIA_HeadingLevelPropertyId:
708 setHeadingLevel(accessible, pRetVal);
710 case UIA_IsDialogPropertyId:
711 *pRetVal = QComVariant{ accessible->role() == QAccessible::Dialog
712 || accessible->role() == QAccessible::AlertMessage }
715 case UIA_FullDescriptionPropertyId:
716 *pRetVal = QComVariant{ accessible->text(QAccessible::Description) }.release();
718 case UIA_LocalizedControlTypePropertyId:
721 if (accessible->role() == QAccessible::BlockQuote)
722 *pRetVal = QComVariant{ tr(
"blockquote") }.release();
724 case UIA_NamePropertyId: {
725 QString name = accessible->text(QAccessible::Name);
726 if (name.isEmpty() && topLevelWindow)
727 name = QCoreApplication::applicationName();
728 *pRetVal = QComVariant{ name }.release();
731 case UIA_OrientationPropertyId: {
732 OrientationType orientationType = OrientationType_None;
733 if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
734 const QVariant orientationVariant =
735 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
736 if (orientationVariant.isValid()) {
737 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
738 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
739 orientationType = orientation == Qt::Horizontal ? OrientationType_Horizontal
740 : OrientationType_Vertical;
743 *pRetVal = QComVariant{
long(orientationType) }.release();
746 case UIA_StyleIdAttributeId:
747 setStyle(accessible, pRetVal);
755HRESULT QWindowsUiaMainProvider::get_HostRawElementProvider(IRawElementProviderSimple **pRetVal)
757 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
764 if (QAccessibleInterface *accessible = accessibleInterface()) {
765 if (HWND hwnd = hwndForAccessible(accessible)) {
766 return UiaHostProviderFromHwnd(hwnd, pRetVal);
773HRESULT QWindowsUiaMainProvider::Navigate(NavigateDirection direction, IRawElementProviderFragment **pRetVal)
775 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << direction <<
" this: " <<
this;
781 QAccessibleInterface *accessible = accessibleInterface();
783 return UIA_E_ELEMENTNOTAVAILABLE;
785 QAccessibleInterface *targetacc =
nullptr;
787 if (direction == NavigateDirection_Parent) {
788 if (QAccessibleInterface *parent = accessible->parent()) {
790 if (parent->isValid() && parent->role() != QAccessible::Application) {
795 QAccessibleInterface *parent =
nullptr;
799 case NavigateDirection_FirstChild:
804 case NavigateDirection_LastChild:
806 index = accessible->childCount() - 1;
809 case NavigateDirection_NextSibling:
810 if ((parent = accessible->parent()))
811 index = parent->indexOfChild(accessible) + 1;
814 case NavigateDirection_PreviousSibling:
815 if ((parent = accessible->parent()))
816 index = parent->indexOfChild(accessible) - 1;
824 if (parent && parent->isValid()) {
825 for (
int count = parent->childCount(); index >= 0 && index < count; index += incr) {
826 if (QAccessibleInterface *child = parent->child(index)) {
827 if (child->isValid() && !child->state().invisible) {
837 *pRetVal = providerForAccessible(targetacc).Detach();
842HRESULT QWindowsUiaMainProvider::GetRuntimeId(SAFEARRAY **pRetVal)
844 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
850 QAccessibleInterface *accessible = accessibleInterface();
852 return UIA_E_ELEMENTNOTAVAILABLE;
856 int rtId[] = { UiaAppendRuntimeId,
int(id()) };
858 if ((*pRetVal = SafeArrayCreateVector(VT_I4, 0, 2))) {
859 for (LONG i = 0; i < 2; ++i)
860 SafeArrayPutElement(*pRetVal, &i, &rtId[i]);
866HRESULT QWindowsUiaMainProvider::get_BoundingRectangle(UiaRect *pRetVal)
868 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
873 QAccessibleInterface *accessible = accessibleInterface();
875 return UIA_E_ELEMENTNOTAVAILABLE;
877 QWindow *window = windowForAccessible(accessible);
879 return UIA_E_ELEMENTNOTAVAILABLE;
881 rectToNativeUiaRect(accessible->rect(), window, pRetVal);
885HRESULT QWindowsUiaMainProvider::GetEmbeddedFragmentRoots(SAFEARRAY **pRetVal)
887 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
897HRESULT QWindowsUiaMainProvider::SetFocus()
899 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
901 QAccessibleInterface *accessible = accessibleInterface();
903 return UIA_E_ELEMENTNOTAVAILABLE;
905 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
906 if (!actionInterface)
907 return UIA_E_ELEMENTNOTAVAILABLE;
909 actionInterface->doAction(QAccessibleActionInterface::setFocusAction());
913HRESULT QWindowsUiaMainProvider::get_FragmentRoot(IRawElementProviderFragmentRoot **pRetVal)
915 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
923 if (QAccessibleInterface *accessible = accessibleInterface()) {
924 if (QWindow *window = windowForAccessible(accessible)) {
925 if (QAccessibleInterface *rootacc = window->accessibleRoot())
926 *pRetVal = providerForAccessible(rootacc).Detach();
933HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(
double x,
double y, IRawElementProviderFragment **pRetVal)
935 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ << x << y;
942 QAccessibleInterface *accessible = accessibleInterface();
944 return UIA_E_ELEMENTNOTAVAILABLE;
946 QWindow *window = windowForAccessible(accessible);
948 return UIA_E_ELEMENTNOTAVAILABLE;
951 UiaPoint uiaPoint = {x, y};
953 nativeUiaPointToPoint(uiaPoint, window, &point);
955 QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y());
958 QAccessibleInterface *acc = targetacc;
963 if (targetacc->textInterface())
break;
964 acc = acc->childAt(point.x(), point.y());
966 *pRetVal = providerForAccessible(targetacc).Detach();
972HRESULT QWindowsUiaMainProvider::GetFocus(IRawElementProviderFragment **pRetVal)
974 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
980 if (QAccessibleInterface *accessible = accessibleInterface()) {
981 if (QAccessibleInterface *focusacc = accessible->focusChild()) {
982 *pRetVal = providerForAccessible(focusacc).Detach();