From a65719ec67523cdfc294aeeda527b51ba4d2e17c Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 16 Aug 2022 12:35:56 +0200 Subject: qt a11y: Clear XAccessible reference when disposing The `XEventListener::disposing` doc (in `./udkapi/com/sun/star/lang/XEventListener.idl`) says: > /** gets called when the broadcaster is about to be disposed. > >

All listeners and all other objects, which reference the > broadcaster should release the reference to the source. > No method should be invoked anymore on this object ( > including XComponent::removeEventListener() ). >

> >

This method is called for every listener registration > of derived listener interfaced, not only for registrations > at XComponent.

> */ Therefore, clear the `XAccessible` reference held in the associated `QtAccessibleWidget` in `QtAccessibleEventListener::disposing`. This also implies that `QtAccessibleWidget::isValid()` (overriding the `QAccessibleInterface` method) will return `false` from that point on. Change-Id: I077dffe6ca3e887707d1f578e947ccf3c2c2a492 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138364 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- vcl/inc/qt5/QtAccessibleWidget.hxx | 4 ++++ vcl/qt5/QtAccessibleEventListener.cxx | 6 +++++- vcl/qt5/QtAccessibleWidget.cxx | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vcl/inc/qt5/QtAccessibleWidget.hxx b/vcl/inc/qt5/QtAccessibleWidget.hxx index fdd97b0b407d..0ca17b394123 100644 --- a/vcl/inc/qt5/QtAccessibleWidget.hxx +++ b/vcl/inc/qt5/QtAccessibleWidget.hxx @@ -50,6 +50,10 @@ class QtAccessibleWidget final : public QObject, public: QtAccessibleWidget(const css::uno::Reference xAccessible, QObject* pObject); + + void invalidate(); + + // QAccessibleInterface QWindow* window() const override; int childCount() const override; int indexOfChild(const QAccessibleInterface* child) const override; diff --git a/vcl/qt5/QtAccessibleEventListener.cxx b/vcl/qt5/QtAccessibleEventListener.cxx index ee562a4eca38..53256181ea4e 100644 --- a/vcl/qt5/QtAccessibleEventListener.cxx +++ b/vcl/qt5/QtAccessibleEventListener.cxx @@ -353,6 +353,10 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible } } -void QtAccessibleEventListener::disposing(const EventObject& /* Source */) {} +void QtAccessibleEventListener::disposing(const EventObject& /* Source */) +{ + assert(m_pAccessibleWidget); + m_pAccessibleWidget->invalidate(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx index d6370877f449..83733e04c285 100644 --- a/vcl/qt5/QtAccessibleWidget.cxx +++ b/vcl/qt5/QtAccessibleWidget.cxx @@ -73,6 +73,8 @@ QtAccessibleWidget::QtAccessibleWidget(const Reference xAccessible, } } +void QtAccessibleWidget::invalidate() { m_xAccessible.clear(); } + Reference QtAccessibleWidget::getAccessibleContextImpl() const { Reference xAc; -- cgit