Add QAccessible::ActivationObserver

Makes it possible to follow changes in activation an deactivation of a11y.
Needed for WebEngine to know when to activate a11y.

Change-Id: Ia264a76974224d1baad3e88c34a4b8a9f1a3695d
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Frederik Gladhorn 2014-08-04 17:48:42 +02:00
parent 9d19be5994
commit 9ba3145f79
4 changed files with 68 additions and 2 deletions

View File

@ -465,9 +465,11 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
#endif
#endif
// FIXME turn this into one global static struct
Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins);
Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
QAccessible::UpdateHandler QAccessible::updateHandler = 0;
QAccessible::RootObjectHandler QAccessible::rootObjectHandler = 0;
@ -504,6 +506,7 @@ void QAccessible::cleanup()
static void qAccessibleCleanup()
{
qAccessibleActivationObservers()->clear();
qAccessibleFactories()->clear();
}
@ -603,6 +606,44 @@ QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectH
return old;
}
/*!
\class QAccessible::ActivationObserver
\internal
Interface to listen to activation or deactivation of the accessibility framework.
\sa installActivationObserver()
*/
/*!
\internal
Install \a observer to get notified of activation or deactivation (global accessibility has been enabled or disabled).
*/
void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
{
if (!observer)
return;
if (!cleanupAdded) {
qAddPostRoutine(qAccessibleCleanup);
cleanupAdded = true;
}
if (qAccessibleActivationObservers()->contains(observer))
return;
qAccessibleActivationObservers()->append(observer);
}
/*!
\internal
Remove an \a observer to no longer get notified of state changes.
\sa installActivationObserver()
*/
void QAccessible::removeActivationObserver(ActivationObserver *observer)
{
qAccessibleActivationObservers()->removeAll(observer);
}
/*!
If a QAccessibleInterface implementation exists for the given \a object,
this function returns a pointer to the implementation; otherwise it
@ -756,6 +797,15 @@ bool QAccessible::isActive()
return false;
}
/*!
\internal
*/
void QAccessible::setActive(bool active)
{
for (int i = 0; i < qAccessibleActivationObservers()->count() ;++i)
qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
}
/*!
Sets the root object of the accessible objects of this application

View File

@ -352,6 +352,15 @@ public:
static UpdateHandler installUpdateHandler(UpdateHandler);
static RootObjectHandler installRootObjectHandler(RootObjectHandler);
class ActivationObserver
{
public:
virtual ~ActivationObserver() {}
virtual void accessibilityActiveChanged(bool active) = 0;
};
static void installActivationObserver(ActivationObserver *);
static void removeActivationObserver(ActivationObserver *);
static QAccessibleInterface *queryAccessibleInterface(QObject *);
static Id uniqueId(QAccessibleInterface *iface);
static QAccessibleInterface *accessibleInterface(Id uniqueId);
@ -365,6 +374,7 @@ public:
static void updateAccessibility(QAccessibleEvent *event);
static bool isActive();
static void setActive(bool active);
static void setRootObject(QObject *object);
static void cleanup();

View File

@ -139,6 +139,12 @@ void QPlatformAccessibility::cleanup()
qDeleteAll(*bridges());
}
void QPlatformAccessibility::setActive(bool active)
{
m_active = active;
QAccessible::setActive(active);
}
#endif // QT_NO_ACCESSIBILITY
QT_END_NAMESPACE

View File

@ -70,7 +70,7 @@ public:
virtual void cleanup();
inline bool isActive() const { return m_active; }
inline void setActive(bool active) { m_active = active; }
void setActive(bool active);
private:
bool m_active;