4#include <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
7#include "qwindowsuiautils.h"
8#include "qwindowscontext.h"
9#include "qwindowswindow.h"
11#include <QtGui/qwindow.h>
12#include <QtGui/private/qhighdpiscaling_p.h>
13#include <qpa/qplatforminputcontextfactory_p.h>
19namespace QWindowsUiAutomation {
22QWindow *windowForAccessible(
const QAccessibleInterface *accessible)
24 QWindow *window = accessible->window();
26 const QAccessibleInterface *acc = accessible;
27 const QAccessibleInterface *par = accessible->parent();
28 while (par && par->isValid() && !window) {
29 window = par->window();
35 const auto appWindows = QGuiApplication::topLevelWindows();
36 for (QWindow *w : appWindows) {
37 if (QAccessibleInterface *root = w->accessibleRoot()) {
38 int count = root->childCount();
39 for (
int i = 0; i < count; ++i) {
40 if (root->child(i) == acc)
52HWND hwndForAccessible(
const QAccessibleInterface *accessible)
54 if (QWindow *window = accessible->window()) {
55 if (!accessible->parent() || (accessible->parent()->window() != window)) {
56 return QWindowsBaseWindow::handleOf(window);
62void clearVariant(VARIANT *variant)
64 variant->vt = VT_EMPTY;
65 variant->punkVal =
nullptr;
69void rectToNativeUiaRect(
const QRect &rect,
const QWindow *w, UiaRect *uiaRect)
72 QRectF r = QHighDpi::toNativePixels(QRectF(rect), w);
75 uiaRect->width = r.width();
76 uiaRect->height = r.height();
81void nativeUiaPointToPoint(
const UiaPoint &uiaPoint,
const QWindow *w, QPoint *point)
84 *point = QHighDpi::fromNativePixels(QPoint(uiaPoint.x, uiaPoint.y), w);
88long roleToControlTypeId(QAccessible::Role role)
90 static const QHash<QAccessible::Role,
long> mapping {
91 {QAccessible::TitleBar, UIA_TitleBarControlTypeId},
92 {QAccessible::MenuBar, UIA_MenuBarControlTypeId},
93 {QAccessible::ScrollBar, UIA_ScrollBarControlTypeId},
94 {QAccessible::Grip, UIA_ThumbControlTypeId},
95 {QAccessible::Sound, UIA_CustomControlTypeId},
96 {QAccessible::Cursor, UIA_CustomControlTypeId},
97 {QAccessible::Caret, UIA_CustomControlTypeId},
98 {QAccessible::AlertMessage, UIA_WindowControlTypeId},
99 {QAccessible::Window, UIA_WindowControlTypeId},
100 {QAccessible::Client, UIA_GroupControlTypeId},
101 {QAccessible::PopupMenu, UIA_MenuControlTypeId},
102 {QAccessible::MenuItem, UIA_MenuItemControlTypeId},
103 {QAccessible::ToolTip, UIA_ToolTipControlTypeId},
104 {QAccessible::Application, UIA_CustomControlTypeId},
105 {QAccessible::Document, UIA_DocumentControlTypeId},
106 {QAccessible::Pane, UIA_PaneControlTypeId},
107 {QAccessible::Chart, UIA_CustomControlTypeId},
108 {QAccessible::Dialog, UIA_WindowControlTypeId},
109 {QAccessible::Border, UIA_CustomControlTypeId},
110 {QAccessible::Grouping, UIA_GroupControlTypeId},
111 {QAccessible::Separator, UIA_SeparatorControlTypeId},
112 {QAccessible::ToolBar, UIA_ToolBarControlTypeId},
113 {QAccessible::StatusBar, UIA_StatusBarControlTypeId},
114 {QAccessible::Table, UIA_TableControlTypeId},
115 {QAccessible::ColumnHeader, UIA_HeaderControlTypeId},
116 {QAccessible::RowHeader, UIA_HeaderControlTypeId},
117 {QAccessible::Column, UIA_HeaderItemControlTypeId},
118 {QAccessible::Row, UIA_HeaderItemControlTypeId},
119 {QAccessible::Cell, UIA_DataItemControlTypeId},
120 {QAccessible::Link, UIA_HyperlinkControlTypeId},
121 {QAccessible::HelpBalloon, UIA_ToolTipControlTypeId},
122 {QAccessible::Assistant, UIA_CustomControlTypeId},
123 {QAccessible::List, UIA_ListControlTypeId},
124 {QAccessible::ListItem, UIA_ListItemControlTypeId},
125 {QAccessible::Tree, UIA_TreeControlTypeId},
126 {QAccessible::TreeItem, UIA_TreeItemControlTypeId},
127 {QAccessible::PageTab, UIA_TabItemControlTypeId},
128 {QAccessible::PropertyPage, UIA_CustomControlTypeId},
129 {QAccessible::Indicator, UIA_CustomControlTypeId},
130 {QAccessible::Graphic, UIA_ImageControlTypeId},
131 {QAccessible::StaticText, UIA_TextControlTypeId},
132 {QAccessible::EditableText, UIA_EditControlTypeId},
133 {QAccessible::Button, UIA_ButtonControlTypeId},
134 {QAccessible::CheckBox, UIA_CheckBoxControlTypeId},
135 {QAccessible::RadioButton, UIA_RadioButtonControlTypeId},
136 {QAccessible::ComboBox, UIA_ComboBoxControlTypeId},
137 {QAccessible::ProgressBar, UIA_ProgressBarControlTypeId},
138 {QAccessible::Dial, UIA_CustomControlTypeId},
139 {QAccessible::HotkeyField, UIA_CustomControlTypeId},
140 {QAccessible::Slider, UIA_SliderControlTypeId},
141 {QAccessible::SpinBox, UIA_SpinnerControlTypeId},
142 {QAccessible::Canvas, UIA_CustomControlTypeId},
143 {QAccessible::Animation, UIA_CustomControlTypeId},
144 {QAccessible::Equation, UIA_CustomControlTypeId},
145 {QAccessible::ButtonDropDown, UIA_ButtonControlTypeId},
146 {QAccessible::ButtonMenu, UIA_ButtonControlTypeId},
147 {QAccessible::ButtonDropGrid, UIA_ButtonControlTypeId},
148 {QAccessible::Whitespace, UIA_CustomControlTypeId},
149 {QAccessible::PageTabList, UIA_TabControlTypeId},
150 {QAccessible::Clock, UIA_CustomControlTypeId},
151 {QAccessible::Splitter, UIA_CustomControlTypeId},
152 {QAccessible::Paragraph, UIA_TextControlTypeId},
153 {QAccessible::WebDocument, UIA_DocumentControlTypeId},
154 {QAccessible::Heading, UIA_TextControlTypeId},
155 {QAccessible::BlockQuote, UIA_GroupControlTypeId},
158 long controlType = mapping.value(role, UIA_CustomControlTypeId);
162 static bool imModuleEmpty = QPlatformInputContextFactory::requested().isEmpty();
163 bool nativeVKDisabled = QCoreApplication::testAttribute(Qt::AA_DisableNativeVirtualKeyboard);
167 if (controlType == UIA_EditControlTypeId && (!imModuleEmpty || nativeVKDisabled))
168 controlType = UIA_TextControlTypeId;
174bool isTextUnitSeparator(TextUnit unit,
const QChar &ch)
176 return (((unit == TextUnit_Word) || (unit == TextUnit_Format)) && ch.isSpace())
177 || ((unit == TextUnit_Line) && (ch.toLatin1() ==
'\n'));