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};
37#else
38class QWasmAccessibility : public QPlatformAccessibility
39{
40public:
41 QWasmAccessibility();
42 ~QWasmAccessibility();
43
44 static QWasmAccessibility* get();
45
46 static void addAccessibilityEnableButton(QWindow *window);
47 static void onShowWindow(QWindow *);
48 static void onRemoveWindow(QWindow *);
49 static bool isEnabled();
50 static void enable();
51
52private:
53 void addAccessibilityEnableButtonImpl(QWindow *window);
54 void enableAccessibility();
55 void onShowWindowImpl(QWindow *);
56 void onRemoveWindowImpl(QWindow *);
57
58 emscripten::val getA11yContainer(QWindow *window);
59 emscripten::val getA11yContainer(QAccessibleInterface *iface);
60 emscripten::val getDescribedByContainer(QWindow *window);
61 emscripten::val getDescribedByContainer(QAccessibleInterface *iface);
62 emscripten::val getElementContainer(QWindow *window);
63 emscripten::val getElementContainer(QAccessibleInterface *iface);
64 emscripten::val getDocument(const emscripten::val &container);
65 emscripten::val getDocument(QAccessibleInterface *iface);
66 QWindow *getWindow(QAccessibleInterface *iface);
67 bool isWindowNode(QAccessibleInterface *iface);
68
69 emscripten::val createHtmlElement(QAccessibleInterface *iface);
70 void destroyHtmlElement(QAccessibleInterface *iface);
71 emscripten::val getHtmlElement(QAccessibleInterface *iface);
72 void repairLinks(QAccessibleInterface *iface);
73 void linkToParent(QAccessibleInterface *iface);
74 void setHtmlElementVisibility(QAccessibleInterface *iface, bool visible);
75 void setHtmlElementGeometry(QAccessibleInterface *iface);
76 void setHtmlElementGeometry(emscripten::val element, QRect geometry);
77 void setHtmlElementFocus(QAccessibleInterface *iface);
78 void setHtmlElementDisabled(QAccessibleInterface *iface);
79 void setHtmlElementOrientation(emscripten::val element, QAccessibleInterface *iface);
80
81 void handleStaticTextUpdate(QAccessibleEvent *event);
82 void handleButtonUpdate(QAccessibleEvent *event);
83 void handleCheckBoxUpdate(QAccessibleEvent *event);
84 void handleGroupBoxUpdate(QAccessibleEvent *event);
85 void handleSwitchUpdate(QAccessibleEvent *event);
86 void handleDialogUpdate(QAccessibleEvent *event);
87 void handleMenuUpdate(QAccessibleEvent *event);
88 void handleToolUpdate(QAccessibleEvent *event);
89 void handleLineEditUpdate(QAccessibleEvent *event);
90 void handleRadioButtonUpdate(QAccessibleEvent *event);
91 void handleSpinBoxUpdate(QAccessibleEvent *event);
92 void handlePageTabUpdate(QAccessibleEvent *event);
93 void handleSliderUpdate(QAccessibleEvent *event);
94 void handleScrollBarUpdate(QAccessibleEvent *event);
95 void handlePageTabListUpdate(QAccessibleEvent *event);
96 void handleIdentifierUpdate(QAccessibleInterface *iface);
97 void handleDescriptionChanged(QAccessibleInterface *iface);
98
99 void handleEventFromHtmlElement(const emscripten::val event);
100
101 void populateAccessibilityTree(QAccessibleInterface *iface);
102 void createObject(QAccessibleInterface *iface);
103 void removeObject(QAccessibleInterface *iface);
104 void unlinkParentForChildren(QAccessibleInterface *iface);
105 void relinkParentForChildren(QAccessibleInterface *iface);
106
107 void notifyAccessibilityUpdate(QAccessibleEvent *event) override;
108 bool handleUpdateByEventType(QAccessibleEvent *event);
109 void handleUpdateByInterfaceRole(QAccessibleEvent *event);
110
111 void setRootObject(QObject *o) override;
112 void initialize() override;
113 void cleanup() override;
114
115 void setAttribute(emscripten::val element, const std::string &attr, const std::string &val);
116 void setAttribute(emscripten::val element, const std::string &attr, const char *val);
117 void setAttribute(emscripten::val element, const std::string &attr, bool val);
118
119 void setProperty(emscripten::val element, const std::string &attr, const std::string &val);
120 void setProperty(emscripten::val element, const std::string &attr, const char *val);
121 void setProperty(emscripten::val element, const std::string &attr, bool val);
122
123 void setNamedAttribute(QAccessibleInterface *iface, const std::string &attribute, QAccessible::Text text);
124 void setNamedProperty(QAccessibleInterface *iface, const std::string &property, QAccessible::Text text);
125
126 void addEventListener(QAccessibleInterface *, emscripten::val element, const char *eventType);
127 void sendEvent(QAccessibleInterface *iface, QAccessible::Event eventType);
128
129private:
130 static QWasmAccessibility *s_instance;
131 QObject *m_rootObject = nullptr;
132 bool m_accessibilityEnabled = false;
133 std::map<QWindow *, std::tuple<emscripten::val, std::shared_ptr<qstdweb::EventCallback>>> m_enableButtons;
134 QHash<QAccessibleInterface *, emscripten::val> m_elements;
135 int m_eventHandlerIndex;
136};
137
138#endif // QT_CONFIG(accessibility)
139
140#endif
void QWasmAccessibilityEnable()