summaryrefslogtreecommitdiffstats
path: root/src/core/web_event_factory.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-11-03 07:31:53 +0100
committerLiang Qi <liang.qi@qt.io>2017-11-03 07:31:53 +0100
commitb045cf0ab9756a67a5a1037c231199ee9bf2d074 (patch)
tree43831df602905b64552cf31a233127bed9904fc8 /src/core/web_event_factory.cpp
parent0bbaf0d5d7b2d406eda57d40370b00fb79cc0aeb (diff)
parent7f7af6290a63bdab76855da5866881c8a53f045c (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: src/3rdparty Change-Id: Ie6b1922db2269e0e0561022162228a7c8609c9ba
Diffstat (limited to 'src/core/web_event_factory.cpp')
-rw-r--r--src/core/web_event_factory.cpp48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index b785adec0..2e0323f6d 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -1289,38 +1289,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));