| 1 | // Copyright (C) 2016 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 | #include "qplatformaccessibility.h" |
| 4 | #include <private/qfactoryloader_p.h> |
| 5 | #include "qaccessibleplugin.h" |
| 6 | #include "qaccessibleobject.h" |
| 7 | #include "qaccessiblebridge.h" |
| 8 | #include <QtGui/QGuiApplication> |
| 9 | |
| 10 | #include <QDebug> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | using namespace Qt::StringLiterals; |
| 15 | |
| 16 | #if QT_CONFIG(accessibility) |
| 17 | |
| 18 | /* accessiblebridge plugin discovery stuff */ |
| 19 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, bridgeloader, |
| 20 | (QAccessibleBridgeFactoryInterface_iid, "/accessiblebridge"_L1)) |
| 21 | |
| 22 | Q_GLOBAL_STATIC(QList<QAccessibleBridge *>, bridges) |
| 23 | |
| 24 | /*! |
| 25 | \class QPlatformAccessibility |
| 26 | \since 5.0 |
| 27 | \internal |
| 28 | \preliminary |
| 29 | \ingroup qpa |
| 30 | \ingroup accessibility |
| 31 | |
| 32 | \brief The QPlatformAccessibility class is the base class for |
| 33 | integrating accessibility backends |
| 34 | |
| 35 | \sa QAccessible |
| 36 | */ |
| 37 | QPlatformAccessibility::QPlatformAccessibility() |
| 38 | : m_active(false) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | QPlatformAccessibility::~QPlatformAccessibility() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void QPlatformAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) |
| 47 | { |
| 48 | initialize(); |
| 49 | |
| 50 | if (!bridges() || bridges()->isEmpty()) |
| 51 | return; |
| 52 | |
| 53 | for (int i = 0; i < bridges()->size(); ++i) |
| 54 | bridges()->at(i)->notifyAccessibilityUpdate(event); |
| 55 | } |
| 56 | |
| 57 | void QPlatformAccessibility::setRootObject(QObject *o) |
| 58 | { |
| 59 | initialize(); |
| 60 | if (bridges()->isEmpty()) |
| 61 | return; |
| 62 | |
| 63 | if (!o) |
| 64 | return; |
| 65 | |
| 66 | for (int i = 0; i < bridges()->size(); ++i) { |
| 67 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(o); |
| 68 | bridges()->at(i)->setRootObject(iface); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void QPlatformAccessibility::initialize() |
| 73 | { |
| 74 | static bool isInit = false; |
| 75 | if (isInit) |
| 76 | return; |
| 77 | isInit = true; // ### not atomic |
| 78 | |
| 79 | typedef QMultiMap<int, QString> PluginKeyMap; |
| 80 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; |
| 81 | |
| 82 | const PluginKeyMap keyMap = bridgeloader()->keyMap(); |
| 83 | QAccessibleBridgePlugin *factory = nullptr; |
| 84 | int i = -1; |
| 85 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); |
| 86 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { |
| 87 | if (it.key() != i) { |
| 88 | i = it.key(); |
| 89 | factory = qobject_cast<QAccessibleBridgePlugin*>(object: bridgeloader()->instance(index: i)); |
| 90 | } |
| 91 | if (factory) |
| 92 | if (QAccessibleBridge *bridge = factory->create(key: it.value())) |
| 93 | bridges()->append(t: bridge); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void QPlatformAccessibility::cleanup() |
| 98 | { |
| 99 | qDeleteAll(c: *bridges()); |
| 100 | } |
| 101 | |
| 102 | void QPlatformAccessibility::setActive(bool active) |
| 103 | { |
| 104 | m_active = active; |
| 105 | QAccessible::setActive(active); |
| 106 | } |
| 107 | |
| 108 | #endif // QT_CONFIG(accessibility) |
| 109 | |
| 110 | QT_END_NAMESPACE |
| 111 |
