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>
This commit is contained in:
parent
ff59343490
commit
e3b3c77d0e
@ -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;
|
||||
}
|
||||
|
||||
|
@ -175,6 +175,7 @@ void RasterWindow::wheelEvent(QWheelEvent * ev)
|
||||
qDebug() << __PRETTY_FUNCTION__;
|
||||
QRasterWindow::wheelEvent(ev);
|
||||
incrementEventCount();
|
||||
m_offset += ev->pixelDelta();
|
||||
}
|
||||
|
||||
void RasterWindow::incrementEventCount()
|
||||
|
Loading…
x
Reference in New Issue
Block a user