vcl/inc/qt5/QtAccessibleWidget.hxx | 9 +++++++++ vcl/qt5/QtAccessibleWidget.cxx | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-)
New commits: commit 3a9d36d49d1fc7bd0b461d0ef1d1cc5a6c3a76dd Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Jul 2 14:11:34 2022 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Jul 2 16:25:07 2022 +0200 qt a11y: Only return actually supported a11y interfaces Let `QtAccessibleWidget::interface_cast` only return a pointer to self if the underlying accessible (`m_xAccessible`)'s context implements the `XAccessible...` interface needed to have the corresponding `QAccessible...Interface` methods do anything useful (s.a. the checks at the beginning of the implementations of the corresponding `QAccessible...Interface` methods). This way, the other interfaces (or their AT-SPI equivalents) are no longer advertised as supported. (See the corresponding handling of the "GetInterfaces" AT-SPI method inside of the Qt library [1].) While at it, also add/adjust the comments indicating what methods override those from `QAccessibleTable{,Cell}Interface`. I ran into this when clicking through the LO a11y hierarchy in the Accerciser tree view and seeing the following warning in the terminal from which I had started Accerciser, after clicking on an item that was in no way related to any table in the first place: > (accerciser:192270): dbind-WARNING **: 14:05:51.582: atspi_dbus_get_property: expected a variant when fetching Caption from interface org.a11y.atspi.Table; got (so) With this change in place, unsupported interfaces are grayed out in Accerciser's "Interface Viewer" as expected, rather than being shown as active, but not displaying any useful data. [1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/accessible/linux/atspiadaptor.cpp?h=6.3.0#n1408 Change-Id: I1edbd451514253392e6b0a9caa6ffef2f789b55c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136782 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtAccessibleWidget.hxx b/vcl/inc/qt5/QtAccessibleWidget.hxx index 102b5658fb28..fdd97b0b407d 100644 --- a/vcl/inc/qt5/QtAccessibleWidget.hxx +++ b/vcl/inc/qt5/QtAccessibleWidget.hxx @@ -153,6 +153,15 @@ private: css::uno::Reference<css::accessibility::XAccessible> m_xAccessible; css::uno::Reference<css::accessibility::XAccessibleContext> getAccessibleContextImpl() const; css::uno::Reference<css::accessibility::XAccessibleTable> getAccessibleTableForParent() const; + + template <class Interface> bool accessibleProvidesInterface() const + { + css::uno::Reference<css::accessibility::XAccessibleContext> xContext + = getAccessibleContextImpl(); + css::uno::Reference<Interface> xInterface(xContext, css::uno::UNO_QUERY); + return xInterface.is(); + } + QObject* m_pObject; }; diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx index 5e66459ce054..88616a555efd 100644 --- a/vcl/qt5/QtAccessibleWidget.cxx +++ b/vcl/qt5/QtAccessibleWidget.cxx @@ -734,17 +734,23 @@ QColor QtAccessibleWidget::backgroundColor() const void* QtAccessibleWidget::interface_cast(QAccessible::InterfaceType t) { - if (t == QAccessible::ActionInterface) + if (t == QAccessible::ActionInterface && accessibleProvidesInterface<XAccessibleAction>()) return static_cast<QAccessibleActionInterface*>(this); - if (t == QAccessible::TextInterface) + if (t == QAccessible::TextInterface && accessibleProvidesInterface<XAccessibleText>()) return static_cast<QAccessibleTextInterface*>(this); - if (t == QAccessible::EditableTextInterface) + if (t == QAccessible::EditableTextInterface + && accessibleProvidesInterface<XAccessibleEditableText>()) return static_cast<QAccessibleEditableTextInterface*>(this); - if (t == QAccessible::ValueInterface) + if (t == QAccessible::ValueInterface && accessibleProvidesInterface<XAccessibleValue>()) return static_cast<QAccessibleValueInterface*>(this); if (t == QAccessible::TableCellInterface) - return static_cast<QAccessibleTableCellInterface*>(this); - if (t == QAccessible::TableInterface) + { + // parent must be a table + Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); + if (xTable.is()) + return static_cast<QAccessibleTableCellInterface*>(this); + } + if (t == QAccessible::TableInterface && accessibleProvidesInterface<XAccessibleTable>()) return static_cast<QAccessibleTableInterface*>(this); return nullptr; } @@ -1164,7 +1170,7 @@ void QtAccessibleWidget::setCurrentValue(const QVariant& value) xValue->setCurrentValue(Any(value.toDouble())); } -// QAccessibleTable +// QAccessibleTableInterface QAccessibleInterface* QtAccessibleWidget::caption() const { Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); @@ -1386,6 +1392,7 @@ bool QtAccessibleWidget::unselectRow(int row) return xTableSelection->unselectRow(row); } +// QAccessibleTableCellInterface QList<QAccessibleInterface*> QtAccessibleWidget::columnHeaderCells() const { SAL_WARN("vcl.qt", "Unsupported QAccessibleTableCellInterface::columnHeaderCells");