wasm: fix mouse move and right click

Emscripten has no concept of 'no mouse button', so when there
is no button down, it was sending left mouse.

Also we were hiding mousepress for only leftmouse downs.

Fixes: QTBUG-97431
Pick-to: 6.2
Change-Id: Ibf078705c343944e45551830b7fee94ed5aa7333
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Lorn Potter 2021-11-25 16:39:45 +10:00
parent 625cfb6b40
commit 820a6d4117

View File

@ -437,7 +437,7 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
QPoint globalPoint = screen()->geometry().topLeft() + targetPoint; QPoint globalPoint = screen()->geometry().topLeft() + targetPoint;
QEvent::Type buttonEventType = QEvent::None; QEvent::Type buttonEventType = QEvent::None;
Qt::MouseButton button = translateMouseButton(mouseEvent->button); Qt::MouseButton button = Qt::NoButton;
Qt::KeyboardModifiers modifiers = translateMouseEventModifier(mouseEvent); Qt::KeyboardModifiers modifiers = translateMouseEventModifier(mouseEvent);
QWindow *window2 = nullptr; QWindow *window2 = nullptr;
@ -457,19 +457,22 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
switch (eventType) { switch (eventType) {
case EMSCRIPTEN_EVENT_MOUSEDOWN: case EMSCRIPTEN_EVENT_MOUSEDOWN:
{ {
button = translateMouseButton(mouseEvent->button);
if (window2) if (window2)
window2->requestActivate(); window2->requestActivate();
pressedButtons.setFlag(button); pressedButtons.setFlag(button);
pressedWindow = window2;
buttonEventType = QEvent::MouseButtonPress;
// button overview: // button overview:
// 0 = primary mouse button, usually left click // 0 = primary mouse button, usually left click
// 1 = middle mouse button, usually mouse wheel // 1 = middle mouse button, usually mouse wheel
// 2 = right mouse button, usually right click // 2 = right mouse button, usually right click
// from: https://w3c.github.io/uievents/#dom-mouseevent-button // from: https://w3c.github.io/uievents/#dom-mouseevent-button
if (mouseEvent->button == 0) { if (mouseEvent->button == 0) {
pressedWindow = window2;
buttonEventType = QEvent::MouseButtonPress;
if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) { if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) {
if (htmlWindow && window2->flags().testFlag(Qt::WindowTitleHint) && htmlWindow->isPointOnTitle(globalPoint)) if (htmlWindow && window2->flags().testFlag(Qt::WindowTitleHint) && htmlWindow->isPointOnTitle(globalPoint))
draggedWindow = window2; draggedWindow = window2;
@ -487,7 +490,8 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
} }
case EMSCRIPTEN_EVENT_MOUSEUP: case EMSCRIPTEN_EVENT_MOUSEUP:
{ {
pressedButtons.setFlag(translateMouseButton(mouseEvent->button), false); button = translateMouseButton(mouseEvent->button);
pressedButtons.setFlag(button, false);
buttonEventType = QEvent::MouseButtonRelease; buttonEventType = QEvent::MouseButtonRelease;
QWasmWindow *oldWindow = nullptr; QWasmWindow *oldWindow = nullptr;