4#ifndef QWASMACCESIBILITY_H
5#define QWASMACCESIBILITY_H
7#include <QtCore/qtconfigmacros.h>
8#include <QtGui/qtguiglobal.h>
10#include <QtCore/qhash.h>
11#include <private/qstdweb_p.h>
12#include <qpa/qplatformaccessibility.h>
14#include <emscripten/val.h>
15#include <QLoggingCategory>
18#include <emscripten/bind.h>
20Q_DECLARE_LOGGING_CATEGORY(lcQpaAccessibility)
24#if !QT_CONFIG(accessibility)
25class QWasmAccessibility
28 static void addAccessibilityEnableButton(QWindow *window) {}
29 static void onShowWindow(QWindow *) {}
30 static void onRemoveWindow(QWindow *) {}
31 static bool isEnabled() {
34 static void enable() {}
37class QWasmAccessibility :
public QPlatformAccessibility
41 ~QWasmAccessibility();
43 static QWasmAccessibility* get();
45 static void addAccessibilityEnableButton(QWindow *window);
46 static void onShowWindow(QWindow *);
47 static void onRemoveWindow(QWindow *);
48 static bool isEnabled();
52 void addAccessibilityEnableButtonImpl(QWindow *window);
53 void enableAccessibility();
54 void onShowWindowImpl(QWindow *);
55 void onRemoveWindowImpl(QWindow *);
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);
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 setHtmlElementFocus(QAccessibleInterface *iface);
77 void setHtmlElementDisabled(QAccessibleInterface *iface);
78 void setHtmlElementOrientation(emscripten::val element, QAccessibleInterface *iface);
80 void handleStaticTextUpdate(QAccessibleEvent *event);
81 void handleButtonUpdate(QAccessibleEvent *event);
82 void handleCheckBoxUpdate(QAccessibleEvent *event);
83 void handleGroupBoxUpdate(QAccessibleEvent *event);
84 void handleSwitchUpdate(QAccessibleEvent *event);
85 void handleDialogUpdate(QAccessibleEvent *event);
86 void handleMenuUpdate(QAccessibleEvent *event);
87 void handleToolUpdate(QAccessibleEvent *event);
88 void handleLineEditUpdate(QAccessibleEvent *event);
89 void handleRadioButtonUpdate(QAccessibleEvent *event);
90 void handleSpinBoxUpdate(QAccessibleEvent *event);
91 void handlePageTabUpdate(QAccessibleEvent *event);
92 void handleSliderUpdate(QAccessibleEvent *event);
93 void handleScrollBarUpdate(QAccessibleEvent *event);
94 void handlePageTabListUpdate(QAccessibleEvent *event);
95 void handleIdentifierUpdate(QAccessibleInterface *iface);
96 void handleDescriptionChanged(QAccessibleInterface *iface);
98 void handleEventFromHtmlElement(
const emscripten::val event);
100 void populateAccessibilityTree(QAccessibleInterface *iface);
101 void createObject(QAccessibleInterface *iface);
102 void removeObject(QAccessibleInterface *iface);
103 void unlinkParentForChildren(QAccessibleInterface *iface);
104 void relinkParentForChildren(QAccessibleInterface *iface);
106 void notifyAccessibilityUpdate(QAccessibleEvent *event)
override;
107 bool handleUpdateByEventType(QAccessibleEvent *event);
108 void handleUpdateByInterfaceRole(QAccessibleEvent *event);
110 void setRootObject(QObject *o)
override;
111 void initialize() override;
112 void cleanup() override;
114 void setAttribute(emscripten::val element,
const std::string &attr,
const std::string &val);
115 void setAttribute(emscripten::val element,
const std::string &attr,
const char *val);
116 void setAttribute(emscripten::val element,
const std::string &attr,
bool val);
118 void setProperty(emscripten::val element,
const std::string &attr,
const std::string &val);
119 void setProperty(emscripten::val element,
const std::string &attr,
const char *val);
120 void setProperty(emscripten::val element,
const std::string &attr,
bool val);
122 void setNamedAttribute(QAccessibleInterface *iface,
const std::string &attribute, QAccessible::Text text);
123 void setNamedProperty(QAccessibleInterface *iface,
const std::string &property, QAccessible::Text text);
125 void addEventListener(QAccessibleInterface *, emscripten::val element,
const char *eventType);
126 void sendEvent(QAccessibleInterface *iface, QAccessible::Event eventType);
129 static QWasmAccessibility *s_instance;
130 QObject *m_rootObject =
nullptr;
131 bool m_accessibilityEnabled =
false;
132 std::map<QWindow *, std::tuple<emscripten::val, std::shared_ptr<qstdweb::EventCallback>>> m_enableButtons;
133 QHash<QAccessibleInterface *, emscripten::val> m_elements;
134 int m_eventHandlerIndex;
void QWasmAccessibilityEnable()