1// Copyright (C) 2021 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
4#include "qaccessiblequickwidget_p.h"
5
6#include "qquickwidget_p.h"
7
8QT_BEGIN_NAMESPACE
9
10#if QT_CONFIG(accessibility)
11
12QAccessibleQuickWidget::QAccessibleQuickWidget(QQuickWidget* widget)
13: QAccessibleWidget(widget)
14{
15 // NOTE: m_accessibleWindow is a QAccessibleQuickWindow, and not a
16 // QAccessibleQuickWidgetOffscreenWindow (defined below). This means
17 // it will return the Quick item child interfaces, which is what's needed here
18 // (unlike QAccessibleQuickWidgetOffscreenWindow, which will report 0 children).
19 repairWindow();
20}
21
22QAccessibleQuickWidget::~QAccessibleQuickWidget()
23{
24 QObject::disconnect(m_connection);
25}
26
27void QAccessibleQuickWidget::repairWindow()
28{
29 if (!m_accessibleWindow || !m_accessibleWindow->object()) {
30 QQuickWidget *theWidget = static_cast<QQuickWidget *>(object());
31 QQuickWindow *newOffscreen = QQuickWidgetPrivate::get(view: theWidget)->offscreenWindow;
32 // We use the qobject_cast here to detect that the newOffscreen is
33 // not the one getting destroyed right now.
34 if (qobject_cast<QQuickWindow *>(object: newOffscreen)) {
35 m_accessibleWindow.reset(p: new QAccessibleQuickWindow(newOffscreen));
36 m_connection = QObject::connect(sender: newOffscreen, signal: &QObject::destroyed, context: theWidget,
37 slot: [this] { repairWindow(); });
38 }
39 }
40}
41
42QAccessibleInterface *QAccessibleQuickWidget::child(int index) const
43{
44 return m_accessibleWindow->child(index);
45}
46
47int QAccessibleQuickWidget::childCount() const
48{
49 return m_accessibleWindow->childCount();
50}
51
52int QAccessibleQuickWidget::indexOfChild(const QAccessibleInterface *iface) const
53{
54 return m_accessibleWindow->indexOfChild(iface);
55}
56
57QAccessibleInterface *QAccessibleQuickWidget::childAt(int x, int y) const
58{
59 return m_accessibleWindow->childAt(x, y);
60}
61
62QAccessibleQuickWidgetOffscreenWindow::QAccessibleQuickWidgetOffscreenWindow(QQuickWindow *window)
63:QAccessibleQuickWindow(window)
64{
65
66}
67
68QAccessibleInterface *QAccessibleQuickWidgetOffscreenWindow::child(int index) const
69{
70 Q_UNUSED(index);
71 return nullptr;
72}
73
74int QAccessibleQuickWidgetOffscreenWindow::childCount() const
75{
76 return 0;
77}
78
79int QAccessibleQuickWidgetOffscreenWindow::indexOfChild(const QAccessibleInterface *iface) const
80{
81 Q_UNUSED(iface);
82 return -1;
83}
84
85QAccessibleInterface *QAccessibleQuickWidgetOffscreenWindow::QAccessibleQuickWidgetOffscreenWindow::childAt(int x, int y) const
86{
87 Q_UNUSED(x);
88 Q_UNUSED(y);
89 return nullptr;
90}
91
92#endif // accessibility
93
94QT_END_NAMESPACE
95

source code of qtdeclarative/src/quickwidgets/qaccessiblequickwidget.cpp