diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 44dce630867c962937077d2cf3bb44a57b34bcd3..18eabd5c0bd6ce00214218a6822df2f1f1bcae58 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -954,12 +954,21 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev) void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) { + // Chromium expects the touch event timestamps to be comparable to base::TimeTicks::Now(). + // Most importantly we also have to preserve the relative time distance between events. + // Calculate a delta between event timestamps and Now() on the first received event, and + // apply this delta to all successive events. This delta is most likely smaller than it + // should by calculating it here but this will hopefully cause less than one frame of delay. + base::TimeDelta eventTimestamp = base::TimeDelta::FromMilliseconds(ev->timestamp()); + if (m_eventsToNowDelta == base::TimeDelta()) + m_eventsToNowDelta = base::TimeTicks::Now() - base::TimeTicks() - eventTimestamp; + eventTimestamp += m_eventsToNowDelta; + // Convert each of our QTouchEvent::TouchPoint to the simpler ui::TouchEvent to // be able to use the same code path for both gesture recognition and WebTouchEvents. // It's a waste to do a double QTouchEvent -> ui::TouchEvent -> blink::WebTouchEvent // conversion but this should hopefully avoid a few bugs in the future. // FIXME: Carry Qt::TouchCancel from the event to each TouchPoint. - base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(ev->timestamp()); Q_FOREACH (const QTouchEvent::TouchPoint& touchPoint, ev->touchPoints()) { // Stationary touch points are already in our accumulator. if (touchPoint.state() == Qt::TouchPointStationary) @@ -970,7 +979,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) toGfxPoint((touchPoint.pos() / dpiScale()).toPoint()), 0, // flags GetMappedTouch(touchPoint.id()), - timestamp, + eventTimestamp, 0, 0, // radius 0, // angle touchPoint.pressure()); diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index f91beb6d23e70cd11d5aa9ba5449f935354a956b..ff73b5734dcafbe93095175c056249147fb114ce 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -220,6 +220,7 @@ private: content::RenderWidgetHostImpl *m_host; scoped_ptr<ui::GestureRecognizer> m_gestureRecognizer; + base::TimeDelta m_eventsToNowDelta; QMap<int, int> m_touchIdMapping; blink::WebTouchEvent m_accumTouchEvent; scoped_ptr<RenderWidgetHostViewQtDelegate> m_delegate;