From 30daa8248ecdad75cfc0d3ce26309abf7e8059f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20de=20la=20Rocha?= Date: Wed, 25 May 2022 14:56:02 +0200 Subject: [PATCH] Add ExpandCollapse UI Automation pattern to combo boxes Also add support to expandable/expanded states to QAccessibleComboBox in widgets. QtDeclarative will still require updates so that QML combo boxes report the expanded/collapsed state and react to UIA actions. Task-number: QTBUG-103591 Change-Id: Iff8ba5e3143778ce17998dbe7f5f76cae658dc19 Reviewed-by: Volker Hilsheimer (cherry picked from commit ecd41111a3a7100f20e72b811b1010bc45e94127) Reviewed-by: Qt Cherry-pick Bot --- .../qwindowsuiaexpandcollapseprovider.cpp | 16 +++++++++++----- .../uiautomation/qwindowsuiamainprovider.cpp | 5 +++-- src/widgets/accessible/complexwidgets.cpp | 10 ++++++++++ src/widgets/accessible/complexwidgets_p.h | 2 ++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiaexpandcollapseprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiaexpandcollapseprovider.cpp index 33900a8d66e..8eb9baa8ef8 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiaexpandcollapseprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiaexpandcollapseprovider.cpp @@ -16,6 +16,14 @@ QT_BEGIN_NAMESPACE using namespace QWindowsUiAutomation; +static bool isExpanded(QAccessibleInterface *accessible) +{ + Q_ASSERT(accessible); + if (accessible->role() == QAccessible::MenuItem) + return accessible->childCount() > 0 && !accessible->child(0)->state().invisible; + else + return accessible->state().expandable && accessible->state().expanded; +} QWindowsUiaExpandCollapseProvider::QWindowsUiaExpandCollapseProvider(QAccessible::Id id) : QWindowsUiaBaseProvider(id) @@ -36,7 +44,7 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Expand() if (!actionInterface) return UIA_E_ELEMENTNOTAVAILABLE; - if (accessible->childCount() > 0 && accessible->child(0)->state().invisible) + if (!isExpanded(accessible)) actionInterface->doAction(QAccessibleActionInterface::showMenuAction()); return S_OK; @@ -54,7 +62,7 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Collapse() if (!actionInterface) return UIA_E_ELEMENTNOTAVAILABLE; - if (accessible->childCount() > 0 && !accessible->child(0)->state().invisible) + if (isExpanded(accessible)) actionInterface->doAction(QAccessibleActionInterface::showMenuAction()); return S_OK; @@ -72,9 +80,7 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::get_ExpandCollapseS if (!accessible) return UIA_E_ELEMENTNOTAVAILABLE; - if (accessible->childCount() > 0) - *pRetVal = accessible->child(0)->state().invisible ? - ExpandCollapseState_Collapsed : ExpandCollapseState_Expanded; + *pRetVal = isExpanded(accessible) ? ExpandCollapseState_Expanded : ExpandCollapseState_Collapsed; return S_OK; } diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index bd8553532a9..4d4d706b83e 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -342,9 +342,10 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow break; case UIA_ExpandCollapsePatternId: // Menu items with submenus. - if (accessible->role() == QAccessible::MenuItem + if ((accessible->role() == QAccessible::MenuItem && accessible->childCount() > 0 - && accessible->child(0)->role() == QAccessible::PopupMenu) { + && accessible->child(0)->role() == QAccessible::PopupMenu) + || accessible->role() == QAccessible::ComboBox) { *pRetVal = new QWindowsUiaExpandCollapseProvider(id()); } break; diff --git a/src/widgets/accessible/complexwidgets.cpp b/src/widgets/accessible/complexwidgets.cpp index 6a3dedc162f..3d5154a30fc 100644 --- a/src/widgets/accessible/complexwidgets.cpp +++ b/src/widgets/accessible/complexwidgets.cpp @@ -350,6 +350,16 @@ QString QAccessibleComboBox::text(QAccessible::Text t) const return str; } +QAccessible::State QAccessibleComboBox::state() const +{ + QAccessible::State s = QAccessibleWidget::state(); + + s.expandable = true; + s.expanded = isValid() && comboBox()->view()->isVisible(); + + return s; +} + QStringList QAccessibleComboBox::actionNames() const { return QStringList() << showMenuAction() << pressAction(); diff --git a/src/widgets/accessible/complexwidgets_p.h b/src/widgets/accessible/complexwidgets_p.h index 65d995d9337..1fd5d5aeebc 100644 --- a/src/widgets/accessible/complexwidgets_p.h +++ b/src/widgets/accessible/complexwidgets_p.h @@ -102,6 +102,8 @@ public: QString text(QAccessible::Text t) const override; + QAccessible::State state() const override; + // QAccessibleActionInterface QStringList actionNames() const override; QString localizedActionDescription(const QString &actionName) const override;