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 void addAccessibilityEnableButton(QWindow *window);
45 static void onShowWindow(QWindow *);
46 static void onRemoveWindow(QWindow *);
47 static bool isEnabled();
48 static void enable();
49
50private:
51 static QWasmAccessibility *instance();
52
53 void addEnableButton(QWindow *window);
54 void enableAccessibility();
55 void removeWindow(QWindow *window);
56
57 emscripten::val getDescribedByContainer(QWindow *window);
58 emscripten::val getDescribedByContainer(QAccessibleInterface *iface);
59 emscripten::val getElementContainer(QWindow *window);
60 emscripten::val getElementContainer(QAccessibleInterface *iface);
61 emscripten::val getDocument(const emscripten::val &container);
62 QWindow *getWindow(QAccessibleInterface *iface);
63 bool isWindowNode(QAccessibleInterface *iface);
64
65 emscripten::val createHtmlElement(QAccessibleInterface *iface);
66 void destroyHtmlElement(QAccessibleInterface *iface);
67 emscripten::val getHtmlElement(QAccessibleInterface *iface);
68 void repairLinks(QAccessibleInterface *iface);
69 void linkToParent(QAccessibleInterface *iface);
70 void setHtmlElementVisibility(QAccessibleInterface *iface, bool visible);
71 void setHtmlElementGeometry(QAccessibleInterface *iface);
72 void setHtmlElementGeometry(emscripten::val element, QRect geometry);
73 void setHtmlElementFocus(QAccessibleInterface *iface);
74 void setHtmlElementDisabled(QAccessibleInterface *iface);
75 void setHtmlElementOrientation(emscripten::val element, QAccessibleInterface *iface);
76
77 void handleListItemUpdate(QAccessibleEvent *event);
78 void handleStaticTextUpdate(QAccessibleEvent *event);
79 void handleButtonUpdate(QAccessibleEvent *event);
80 void handleCheckBoxUpdate(QAccessibleEvent *event);
81 void handleGroupBoxUpdate(QAccessibleEvent *event);
82 void handleSwitchUpdate(QAccessibleEvent *event);
83 void handleDialogUpdate(QAccessibleEvent *event);
84 void handleMenuUpdate(QAccessibleEvent *event);
85 void handleToolUpdate(QAccessibleEvent *event);
86 void handleLineEditUpdate(QAccessibleEvent *event);
87 void handleRadioButtonUpdate(QAccessibleEvent *event);
88 void handleDialUpdate(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 void handleAnnouncement(QAccessibleInterface *iface,
97 QAccessibleAnnouncementEvent *announcementEvent);
98 void handleProgressBarUpdate(QAccessibleEvent *event);
99
100 void handleEventFromHtmlElement(const emscripten::val event);
101
102 void populateAccessibilityTree(QAccessibleInterface *iface);
103 void createObject(QAccessibleInterface *iface);
104 void removeObject(QAccessible::Id id);
105 void unlinkParentForChildren(QAccessibleInterface *iface);
106 void relinkParentForChildren(QAccessibleInterface *iface);
107
108 void notifyAccessibilityUpdate(QAccessibleEvent *event) override;
109 bool handleUpdateByEventType(QAccessibleEvent *event);
110 void handleUpdateByInterfaceRole(QAccessibleEvent *event);
111
112 void setAttribute(emscripten::val element, const std::string &attr, const std::string &val);
113 void setAttribute(emscripten::val element, const std::string &attr, const char *val);
114 void setAttribute(emscripten::val element, const std::string &attr, bool val);
115
116 void setProperty(emscripten::val element, const std::string &attr, const std::string &val);
117 void setProperty(emscripten::val element, const std::string &attr, const char *val);
118 void setProperty(emscripten::val element, const std::string &attr, bool val);
119
120 void setNamedAttribute(QAccessibleInterface *iface, const std::string &attribute, QAccessible::Text text);
121 void setNamedProperty(QAccessibleInterface *iface, const std::string &property, QAccessible::Text text);
122
123 void addEventListener(QAccessibleInterface *, emscripten::val element, const char *eventType);
124 void sendEvent(QAccessibleInterface *iface, QAccessible::Event eventType);
125
126private:
127 std::map<QWindow *, std::tuple<emscripten::val, std::shared_ptr<qstdweb::EventCallback>>> m_enableButtons;
128 QHash<QAccessible::Id, emscripten::val> m_elements;
129 int m_eventHandlerIndex;
130};
131
132#endif // QT_CONFIG(accessibility)
133
134#endif
void QWasmAccessibilityEnable()