wasm: sync pointer button state on pointer down

We may get PointerDown events with "no buttons" as the button
state in some cases such as for tap events on Apple trackpads.

Make sure the mouse button which caused the pointer down
event is in the mouse buttons set for the event.

Fixes: QTBUG-108639
Change-Id: I0a49abc398308bbfed657b99fc74f60c16e05a59
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit 1d3d7bfbbcfde475804db31747c3a4b42d3bfc9b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2023-01-05 14:59:22 +01:00 committed by Qt Cherry-pick Bot
parent 96aeba6bb1
commit 0c10be1859

View File

@ -43,6 +43,14 @@ std::optional<PointerEvent> PointerEvent::fromWeb(emscripten::val event)
PointerType::Mouse : PointerType::Other;
ret.mouseButton = MouseEvent::buttonFromWeb(event["button"].as<int>());
ret.mouseButtons = MouseEvent::buttonsFromWeb(event["buttons"].as<unsigned short>());
// The current button state (event.buttons) may be out of sync for some PointerDown
// events where the "down" state is very brief, for example taps on Apple trackpads.
// Qt expects that the current button state is in sync with the event, so we sync
// it up here.
if (*eventType == EventType::PointerDown)
ret.mouseButtons |= ret.mouseButton;
ret.localPoint = QPoint(event["offsetX"].as<int>(), event["offsetY"].as<int>());
ret.pointInPage = QPoint(event["pageX"].as<int>(), event["pageY"].as<int>());
ret.pointInViewport = QPoint(event["clientX"].as<int>(), event["clientY"].as<int>());