summaryrefslogtreecommitdiff
path: root/winaccessibility
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-08-08 19:43:09 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2023-08-09 06:14:52 +0200
commitd1d07992a89ba503f1d457a8f79926063f4d3f9c (patch)
tree12153b7ec73103314c3ba8a91c7926be9dc333ed /winaccessibility
parent39302875c27d4cf4246bb7520ed90abcf0af777a (diff)
tdf#156679 wina11y: Convert screen to local coords as needed
When `AccTextBase::get_offsetAtPoint` gets called with screen coordinates, convert them to local coordinates within the text object first, because that is what `XAccessibleText::getIndexAtPoint` expects. Not doing so resulted in NVDA failing to create a TextInfo object in the mouse event handler [1] when hovering over a Calc cell containing text, because the method would always return an offset of -1. With this change in place, NVDA now announces the text when hovering over the text and mouse tracking is enabled in NVDA (which is the case by default). Other than with Microsoft Excel, the text is only announced when the mouse is actually over the text, not over free space in the cell, which might be because Excel uses UIA and the UIA equivalent, `ITextProvider::RangeFromPoint` [2] shall also return the index of the closest character when the point itself is not over the actual bounds of any character. [1] https://github.com/nvaccess/nvda/blob/a198c9b5f27e47ff2830f77c833eec584078dfd8/source/NVDAObjects/__init__.py#L1209 [2] https://learn.microsoft.com/en-us/windows/win32/api/uiautomationcore/nf-uiautomationcore-itextprovider-rangefrompoint Change-Id: I1e4ab2dd3dace5fea1de2eef67a91fe3c31218a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155492 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'winaccessibility')
-rw-r--r--winaccessibility/source/UAccCOM/AccTextBase.cxx16
1 files changed, 15 insertions, 1 deletions
diff --git a/winaccessibility/source/UAccCOM/AccTextBase.cxx b/winaccessibility/source/UAccCOM/AccTextBase.cxx
index 183ec3467655..b70b13c0a980 100644
--- a/winaccessibility/source/UAccCOM/AccTextBase.cxx
+++ b/winaccessibility/source/UAccCOM/AccTextBase.cxx
@@ -417,7 +417,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_nSelections(long * nSelectio
* @param offset Variant to accept offset.
* @return Result.
*/
-COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_offsetAtPoint(long x, long y, IA2CoordinateType, long * offset)
+COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_offsetAtPoint(long x, long y, IA2CoordinateType coordType, long * offset)
{
SolarMutexGuard g;
@@ -432,6 +432,20 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_offsetAtPoint(long x, long y
css::awt::Point point;
point.X = x;
point.Y = y;
+
+ if (coordType == IA2_COORDTYPE_SCREEN_RELATIVE)
+ {
+ // convert from screen to local coordinates
+ Reference<XAccessibleContext> xContext = pUNOInterface->getAccessibleContext();
+ Reference<XAccessibleComponent> xComponent(xContext, UNO_QUERY);
+ if (!xComponent.is())
+ return S_FALSE;
+
+ css::awt::Point aObjectPos = xComponent->getLocationOnScreen();
+ point.X -= aObjectPos.X;
+ point.Y -= aObjectPos.Y;
+ }
+
*offset = GetXInterface()->getIndexAtPoint(point);
return S_OK;