File indexing completed on 2024-12-08 04:19:12

0001 /*
0002     SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef QACCESSIBILITYCLIENT_REGISTRY_P_H
0008 #define QACCESSIBILITYCLIENT_REGISTRY_P_H
0009 
0010 #include <atspi/atspi-constants.h>
0011 
0012 #include <QObject>
0013 #include <QMap>
0014 #include <QDBusContext>
0015 #include <QSignalMapper>
0016 #include <QSharedPointer>
0017 
0018 #include "atspi/dbusconnection.h"
0019 #include "qaccessibilityclient/registry.h"
0020 #include "qaccessibilityclient/accessibleobject.h"
0021 #include "qaccessibilityclient/accessibleobject_p.h"
0022 #include "atspi/qt-atspi.h"
0023 #include "cachestrategy_p.h"
0024 
0025 class QDBusPendingCallWatcher;
0026 
0027 namespace QAccessibleClient {
0028 
0029 class DBusConnection;
0030 
0031 class RegistryPrivate :public QObject, public QDBusContext
0032 {
0033     Q_OBJECT
0034 public:
0035     RegistryPrivate(Registry *qq);
0036     ~RegistryPrivate() override;
0037 
0038     void init();
0039 
0040     bool isEnabled() const;
0041     void setEnabled(bool enable);
0042     bool isScreenReaderEnabled() const;
0043     void setScreenReaderEnabled(bool enable);
0044 
0045     QUrl url(const AccessibleObject &object) const;
0046     AccessibleObject fromUrl(const QUrl &url) const;
0047 
0048     void subscribeEventListeners(const Registry::EventListeners & listeners);
0049     Registry::EventListeners eventListeners() const;
0050 
0051     QString accessibleId(const AccessibleObject &object) const;
0052     QString name(const AccessibleObject &object) const;
0053     QString description(const AccessibleObject &object) const;
0054     AccessibleObject::Role role(const AccessibleObject &object) const;
0055     QString roleName(const AccessibleObject &object) const;
0056     QString localizedRoleName(const AccessibleObject &object) const;
0057     quint64 state(const AccessibleObject &object) const;
0058     int layer(const AccessibleObject &object) const;
0059     int mdiZOrder(const AccessibleObject &object) const;
0060     double alpha(const AccessibleObject &object) const;
0061     QRect boundingRect(const AccessibleObject &object) const;
0062     QRect characterRect(const AccessibleObject &object, int offset) const;
0063     AccessibleObject::Interfaces supportedInterfaces(const AccessibleObject &object) const;
0064 
0065     int caretOffset(const AccessibleObject &object) const;
0066     int characterCount(const AccessibleObject &object) const;
0067     QList< QPair<int,int> > textSelections(const AccessibleObject &object) const;
0068     void setTextSelections(const AccessibleObject &object, const QList< QPair<int,int> > &selections);
0069     QString text(const AccessibleObject &object, int startOffset = 0, int endOffset = -1) const;
0070     QString textWithBoundary(const AccessibleObject &object, int offset, AccessibleObject::TextBoundary boundary, int *startOffset, int *endOffset) const;
0071 
0072     bool setText(const AccessibleObject &object, const QString &text);
0073     bool insertText(const AccessibleObject &object, const QString &text, int position, int length = -1);
0074     bool copyText(const AccessibleObject &object, int startPos, int endPos);
0075     bool cutText(const AccessibleObject &object, int startPos, int endPos);
0076     bool deleteText(const AccessibleObject &object, int startPos, int endPos);
0077     bool pasteText(const AccessibleObject &object, int position);
0078 
0079     AccessibleObject application(const AccessibleObject &object) const;
0080     QString appToolkitName(const AccessibleObject &object) const;
0081     QString appVersion(const AccessibleObject &object) const;
0082     int appId(const AccessibleObject &object) const;
0083     QString appLocale(const AccessibleObject &object, uint lctype) const;
0084     QString appBusAddress(const AccessibleObject &object) const;
0085 
0086     double minimumValue(const AccessibleObject &object) const;
0087     double maximumValue(const AccessibleObject &object) const;
0088     double minimumValueIncrement(const AccessibleObject &object) const;
0089     double currentValue(const AccessibleObject &object) const;
0090     bool setCurrentValue(const AccessibleObject &object, double value);
0091 
0092     QList<AccessibleObject> selection(const AccessibleObject &object) const;
0093 
0094     QString imageDescription(const AccessibleObject &object) const;
0095     QString imageLocale(const AccessibleObject &object) const;
0096     QRect imageRect(const AccessibleObject &object) const;
0097 
0098     QVector< QSharedPointer<QAction> > actions(const AccessibleObject &object);
0099 
0100     QList<AccessibleObject> topLevelAccessibles() const;
0101     AccessibleObject parentAccessible(const AccessibleObject &object) const;
0102 
0103     int childCount(const AccessibleObject &object) const;
0104     int indexInParent(const AccessibleObject &object) const;
0105     AccessibleObject child(const AccessibleObject &object, int index) const;
0106     QList<AccessibleObject> children(const AccessibleObject &object) const;
0107 
0108     static QString ACCESSIBLE_OBJECT_SCHEME_STRING;
0109 
0110 private Q_SLOTS:
0111     AccessibleObject accessibleFromPath(const QString &service, const QString &path) const;
0112     AccessibleObject accessibleFromReference(const QSpiObjectReference &reference) const;
0113     AccessibleObject accessibleFromContext() const;
0114 
0115     void connectionFetched();
0116     void slotSubscribeEventListenerFinished(QDBusPendingCallWatcher *call);
0117     void a11yConnectionChanged(const QString &interface,const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
0118 
0119     void slotPropertyChange(const QString &property, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0120     void slotWindowCreate(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0121     void slotWindowDestroy(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0122     void slotWindowClose(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0123     void slotWindowReparent(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0124     void slotWindowMinimize(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0125     void slotWindowMaximize(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0126     void slotWindowRestore(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0127     void slotWindowActivate(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0128     void slotWindowDeactivate(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0129     void slotWindowDesktopCreate(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0130     void slotWindowDesktopDestroy(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0131     void slotWindowRaise(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0132     void slotWindowLower(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0133     void slotWindowMove(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0134     void slotWindowResize(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0135     void slotWindowShade(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0136     void slotWindowUnshade(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0137 
0138     void slotStateChanged(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0139     //void slotPropertyChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0140     //void slotBoundsChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0141     //void slotLinkSelected(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0142 
0143     void slotChildrenChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0144     void slotVisibleDataChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0145     void slotSelectionChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0146     void slotModelChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0147 
0148     void slotTextCaretMoved(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0149     void slotTextSelectionChanged(const QString &state, int detail1, int detail2, const QDBusVariant &/*args*/, const QAccessibleClient::QSpiObjectReference &reference);
0150 
0151     //void slotTextBoundsChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0152     void slotTextChanged(const QString &state, int start, int end, const QDBusVariant &text, const QAccessibleClient::QSpiObjectReference &reference);
0153     //void slotTextAttributesChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0154     //void slotAttributesChanged(const QString &state, int detail1, int detail2, const QDBusVariant &args, const QAccessibleClient::QSpiObjectReference &reference);
0155 
0156     void actionTriggered(const QString &action);
0157 
0158 private:
0159     QVariant getProperty ( const QString &service, const QString &path, const QString &interface, const QString &name ) const;
0160     static AccessibleObject::Role atspiRoleToRole(AtspiRole role);
0161 
0162     DBusConnection conn;
0163     QSignalMapper m_actionMapper;
0164     Registry *const q;
0165     Registry::EventListeners m_subscriptions;
0166     Registry::EventListeners m_pendingSubscriptions;
0167     QHash<QString, AccessibleObject::Interface> interfaceHash;
0168     QSignalMapper m_eventMapper;
0169     ObjectCache *m_cache = nullptr;
0170 //     typedef QMap<QString, QSharedPointer<AccessibleObjectPrivate> >::Iterator AccessibleObjectsHashIterator;
0171 //     typedef QMap<QString, QSharedPointer<AccessibleObjectPrivate> >::ConstIterator AccessibleObjectsHashConstIterator;
0172 //     QMap<QString, QSharedPointer<AccessibleObjectPrivate> > accessibleObjectsHash;
0173     bool removeAccessibleObject(const QAccessibleClient::AccessibleObject &accessible);
0174     bool removeAccessibleObject(const QAccessibleClient::QSpiObjectReference &reference);
0175 
0176     friend class Registry;
0177     friend class AccessibleObject;
0178     friend class AccessibleObjectPrivate;
0179 };
0180 
0181 }
0182 
0183 #endif