diff options
author | André de la Rocha <andre.rocha@qt.io> | 2021-07-27 04:09:45 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-27 15:15:31 +0000 |
commit | 3df0fa35822fa0790316fc29d07a7dc740da40d5 (patch) | |
tree | 16626d39185812493a4c5e2d362b6766b50dcdb1 | |
parent | 6fb812f574e1e1a84738531f9e540d24d6825c3a (diff) |
Windows QPA: Fix coordinates reported through UI Automation
Conversion to/from native screen coordinates was incorrect and could
fail for non-primary screens. This could cause a control's bounding
rectangle to be incorrectly reported, or a search for a control based
on its position within the window to fail, causing incorrect behavior
with accessibility tools and other software interacting with the
application using UI Automation.
Fixes: QTBUG-91459
Change-Id: I5d56584ff26d977cdd34d35af46644e32aa11e7c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 0235c0217883bc9d0ca83c7533e9c0286901bb3c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/windows/uiautomation/qwindowsuiautils.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiautils.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiautils.cpp index 682b8c19c0..12bdc9e6b7 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiautils.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiautils.cpp @@ -132,22 +132,19 @@ void setVariantString(const QString &value, VARIANT *variant) void rectToNativeUiaRect(const QRect &rect, const QWindow *w, UiaRect *uiaRect) { if (w && uiaRect) { - const qreal factor = QHighDpiScaling::factor(w); - uiaRect->left = qreal(rect.x()) * factor; - uiaRect->top = qreal(rect.y()) * factor; - uiaRect->width = qreal(rect.width()) * factor; - uiaRect->height = qreal(rect.height()) * factor; + QRectF r = QHighDpi::toNativePixels(QRectF(rect), w); + uiaRect->left =r.x(); + uiaRect->top = r.y(); + uiaRect->width = r.width(); + uiaRect->height = r.height(); } } // Scales a point from native coordinates, according to high dpi settings. void nativeUiaPointToPoint(const UiaPoint &uiaPoint, const QWindow *w, QPoint *point) { - if (w && point) { - const qreal factor = QHighDpiScaling::factor(w); - point->setX(int(std::lround(uiaPoint.x / factor))); - point->setY(int(std::lround(uiaPoint.y / factor))); - } + if (w && point) + *point = QHighDpi::fromNativePixels(QPoint(uiaPoint.x, uiaPoint.y), w); } // Maps an accessibility role ID to an UI Automation control type ID. |