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
4#ifndef QACCESSIBLEQUICKITEM_H
5#define QACCESSIBLEQUICKITEM_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/QQuickItem>
19#include <QtQuick/QQuickView>
20#include <QtGui/qaccessibleobject.h>
21#include <QtQuick/private/qtquickglobal_p.h>
22
23QT_BEGIN_NAMESPACE
24
25#if QT_CONFIG(accessibility)
26
27class QTextDocument;
28
29class Q_QUICK_PRIVATE_EXPORT QAccessibleQuickItem : public QAccessibleObject, public QAccessibleActionInterface, public QAccessibleValueInterface, public QAccessibleTextInterface
30{
31public:
32 QAccessibleQuickItem(QQuickItem *item);
33
34 QWindow *window() const override;
35
36 QRect rect() const override;
37 QRect viewRect() const;
38
39 bool clipsChildren() const;
40 QAccessibleInterface *childAt(int x, int y) const override;
41
42 QAccessibleInterface *parent() const override;
43 QAccessibleInterface *child(int index) const override;
44 int childCount() const override;
45 int indexOfChild(const QAccessibleInterface *iface) const override;
46 QList<QQuickItem *> childItems() const;
47
48 QAccessible::State state() const override;
49 QAccessible::Role role() const override;
50 QString text(QAccessible::Text) const override;
51 void setText(QAccessible::Text, const QString &text) override;
52
53 bool isAccessible() const;
54
55 // Action Interface
56 QStringList actionNames() const override;
57 void doAction(const QString &actionName) override;
58 QStringList keyBindingsForAction(const QString &actionName) const override;
59
60 // Value Interface
61 QVariant currentValue() const override;
62 void setCurrentValue(const QVariant &value) override;
63 QVariant maximumValue() const override;
64 QVariant minimumValue() const override;
65 QVariant minimumStepSize() const override;
66
67
68 // Text Interface
69 void selection(int selectionIndex, int *startOffset, int *endOffset) const override;
70 int selectionCount() const override;
71 void addSelection(int startOffset, int endOffset) override;
72 void removeSelection(int selectionIndex) override;
73 void setSelection(int selectionIndex, int startOffset, int endOffset) override;
74
75 // cursor
76 int cursorPosition() const override;
77 void setCursorPosition(int position) override;
78
79 // text
80 QString text(int startOffset, int endOffset) const override;
81 QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
82 int *startOffset, int *endOffset) const override;
83 QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
84 int *startOffset, int *endOffset) const override;
85 QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
86 int *startOffset, int *endOffset) const override;
87 int characterCount() const override;
88
89 // character <-> geometry
90 QRect characterRect(int /* offset */) const override { return QRect(); }
91 int offsetAtPoint(const QPoint & /* point */) const override { return -1; }
92
93 void scrollToSubstring(int /* startIndex */, int /* endIndex */) override {}
94 QString attributes(int /* offset */, int *startOffset, int *endOffset) const override
95 { *startOffset = 0; *endOffset = 0; return QString(); }
96
97 QTextDocument *textDocument() const;
98
99protected:
100 QQuickItem *item() const { return static_cast<QQuickItem*>(object()); }
101 void *interface_cast(QAccessible::InterfaceType t) override;
102
103private:
104 // for Text nodes:
105 QTextDocument *m_doc;
106 typedef QHash<int, QAccessible::Id> ChildCache;
107 mutable ChildCache m_childToId;
108
109};
110
111QRect itemScreenRect(QQuickItem *item);
112QList<QQuickItem *> accessibleUnignoredChildren(QQuickItem *item, bool paintOrder = false);
113
114#endif // accessibility
115
116QT_END_NAMESPACE
117
118#endif // QACCESSIBLEQUICKITEM_H
119

source code of qtdeclarative/src/quick/accessible/qaccessiblequickitem_p.h