Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsuiaexpandcollapseprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include <QtGui/qtguiglobal.h>
6#if QT_CONFIG(accessibility)
7
8#include "qwindowsuiaexpandcollapseprovider.h"
9#include "qwindowsuiautils.h"
10#include "qwindowscontext.h"
11
12#include <QtGui/qaccessible.h>
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qstring.h>
15
16QT_BEGIN_NAMESPACE
17
18using namespace QWindowsUiAutomation;
19
20static bool isExpanded(QAccessibleInterface *accessible)
21{
22 Q_ASSERT(accessible);
23 if (accessible->role() == QAccessible::MenuItem)
24 return accessible->childCount() > 0 && !accessible->child(0)->state().invisible;
25 else
26 return accessible->state().expandable && accessible->state().expanded;
27}
28
29QWindowsUiaExpandCollapseProvider::QWindowsUiaExpandCollapseProvider(QAccessible::Id id) :
30 QWindowsUiaBaseProvider(id)
31{
32}
33
34QWindowsUiaExpandCollapseProvider::~QWindowsUiaExpandCollapseProvider() = default;
35
36HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Expand()
37{
38 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
39
40 QAccessibleInterface *accessible = accessibleInterface();
41 if (!accessible)
42 return UIA_E_ELEMENTNOTAVAILABLE;
43
44 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
45 if (!actionInterface)
46 return UIA_E_ELEMENTNOTAVAILABLE;
47
48 if (!isExpanded(accessible))
49 actionInterface->doAction(QAccessibleActionInterface::showMenuAction());
50
51 return S_OK;
52}
53
54HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::Collapse()
55{
56 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
57
58 QAccessibleInterface *accessible = accessibleInterface();
59 if (!accessible)
60 return UIA_E_ELEMENTNOTAVAILABLE;
61
62 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
63 if (!actionInterface)
64 return UIA_E_ELEMENTNOTAVAILABLE;
65
66 if (isExpanded(accessible))
67 actionInterface->doAction(QAccessibleActionInterface::showMenuAction());
68
69 return S_OK;
70}
71
72HRESULT STDMETHODCALLTYPE QWindowsUiaExpandCollapseProvider::get_ExpandCollapseState(__RPC__out ExpandCollapseState *pRetVal)
73{
74 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
75
76 if (!pRetVal)
77 return E_INVALIDARG;
78 *pRetVal = ExpandCollapseState_LeafNode;
79
80 QAccessibleInterface *accessible = accessibleInterface();
81 if (!accessible)
82 return UIA_E_ELEMENTNOTAVAILABLE;
83
84 *pRetVal = isExpanded(accessible) ? ExpandCollapseState_Expanded : ExpandCollapseState_Collapsed;
85
86 return S_OK;
87}
88
89QT_END_NAMESPACE
90
91#endif // QT_CONFIG(accessibility)