vcl/qt5/QtAccessibleWidget.cxx |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

New commits:
commit 99640693d28ca11b31a1d3855e104d2d8c5122d7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 3 16:49:48 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Aug 4 08:35:31 2022 +0200

    qt a11y: Implement QtAccessibleWidget::window
    
    Quoting the Qt doc [1]:
    
    > Returns the window associated with the underlying object.
    > For instance, QAccessibleWidget reimplements this and returns
    > the windowHandle() of the QWidget.
    >
    > It is used on some platforms to be able to notify the AT client
    > about state changes. The backend will traverse up all ancestors
    > until it finds a window. (This means that at least one interface
    > among the ancestors should return a valid QWindow
    > pointer).
    
    Check if the associated QObject is a QWidget and if so,
    get the associated window, otherwise walk up the a11y tree.
    
    Note however that this change alone is not yet sufficient
    for a window to actually be returned for any arbitrary a11y
    object deeper down the hierarchy. This is because
    walking up the a11y hierarchy currently results in new
    Qt a11y objects being created for the parents instead of
    using existing ones, and the newly created ones lack
    the association to the widgets.
    (This works in a WIP branch that remembers/caches
    a11y objects, but that needs some additional work before
    it can be merged.)
    
    [1] https://doc.qt.io/qt-5/qaccessibleinterface.html#window
    
    Change-Id: Iba05f7bd3fba30fb2ca741179abbda2d60bee980
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137753
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index 1634912c8fa7..a73681cdf417 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -117,7 +117,23 @@ QtAccessibleWidget::getAccessibleTableForParent() const
     return Reference<XAccessibleTable>(xParentContext, UNO_QUERY);
 }
 
-QWindow* QtAccessibleWidget::window() const { return nullptr; }
+QWindow* QtAccessibleWidget::window() const
+{
+    assert(m_pObject);
+    if (m_pObject->isWidgetType())
+    {
+        QWidget* pWidget = static_cast<QWidget*>(m_pObject);
+        QWidget* pWindow = pWidget->window();
+        if (pWindow)
+            return pWindow->windowHandle();
+    }
+
+    QAccessibleInterface* pParent = parent();
+    if (pParent)
+        return pParent->window();
+
+    return nullptr;
+}
 
 int QtAccessibleWidget::childCount() const
 {

Reply via email to