summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmdrag.cpp
diff options
context:
space:
mode:
authorMikolaj Boc <[email protected]>2023-01-20 15:12:38 +0100
committerMikolaj Boc <[email protected]>2023-01-20 18:00:26 +0100
commit9b64bf0874b9e9323d6eadad2a8023c888f25182 (patch)
tree89bfd88836f6ba61c653dbe083612c1fb3ae636f /src/plugins/platforms/wasm/qwasmdrag.cpp
parentc290e742c6e780f0b507ea0f3ba287f2f6045572 (diff)
Handle the drop event in the wasm window element
Drop events are now handled in the wasm window element, which allows the browser to select the drop target automatically. This also fixes the case where drop data transfer finishes reading when a window has already been closed and destroyed - the cancellation flag is now owned by window so it gets invalidated as soon as window is gone. The code has also been structured with a new DragEvent passthrough. Fixes: QTBUG-109581 Change-Id: Ie3eb7446e2181fd540517f39397e8b35f111d009 Reviewed-by: MikoĊ‚aj Boc <[email protected]>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmdrag.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmdrag.cpp78
1 files changed, 0 insertions, 78 deletions
diff --git a/src/plugins/platforms/wasm/qwasmdrag.cpp b/src/plugins/platforms/wasm/qwasmdrag.cpp
deleted file mode 100644
index 144c30e0fb4..00000000000
--- a/src/plugins/platforms/wasm/qwasmdrag.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-#include "qwasmdrag.h"
-
-#include "qwasmdom.h"
-#include "qwasmeventtranslator.h"
-#include <qpa/qwindowsysteminterface.h>
-#include <QMimeData>
-
-#include <emscripten.h>
-#include <emscripten/val.h>
-#include <emscripten/bind.h>
-
-#include <memory>
-#include <string>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-Qt::DropAction parseDropActions(emscripten::val event)
-{
- const std::string dEffect = event["dataTransfer"]["dropEffect"].as<std::string>();
-
- if (dEffect == "copy")
- return Qt::CopyAction;
- else if (dEffect == "move")
- return Qt::MoveAction;
- else if (dEffect == "link")
- return Qt::LinkAction;
- return Qt::IgnoreAction;
-}
-} // namespace
-
-void dropEvent(emscripten::val event)
-{
- // someone dropped a file into the browser window
- // event is dataTransfer object
- // if drop event from outside browser, we do not get any mouse release, maybe mouse move
- // after the drop event
- event.call<void>("preventDefault"); // prevent browser from handling drop event
-
- static std::shared_ptr<qstdweb::CancellationFlag> readDataCancellation = nullptr;
- readDataCancellation = qstdweb::readDataTransfer(
- event["dataTransfer"],
- [](QByteArray fileContent) {
- QImage image;
- image.loadFromData(fileContent, nullptr);
- return image;
- },
- [wasmScreen = reinterpret_cast<QWasmScreen *>(
- event["target"]["data-qtdropcontext"].as<quintptr>()),
- event](std::unique_ptr<QMimeData> data) {
- const auto mouseDropPoint = QPoint(event["x"].as<int>(), event["y"].as<int>());
- const auto button = MouseEvent::buttonFromWeb(event["button"].as<int>());
- const Qt::KeyboardModifiers modifiers = KeyboardModifier::getForEvent(event);
- const auto dropAction = parseDropActions(event);
- auto *window = wasmScreen->topLevelAt(mouseDropPoint);
-
- QWindowSystemInterface::handleDrag(window, data.get(), mouseDropPoint, dropAction,
- button, modifiers);
-
- // drag drop
- QWindowSystemInterface::handleDrop(window, data.get(), mouseDropPoint, dropAction,
- button, modifiers);
-
- // drag leave
- QWindowSystemInterface::handleDrag(window, nullptr, QPoint(), Qt::IgnoreAction, {},
- {});
- });
-}
-
-EMSCRIPTEN_BINDINGS(drop_module)
-{
- function("qtDrop", &dropEvent);
-}
-
-QT_END_NAMESPACE