diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-07-31 12:49:02 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-01 12:20:37 +0200 |
commit | f3db445d66924153905997c91f6aa4b36e787ea7 (patch) | |
tree | 5200f7aa13796e1e56d861bad09a67324f045495 /lib | |
parent | 6bce05748e7ff25f2e487357e3fa40b5943ec664 (diff) |
Transform QTouchEvent into ui::TouchEvent first.
WebTouchEvents have a slightly different behavior than QTouchEvent in
that the type of the event is TouchStart for each new point press,
while Qt sends a TouchBegin only for the first point press.
Since we already need to use ui::TouchEvent to be able to use
ui::GestureRecognizer, always do this conversion first to also let
UpdateWebTouchEventAfterDispatch chose the proper event type.
Some of the code from render_widget_host_view_aura.cc was copied into
render_widget_host_view_qt.cpp to fill the needed functionality.
Change-Id: Iab1ca0c449b5256a39b5479ce89b662d4e133935
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/render_widget_host_view_qt.cpp | 64 | ||||
-rw-r--r-- | lib/render_widget_host_view_qt.h | 1 | ||||
-rw-r--r-- | lib/web_event_factory.cpp | 43 | ||||
-rw-r--r-- | lib/web_event_factory.h | 2 |
4 files changed, 63 insertions, 47 deletions
diff --git a/lib/render_widget_host_view_qt.cpp b/lib/render_widget_host_view_qt.cpp index 82ec9ea83..5ee1ff359 100644 --- a/lib/render_widget_host_view_qt.cpp +++ b/lib/render_widget_host_view_qt.cpp @@ -48,7 +48,9 @@ #include "shared/shared_globals.h" #include "content/browser/renderer_host/render_view_host_impl.h" +#include "content/browser/renderer_host/ui_events_helper.h" #include "content/common/gpu/gpu_messages.h" +#include "ui/base/events/event.h" #include "ui/gfx/size_conversions.h" #include <QEvent> @@ -59,6 +61,38 @@ #include <QWheelEvent> #include <QWindow> +static inline ui::EventType toUIEventType(Qt::TouchPointState state) +{ + switch (state) { + case Qt::TouchPointPressed: + return ui::ET_TOUCH_PRESSED; + case Qt::TouchPointMoved: + return ui::ET_TOUCH_MOVED; + case Qt::TouchPointStationary: + return ui::ET_TOUCH_STATIONARY; + case Qt::TouchPointReleased: + return ui::ET_TOUCH_RELEASED; + default: + Q_ASSERT(false); + return ui::ET_UNKNOWN; + } +} + +static inline gfx::Point toGfxPoint(const QPoint& point) +{ + return gfx::Point(point.x(), point.y()); +} + +static void UpdateWebTouchEventAfterDispatch(WebKit::WebTouchEvent* event, WebKit::WebTouchPoint* point) { + if (point->state != WebKit::WebTouchPoint::StateReleased && + point->state != WebKit::WebTouchPoint::StateCancelled) + return; + --event->touchesLength; + for (unsigned i = point - event->touches; i < event->touchesLength; ++i) { + event->touches[i] = event->touches[i + 1]; + } +} + RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget) : m_host(content::RenderWidgetHostImpl::From(widget)) { @@ -469,8 +503,34 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev) void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) { - if (m_host->ShouldForwardTouchEvent()) - m_host->ForwardTouchEventWithLatencyInfo(WebEventFactory::toWebTouchEvent(ev), ui::LatencyInfo()); + // 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 -> WebKit::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) + continue; + + ui::TouchEvent uiEvent( + toUIEventType(touchPoint.state()), + toGfxPoint(touchPoint.pos().toPoint()), + 0, // flags + touchPoint.id(), + timestamp, + 0, 0, // radius + 0, // angle + touchPoint.pressure()); + + WebKit::WebTouchPoint *point = content::UpdateWebTouchEventFromUIEvent(uiEvent, &m_accumTouchEvent); + if (point) { + if (m_host->ShouldForwardTouchEvent()) + m_host->ForwardTouchEventWithLatencyInfo(m_accumTouchEvent, ui::LatencyInfo()); + UpdateWebTouchEventAfterDispatch(&m_accumTouchEvent, point); + } + } } void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev) diff --git a/lib/render_widget_host_view_qt.h b/lib/render_widget_host_view_qt.h index 05713d2b2..542448424 100644 --- a/lib/render_widget_host_view_qt.h +++ b/lib/render_widget_host_view_qt.h @@ -151,6 +151,7 @@ private: bool IsPopup() const; content::RenderWidgetHostImpl *m_host; + WebKit::WebTouchEvent m_accumTouchEvent; scoped_ptr<RenderWidgetHostViewQtDelegate> m_delegate; gfx::Size m_requestedSize; }; diff --git a/lib/web_event_factory.cpp b/lib/web_event_factory.cpp index 40b6b5e6f..8ba4a159d 100644 --- a/lib/web_event_factory.cpp +++ b/lib/web_event_factory.cpp @@ -44,7 +44,6 @@ #include "third_party/WebKit/Source/core/platform/WindowsKeyboardCodes.h" #include <QElapsedTimer> -#include <QEvent> #include <QKeyEvent> #include <QMouseEvent> #include <QWheelEvent> @@ -524,26 +523,6 @@ static WebInputEvent::Type webEventTypeForEvent(const QEvent* event) } } -static WebKit::WebTouchPoint::State toWebTouchPointState(Qt::TouchPointState state) { - switch (state) { - case Qt::TouchPointPressed: - return WebKit::WebTouchPoint::StatePressed; - case Qt::TouchPointMoved: - return WebKit::WebTouchPoint::StateMoved; - case Qt::TouchPointStationary: - return WebKit::WebTouchPoint::StateStationary; - case Qt::TouchPointReleased: - return WebKit::WebTouchPoint::StateReleased; - default: - Q_ASSERT(false); - return WebKit::WebTouchPoint::StateUndefined; - } -} - -static inline WebKit::WebPoint toWebPoint(const QPoint& point) { - return WebKit::WebPoint(point.x(), point.y()); -} - WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev) { WebMouseEvent webKitEvent; @@ -604,28 +583,6 @@ WebKit::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev) return webEvent; } -WebKit::WebTouchEvent WebEventFactory::toWebTouchEvent(QTouchEvent *ev) -{ - WebTouchEvent webEvent; - webEvent.type = webEventTypeForEvent(ev); - webEvent.timeStampSeconds = currentTimeForEvent(ev); - webEvent.modifiers = modifiersForEvent(ev); - - webEvent.touchesLength = ev->touchPoints().size(); - webEvent.changedTouchesLength = 0; - for (unsigned i = 0; i < webEvent.touchesLength; ++i) { - const QTouchEvent::TouchPoint& touchPoint = ev->touchPoints()[i]; - WebTouchPoint& webTouchPoint = webEvent.touches[i]; - webTouchPoint.id = touchPoint.id(); - webTouchPoint.state = toWebTouchPointState(touchPoint.state()); - webTouchPoint.screenPosition = toWebPoint(touchPoint.screenPos().toPoint()); - webTouchPoint.position = toWebPoint(touchPoint.pos().toPoint()); - if (webTouchPoint.state != WebKit::WebTouchPoint::StateStationary) - webEvent.changedTouches[webEvent.changedTouchesLength++] = webTouchPoint; - } - return webEvent; -} - content::NativeWebKeyboardEvent WebEventFactory::toWebKeyboardEvent(QKeyEvent *ev) { content::NativeWebKeyboardEvent webKitEvent; diff --git a/lib/web_event_factory.h b/lib/web_event_factory.h index a8f5ab306..bacb7132c 100644 --- a/lib/web_event_factory.h +++ b/lib/web_event_factory.h @@ -47,7 +47,6 @@ class QMouseEvent; class QKeyEvent; -class QTouchEvent; class QWheelEvent; class WebEventFactory { @@ -55,7 +54,6 @@ class WebEventFactory { public: static WebKit::WebMouseEvent toWebMouseEvent(QMouseEvent*); static WebKit::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*); - static WebKit::WebTouchEvent toWebTouchEvent(QTouchEvent*); static content::NativeWebKeyboardEvent toWebKeyboardEvent(QKeyEvent*); }; |