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

New commits:
commit 3cf7b358799dfde4da1df3f0b9d6cf726d22a22b
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Aug 4 14:13:35 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Aug 4 22:42:23 2022 +0200

    qt a11y: Implement QtAccessibleWidget::offsetAtPoint
    
    Since `QAccessibleTextInterface::offsetAtPoint`
    uses screen coordinates, but
    `XAccessibleText::getIndexAtPoint` takes
    local coordinates (i.e. position within the object
    itself), convert that first.
    
    Tested as follows:
    
    1) start new document in Writer
    2) paste this text into the first paragraph:
       "Hello world, this is some test text. Lorem ipsum."
    3) start Accerciser
    4) select the paragraph in Accerciser's tree view of the
       LO a11y hierarchy.
    5) use Accerciser's IPython console to check the results
       returned by calling the corresponding AT-SPI methods:
    
        In [69]: 
acc.queryText().getOffsetAtPoint(acc.get_position(pyatspi.component.XY_SCREEN).x
 + 200,  acc.get_position(pyatspi.component.XY_SCREEN).y + 5, 
pyatspi.component.XY_SCREEN)
        Out[69]: 20
        In [70]: 
acc.queryText().getOffsetAtPoint(acc.get_position(pyatspi.component.XY_SCREEN).x
 + 250,  acc.get_position(pyatspi.component.XY_SCREEN).y + 5, 
pyatspi.component.XY_SCREEN)
        Out[70]: 27
        In [71]: 
acc.queryText().getOffsetAtPoint(acc.get_position(pyatspi.component.XY_SCREEN).x
 + 300,  acc.get_position(pyatspi.component.XY_SCREEN).y + 5, 
pyatspi.component.XY_SCREEN)
        Out[71]: 37
    
    With this change and the Qt changes mentioned in
    
        commit 35be93f83ac866ef18f0e06853c9818cd1d1bd56
        Date:   Wed Aug 3 09:18:46 2022 +0200
    
            qt a11y: Implement QtAccessibleWidget::characterRect
    
    , the results with the qt6 VCL plugin are the same as with
    the gtk3 one.
    
    Change-Id: Ie75fa9b7a64c413251c771f0379d9f3a3b200c30
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137795
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index 493292537050..940d8c29f513 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -912,11 +912,18 @@ int QtAccessibleWidget::cursorPosition() const
     return 0;
 }
 
-int QtAccessibleWidget::offsetAtPoint(const QPoint& /* point */) const
+int QtAccessibleWidget::offsetAtPoint(const QPoint& rPoint) const
 {
-    SAL_INFO("vcl.qt", "Unsupported QAccessibleTextInterface::offsetAtPoint");
-    return 0;
+    Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY);
+    if (!xText.is())
+        return -1;
+
+    // convert from screen to local coordinates
+    QPoint aLocalCoords = rPoint - rect().topLeft();
+    awt::Point aPoint(aLocalCoords.x(), aLocalCoords.y());
+    return xText->getIndexAtPoint(aPoint);
 }
+
 void QtAccessibleWidget::removeSelection(int /* selectionIndex */)
 {
     SAL_INFO("vcl.qt", "Unsupported 
QAccessibleTextInterface::removeSelection");

Reply via email to