diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-24 16:30:31 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-27 06:52:08 +0000 |
commit | 4267567f5366b237c763d1b93cd09501a483a070 (patch) | |
tree | 06ac8607b5bcfabf94d7270209596b7120563110 /src/core/web_event_factory.cpp | |
parent | 684cfe05641ba9f3abc7e128d9dab5b331ef0689 (diff) |
Coalesce wheel events when possible
Combine wheel events if we are getting more than Chromium can handle.
This improves latency and perceived performance when scrolling with
touchpads or fine-grained mouse, on a slow machine or with a debug
build.
Change-Id: Id847c8e7782e155c28067b6051ce92896b68ca7a
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/web_event_factory.cpp')
-rw-r--r-- | src/core/web_event_factory.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index 18f8d393f..c31de19a2 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1247,38 +1247,56 @@ WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev, doub } #endif -blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, double dpiScale) +static void setBlinkWheelEventDelta(blink::WebMouseWheelEvent &webEvent) { - WebMouseWheelEvent webEvent; - webEvent.delta_x = 0; - webEvent.delta_y = 0; - webEvent.wheel_ticks_x = 0; - webEvent.wheel_ticks_y = 0; - webEvent.SetType(webEventTypeForEvent(ev)); - webEvent.SetModifiers(modifiersForEvent(ev)); - webEvent.SetTimeStampSeconds(currentTimeForEvent(ev)); - - webEvent.wheel_ticks_x = static_cast<float>(ev->angleDelta().x()) / QWheelEvent::DefaultDeltasPerStep; - webEvent.wheel_ticks_y = static_cast<float>(ev->angleDelta().y()) / QWheelEvent::DefaultDeltasPerStep; - // We can't use the device specific QWheelEvent::pixelDelta(), so we calculate // a pixel delta based on ticks and scroll per line. static const float cDefaultQtScrollStep = 20.f; #if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - const int wheelScrollLines = QGuiApplication::styleHints()->wheelScrollLines(); + static const int wheelScrollLines = QGuiApplication::styleHints()->wheelScrollLines(); #else - const int wheelScrollLines = 3; + static const int wheelScrollLines = 3; #endif webEvent.delta_x = webEvent.wheel_ticks_x * wheelScrollLines * cDefaultQtScrollStep; webEvent.delta_y = webEvent.wheel_ticks_y * wheelScrollLines * cDefaultQtScrollStep; +} + +blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, double dpiScale) +{ + WebMouseWheelEvent webEvent; + webEvent.SetType(webEventTypeForEvent(ev)); + webEvent.SetModifiers(modifiersForEvent(ev)); + webEvent.SetTimeStampSeconds(currentTimeForEvent(ev)); webEvent.SetPositionInWidget(ev->x() / dpiScale, ev->y() / dpiScale); webEvent.SetPositionInScreen(ev->globalX(), ev->globalY()); + webEvent.wheel_ticks_x = static_cast<float>(ev->angleDelta().x()) / QWheelEvent::DefaultDeltasPerStep; + webEvent.wheel_ticks_y = static_cast<float>(ev->angleDelta().y()) / QWheelEvent::DefaultDeltasPerStep; + setBlinkWheelEventDelta(webEvent); + return webEvent; } +bool WebEventFactory::coalesceWebWheelEvent(blink::WebMouseWheelEvent &webEvent, QWheelEvent *ev, double dpiScale) +{ + if (webEventTypeForEvent(ev) != webEvent.GetType()) + return false; + if (modifiersForEvent(ev) != webEvent.GetModifiers()) + return false; + + webEvent.SetTimeStampSeconds(currentTimeForEvent(ev)); + webEvent.SetPositionInWidget(ev->x() / dpiScale, ev->y() / dpiScale); + webEvent.SetPositionInScreen(ev->globalX(), ev->globalY()); + + webEvent.wheel_ticks_x += static_cast<float>(ev->angleDelta().x()) / QWheelEvent::DefaultDeltasPerStep; + webEvent.wheel_ticks_y += static_cast<float>(ev->angleDelta().y()) / QWheelEvent::DefaultDeltasPerStep; + setBlinkWheelEventDelta(webEvent); + + return true; +} + content::NativeWebKeyboardEvent WebEventFactory::toWebKeyboardEvent(QKeyEvent *ev) { content::NativeWebKeyboardEvent webKitEvent(reinterpret_cast<gfx::NativeEvent>(ev)); |