SPI Accessibility: Remove global variable
Change it into a member variable of QSpiAccessibleBridge. Task-number: QTBUG-83255 Change-Id: Ia781a7c86723e343680bf804be6393640f83a516 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
563fbe79e5
commit
23282ac23d
@ -38,6 +38,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "atspiadaptor_p.h"
|
||||
#include "qspiaccessiblebridge_p.h"
|
||||
|
||||
#include <QtGui/qwindow.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
@ -1364,9 +1365,9 @@ bool AtSpiAdaptor::accessibleInterface(QAccessibleInterface *interface, const QS
|
||||
} else if (function == QLatin1String("GetName")) {
|
||||
sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Name))));
|
||||
} else if (function == QLatin1String("GetRoleName")) {
|
||||
sendReply(connection, message, qSpiRoleMapping[interface->role()].name());
|
||||
sendReply(connection, message, QSpiAccessibleBridge::namesForRole(interface->role()).name());
|
||||
} else if (function == QLatin1String("GetLocalizedRoleName")) {
|
||||
sendReply(connection, message, QVariant::fromValue(qSpiRoleMapping[interface->role()].localizedName()));
|
||||
sendReply(connection, message, QVariant::fromValue(QSpiAccessibleBridge::namesForRole(interface->role()).localizedName()));
|
||||
} else if (function == QLatin1String("GetChildCount")) {
|
||||
sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->childCount())));
|
||||
} else if (function == QLatin1String("GetIndexInParent")) {
|
||||
@ -1450,7 +1451,7 @@ AtspiRole AtSpiAdaptor::getRole(QAccessibleInterface *interface) const
|
||||
{
|
||||
if ((interface->role() == QAccessible::EditableText) && interface->state().passwordEdit)
|
||||
return ATSPI_ROLE_PASSWORD_TEXT;
|
||||
return qSpiRoleMapping[interface->role()].spiRole();
|
||||
return QSpiAccessibleBridge::namesForRole(interface->role()).spiRole();
|
||||
}
|
||||
|
||||
QStringList AtSpiAdaptor::accessibleInterfaces(QAccessibleInterface *interface) const
|
||||
|
@ -54,8 +54,6 @@
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QHash <QAccessible::Role, RoleNames> qSpiRoleMapping;
|
||||
|
||||
quint64 spiStatesFromQState(QAccessible::State state)
|
||||
{
|
||||
quint64 spiState = 0;
|
||||
|
@ -123,8 +123,6 @@ private:
|
||||
QString m_localizedName;
|
||||
};
|
||||
|
||||
extern QHash <QAccessible::Role, RoleNames> qSpiRoleMapping;
|
||||
|
||||
inline void setSpiStateBit(quint64* state, AtspiStateType spiState)
|
||||
{
|
||||
*state |= quint64(1) << spiState;
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "qspiaccessiblebridge_p.h"
|
||||
|
||||
#include <atspi/atspi-constants.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <qstring.h>
|
||||
|
||||
#include "atspiadaptor_p.h"
|
||||
@ -273,14 +275,29 @@ static RoleMapping map[] = {
|
||||
void QSpiAccessibleBridge::initializeConstantMappings()
|
||||
{
|
||||
for (uint i = 0; i < sizeof(map) / sizeof(RoleMapping); ++i)
|
||||
qSpiRoleMapping.insert(map[i].role, RoleNames(map[i].spiRole, QLatin1String(map[i].name), tr(map[i].name)));
|
||||
m_spiRoleMapping.insert(map[i].role, RoleNames(map[i].spiRole, QLatin1String(map[i].name), tr(map[i].name)));
|
||||
|
||||
// -1 because we have button duplicated, as PushButton and Button.
|
||||
Q_ASSERT_X(qSpiRoleMapping.size() ==
|
||||
Q_ASSERT_X(m_spiRoleMapping.size() ==
|
||||
QAccessible::staticMetaObject.enumerator(
|
||||
QAccessible::staticMetaObject.indexOfEnumerator("Role")).keyCount() - 1,
|
||||
"", "Handle all QAccessible::Role members in qSpiRoleMapping");
|
||||
}
|
||||
|
||||
QSpiAccessibleBridge *QSpiAccessibleBridge::instance()
|
||||
{
|
||||
if (auto integration = QGuiApplicationPrivate::platformIntegration()) {
|
||||
if (auto accessibility = integration->accessibility())
|
||||
return static_cast<QSpiAccessibleBridge *>(accessibility);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RoleNames QSpiAccessibleBridge::namesForRole(QAccessible::Role role)
|
||||
{
|
||||
auto brigde = QSpiAccessibleBridge::instance();
|
||||
return brigde ? brigde->spiRoleNames().value(role) : RoleNames();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
#endif //QT_NO_ACCESSIBILITY
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <QtGui/private/qtguiglobal_p.h>
|
||||
#include <QtDBus/qdbusconnection.h>
|
||||
#include <qpa/qplatformaccessibility.h>
|
||||
#include <QtCore/qhash.h>
|
||||
|
||||
class DeviceEventControllerAdaptor;
|
||||
|
||||
@ -65,11 +66,14 @@ QT_BEGIN_NAMESPACE
|
||||
class DBusConnection;
|
||||
class QSpiDBusCache;
|
||||
class AtSpiAdaptor;
|
||||
struct RoleNames;
|
||||
|
||||
class Q_GUI_EXPORT QSpiAccessibleBridge: public QObject, public QPlatformAccessibility
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using SpiRoleMapping = QHash <QAccessible::Role, RoleNames>;
|
||||
|
||||
QSpiAccessibleBridge();
|
||||
|
||||
virtual ~QSpiAccessibleBridge();
|
||||
@ -77,6 +81,11 @@ public:
|
||||
void notifyAccessibilityUpdate(QAccessibleEvent *event) override;
|
||||
QDBusConnection dBusConnection() const;
|
||||
|
||||
const SpiRoleMapping &spiRoleNames() const { return m_spiRoleMapping; }
|
||||
|
||||
static QSpiAccessibleBridge *instance();
|
||||
static RoleNames namesForRole(QAccessible::Role role);
|
||||
|
||||
public Q_SLOTS:
|
||||
void enabledChanged(bool enabled);
|
||||
|
||||
@ -88,6 +97,7 @@ private:
|
||||
DeviceEventControllerAdaptor *dec;
|
||||
AtSpiAdaptor *dbusAdaptor;
|
||||
DBusConnection* dbusConnection;
|
||||
SpiRoleMapping m_spiRoleMapping;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user