Coverage Report

Created: 2025-09-27 07:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/accessible/qaccessibleobject.cpp
Line
Count
Source
1
/****************************************************************************
2
**
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Contact: https://www.qt.io/licensing/
5
**
6
** This file is part of the QtGui module 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 "qaccessibleobject.h"
41
42
#ifndef QT_NO_ACCESSIBILITY
43
44
#include <QtGui/QGuiApplication>
45
#include <QtGui/QWindow>
46
47
#include "qpointer.h"
48
#include "qmetaobject.h"
49
50
QT_BEGIN_NAMESPACE
51
52
class QAccessibleObjectPrivate
53
{
54
public:
55
    QPointer<QObject> object;
56
};
57
58
/*!
59
    \class QAccessibleObject
60
    \brief The QAccessibleObject class implements parts of the
61
    QAccessibleInterface for QObjects.
62
63
    \ingroup accessibility
64
    \inmodule QtGui
65
66
    This class is part of \l {Accessibility for QWidget Applications}.
67
68
    This class is mainly provided for convenience. All subclasses of
69
    the QAccessibleInterface that provide implementations of non-widget objects
70
    should use this class as their base class.
71
72
    \sa QAccessible, QAccessibleWidget
73
*/
74
75
/*!
76
    Creates a QAccessibleObject for \a object.
77
*/
78
QAccessibleObject::QAccessibleObject(QObject *object)
79
0
{
80
0
    d = new QAccessibleObjectPrivate;
81
0
    d->object = object;
82
0
}
83
84
/*!
85
    Destroys the QAccessibleObject.
86
87
    This only happens when a call to release() decrements the internal
88
    reference counter to zero.
89
*/
90
QAccessibleObject::~QAccessibleObject()
91
0
{
92
0
    delete d;
93
0
}
94
95
/*!
96
    \reimp
97
*/
98
QObject *QAccessibleObject::object() const
99
0
{
100
0
    return d->object;
101
0
}
102
103
/*!
104
    \reimp
105
*/
106
bool QAccessibleObject::isValid() const
107
0
{
108
0
    return !d->object.isNull();
109
0
}
110
111
/*! \reimp */
112
QRect QAccessibleObject::rect() const
113
0
{
114
0
    return QRect();
115
0
}
116
117
/*! \reimp */
118
void QAccessibleObject::setText(QAccessible::Text, const QString &)
119
0
{
120
0
}
121
122
/*! \reimp */
123
QAccessibleInterface *QAccessibleObject::childAt(int x, int y) const
124
0
{
125
0
    for (int i = 0; i < childCount(); ++i) {
126
0
        QAccessibleInterface *childIface = child(i);
127
0
        Q_ASSERT(childIface);
128
0
        if (childIface->isValid() && childIface->rect().contains(x,y))
129
0
            return childIface;
130
0
    }
131
0
    return nullptr;
132
0
}
133
134
/*!
135
    \class QAccessibleApplication
136
    \brief The QAccessibleApplication class implements the QAccessibleInterface for QApplication.
137
138
    \internal
139
140
    \ingroup accessibility
141
*/
142
143
/*!
144
    Creates a QAccessibleApplication for the QApplication object referenced by qApp.
145
*/
146
QAccessibleApplication::QAccessibleApplication()
147
0
: QAccessibleObject(qApp)
148
0
{
149
0
}
150
151
QWindow *QAccessibleApplication::window() const
152
0
{
153
    // an application can have several windows, and AFAIK we don't need
154
    // to notify about changes on the application.
155
0
    return nullptr;
156
0
}
157
158
// all toplevel windows except popups and the desktop
159
static QObjectList topLevelObjects()
160
0
{
161
0
    QObjectList list;
162
0
    const QWindowList tlw(QGuiApplication::topLevelWindows());
163
0
    for (int i = 0; i < tlw.count(); ++i) {
164
0
        QWindow *w = tlw.at(i);
165
0
        if (w->type() != Qt::Popup && w->type() != Qt::Desktop) {
166
0
            if (QAccessibleInterface *root = w->accessibleRoot()) {
167
0
                if (root->object())
168
0
                    list.append(root->object());
169
0
            }
170
0
        }
171
0
    }
172
173
0
    return list;
174
0
}
175
176
/*! \reimp */
177
int QAccessibleApplication::childCount() const
178
0
{
179
0
    return topLevelObjects().count();
180
0
}
181
182
/*! \reimp */
183
int QAccessibleApplication::indexOfChild(const QAccessibleInterface *child) const
184
0
{
185
0
    if (!child)
186
0
        return -1;
187
0
    const QObjectList tlw(topLevelObjects());
188
0
    return tlw.indexOf(child->object());
189
0
}
190
191
QAccessibleInterface *QAccessibleApplication::parent() const
192
0
{
193
0
    return nullptr;
194
0
}
195
196
QAccessibleInterface *QAccessibleApplication::child(int index) const
197
0
{
198
0
    const QObjectList tlo(topLevelObjects());
199
0
    if (index >= 0 && index < tlo.count())
200
0
        return QAccessible::queryAccessibleInterface(tlo.at(index));
201
0
    return nullptr;
202
0
}
203
204
205
/*! \reimp */
206
QAccessibleInterface *QAccessibleApplication::focusChild() const
207
0
{
208
0
    if (QWindow *window = QGuiApplication::focusWindow())
209
0
        return window->accessibleRoot();
210
0
    return nullptr;
211
0
}
212
213
/*! \reimp */
214
QString QAccessibleApplication::text(QAccessible::Text t) const
215
0
{
216
0
    switch (t) {
217
0
    case QAccessible::Name:
218
0
        return QGuiApplication::applicationName();
219
0
    case QAccessible::Description:
220
0
        return QGuiApplication::applicationFilePath();
221
0
    default:
222
0
        break;
223
0
    }
224
0
    return QString();
225
0
}
226
227
/*! \reimp */
228
QAccessible::Role QAccessibleApplication::role() const
229
0
{
230
0
    return QAccessible::Application;
231
0
}
232
233
/*! \reimp */
234
QAccessible::State QAccessibleApplication::state() const
235
0
{
236
0
    return QAccessible::State();
237
0
}
238
239
240
QT_END_NAMESPACE
241
242
#endif //QT_NO_ACCESSIBILITY