diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-07-22 11:19:14 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-07-29 17:38:29 +0200 |
commit | 519367a98334b658a93ed1ba096dba92858445c7 (patch) | |
tree | 44d2e328d3f3075c4c64859ae3d3880c2d9f6116 /lib/web_event_factory.cpp | |
parent | c4083f0d8b06f7ede95968a010153fcc49f8d51c (diff) |
Forward touch events.
This lets the page receive touch events sent to the QWidget/QQuickItem.
Change-Id: Ic358d4963d6af3df57d37a02b471cd442e8947ce
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'lib/web_event_factory.cpp')
-rw-r--r-- | lib/web_event_factory.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/lib/web_event_factory.cpp b/lib/web_event_factory.cpp index ed24c5b6d..388e0f9b2 100644 --- a/lib/web_event_factory.cpp +++ b/lib/web_event_factory.cpp @@ -43,11 +43,12 @@ #include "web_event_factory.h" #include "third_party/WebKit/Source/core/platform/WindowsKeyboardCodes.h" -#include <QMouseEvent> -#include <QKeyEvent> +#include <QApplication> #include <QElapsedTimer> +#include <QEvent> +#include <QKeyEvent> +#include <QMouseEvent> #include <QWheelEvent> -#include <QApplication> using namespace WebKit; @@ -522,6 +523,25 @@ 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) { @@ -585,6 +605,28 @@ 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; |