summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2022-08-24 13:47:25 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2022-08-24 19:05:54 +0200
commit61c0c1286dbd9015809ba8ee5ee687b612438bef (patch)
treea0875d61c31805a10792afb44117d7ecbbd2b82d /vcl/qt5
parent812fe185fba48b439fb1229517d62aa67c209016 (diff)
qt a11y: Remember associated QObject also for non-QtXAcccessible case
This is similar to what Change-Id Ic890a387ff016e889f25dba70c82d0d81ae7a9e3 ("qt a11y: Remember and reuse existing QObject for XAccessible") does to avoid creating another `QtXAccessible` for an `XAccessible` if one has been created earlier. However, there is an additional case that needs to be covered to avoid creating multiple `QObjects` for a single `XAccessible`: `QtAccessibleWidget::customFactory` not only gets called by explicitly calling `QAccessible::queryAccessibleInterface` from within LibreOffice code, but the Qt library itself also calls this method, in which case no entry associating the `XAccessible` with its `QObject` had been inserted into the map handled by our `QtAccessibleRegistry` previously. This would result in a "new" `QtXAccessible` object being created later when a `QObject` would be needed for that `XAccessible`, rather than using the `QtWidget` that is the actual `QObject` associated with the object. Prevent that from happening by inserting an entry into the map for this case as well. With this and two Accerciser fixes [1] [2] in place, jumping to bookmarks in Accerciser's treeview of the LO a11y hierarchy now generally works with the qt6 VCL plugin. It previously failed due to the fact that a new object was created and navigating the tree up to the root application object from the bookmarked object would then fail. The fact that there were two objects could be seen e.g. by using the following commands in Accerciser's IPython console with the root "soffice.bin" application a11y object selected in the treeview after starting Calc: In [25]: acc[1][0][0].get_parent().path Out[25]: '/org/a11y/atspi/accessible/2147483672' In [26]: acc[1][0].path Out[26]: '/org/a11y/atspi/accessible/2147483648' -> Two different IDs/paths for what should be the same object. (The parent of the first child of the object at tree path 1,0 should be the object itself, but here it wasn't.) With this change in place, this now works as expected: In [28]: acc[1][0][0].get_parent().path Out[28]: '/org/a11y/atspi/accessible/2147483648' In [29]: acc[1][0].path Out[29]: '/org/a11y/atspi/accessible/2147483648' Together with Change-Id Ic890a387ff016e889f25dba70c82d0d81ae7a9e3 ("qt a11y: Remember and reuse existing QObject for XAccessible"), this also addresses the remaining issue mentioned in commit 99640693d28ca11b31a1d3855e104d2d8c5122d7 Author: Michael Weghorn <m.weghorn@posteo.de> Date: Wed Aug 3 16:49:48 2022 +0200 > 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.) Note that there are still cases where navigation to bookmarks in Accerciser's tree view doesn't work (reliably), but those would need to be looked at separately and might not be specific to the qt6 VCL plugin. (At least I have come across such cases with gtk3 as well.) [1] https://gitlab.gnome.org/GNOME/accerciser/-/commit/c2a3e9f1eb1fcd6eb059f1f2fe6e629b86521335 [2] https://gitlab.gnome.org/GNOME/accerciser/-/commit/a092dc933985fafd5b1e2cc3374c7bbc0fb2d12e Change-Id: I02262014a45a4b024cdc1bbd385da8a35a2c304a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138764 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/QtAccessibleRegistry.cxx8
-rw-r--r--vcl/qt5/QtAccessibleWidget.cxx8
2 files changed, 15 insertions, 1 deletions
diff --git a/vcl/qt5/QtAccessibleRegistry.cxx b/vcl/qt5/QtAccessibleRegistry.cxx
index e64f8ae03868..88f9abcfd17e 100644
--- a/vcl/qt5/QtAccessibleRegistry.cxx
+++ b/vcl/qt5/QtAccessibleRegistry.cxx
@@ -10,6 +10,8 @@
#include <QtAccessibleRegistry.hxx>
#include <QtXAccessible.hxx>
+#include <cassert>
+
std::map<XAccessible*, QObject*> QtAccessibleRegistry::m_aMapping = {};
QObject* QtAccessibleRegistry::getQObject(css::uno::Reference<XAccessible> xAcc)
@@ -28,6 +30,12 @@ QObject* QtAccessibleRegistry::getQObject(css::uno::Reference<XAccessible> xAcc)
return pQtAcc;
}
+void QtAccessibleRegistry::insert(css::uno::Reference<XAccessible> xAcc, QObject* pQObject)
+{
+ assert(pQObject);
+ m_aMapping.emplace(xAcc.get(), pQObject);
+}
+
void QtAccessibleRegistry::remove(css::uno::Reference<XAccessible> xAcc)
{
assert(xAcc.is());
diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index fc81332465e7..e2e99e6de208 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -755,7 +755,13 @@ QAccessibleInterface* QtAccessibleWidget::customFactory(const QString& classname
vcl::Window* pWindow = pWidget->frame().GetWindow();
if (pWindow)
- return new QtAccessibleWidget(pWindow->GetAccessible(), object);
+ {
+ css::uno::Reference<XAccessible> xAcc = pWindow->GetAccessible();
+ // insert into registry so the association between the XAccessible and the QtWidget
+ // is remembered rather than creating a different QtXAccessible when a QObject is needed later
+ QtAccessibleRegistry::insert(xAcc, object);
+ return new QtAccessibleWidget(xAcc, object);
+ }
}
if (classname == QLatin1String("QtXAccessible") && object)
{