5#ifndef QWASMACCESIBILITY_H
6#define QWASMACCESIBILITY_H
8#include <QtCore/qtconfigmacros.h>
9#include <QtGui/qtguiglobal.h>
11#include <QtCore/qhash.h>
12#include <private/qstdweb_p.h>
13#include <qpa/qplatformaccessibility.h>
15#include <emscripten/val.h>
16#include <QLoggingCategory>
19#include <emscripten/bind.h>
21Q_DECLARE_LOGGING_CATEGORY(lcQpaAccessibility)
25#if !QT_CONFIG(accessibility)
26class QWasmAccessibility
29 static void addAccessibilityEnableButton(QWindow *window) {}
30 static void onShowWindow(QWindow *) {}
31 static void onRemoveWindow(QWindow *) {}
32 static bool isEnabled() {
35 static void enable() {}
36 static bool setFocusObject(QObject *object) {
return false; }
39class QWasmAccessibility :
public QPlatformAccessibility
43 ~QWasmAccessibility();
45 static void addAccessibilityEnableButton(QWindow *window);
46 static void onShowWindow(QWindow *);
47 static void onRemoveWindow(QWindow *);
48 static bool isEnabled();
50 static bool setFocusObject(QObject *object);
53 static QWasmAccessibility *instance();
55 void addEnableButton(QWindow *window);
56 void enableAccessibility();
57 void removeWindow(QWindow *window);
58 bool setFocusObjectImpl(QObject *object);
61 std::string logElementParentChain(emscripten::val element, QAccessibleInterface *iface, std::string tab =
"");
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);
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);
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);
108 void handleEventFromHtmlElement(
const emscripten::val event);
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);
116 void notifyAccessibilityUpdate(QAccessibleEvent *event)
override;
117 bool handleUpdateByEventType(QAccessibleEvent *event);
118 void handleUpdateByInterfaceRole(QAccessibleEvent *event);
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);
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);
128 void setNamedAttribute(QAccessibleInterface *iface,
const std::string &attribute, QAccessible::Text text);
129 void setNamedProperty(QAccessibleInterface *iface,
const std::string &property, QAccessible::Text text);
131 void addEventListener(QAccessibleInterface *, emscripten::val element,
const char *eventType);
132 void sendEvent(QAccessibleInterface *iface, QAccessible::Event eventType);
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;
140 QAccessible::Id m_focusId = 0;
143 emscripten::val m_isSettingFocusIface = emscripten::val::undefined();
146 bool m_isFollowingQtFocus =
false;
void QWasmAccessibilityEnable()