Windows Accessibility: Recurse up to find a window.

Not all classes inheriting QAccessibleInterface implement
QAccessibleInterface::window(), so, go up the hierarchy to find
one that does.
The window is required to be able to determine the correct
scale factor for the screen when High DPI scaling is active.
Fixes multimonitor issues for QtWidgets.

Amends change d7a3b61459.

Task-number: QTBUG-52943
Change-Id: I81733765faee4d296bd6ea046bc2cecb018eb28d
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2016-05-06 12:19:46 +02:00
parent 6eb27afcdf
commit ee51638187

View File

@ -470,6 +470,15 @@ HRESULT STDMETHODCALLTYPE QWindowsMsaaAccessible::Invoke(long dispIdMember,
return hr;
}
static const QWindow *windowOf(const QAccessibleInterface *ai)
{
for ( ; ai; ai = ai->parent()) {
if (const QWindow *window = ai->window())
return window;
}
return Q_NULLPTR;
}
/*
IAccessible
@ -498,7 +507,7 @@ HRESULT STDMETHODCALLTYPE QWindowsMsaaAccessible::accHitTest(long xLeft, long yT
if (!accessible)
return E_FAIL;
const QPoint pos = QHighDpi::fromNativeLocalPosition(QPoint(xLeft, yTop), accessible->window());
const QPoint pos = QHighDpi::fromNativeLocalPosition(QPoint(xLeft, yTop), windowOf(accessible));
QAccessibleInterface *child = accessible->childAt(pos.x(), pos.y());
if (child == 0) {
// no child found, return this item if it contains the coordinates
@ -541,7 +550,7 @@ HRESULT STDMETHODCALLTYPE QWindowsMsaaAccessible::accLocation(long *pxLeft, long
QAccessibleInterface *acc = childPointer(accessible, varID);
if (!acc || !acc->isValid())
return E_FAIL;
const QRect rect = QHighDpi::toNativePixels(acc->rect(), accessible->window());
const QRect rect = QHighDpi::toNativePixels(acc->rect(), windowOf(accessible));
*pxLeft = rect.x();
*pyTop = rect.y();