diff options
author | Morten Sørvig <morten.sorvig@qt.io> | 2022-05-13 14:58:24 +0200 |
---|---|---|
committer | Morten Sørvig <morten.sorvig@qt.io> | 2022-05-24 03:10:10 +0200 |
commit | e3b3c77d0e173c28641decf817ad267c6cf0d967 (patch) | |
tree | 8377f345858a5b7fd01533a889b603204837df65 /src/plugins | |
parent | ff59343490c02e000c379585f41aafa31b92e5ce (diff) |
wasm: Improve wheel event handling
Always invert scroll deltas. This is what the code did
before, expect for on non-Safari macOS. There is no
need any "smart" code here: correct deltas are provided
by the native API regardless of macOS scroll direction
setting.
Reading webkitDirectionInvertedFromDevice is still useful
for certain use cases, such as 3D scene zooming or spinbox
value change, where upwards motion on the trackpad should
always correspond to "increment" regardless of scroll direction.
Propagate this to Qt using one of the handleWheelEvent()
overloads
Finally, we were sending pixel deltas as angle deltas;
fix by sending pixel deltas as well, but keep existing
angle delta behavior for compatibility.
Change-Id: I7a7104c30da057fefc0377816e551a9e7e2fa0e7
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: David Skoland <david.skoland@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcompositor.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index 9f6e686ac4..782e06f69d 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -39,17 +39,13 @@ QWasmCompositedWindow::QWasmCompositedWindow() // macOS CTRL <-> META switching. We most likely want to enable // the existing switching code in QtGui, but for now do it here. +bool g_scrollingInvertedFromDevice = false; - -bool g_useNaturalScrolling = true; // natural scrolling is default on linux/windows - -static void mouseWheelEvent(emscripten::val event) { - - emscripten::val wheelInterted = event["webkitDirectionInvertedFromDevice"]; - - if (wheelInterted.as<bool>()) { - g_useNaturalScrolling = true; - } +static void mouseWheelEvent(emscripten::val event) +{ + emscripten::val wheelInverted = event["webkitDirectionInvertedFromDevice"]; + if (wheelInverted.as<bool>()) + g_scrollingInvertedFromDevice = true; } EMSCRIPTEN_BINDINGS(qtMouseModule) { @@ -145,8 +141,6 @@ void QWasmCompositor::initEventHandlers() eventTranslator->g_usePlatformMacSpecifics = (QWasmIntegration::get()->platform == QWasmIntegration::MacOSPlatform); if (QWasmIntegration::get()->platform == QWasmIntegration::MacOSPlatform) { - g_useNaturalScrolling = false; // make this !default on macOS - if (!emscripten::val::global("window")["safari"].isUndefined()) { val canvas = screen()->canvas(); canvas.call<void>("addEventListener", @@ -1203,10 +1197,10 @@ bool QWasmCompositor::processWheel(int eventType, const EmscriptenWheelEvent *wh int scrollFactor = 0; switch (wheelEvent->deltaMode) { - case DOM_DELTA_PIXEL://chrome safari + case DOM_DELTA_PIXEL: scrollFactor = 1; break; - case DOM_DELTA_LINE: //firefox + case DOM_DELTA_LINE: scrollFactor = 12; break; case DOM_DELTA_PAGE: @@ -1214,8 +1208,7 @@ bool QWasmCompositor::processWheel(int eventType, const EmscriptenWheelEvent *wh break; }; - if (g_useNaturalScrolling) //macOS platform has document oriented scrolling - scrollFactor = -scrollFactor; + scrollFactor = -scrollFactor; // Web scroll deltas are inverted from Qt deltas. Qt::KeyboardModifiers modifiers = eventTranslator->translateMouseEventModifier(&mouseEvent); QPoint targetPoint(mouseEvent.targetX, mouseEvent.targetY); @@ -1231,9 +1224,13 @@ bool QWasmCompositor::processWheel(int eventType, const EmscriptenWheelEvent *wh if (wheelEvent->deltaY != 0) pixelDelta.setY(wheelEvent->deltaY * scrollFactor); if (wheelEvent->deltaX != 0) pixelDelta.setX(wheelEvent->deltaX * scrollFactor); + QPoint angleDelta = pixelDelta; // FIXME: convert from pixels? + bool accepted = QWindowSystemInterface::handleWheelEvent( window2, QWasmIntegration::getTimestamp(), localPoint, - globalPoint, QPoint(), pixelDelta, modifiers); + globalPoint, pixelDelta, angleDelta, modifiers, + Qt::NoScrollPhase, Qt::MouseEventNotSynthesized, + g_scrollingInvertedFromDevice); return accepted; } |