1
/****************************************************************************
3
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
5
** This file is part of the QtGui module of the Qt Toolkit.
7
** This file may be used under the terms of the GNU General Public
8
** License versions 2.0 or 3.0 as published by the Free Software
9
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
10
** included in the packaging of this file. Alternatively you may (at
11
** your option) use any later version of the GNU General Public
12
** License if such license has been publicly approved by Trolltech ASA
13
** (or its successors, if any) and the KDE Free Qt Foundation. In
14
** addition, as a special exception, Trolltech gives you certain
15
** additional rights. These rights are described in the Trolltech GPL
16
** Exception version 1.2, which can be found at
17
** http://www.trolltech.com/products/qt/gplexception/ and in the file
18
** GPL_EXCEPTION.txt in this package.
20
** Please review the following information to ensure GNU General
21
** Public Licensing requirements will be met:
22
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
23
** you are unsure which license is appropriate for your use, please
24
** review the following information:
25
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
26
** or contact the sales department at sales@trolltech.com.
28
** In addition, as a special exception, Trolltech, as the sole
29
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
30
** Integration plug-in the right for the Qt/Eclipse Integration to
31
** link to functionality provided by Qt Designer and its related
34
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
35
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
36
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
39
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
40
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42
****************************************************************************/
44
#ifndef QACCESSIBLE_MAC_P_H
45
#define QACCESSIBLE_MAC_P_H
51
// This file is not part of the Qt API. It exists purely as an
52
// implementation detail. This header file may change from version to
53
// version without notice, or even be removed.
60
#include <private/qt_mac_p.h>
61
#include <qaccessible.h>
65
//#define Q_ACCESSIBLE_MAC_DEBUG
70
QAccessibleInterfaceWrapper wraps QAccessibleInterface and adds
71
a ref count. QAccessibleInterfaceWrapper is a "by-value" class.
73
class Q_AUTOTEST_EXPORT QAccessibleInterfaceWrapper
76
QAccessibleInterfaceWrapper()
77
: interface(0), childrenIsRegistered(new bool(false)), refCount(new int(1)) { }
79
QAccessibleInterfaceWrapper(QAccessibleInterface *interface)
80
:interface(interface), childrenIsRegistered(new bool(false)), refCount(new int(1)) { }
82
~QAccessibleInterfaceWrapper()
84
if (--(*refCount) == 0) {
87
delete childrenIsRegistered;
91
QAccessibleInterfaceWrapper(const QAccessibleInterfaceWrapper &other)
92
:interface(other.interface), childrenIsRegistered(other.childrenIsRegistered), refCount(other.refCount)
97
void operator=(const QAccessibleInterfaceWrapper &other)
99
if (other.interface == interface)
102
if (--(*refCount) == 0) {
105
delete childrenIsRegistered;
108
interface = other.interface;
109
childrenIsRegistered = other.childrenIsRegistered;
110
refCount = other.refCount;
114
QAccessibleInterface *interface;
115
bool *childrenIsRegistered;
121
QAInterface represents one accessiblity item. It hides the fact that
122
one QAccessibleInterface may represent more than one item, and it also
123
automates the memory management for QAccessibleInterfaces using the
124
QAccessibleInterfaceWrapper wrapper class.
126
It has the same API as QAccessibleInterface, minus the child parameter
129
class Q_AUTOTEST_EXPORT QAInterface : public QAccessible
133
: base(QAccessibleInterfaceWrapper())
136
QAInterface(QAccessibleInterface *interface, int child = 0)
138
if (interface == 0 || child > interface->childCount()) {
139
base = QAccessibleInterfaceWrapper();
141
base = QAccessibleInterfaceWrapper(interface);
142
m_cachedObject = interface->object();
147
QAInterface(QAccessibleInterfaceWrapper wrapper, int child = 0)
148
:base(wrapper), m_cachedObject(wrapper.interface->object()), child(child)
151
QAInterface(const QAInterface &other, int child)
153
if (other.isValid() == false || child > other.childCount()) {
154
base = QAccessibleInterfaceWrapper();
157
m_cachedObject = other.m_cachedObject;
162
bool operator==(const QAInterface &other) const;
163
bool operator!=(const QAInterface &other) const;
165
inline QString actionText (int action, Text text) const
166
{ return base.interface->actionText(action, text, child); }
168
QAInterface childAt(int x, int y) const
171
return QAInterface();
173
const int foundChild = base.interface->childAt(x, y);
175
if (foundChild == -1)
176
return QAInterface();
179
return navigate(QAccessible::Child, foundChild);
181
if (foundChild == child)
183
return QAInterface();
186
int indexOfChild(const QAInterface &child) const
191
if (*this != child.parent())
194
if (object() == child.object())
197
return base.interface->indexOfChild(child.base.interface);
200
inline int childCount() const
207
return base.interface->childCount();
210
QList<QAInterface> children() const
213
return QList<QAInterface>();
215
QList<QAInterface> children;
216
for (int i = 1; i <= childCount(); ++i) {
217
children.append(navigate(QAccessible::Child, i));
222
QAInterface childAt(int index) const
224
return navigate(QAccessible::Child, index);
227
inline void doAction(int action, const QVariantList ¶ms = QVariantList()) const
232
base.interface->doAction(action, child, params);
235
QAInterface navigate(RelationFlag relation, int entry) const;
237
inline QObject * object() const
242
return base.interface->object();
245
QAInterface objectInterface() const
248
return QAInterface();
250
QObject *obj = object();
251
QAInterface current = *this;
254
QAInterface parent = current.parent();
255
if (parent.isValid() == false)
257
obj = parent.object();
263
inline HIObjectRef hiObject() const
267
QWidget * const widget = qobject_cast<QWidget * const>(object());
269
return (HIObjectRef)widget->winId();
274
inline QObject * cachedObject() const
278
return m_cachedObject;
281
inline QRect rect() const
285
return base.interface->rect(child);
288
inline Role role() const
291
return QAccessible::NoRole;
292
return base.interface->role(child);
295
inline void setText(Text t, const QString &text) const
299
base.interface->setText(t, child, text);
302
inline State state() const
306
return base.interface->state(child);
309
inline QString text (Text text) const
313
return base.interface->text(text, child);
316
inline QString value() const
317
{ return text(QAccessible::Value); }
319
inline QString name() const
320
{ return text(QAccessible::Name); }
322
inline int userActionCount() const
326
return base.interface->userActionCount(child);
329
inline QString className() const
333
return QLatin1String(base.interface->object()->metaObject()->className());
336
inline bool isHIView() const
337
{ return (child == 0 && object() != 0); }
339
inline int id() const
342
inline bool isValid() const
344
return (base.interface != 0 && base.interface->isValid());
347
QAInterface parent() const
348
{ return navigate(QAccessible::Ancestor, 1); }
350
QAccessibleInterfaceWrapper interfaceWrapper() const
354
bool checkValid() const
356
const bool valid = isValid();
357
#ifdef Q_ACCESSIBLE_MAC_DEBUG
359
qFatal("QAccessible_mac: tried to use invalid interface.");
364
QAccessibleInterfaceWrapper base;
365
QObject *m_cachedObject;
369
Q_AUTOTEST_EXPORT QDebug operator<<(QDebug debug, const QAInterface &interface);
372
QAElement is a thin wrapper around an AXUIElementRef that automates
375
class Q_AUTOTEST_EXPORT QAElement
379
explicit QAElement(AXUIElementRef elementRef);
380
QAElement(const QAElement &element);
381
QAElement(HIObjectRef, int child);
384
inline HIObjectRef object() const
386
return AXUIElementGetHIObject(elementRef);
389
inline int id() const
392
AXUIElementGetIdentifier(elementRef, &id);
396
inline AXUIElementRef element() const
401
inline bool isValid() const
403
return (elementRef != 0);
406
void operator=(const QAElement &other);
407
bool operator==(const QAElement &other) const;
409
AXUIElementRef elementRef;
413
class QInterfaceFactory
416
virtual QAInterface interface(UInt64 identifier) = 0;
417
virtual QAElement element(int id) = 0;
418
virtual QAElement element(const QAInterface &interface)
420
return element(interface.id());
422
virtual void registerChildren() = 0;
423
virtual ~QInterfaceFactory() {}
427
QAccessibleHierarchyManager bridges the Mac and Qt accessibility hierarchies.
428
There is a one-to-one relationship between QAElements on the Mac side
429
and QAInterfaces on the Qt side, and this class provies lookup funcitons
430
that translates between these to items.
432
The identity of a QAInterface is determined by its QAccessibleInterface and
433
child identifier, and the identity of a QAElement is determined by its
434
HIObjectRef and identifier.
436
QAccessibleHierarchyManager receives QObject::destroyed() signals and deletes
437
the accessibility objects for destroyed objects.
439
class Q_AUTOTEST_EXPORT QAccessibleHierarchyManager : public QObject
443
~QAccessibleHierarchyManager() { reset(); }
444
static QAccessibleHierarchyManager *instance();
447
QAElement registerInterface(QObject *object, int child);
448
QAElement registerInterface(const QAInterface &interface);
449
void registerInterface(QObject *object, HIObjectRef hiobject, QInterfaceFactory *interfaceFactory);
451
void registerChildren(const QAInterface &interface);
453
QAInterface lookup(const AXUIElementRef &element);
454
QAInterface lookup(const QAElement &element);
455
QAElement lookup(const QAInterface &interface);
456
QAElement lookup(QObject * const object, int id);
458
void objectDestroyed(QObject *);
460
typedef QHash<QObject *, QInterfaceFactory *> QObjectElementHash;
461
typedef QHash<HIObjectRef, QInterfaceFactory *> HIObjectInterfaceHash;
462
typedef QHash<QObject *, HIObjectRef> QObjectHIObjectHash;
464
QObjectElementHash qobjectElementHash;
465
HIObjectInterfaceHash hiobjectInterfaceHash;
466
QObjectHIObjectHash qobjectHiobjectHash;
469
Q_AUTOTEST_EXPORT bool isItInteresting(const QAInterface &interface);