Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmaccessibility.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QWASMACCESIBILITY_H
6#define QWASMACCESIBILITY_H
7
8#include <QtCore/qtconfigmacros.h>
9#include <QtGui/qtguiglobal.h>
10
11#include <QtCore/qhash.h>
12#include <private/qstdweb_p.h>
13#include <qpa/qplatformaccessibility.h>
14
15#include <emscripten/val.h>
16#include <QLoggingCategory>
17
18#include <map>
19#include <emscripten/bind.h>
20
21Q_DECLARE_LOGGING_CATEGORY(lcQpaAccessibility)
22
24
25#if !QT_CONFIG(accessibility)
26class QWasmAccessibility
27{
28public:
29 static void addAccessibilityEnableButton(QWindow *window) {}
30 static void onShowWindow(QWindow *) {}
31 static void onRemoveWindow(QWindow *) {}
32 static bool isEnabled() {
33 return false;
34 }
35 static void enable() {}
36 static bool setFocusObject(QObject *object) { return false; }
37};
38#else
39class QWasmAccessibility : public QPlatformAccessibility
40{
41public:
42 QWasmAccessibility();
43 ~QWasmAccessibility();
44
45 static void addAccessibilityEnableButton(QWindow *window);
46 static void onShowWindow(QWindow *);
47 static void onRemoveWindow(QWindow *);
48 static bool isEnabled();
49 static void enable();
50 static bool setFocusObject(QObject *object);
51
52private:
53 static QWasmAccessibility *instance();
54
55 void addEnableButton(QWindow *window);
56 void enableAccessibility();
57 void removeWindow(QWindow *window);
58 bool setFocusObjectImpl(QObject *object);
59
60#ifndef QT_NO_DEBUG
61 std::string logElementParentChain(emscripten::val element, QAccessibleInterface *iface, std::string tab = "");
62#endif
63
64 emscripten::val getDescribedByContainer(QWindow *window);
65 emscripten::val getDescribedByContainer(QAccessibleInterface *iface);
66 emscripten::val getElementContainer(QWindow *window);
67 emscripten::val getElementContainer(QAccessibleInterface *iface);
68 emscripten::val getDocument(const emscripten::val &container);
69 QWindow *getWindow(QAccessibleInterface *iface);
70 bool isFocusInChildWindow(QAccessibleInterface *iface);
71 bool isWindowNode(QAccessibleInterface *iface);
72
73 emscripten::val createHtmlElement(QAccessibleInterface *iface);
74 void destroyHtmlElement(QAccessibleInterface *iface);
75 emscripten::val getHtmlElement(QAccessibleInterface *iface);
76 void repairLinks(QAccessibleInterface *iface);
77 void linkToParent(QAccessibleInterface *iface);
78 void setHtmlElementVisibility(QAccessibleInterface *iface, bool visible);
79 void setHtmlElementGeometry(QAccessibleInterface *iface);
80 void setHtmlElementGeometry(emscripten::val element, QRect geometry);
81 bool setHtmlElementFocus(QAccessibleInterface *iface);
82 void setHtmlElementDisabled(QAccessibleInterface *iface);
83 void setHtmlElementOrientation(emscripten::val element, QAccessibleInterface *iface);
84
85 void handleListItemUpdate(QAccessibleEvent *event);
86 void handleStaticTextUpdate(QAccessibleEvent *event);
87 void handleButtonUpdate(QAccessibleEvent *event);
88 void handleCheckBoxUpdate(QAccessibleEvent *event);
89 void handleGroupBoxUpdate(QAccessibleEvent *event);
90 void handleSwitchUpdate(QAccessibleEvent *event);
91 void handleDialogUpdate(QAccessibleEvent *event);
92 void handleMenuUpdate(QAccessibleEvent *event);
93 void handleToolUpdate(QAccessibleEvent *event);
94 void handleLineEditUpdate(QAccessibleEvent *event);
95 void handleRadioButtonUpdate(QAccessibleEvent *event);
96 void handleDialUpdate(QAccessibleEvent *event);
97 void handleSpinBoxUpdate(QAccessibleEvent *event);
98 void handlePageTabUpdate(QAccessibleEvent *event);
99 void handleSliderUpdate(QAccessibleEvent *event);
100 void handleScrollBarUpdate(QAccessibleEvent *event);
101 void handlePageTabListUpdate(QAccessibleEvent *event);
102 void handleIdentifierUpdate(QAccessibleInterface *iface);
103 void handleDescriptionChanged(QAccessibleInterface *iface);
104 void handleAnnouncement(QAccessibleInterface *iface,
105 QAccessibleAnnouncementEvent *announcementEvent);
106 void handleProgressBarUpdate(QAccessibleEvent *event);
107
108 void handleEventFromHtmlElement(const emscripten::val event);
109
110 void populateAccessibilityTree(QAccessibleInterface *iface);
111 void createObject(QAccessibleInterface *iface);
112 void removeObject(QAccessible::Id id);
113 void unlinkParentForChildren(QAccessibleInterface *iface);
114 void relinkParentForChildren(QAccessibleInterface *iface);
115
116 void notifyAccessibilityUpdate(QAccessibleEvent *event) override;
117 bool handleUpdateByEventType(QAccessibleEvent *event);
118 void handleUpdateByInterfaceRole(QAccessibleEvent *event);
119
120 void setAttribute(emscripten::val element, const std::string &attr, const std::string &val);
121 void setAttribute(emscripten::val element, const std::string &attr, const char *val);
122 void setAttribute(emscripten::val element, const std::string &attr, bool val);
123
124 void setProperty(emscripten::val element, const std::string &attr, const std::string &val);
125 void setProperty(emscripten::val element, const std::string &attr, const char *val);
126 void setProperty(emscripten::val element, const std::string &attr, bool val);
127
128 void setNamedAttribute(QAccessibleInterface *iface, const std::string &attribute, QAccessible::Text text);
129 void setNamedProperty(QAccessibleInterface *iface, const std::string &property, QAccessible::Text text);
130
131 void addEventListener(QAccessibleInterface *, emscripten::val element, const char *eventType);
132 void sendEvent(QAccessibleInterface *iface, QAccessible::Event eventType);
133
134private:
135 std::map<QWindow *, std::tuple<emscripten::val, std::shared_ptr<qstdweb::EventCallback>>> m_enableButtons;
136 QHash<QAccessible::Id, emscripten::val> m_elements;
137 int m_eventHandlerIndex;
138
139 // To handle the case where a button in a dialog is focused while the dialog is invisible
140 QAccessible::Id m_focusId = 0;
141
142 // To break focus loops
143 emscripten::val m_isSettingFocusIface = emscripten::val::undefined();
144
145 // Set while setHtmlElementFocus() moves the dom focus to follow Qt
146 bool m_isFollowingQtFocus = false;
147};
148
149#endif // QT_CONFIG(accessibility)
150
151#endif
void QWasmAccessibilityEnable()