diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-12-22 15:31:48 +0100 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-01-18 02:55:12 +0100 |
commit | 16bf899557febb8c0762e64ce88acf21bc84e334 (patch) | |
tree | 2f0598c71edc24e01dbb156754a8943254ff9b9a /src/plugins/platforms/wasm/qwasmintegration.cpp | |
parent | 2e8b75477fdbee53e0cf1266340a8dea6c1718a0 (diff) |
Streamline reading of js DataTransfer object
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 <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmintegration.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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<int>(); @@ -121,7 +127,7 @@ QWasmIntegration::QWasmIntegration() visualViewport.call<void>("addEventListener", val("resize"), val::module_property("qtResizeAllScreens")); } - m_drag = new QWasmDrag(); + m_drag = std::make_unique<QSimpleDrag>(); } 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) |