a11y uia: Don't return "S_OK" and null text range

When QWindowsUiaTextProvider::RangeFromPoint was
called with a point that is not over any
character, it was previously returning S_OK
and a nullptr for the text range.

This is contrary to what the
ITextProvider::RangeFromPoint documentation [1]
says:

> If this method succeeds, it returns S_OK.
> Otherwise, it returns an HRESULT error code.

and

> The property never returns NULL.

Therefore, setting pRetVal to NULL and returning
S_OK at the same time is problematic.
Return UIA_E_ELEMENTNOTAVAILABLE instead for that
case, and only return S_OK when actually
setting a valid text range provider as well.

Ideally, this should return an empty range for
the character that is closest to the given point.
That one could be identified by iterating over all
characters and calculating their distance to the
given point, but that would be too expensive.

[1] https://learn.microsoft.com/en-us/windows/win32/api/uiautomationcore/nf-uiautomationcore-itextprovider-rangefrompoint

Fixes: QTBUG-115801
Pick-to: 6.6 6.5
Change-Id: Ib08d02677935a45517c937613785f1e3f53ee032
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Michael Weghorn 2023-08-04 19:27:58 +02:00
parent beb1a48ef7
commit 9900a12df6

View File

@ -146,9 +146,10 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromPoint(UiaPoint point
nativeUiaPointToPoint(point, window, &pt);
int offset = textInterface->offsetAtPoint(pt);
if ((offset >= 0) && (offset < textInterface->characterCount())) {
*pRetVal = new QWindowsUiaTextRangeProvider(id(), offset, offset);
}
if (offset < 0 || offset >= textInterface->characterCount())
return UIA_E_ELEMENTNOTAVAILABLE;
*pRetVal = new QWindowsUiaTextRangeProvider(id(), offset, offset);
return S_OK;
}