From 16bf899557febb8c0762e64ce88acf21bc84e334 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Thu, 22 Dec 2022 15:31:48 +0100 Subject: Streamline reading of js DataTransfer object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qwasmclipboard.cpp and qwasmdrag.cpp had the same logic that read the js DataTransfer object implemented twice with small differences. Use a single implementation in both. This also introduces a clearer memory ownership model in the reader code, and fixes a potential race condition by introducing a cancellation flag. Removed the useless QWasmDrag type which was in essence a SimpleDrag and made the m_drag in QWasmIntegration a smart pointer. Fixes: QTBUG-109626 Pick-to: 6.5 Change-Id: I5b76dd3b70ab2e5a8364d9a136c970ee8d4fae9c Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index fa4ae981bb..090218a118 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -80,6 +80,12 @@ QWasmIntegration::QWasmIntegration() m_clipboard(new QWasmClipboard), m_accessibility(new QWasmAccessibility) { + // Temporary measure to make dropEvent appear in the library. EMSCRIPTEN_KEEPALIVE does not + // work, nor does a Q_CONSTRUCTOR_FUNCTION in qwasmdrag.cpp. + volatile bool foolEmcc = false; + if (foolEmcc) + dropEvent(emscripten::val::undefined()); + s_instance = this; touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as(); @@ -121,7 +127,7 @@ QWasmIntegration::QWasmIntegration() visualViewport.call("addEventListener", val("resize"), val::module_property("qtResizeAllScreens")); } - m_drag = new QWasmDrag(); + m_drag = std::make_unique(); } QWasmIntegration::~QWasmIntegration() @@ -138,7 +144,6 @@ QWasmIntegration::~QWasmIntegration() delete m_desktopServices; if (m_platformInputContext) delete m_platformInputContext; - delete m_drag; delete m_accessibility; for (const auto &elementAndScreen : m_screens) @@ -330,7 +335,7 @@ quint64 QWasmIntegration::getTimestamp() #if QT_CONFIG(draganddrop) QPlatformDrag *QWasmIntegration::drag() const { - return m_drag; + return m_drag.get(); } #endif // QT_CONFIG(draganddrop) -- cgit v1.2.3