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#include "qplatformaccessibility.h"
40#include <private/qfactoryloader_p.h>
41#include "qaccessibleplugin.h"
42#include "qaccessibleobject.h"
43#include "qaccessiblebridge.h"
44#include <QtGui/QGuiApplication>
45
46#include <QDebug>
47
48QT_BEGIN_NAMESPACE
49
50#ifndef QT_NO_ACCESSIBILITY
51
52/* accessiblebridge plugin discovery stuff */
53Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, bridgeloader,
54 (QAccessibleBridgeFactoryInterface_iid, QLatin1String("/accessiblebridge")))
55
56Q_GLOBAL_STATIC(QList<QAccessibleBridge *>, bridges)
57
58/*!
59 \class QPlatformAccessibility
60 \since 5.0
61 \internal
62 \preliminary
63 \ingroup qpa
64 \ingroup accessibility
65
66 \brief The QPlatformAccessibility class is the base class for
67 integrating accessibility backends
68
69 \sa QAccessible
70*/
71QPlatformAccessibility::QPlatformAccessibility()
72 : m_active(false)
73{
74}
75
76QPlatformAccessibility::~QPlatformAccessibility()
77{
78}
79
80void QPlatformAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
81{
82 initialize();
83
84 if (!bridges() || bridges()->isEmpty())
85 return;
86
87 for (int i = 0; i < bridges()->count(); ++i)
88 bridges()->at(i)->notifyAccessibilityUpdate(event);
89}
90
91void QPlatformAccessibility::setRootObject(QObject *o)
92{
93 initialize();
94 if (bridges()->isEmpty())
95 return;
96
97 if (!o)
98 return;
99
100 for (int i = 0; i < bridges()->count(); ++i) {
101 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(o);
102 bridges()->at(i)->setRootObject(iface);
103 }
104}
105
106void QPlatformAccessibility::initialize()
107{
108 static bool isInit = false;
109 if (isInit)
110 return;
111 isInit = true; // ### not atomic
112
113 typedef QMultiMap<int, QString> PluginKeyMap;
114 typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
115
116 const PluginKeyMap keyMap = bridgeloader()->keyMap();
117 QAccessibleBridgePlugin *factory = nullptr;
118 int i = -1;
119 const PluginKeyMapConstIterator cend = keyMap.constEnd();
120 for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
121 if (it.key() != i) {
122 i = it.key();
123 factory = qobject_cast<QAccessibleBridgePlugin*>(bridgeloader()->instance(i));
124 }
125 if (factory)
126 if (QAccessibleBridge *bridge = factory->create(it.value()))
127 bridges()->append(bridge);
128 }
129}
130
131void QPlatformAccessibility::cleanup()
132{
133 qDeleteAll(*bridges());
134}
135
136void QPlatformAccessibility::setActive(bool active)
137{
138 m_active = active;
139 QAccessible::setActive(active);
140}
141
142#endif // QT_NO_ACCESSIBILITY
143
144QT_END_NAMESPACE
145