summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-08-12 09:27:39 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-08-12 09:27:39 +0200
commit3749d61e1f7a59f5ec5067e560af1eb610c82015 (patch)
tree73dc228333948738bbe02976cacca8cd382bc978 /Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
parentb32b4dcd9a51ab8de6afc53d9e17f8707e1f7a5e (diff)
Imported WebKit commit a77350243e054f3460d1137301d8b3faee3d2052 (http://svn.webkit.org/repository/webkit/trunk@125365)
New snapshot with build fixes for latest API changes in Qt and all WK1 Win MSVC fixes upstream
Diffstat (limited to 'Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp')
-rw-r--r--Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp103
1 files changed, 76 insertions, 27 deletions
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
index d82eba2f9..a02900fcd 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
@@ -31,8 +31,10 @@
#include <QCursor>
#include <QDrag>
#include <QGuiApplication>
+#include <QInputEvent>
#include <QInputMethod>
#include <QMimeData>
+#include <QMouseEvent>
#include <QQuickWindow>
#include <QStyleHints>
#include <QTextFormat>
@@ -99,6 +101,7 @@ QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, QQuickWebPage* q
, m_clickCount(0)
, m_postponeTextInputStateChanged(false)
, m_isTapHighlightActive(false)
+ , m_isMouseButtonPressed(false)
{
connect(qApp->inputMethod(), SIGNAL(visibleChanged()), this, SLOT(inputPanelVisibleChanged()));
}
@@ -427,7 +430,7 @@ void QtWebPageEventHandler::updateTextInputState()
if (!m_webView->hasActiveFocus())
return;
- qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled);
+ qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints);
setInputPanelVisible(editor.isContentEditable);
}
@@ -445,23 +448,17 @@ void QtWebPageEventHandler::doneWithGestureEvent(const WebGestureEvent& event, b
updateTextInputState();
}
-#if ENABLE(TOUCH_EVENTS)
-void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
+void QtWebPageEventHandler::handleInputEvent(const QInputEvent* event)
{
- if (!m_viewportHandler)
- return;
+ ASSERT(m_viewportHandler);
- if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
- m_panGestureRecognizer.cancel();
- m_pinchGestureRecognizer.cancel();
- if (event.type() != WebEvent::TouchMove)
- m_tapGestureRecognizer.cancel();
- return;
- }
-
- const QTouchEvent* ev = event.nativeEvent();
+ bool isMouseEvent = false;
- switch (ev->type()) {
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ isMouseEvent = true;
+ m_isMouseButtonPressed = true;
+ // Fall through.
case QEvent::TouchBegin:
ASSERT(!m_viewportHandler->panGestureActive());
ASSERT(!m_viewportHandler->pinchGestureActive());
@@ -472,16 +469,27 @@ void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event,
// where as it does not stop the scale animation.
// The gesture recognizer stops the kinetic scrolling animation if needed.
break;
+ case QEvent::MouseMove:
+ if (!m_isMouseButtonPressed)
+ return;
+
+ isMouseEvent = true;
+ // Fall through.
case QEvent::TouchUpdate:
// The scale animation can only be interrupted by a pinch gesture, which will then take over.
if (m_viewportHandler->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized())
m_viewportHandler->interruptScaleAnimation();
break;
+ case QEvent::MouseButtonRelease:
+ isMouseEvent = true;
+ m_isMouseButtonPressed = false;
+ // Fall through.
case QEvent::TouchEnd:
m_viewportHandler->touchEnd();
break;
default:
- break;
+ ASSERT(event->type() == QEvent::MouseButtonDblClick);
+ return;
}
// If the scale animation is active we don't pass the event to the recognizers. In the future
@@ -489,15 +497,36 @@ void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event,
if (m_viewportHandler->scaleAnimationActive())
return;
- const QList<QTouchEvent::TouchPoint>& touchPoints = ev->touchPoints();
- const int touchPointCount = touchPoints.size();
- qint64 eventTimestampMillis = ev->timestamp();
QList<QTouchEvent::TouchPoint> activeTouchPoints;
- activeTouchPoints.reserve(touchPointCount);
-
- for (int i = 0; i < touchPointCount; ++i) {
- if (touchPoints[i].state() != Qt::TouchPointReleased)
- activeTouchPoints << touchPoints[i];
+ QTouchEvent::TouchPoint currentTouchPoint;
+ qint64 eventTimestampMillis = event->timestamp();
+ int touchPointCount = 0;
+
+ if (!isMouseEvent) {
+ const QTouchEvent* touchEvent = static_cast<const QTouchEvent*>(event);
+ const QList<QTouchEvent::TouchPoint>& touchPoints = touchEvent->touchPoints();
+ currentTouchPoint = touchPoints.first();
+ touchPointCount = touchPoints.size();
+ activeTouchPoints.reserve(touchPointCount);
+
+ for (int i = 0; i < touchPointCount; ++i) {
+ if (touchPoints[i].state() != Qt::TouchPointReleased)
+ activeTouchPoints << touchPoints[i];
+ }
+ } else {
+ const QMouseEvent* mouseEvent = static_cast<const QMouseEvent*>(event);
+ touchPointCount = 1;
+
+ // Make a distinction between mouse events on the basis of pressed buttons.
+ currentTouchPoint.setId(mouseEvent->buttons());
+ currentTouchPoint.setScreenPos(mouseEvent->screenPos());
+ // For tap gesture hit testing the float touch rect is translated to
+ // an int rect representing the radius of the touch point (size/2),
+ // thus the touch rect has to have a size of at least 2.
+ currentTouchPoint.setRect(QRectF(mouseEvent->localPos(), QSizeF(2, 2)));
+
+ if (m_isMouseButtonPressed)
+ activeTouchPoints << currentTouchPoint;
}
const int activeTouchPointCount = activeTouchPoints.size();
@@ -506,11 +535,11 @@ void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event,
if (touchPointCount == 1) {
// No active touch points, one finger released.
if (m_panGestureRecognizer.isRecognized())
- m_panGestureRecognizer.finish(touchPoints.first(), eventTimestampMillis);
+ m_panGestureRecognizer.finish(currentTouchPoint, eventTimestampMillis);
else {
// The events did not result in a pan gesture.
m_panGestureRecognizer.cancel();
- m_tapGestureRecognizer.finish(touchPoints.first());
+ m_tapGestureRecognizer.finish(currentTouchPoint);
}
} else
@@ -532,7 +561,27 @@ void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event,
if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized() || m_webView->isMoving())
m_tapGestureRecognizer.cancel();
else if (touchPointCount == 1)
- m_tapGestureRecognizer.update(touchPoints.first());
+ m_tapGestureRecognizer.update(currentTouchPoint);
+
+}
+
+#if ENABLE(TOUCH_EVENTS)
+void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
+{
+ if (!m_viewportHandler)
+ return;
+
+ if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
+ m_panGestureRecognizer.cancel();
+ m_pinchGestureRecognizer.cancel();
+ if (event.type() != WebEvent::TouchMove)
+ m_tapGestureRecognizer.cancel();
+ return;
+ }
+
+ const QTouchEvent* ev = event.nativeEvent();
+
+ handleInputEvent(ev);
}
#endif