wasm: ensure cursor reverts after window resize

This partially reverts 97be0cca17
but without the crash

We temporarily override the wasm cursor while leaving the
application/window cursor alone to mimic what desktop application
behavior is like.

Pick-to: 6.3
Fixes: QTBUG-99111
Change-Id: I23df48b2eaa82830593f1753ec23d14fe375b70c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
bb10
Lorn Potter 2021-12-16 12:54:31 +10:00
parent 66a183298a
commit 8f7bebb611
4 changed files with 46 additions and 9 deletions

View File

@ -47,7 +47,6 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
if (!screen)
return;
QByteArray htmlCursorName;
if (windowCursor) {
// Bitmap and custom cursors are not implemented (will fall back to "auto")
@ -60,10 +59,7 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
if (htmlCursorName.isEmpty())
htmlCursorName = "default";
// Set cursor on the canvas
val canvas = QWasmScreen::get(screen)->canvas();
val canvasStyle = canvas["style"];
canvasStyle.set("cursor", val(htmlCursorName.constData()));
setWasmCursor(screen, htmlCursorName);
}
QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape)
@ -143,3 +139,23 @@ QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape)
return cursorName;
}
void QWasmCursor::setWasmCursor(QScreen *screen, const QByteArray &name)
{
// Set cursor on the canvas
val canvas = QWasmScreen::get(screen)->canvas();
val canvasStyle = canvas["style"];
canvasStyle.set("cursor", val(name.constData()));
}
void QWasmCursor::setOverrideWasmCursor(QCursor *windowCursor, QScreen *screen)
{
QWasmCursor *wCursor = static_cast<QWasmCursor *>(QWasmScreen::get(screen)->cursor());
wCursor->setWasmCursor(screen, wCursor->cursorShapeToHtml(windowCursor->shape()));
}
void QWasmCursor::clearOverrideWasmCursor(QScreen *screen)
{
QWasmCursor *wCursor = static_cast<QWasmCursor *>(QWasmScreen::get(screen)->cursor());
wCursor->setWasmCursor(screen, wCursor->htmlCursorName);
}

View File

@ -38,6 +38,11 @@ public:
void changeCursor(QCursor *windowCursor, QWindow *window) override;
QByteArray cursorShapeToHtml(Qt::CursorShape shape);
static void setOverrideWasmCursor(QCursor *windowCursor, QScreen *screen);
static void clearOverrideWasmCursor(QScreen *screen);
private:
QByteArray htmlCursorName;
void setWasmCursor(QScreen *screen, const QByteArray &name);
};
#endif

View File

@ -33,7 +33,7 @@
#include "qwasmintegration.h"
#include "qwasmclipboard.h"
#include "qwasmstring.h"
#include "qwasmcursor.h"
#include <QtGui/qevent.h>
#include <qpa/qwindowsysteminterface.h>
#include <QtCore/qcoreapplication.h>
@ -499,7 +499,7 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
pressedWindow = nullptr;
}
if (mouseEvent->button == 0) {
if (draggedWindow && pressedButtons.testFlag(Qt::NoButton)) {
draggedWindow = nullptr;
resizeMode = QWasmWindow::ResizeNone;
}
@ -514,8 +514,22 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
{
buttonEventType = QEvent::MouseMove;
if (htmlWindow && htmlWindow->isPointOnResizeRegion(globalPoint))
window2->setCursor(cursorForMode(htmlWindow->resizeModeAtPoint(globalPoint)));
if (htmlWindow && pressedButtons.testFlag(Qt::NoButton)) {
if (htmlWindow->isPointOnResizeRegion(globalPoint)) {
QCursor resizingCursor = cursorForMode(htmlWindow->resizeModeAtPoint(globalPoint));
if (resizingCursor != window2->cursor()) {
isCursorOverridden = true;
QWasmCursor::setOverrideWasmCursor(&resizingCursor, window2->screen());
}
} else { // off resizing area
if (isCursorOverridden) {
isCursorOverridden = false;
QWasmCursor::clearOverrideWasmCursor(window2->screen());
}
}
}
if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) {
if (resizeMode == QWasmWindow::ResizeNone && draggedWindow) {

View File

@ -100,6 +100,8 @@ private:
Qt::Key m_emDeadKey = Qt::Key_unknown;
bool m_emStickyDeadKey = false;
QCursor cursorForMode(QWasmWindow::ResizeMode mode);
QCursor overriddenCursor;
bool isCursorOverridden = false;
};
QT_END_NAMESPACE