From 7304cf9e0742fe112d8bf654fa5cd479523ea07a Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 11 Mar 2010 10:23:22 +0100 Subject: Mac: scroll speed does not match native applications It turns out that we limit wheel scrolling on mac to an upper limit per event to one page. This behaviour is a bit strange in the first place, and on mac, it is just wrong. Besides, even when this limitation is removed, we still scroll a bit slower that native. The 'problem' is to come up with a good conversion from pixel scrolling to line based scrolling (Qt does not really have an API for pixel scrolling). But we up the speed a bit to make it perform more similar to xcode. Rev-by: msorvig --- src/gui/kernel/qapplication_mac.mm | 9 +++++++-- src/gui/kernel/qcocoaview_mac.mm | 13 +++++++------ src/gui/widgets/qabstractslider.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index c7d0e48..28072fc 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1759,14 +1759,19 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event // (actually two events; one for horizontal and one for vertical). // As a results of this, and to make sure we dont't receive duplicate events, // we try to detect when this happend by checking the 'compatibilityEvent'. + // Since delta is delivered as pixels rather than degrees, we need to + // convert from pixels to degrees in a sensible manner. + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; SInt32 mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaX = mdelt; + wheel_deltaX = mdelt * pixelsToDegrees; mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaY = mdelt; + wheel_deltaY = mdelt * pixelsToDegrees; GetEventParameter(event, kEventParamEventRef, typeEventRef, 0, sizeof(compatibilityEvent), 0, &compatibilityEvent); } else if (ekind == kEventMouseWheelMoved) { diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index f7cb21f..4f71681 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -480,7 +480,7 @@ static int qCocoaViewCount = 0; return; if (QApplicationPrivate::graphicsSystem() != 0) { - if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) { + if (qwidgetprivate->maybeBackingStore()) { // Drawing is handled on the window level // See qcocoasharedwindowmethods_mac_p.h if (!qwidget->testAttribute(Qt::WA_PaintOnScreen)) @@ -819,11 +819,12 @@ static int qCocoaViewCount = 0; // The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad). // Since deviceDelta is delivered as pixels rather than degrees, we need to // convert from pixels to degrees in a sensible manner. - // It looks like four degrees per pixel behaves most native. - // Qt expects the unit for delta to be 1/8 of a degree: - deltaX = [theEvent deviceDeltaX]; - deltaY = [theEvent deviceDeltaY]; - deltaZ = [theEvent deviceDeltaZ]; + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; // 8 * 1/4 + deltaX = [theEvent deviceDeltaX] * pixelsToDegrees; + deltaY = [theEvent deviceDeltaY] * pixelsToDegrees; + deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees; } else { // carbonEventKind == kEventMouseWheelMoved // Remove acceleration, and use either -120 or 120 as delta: diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 2888490..522d472 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -712,7 +712,15 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb offset_accumulated = 0; offset_accumulated += stepsToScrollF; +#ifndef Q_WS_MAC + // Dont't scroll more than one page in any case: stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); +#else + // Native UI-elements on Mac can scroll hundreds of lines at a time as + // a result of acceleration. So keep the same behaviour in Qt, and + // dont restrict stepsToScroll to certain maximum (pageStep): + stepsToScroll = int(offset_accumulated); +#endif offset_accumulated -= int(offset_accumulated); if (stepsToScroll == 0) return false; -- cgit v0.12 From 471d020c212266cd84481cf60a61fc223f8ab316 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 11 Mar 2010 10:26:04 +0100 Subject: Compile --- src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h index 307ce68..2e21f9d 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h @@ -36,6 +36,10 @@ #include #include +#if PLATFORM(QT) +#include +#endif + namespace JSC { using WTF::PlacementNewAdoptType; -- cgit v0.12 From 143f16aedf9cf47e8848637152899447c3ca148c Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 11 Mar 2010 11:39:47 +0100 Subject: Autotest: make the qabstractslider test pass on mac Since we changed the behaviour for scrolling on mac to not be restriced to an upper limit (pagestep), we need to adjust the auto test accordingly Rev-by: prasanth --- tests/auto/qabstractslider/tst_qabstractslider.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/auto/qabstractslider/tst_qabstractslider.cpp b/tests/auto/qabstractslider/tst_qabstractslider.cpp index 293af36..cf069db 100644 --- a/tests/auto/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/qabstractslider/tst_qabstractslider.cpp @@ -728,7 +728,12 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // delta << int(Qt::Vertical) // orientation of slider << int(Qt::Vertical) // orientation of wheel +#ifndef Q_WS_MAC << 1 // expected position after +#else + // We don't restrict scrolling to pageStep on Mac + << 100 // expected position after +#endif << QPoint(1,1); QTest::newRow("Different orientation") << 0 // initial position @@ -742,7 +747,12 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // delta << int(Qt::Horizontal) // orientation of slider << int(Qt::Vertical) // orientation of wheel +#ifndef Q_WS_MAC << 1 // expected position after +#else + // We don't restrict scrolling to pageStep on Mac + << 100 // expected position after +#endif << QPoint(1,1); QTest::newRow("Different orientation2")<< 0 // initial position @@ -756,7 +766,12 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // delta << int(Qt::Horizontal) // orientation of slider << int(Qt::Vertical) // orientation of wheel +#ifndef Q_WS_MAC << 1 // expected position after +#else + // We don't restrict scrolling to pageStep on Mac + << 100 // expected position after +#endif << QPoint(0,0); -- cgit v0.12