Windows QPA: Implement IExpandCollapseProvider for submenus

Menu items with submenus should implement the Expand/Collapse UI Automation
pattern in order to allow screen readers to say whether they are expandable
items.

Fixes: QTBUG-80550
Change-Id: I4f72d30172f76f028be5cbdeb1fd85fca6b07acf
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Andre de la Rocha 2019-12-13 17:13:44 +01:00
parent 217b7d2dd6
commit a82f9f1a1d
6 changed files with 224 additions and 0 deletions

View File

@ -383,4 +383,21 @@ __CRT_UUID_DECL(IWindowProvider, 0x987df77b, 0xdb06, 0x4d77, 0x8f,0x8a, 0x86,0xa
#endif
#endif
#ifndef __IExpandCollapseProvider_INTERFACE_DEFINED__
#define __IExpandCollapseProvider_INTERFACE_DEFINED__
DEFINE_GUID(IID_IExpandCollapseProvider, 0xd847d3a5, 0xcab0, 0x4a98, 0x8c,0x32, 0xec,0xb4,0x5c,0x59,0xad,0x24);
MIDL_INTERFACE("d847d3a5-cab0-4a98-8c32-ecb45c59ad24")
IExpandCollapseProvider : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Expand() = 0;
virtual HRESULT STDMETHODCALLTYPE Collapse() = 0;
virtual HRESULT STDMETHODCALLTYPE get_ExpandCollapseState(__RPC__out enum ExpandCollapseState *pRetVal) = 0;
};
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(IExpandCollapseProvider, 0xd847d3a5, 0xcab0, 0x4a98, 0x8c,0x32, 0xec,0xb4,0x5c,0x59,0xad,0x24)
#endif
#endif
#endif

View File

@ -155,6 +155,13 @@ enum WindowInteractionState {
WindowInteractionState_NotResponding = 4
};
enum ExpandCollapseState {
ExpandCollapseState_Collapsed = 0,
ExpandCollapseState_Expanded = 1,
ExpandCollapseState_PartiallyExpanded = 2,
ExpandCollapseState_LeafNode = 3
};
struct UiaRect {
double left;
double top;

View File

@ -0,0 +1,120 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtGui/qtguiglobal.h>
#if QT_CONFIG(accessibility)
#include "qwindowsuiaexpandcollapseprovider.h"
#include "qwindowsuiautils.h"
#include "qwindowscontext.h"
#include <QtGui/qaccessible.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
using namespace QWindowsUiAutomation;
QWindowsUiaExpandCollapseProvider::QWindowsUiaExpandCollapseProvider(QAccessible::Id id) :
QWindowsUiaBaseProvider(id)
{
}
QWindowsUiaExpandCollapseProvider::~QWindowsUiaExpandCollapseProvider() = default;
HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Expand()
{
qCDebug(lcQpaUiAutomation) << __FUNCTION__;
QAccessibleInterface *accessible = accessibleInterface();
if (!accessible)
return UIA_E_ELEMENTNOTAVAILABLE;
QAccessibleActionInterface *actionInterface = accessible->actionInterface();
if (!actionInterface)
return UIA_E_ELEMENTNOTAVAILABLE;
if (accessible->childCount() > 0 && accessible->child(0)->state().invisible)
actionInterface->doAction(QAccessibleActionInterface::showMenuAction());
return S_OK;
}
HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Collapse()
{
qCDebug(lcQpaUiAutomation) << __FUNCTION__;
QAccessibleInterface *accessible = accessibleInterface();
if (!accessible)
return UIA_E_ELEMENTNOTAVAILABLE;
QAccessibleActionInterface *actionInterface = accessible->actionInterface();
if (!actionInterface)
return UIA_E_ELEMENTNOTAVAILABLE;
if (accessible->childCount() > 0 && !accessible->child(0)->state().invisible)
actionInterface->doAction(QAccessibleActionInterface::showMenuAction());
return S_OK;
}
HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::get_ExpandCollapseState(__RPC__out ExpandCollapseState *pRetVal)
{
qCDebug(lcQpaUiAutomation) << __FUNCTION__;
if (!pRetVal)
return E_INVALIDARG;
*pRetVal = ExpandCollapseState_LeafNode;
QAccessibleInterface *accessible = accessibleInterface();
if (!accessible)
return UIA_E_ELEMENTNOTAVAILABLE;
if (accessible->childCount() > 0)
*pRetVal = accessible->child(0)->state().invisible ?
ExpandCollapseState_Collapsed : ExpandCollapseState_Expanded;
return S_OK;
}
QT_END_NAMESPACE
#endif // QT_CONFIG(accessibility)

View File

@ -0,0 +1,69 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QWINDOWSUIAEXPANDCOLLAPSEPROVIDER_H
#define QWINDOWSUIAEXPANDCOLLAPSEPROVIDER_H
#include <QtGui/qtguiglobal.h>
#if QT_CONFIG(accessibility)
#include "qwindowsuiabaseprovider.h"
QT_BEGIN_NAMESPACE
// Implements the Expand/Collapse control pattern provider. Used for menu items with submenus.
class QWindowsUiaExpandCollapseProvider : public QWindowsUiaBaseProvider,
public QWindowsComBase<IExpandCollapseProvider>
{
Q_DISABLE_COPY_MOVE(QWindowsUiaExpandCollapseProvider)
public:
explicit QWindowsUiaExpandCollapseProvider(QAccessible::Id id);
virtual ~QWindowsUiaExpandCollapseProvider() override;
// IExpandCollapseProvider
HRESULT STDMETHODCALLTYPE Expand() override;
HRESULT STDMETHODCALLTYPE Collapse() override;
HRESULT STDMETHODCALLTYPE get_ExpandCollapseState(__RPC__out ExpandCollapseState *pRetVal) override;
};
QT_END_NAMESPACE
#endif // QT_CONFIG(accessibility)
#endif // QWINDOWSUIAEXPANDCOLLAPSEPROVIDER_H

View File

@ -53,6 +53,7 @@
#include "qwindowsuiagridprovider.h"
#include "qwindowsuiagriditemprovider.h"
#include "qwindowsuiawindowprovider.h"
#include "qwindowsuiaexpandcollapseprovider.h"
#include "qwindowscombase.h"
#include "qwindowscontext.h"
#include "qwindowsuiautils.h"
@ -341,6 +342,14 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow
*pRetVal = new QWindowsUiaInvokeProvider(id());
}
break;
case UIA_ExpandCollapsePatternId:
// Menu items with submenus.
if (accessible->role() == QAccessible::MenuItem
&& accessible->childCount() > 0
&& accessible->child(0)->role() == QAccessible::PopupMenu) {
*pRetVal = new QWindowsUiaExpandCollapseProvider(id());
}
break;
default:
break;
}

View File

@ -19,6 +19,7 @@ SOURCES += \
$$PWD/qwindowsuiagridprovider.cpp \
$$PWD/qwindowsuiagriditemprovider.cpp \
$$PWD/qwindowsuiawindowprovider.cpp \
$$PWD/qwindowsuiaexpandcollapseprovider.cpp \
$$PWD/qwindowsuiautils.cpp
HEADERS += \
@ -39,6 +40,7 @@ HEADERS += \
$$PWD/qwindowsuiagridprovider.h \
$$PWD/qwindowsuiagriditemprovider.h \
$$PWD/qwindowsuiawindowprovider.h \
$$PWD/qwindowsuiaexpandcollapseprovider.h \
$$PWD/qwindowsuiautils.h
mingw: QMAKE_USE *= uuid