summaryrefslogtreecommitdiffstats
path: root/src/corelib/platform/wasm/qstdweb_p.h
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2024-01-23 00:10:54 +0100
committerMorten Sørvig <morten.sorvig@qt.io>2024-01-25 18:37:49 +0100
commit50a5744460f60f68e57118cfad924af556f93f34 (patch)
treed9d195dde75e5cfd623834773124789fc17518f0 /src/corelib/platform/wasm/qstdweb_p.h
parentffe0271a21e9574d1c9eab5fb9803573e17e0f22 (diff)
wasm: make EventCallback use addEventListener()
EventCallback would previously set the on<Event> property on the event target, which is a singleton property where there can be only one event handler. This was OK if the event target was owned by Qt, for example the canvas element, where we could guarantee that there was only one event handler. However this approach fell through when registering event handlers for global event targets, such as for window.onLanguageChange, where setting a singleton event handler may conflict with other users. Fix this by using the addEventListener() API instead, which has a variant which takes an event listener object, which gives us the ability to provide C++ context for the listener. The C++ context in this case is a std::function that contains the event handler callback. Attempts to pass this type to JavaScript was met with some resistance from Emscripten, so as a late night hack pass it as a uintptr_t for now. Change-Id: I1a547b49af467882ae4f57f8d909ffdff0be6b51 Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/corelib/platform/wasm/qstdweb_p.h')
-rw-r--r--src/corelib/platform/wasm/qstdweb_p.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/platform/wasm/qstdweb_p.h b/src/corelib/platform/wasm/qstdweb_p.h
index 707d96704b..566e02e8a1 100644
--- a/src/corelib/platform/wasm/qstdweb_p.h
+++ b/src/corelib/platform/wasm/qstdweb_p.h
@@ -199,13 +199,12 @@ namespace qstdweb {
EventCallback& operator=(EventCallback const&) = delete;
EventCallback(emscripten::val element, const std::string &name,
const std::function<void(emscripten::val)> &fn);
- static void activate(emscripten::val event);
private:
- static std::string contextPropertyName(const std::string &eventName);
emscripten::val m_element = emscripten::val::undefined();
std::string m_eventName;
- std::function<void(emscripten::val)> m_fn;
+ std::unique_ptr<std::function<void(emscripten::val)>> m_handler;
+ emscripten::val m_eventListener = emscripten::val::undefined();
};
struct PromiseCallbacks