vcl/qt5/QtAccessibleEventListener.cxx |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

New commits:
commit 9d2c9a592ad697fd332b9bccb63e30c955f49422
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Aug 25 13:56:53 2022 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Thu Aug 25 14:55:31 2022 +0200

    qt a11y: Work around Qt ignoring ActiveDescendantChanged events
    
    While Qt has a `QAccessible::ActiveDescendantChanged` event type,
    events of that type are just ignored in Qt's AT-SPI adapter [1].
    
    Work around that by sending a "focused" event for the child
    instead, for which handling inside Qt has been added in [2].
    
    While adding support for properly handling
    `QAccessible::ActiveDescendantChanged` in Qt might be
    worth looking into at some point, this appears to
    work just fine for now and e.g. makes Orca announce
    the focused cell in Calc when moving between cells using
    the keyboard in the qt6 VCL plugin.
    
    [1] 
https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/accessible/linux/atspiadaptor.cpp?id=0131dbd2f95449c09758208d8b190c9238a5c46a#n1121
    [2] 
https://code.qt.io/cgit/qt/qtbase.git/commit/?id=f3509565480107c2587212f7d55cc5f92facc417
    
    Change-Id: I809695de427b6438d37a5a4840044e7ca3d4cd08
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138809
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/qt5/QtAccessibleEventListener.cxx 
b/vcl/qt5/QtAccessibleEventListener.cxx
index 53256181ea4e..dd2ee1b2eae6 100644
--- a/vcl/qt5/QtAccessibleEventListener.cxx
+++ b/vcl/qt5/QtAccessibleEventListener.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <QtAccessibleEventListener.hxx>
+#include <QtAccessibleRegistry.hxx>
 #include <QtTools.hxx>
 
 #include <sal/log.hxx>
@@ -171,9 +172,23 @@ void QtAccessibleEventListener::notifyEvent(const 
css::accessibility::Accessible
                 new QAccessibleEvent(pQAccessibleInterface, 
QAccessible::ActionChanged));
             return;
         case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED:
-            QAccessible::updateAccessibility(
-                new QAccessibleEvent(pQAccessibleInterface, 
QAccessible::ActiveDescendantChanged));
+        {
+            // Qt has a QAccessible::ActiveDescendantChanged event type, but 
events of
+            // that type are currently just ignored on Qt side and not 
forwarded to AT-SPI.
+            // Send a state change event for the focused state of the newly
+            // active descendant instead
+            uno::Reference<accessibility::XAccessible> xActiveAccessible;
+            aEvent.NewValue >>= xActiveAccessible;
+            if (!xActiveAccessible.is())
+                return;
+
+            QObject* pQtAcc = 
QtAccessibleRegistry::getQObject(xActiveAccessible);
+            QAccessibleInterface* pInterface = 
QAccessible::queryAccessibleInterface(pQtAcc);
+            QAccessible::State aState;
+            aState.focused = true;
+            QAccessible::updateAccessibility(new 
QAccessibleStateChangeEvent(pInterface, aState));
             return;
+        }
         case AccessibleEventId::CARET_CHANGED:
         {
             sal_Int32 nNewCursorPos = 0;

Reply via email to