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
4#ifndef QWASMACCESIBILITY_H
5#define QWASMACCESIBILITY_H
6
7#include <QtCore/qtconfigmacros.h>
8#include <QtGui/qtguiglobal.h>
9
10#include <QtCore/qhash.h>
11#include <private/qstdweb_p.h>
12#include <qpa/qplatformaccessibility.h>
13
14#include <emscripten/val.h>
15#include <QLoggingCategory>
16
17#include <map>
18#include <emscripten/bind.h>
19
20Q_DECLARE_LOGGING_CATEGORY(lcQpaAccessibility)
21
23
24#if !QT_CONFIG(accessibility)
25class QWasmAccessibility
26{
27public:
28 static void addAccessibilityEnableButton(QWindow *window) {}
29 static void onShowWindow(QWindow *) {}
30 static void onRemoveWindow(QWindow *) {}
31 static bool isEnabled() {
32 return false;
33 }
34 static void enable() {}
35};
36#else
37class QWasmAccessibility : public QPlatformAccessibility
38{
39public:
40 QWasmAccessibility();
41 ~QWasmAccessibility();
42
43 static QWasmAccessibility* get();
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
51private:
52 void addAccessibilityEnableButtonImpl(QWindow *window);
53 void enableAccessibility();
54 void onShowWindowImpl(QWindow *);
55 void onRemoveWindowImpl(QWindow *);
56
57 emscripten::val getA11yContainer(QWindow *window);
58 emscripten::val getA11yContainer(QAccessibleInterface *iface);
59 emscripten::val getDescribedByContainer(QWindow *window);
60 emscripten::val getDescribedByContainer(QAccessibleInterface *iface);
61 emscripten::val getElementContainer(QWindow *window);
62 emscripten::val getElementContainer(QAccessibleInterface *iface);
63 emscripten::val getDocument(const emscripten::val &container);
64 emscripten::val getDocument(QAccessibleInterface *iface);
65 QWindow *getWindow(QAccessibleInterface *iface);
66 bool isWindowNode(QAccessibleInterface *iface);
67
68 emscripten::val createHtmlElement(QAccessibleInterface *iface);
69 void destroyHtmlElement(QAccessibleInterface *iface);
70 emscripten::val getHtmlElement(QAccessibleInterface *iface);
71 void repairLinks(QAccessibleInterface *iface);
72 void linkToParent(QAccessibleInterface *iface);
73 void setHtmlElementVisibility(QAccessibleInterface *iface, bool visible);
74 void setHtmlElementGeometry(QAccessibleInterface *iface);
75 void setHtmlElementGeometry(emscripten::val element, QRect geometry);
76 void setHtmlElementTextName(QAccessibleInterface *iface);
77 void setHtmlElementTextNameLE(QAccessibleInterface *iface);
78 void setHtmlElementFocus(QAccessibleInterface *iface);
79 void setHtmlElementDisabled(QAccessibleInterface *iface);
80
81 void handleStaticTextUpdate(QAccessibleEvent *event);
82 void handleButtonUpdate(QAccessibleEvent *event);
83 void handleCheckBoxUpdate(QAccessibleEvent *event);
84 void handleDialogUpdate(QAccessibleEvent *event);
85 void handleMenuUpdate(QAccessibleEvent *event);
86 void handleToolUpdate(QAccessibleEvent *event);
87 void handleLineEditUpdate(QAccessibleEvent *event);
88 void handleRadioButtonUpdate(QAccessibleEvent *event);
89 void handleSpinBoxUpdate(QAccessibleEvent *event);
90 void handlePageTabUpdate(QAccessibleEvent *event);
91 void handleSliderUpdate(QAccessibleEvent *event);
92 void handleScrollBarUpdate(QAccessibleEvent *event);
93 void handlePageTabListUpdate(QAccessibleEvent *event);
94 void handleIdentifierUpdate(QAccessibleInterface *iface);
95 void handleDescriptionChanged(QAccessibleInterface *iface);
96
97 void handleEventFromHtmlElement(const emscripten::val event);
98
99 void populateAccessibilityTree(QAccessibleInterface *iface);
100 void createObject(QAccessibleInterface *iface);
101 void removeObject(QAccessibleInterface *iface);
102 void unlinkParentForChildren(QAccessibleInterface *iface);
103 void relinkParentForChildren(QAccessibleInterface *iface);
104
105 void notifyAccessibilityUpdate(QAccessibleEvent *event) override;
106 void setRootObject(QObject *o) override;
107 void initialize() override;
108 void cleanup() override;
109
110 void setAttribute(emscripten::val element, const std::string &attr, const std::string &val);
111 void setAttribute(emscripten::val element, const std::string &attr, const char *val);
112 void setAttribute(emscripten::val element, const std::string &attr, bool val);
113
114 void setProperty(emscripten::val element, const std::string &attr, const std::string &val);
115 void setProperty(emscripten::val element, const std::string &attr, const char *val);
116 void setProperty(emscripten::val element, const std::string &attr, bool val);
117
118 void addEventListener(emscripten::val element, const char *eventType);
119
120private:
121 static QWasmAccessibility *s_instance;
122 QObject *m_rootObject = nullptr;
123 bool m_accessibilityEnabled = false;
124 std::map<QWindow *, std::tuple<emscripten::val, std::shared_ptr<qstdweb::EventCallback>>> m_enableButtons;
125 QHash<QAccessibleInterface *, emscripten::val> m_elements;
126 int m_eventHandlerIndex;
127};
128
129#endif // QT_CONFIG(accessibility)
130
131#endif
void QWasmAccessibilityEnable()