1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include <QtGui/qtguiglobal.h>
41 #if QT_CONFIG(accessibility)
42 
43 #include "qwinrtuiatableitemprovider.h"
44 #include "qwinrtuiamainprovider.h"
45 #include "qwinrtuiametadatacache.h"
46 #include "qwinrtuiautils.h"
47 
48 #include <QtGui/QAccessible>
49 #include <QtGui/QAccessibleInterface>
50 #include <QtCore/QLoggingCategory>
51 #include <QtCore/QString>
52 #include <QtCore/private/qeventdispatcher_winrt_p.h>
53 
54 #include <memory>
55 
56 QT_BEGIN_NAMESPACE
57 
58 using namespace QWinRTUiAutomation;
59 using namespace ABI::Windows::UI::Xaml::Automation;
60 using namespace ABI::Windows::UI::Xaml::Automation::Provider;
61 
QWinRTUiaTableItemProvider(QAccessible::Id id)62 QWinRTUiaTableItemProvider::QWinRTUiaTableItemProvider(QAccessible::Id id) :
63     QWinRTUiaBaseProvider(id)
64 {
65     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
66 }
67 
~QWinRTUiaTableItemProvider()68 QWinRTUiaTableItemProvider::~QWinRTUiaTableItemProvider()
69 {
70     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
71 }
72 
73 // Returns the providers for the column headers associated with the item.
GetColumnHeaderItems(UINT32 * returnValueSize,IIRawElementProviderSimple *** returnValue)74 HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue)
75 {
76     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
77 
78     if (!returnValueSize || !returnValue)
79         return E_INVALIDARG;
80     *returnValueSize = 0;
81     *returnValue = nullptr;
82 
83     auto accid = id();
84     auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
85 
86     if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
87         if (QAccessibleInterface *accessible = accessibleForId(accid)) {
88             if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) {
89                 QList<QAccessibleInterface *> headers = tableCellInterface->columnHeaderCells();
90                 for (auto header : qAsConst(headers)) {
91                     QAccessible::Id headerId = idForAccessible(header);
92                     QWinRTUiaMetadataCache::instance()->load(headerId);
93                     elementIds->append(headerId);
94                 }
95             }
96         }
97         return S_OK;
98     }))) {
99         return E_FAIL;
100     }
101 
102     return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue);
103 }
104 
105 // Returns the providers for the row headers associated with the item.
GetRowHeaderItems(UINT32 * returnValueSize,IIRawElementProviderSimple *** returnValue)106 HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue)
107 {
108     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
109 
110     if (!returnValueSize || !returnValue)
111         return E_INVALIDARG;
112     *returnValueSize = 0;
113     *returnValue = nullptr;
114 
115     auto accid = id();
116     auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
117 
118     if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
119         if (QAccessibleInterface *accessible = accessibleForId(accid)) {
120             if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) {
121                 QList<QAccessibleInterface *> headers = tableCellInterface->rowHeaderCells();
122                 for (auto header : qAsConst(headers)) {
123                     QAccessible::Id headerId = idForAccessible(header);
124                     QWinRTUiaMetadataCache::instance()->load(headerId);
125                     elementIds->append(headerId);
126                 }
127             }
128         }
129         return S_OK;
130     }))) {
131         return E_FAIL;
132     }
133 
134     return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue);
135 }
136 
137 QT_END_NAMESPACE
138 
139 #endif // QT_CONFIG(accessibility)
140