Skip to content

Commit

Permalink
wasm: add dragleave event handling
Browse files Browse the repository at this point in the history
Fixes: QTBUG-129149
Pick-to: 6.8
Change-Id: I946f43e3a696c801a60a9a209a70ccaf57252a60
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
  • Loading branch information
Lorn Potter committed Oct 11, 2024
1 parent d13de6a commit 8a93093
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/plugins/platforms/wasm/qwasmdrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ void QWasmDrag::onNativeDragFinished(DragEvent *event)
m_dragState->quitEventLoopClosure();
}

void QWasmDrag::onNativeDragLeave(DragEvent *event)
{
m_dragState->dropAction = event->dropAction;
event->dataTransfer.setDropAction(Qt::DropAction::IgnoreAction);
}

QWasmDrag::DragState::DragImage::DragImage(const QPixmap &pixmap, const QMimeData *mimeData,
QWindow *window)
: m_temporaryImageElementParent(QWasmWindow::fromWindow(window)->containerElement())
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/wasm/qwasmdrag.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QWasmDrag final : public QSimpleDrag
void onNativeDrop(DragEvent *event);
void onNativeDragStarted(DragEvent *event);
void onNativeDragFinished(DragEvent *event);
void onNativeDragLeave(DragEvent *event);

// QPlatformDrag:
Qt::DropAction drag(QDrag *drag) final;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/platforms/wasm/qwasmevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ std::optional<DragEvent> DragEvent::fromWeb(emscripten::val event, QWindow *targ
{
const auto eventType = ([&event]() -> std::optional<EventType> {
const auto eventTypeString = event["type"].as<std::string>();

if (eventTypeString == "dragend")
return EventType::DragEnd;
if (eventTypeString == "dragover")
Expand All @@ -269,6 +268,8 @@ std::optional<DragEvent> DragEvent::fromWeb(emscripten::val event, QWindow *targ
return EventType::DragStart;
if (eventTypeString == "drop")
return EventType::Drop;
if (eventTypeString == "dragleave")
return EventType::DragLeave;
return std::nullopt;
})();
if (!eventType)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/wasm/qwasmevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class EventType {
DragEnd,
DragOver,
DragStart,
DragLeave,
Drop,
KeyDown,
KeyUp,
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/platforms/wasm/qwasmwindowclientarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ ClientArea::ClientArea(QWasmWindow *window, QWasmScreen *screen, emscripten::val
QWasmDrag::instance()->onNativeDragFinished(&event);
});

m_dragLeaveCallback = std::make_unique<qstdweb::EventCallback>(
element, "dragleave", [this](emscripten::val webEvent) {
webEvent.call<void>("preventDefault");
auto event = *DragEvent::fromWeb(webEvent, m_window->window());
QWasmDrag::instance()->onNativeDragLeave(&event);
});

}

bool ClientArea::processPointer(const PointerEvent &event)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/wasm/qwasmwindowclientarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ClientArea
std::unique_ptr<qstdweb::EventCallback> m_dragStartCallback;
std::unique_ptr<qstdweb::EventCallback> m_dragEndCallback;
std::unique_ptr<qstdweb::EventCallback> m_dropCallback;
std::unique_ptr<qstdweb::EventCallback> m_dragLeaveCallback;

QMap<int, QWindowSystemInterface::TouchPoint> m_pointerIdToTouchPoints;

Expand Down

0 comments on commit 8a93093

Please sign in to comment.