vcl/qt5/QtAccessibleWidget.cxx |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

New commits:
commit 35be93f83ac866ef18f0e06853c9818cd1d1bd56
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 3 09:18:46 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 3 11:16:49 2022 +0200

    qt a11y: Implement QtAccessibleWidget::characterRect
    
    With this and the suggested changes ([1], [2], [3], [4])
    for 4 Qt issues I ran into ([5], [6], [7], [8]),
    the Accerciser scenario described in
    
        commit 7b312771d7eb33f7410167e36efdaeca6f540b1c
        Date:   Thu Jul 14 08:35:53 2022 +0200
    
            tdf#149952 gtk3 a11y: Return pos relative to window when requested
    
    works for the qt6 VCL plugin as well.
    (The complete GNOME Magnifier scenario from tdf#149952
    still doesn't work with qt6, probably because a11y
    events are not sent (reliably) so far.)
    
    [1] https://codereview.qt-project.org/c/qt/qtbase/+/422251/1
    [2] https://codereview.qt-project.org/c/qt/qtbase/+/422333/1
    [3] https://codereview.qt-project.org/c/qt/qtbase/+/424510/2
    [4] https://codereview.qt-project.org/c/qt/qtbase/+/424731/1
    [5] https://bugreports.qt.io/browse/QTBUG-105031
    [6] https://bugreports.qt.io/browse/QTBUG-105042
    [7] https://bugreports.qt.io/browse/QTBUG-105281
    [8] https://bugreports.qt.io/browse/QTBUG-105313
    
    Change-Id: Iaccc89bf62c4617bee06f34ffebbd309a62212e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137735
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index 74dc79cb7023..fd0a858c564c 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -941,10 +941,24 @@ int QtAccessibleWidget::characterCount() const
         return xText->getCharacterCount();
     return 0;
 }
-QRect QtAccessibleWidget::characterRect(int /* offset */) const
+QRect QtAccessibleWidget::characterRect(int nOffset) const
 {
-    SAL_INFO("vcl.qt", "Unsupported QAccessibleTextInterface::characterRect");
-    return QRect();
+    Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY);
+    if (!xText.is())
+        return QRect();
+
+    if (nOffset < 0 || nOffset > xText->getCharacterCount())
+    {
+        SAL_WARN("vcl.qt",
+                 "QtAccessibleWidget::characterRect called with invalid 
offset: " << nOffset);
+        return QRect();
+    }
+
+    const awt::Rectangle aBounds = xText->getCharacterBounds(nOffset);
+    const QRect aRect(aBounds.X, aBounds.Y, aBounds.Width, aBounds.Height);
+    // convert to screen coordinates
+    const QRect aScreenPos = rect();
+    return aRect.translated(aScreenPos.x(), aScreenPos.y());
 }
 
 int QtAccessibleWidget::cursorPosition() const

Reply via email to