Skip to content

Instantly share code, notes, and snippets.

@kenchris
Created May 24, 2012 10:30
Show Gist options
  • Save kenchris/2780751 to your computer and use it in GitHub Desktop.
Save kenchris/2780751 to your computer and use it in GitHub Desktop.
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
index 5b4ea2b..88e41a8 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
@@ -124,7 +124,7 @@ void QQuickWebPage::setContentsScale(qreal scale)
ASSERT(scale > 0);
d->contentsScale = scale;
d->updateSize();
- emit d->viewportItem->experimental()->test()->contentsScaleCommitted();
+ emit d->viewportItem->experimental()->test()->contentsScaleChanged();
}
qreal QQuickWebPage::contentsScale() const
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
index 770baa1..0e73a34 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
@@ -770,7 +770,7 @@ void QQuickWebViewLegacyPrivate::setZoomFactor(qreal factor)
QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate(QQuickWebView* viewport)
: QQuickWebViewPrivate(viewport)
- , pageIsSuspended(true)
+ , pageIsSuspended(false)
{
// Disable mouse events on the flickable web view so we do not
// select text during pan gestures on platforms which send both
@@ -801,7 +801,7 @@ void QQuickWebViewFlickablePrivate::onComponentComplete()
QObject::connect(interactionEngine.data(), SIGNAL(contentSuspendRequested()), q, SLOT(_q_suspend()));
QObject::connect(interactionEngine.data(), SIGNAL(contentResumeRequested()), q, SLOT(_q_resume()));
- QObject::connect(interactionEngine.data(), SIGNAL(contentViewportChanged(QPointF)), q, SLOT(_q_contentViewportChanged(QPointF)));
+ QObject::connect(interactionEngine.data(), SIGNAL(informVisibleContentChange(QPointF)), q, SLOT(_q_onInformVisibleContentChange(QPointF)));
_q_resume();
@@ -853,25 +853,35 @@ void QQuickWebViewFlickablePrivate::updateViewportSize()
// it can resize the content accordingly.
webPageProxy->setViewportSize(viewportSize);
- _q_contentViewportChanged(QPointF());
+ _q_onInformVisibleContentChange(QPointF());
}
-void QQuickWebViewFlickablePrivate::_q_contentViewportChanged(const QPointF& trajectoryVector)
+void QQuickWebViewFlickablePrivate::_q_onInformVisibleContentChange(const QPointF& trajectoryVector)
{
Q_Q(QQuickWebView);
+ ASSERT(pageIsSuspended);
+ if (pageIsSuspended)
+ return;
+
DrawingAreaProxy* drawingArea = webPageProxy->drawingArea();
if (!drawingArea)
return;
- const QRect visibleRect(visibleContentsRect());
+ QRectF accurateVisibleRect(q->boundingRect());
+ accurateVisibleRect.translate(contentPos());
+
+ if (accurateVisibleRect == drawingArea->contentsRect())
+ return;
+
float scale = pageView->contentsScale();
- emit q->experimental()->test()->contentsScaleChanged();
+ static float lastCommittedScale = -1;
+ if (scale != lastCommittedScale)
+ emit q->experimental()->test()->contentsScaleCommitted();
+ lastCommittedScale = scale;
- QRectF accurateVisibleRect(q->boundingRect());
- accurateVisibleRect.translate(contentPos());
- drawingArea->setVisibleContentsRect(visibleRect, scale, trajectoryVector, FloatPoint(accurateVisibleRect.x(), accurateVisibleRect.y()));
+ drawingArea->setVisibleContentsRect(QRect(visibleContentsRect()), scale, trajectoryVector, FloatPoint(accurateVisibleRect.x(), accurateVisibleRect.y()));
// Ensure that updatePaintNode is always called before painting.
pageView->update();
@@ -891,7 +901,7 @@ void QQuickWebViewFlickablePrivate::_q_resume()
pageIsSuspended = false;
webPageProxy->resumeActiveDOMObjectsAndAnimations();
- _q_contentViewportChanged(QPointF());
+ _q_onInformVisibleContentChange(QPointF());
}
void QQuickWebViewFlickablePrivate::pageDidRequestScroll(const QPoint& pos)
@@ -908,26 +918,22 @@ void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize)
float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(attributes, viewportSize, newSize);
- bool scaleCommitNotified = false;
-
if (!qFuzzyCompare(minimumScale, attributes.minimumScale)) {
interactionEngine->setCSSScaleBounds(minimumScale, attributes.maximumScale);
emit q->experimental()->test()->viewportChanged();
if (!interactionEngine->hadUserInteraction() && !pageIsSuspended) {
- // Emits contentsScaleCommitted();
- scaleCommitNotified = true;
+ // Emits contentsScaleChanged();
interactionEngine->setCSSScale(minimumScale);
}
}
// Emit for testing purposes, so that it can be verified that
// we didn't do scale adjustment.
- if (!scaleCommitNotified)
- emit q->experimental()->test()->contentsScaleCommitted();
+ interactionEngine->setItemRectVisible(interactionEngine->nearestValidBounds());
+ emit q->experimental()->test()->contentsScaleCommitted();
}
-
/*!
\qmlsignal WebView::onNavigationRequested(WebNavigationRequest request)
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
index 450ea1d..de50810 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
@@ -205,7 +205,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_suspend());
Q_PRIVATE_SLOT(d_func(), void _q_resume());
- Q_PRIVATE_SLOT(d_func(), void _q_contentViewportChanged(const QPointF&));
+ Q_PRIVATE_SLOT(d_func(), void _q_onInformVisibleContentChange(const QPointF&));
Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged());
Q_PRIVATE_SLOT(d_func(), void _q_onUrlChanged());
@@ -215,6 +215,7 @@ private:
QScopedPointer<QQuickWebViewPrivate> d_ptr;
QQuickWebViewExperimental* m_experimental;
+ friend class QWebKitTest;
friend class WebKit::QtViewportInteractionEngine;
friend class WebKit::QtWebPageLoadClient;
friend class WebKit::QtWebPagePolicyClient;
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
index 3069f0d..2c0de7b 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
@@ -94,7 +94,7 @@ public:
virtual void _q_suspend() { }
virtual void _q_resume() { }
- virtual void _q_contentViewportChanged(const QPointF& trajectory) { };
+ virtual void _q_onInformVisibleContentChange(const QPointF& trajectory) { };
virtual qreal zoomFactor() const { return 1; }
virtual void setZoomFactor(qreal) { }
@@ -229,7 +229,7 @@ public:
virtual void _q_suspend();
virtual void _q_resume();
- virtual void _q_contentViewportChanged(const QPointF& trajectory);
+ virtual void _q_onInformVisibleContentChange(const QPointF& trajectory);
virtual void pageDidRequestScroll(const QPoint& pos);
virtual void didChangeContentsSize(const QSize& newSize);
diff --git a/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp b/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp
index 84b6a9f..85421e8 100644
--- a/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp
@@ -21,6 +21,12 @@
#include "config.h"
#include "qwebkittest_p.h"
+#include <QEvent>
+#include <QList>
+#include <QTouchEvent>
+#include <QQuickCanvas>
+#include <QMutableListIterator>
+#include "qwindowsysteminterface_qpa.h"
#include "QtViewportInteractionEngine.h"
#include "QtWebPageEventHandler.h"
#include "qquickwebview_p.h"
@@ -43,41 +49,79 @@ static QTouchEvent::TouchPoint touchPoint(qreal x, qreal y)
QPointF localPos(x, y);
QTouchEvent::TouchPoint point;
+ point.setId(1);
point.setLastPos(localPos);
QRectF touchRect(0, 0, 40, 40);
touchRect.moveCenter(localPos);
point.setRect(touchRect);
+ point.setPressure(1);
return point;
}
+bool QWebKitTest::sendTouchEvent(QQuickWebView* window, QEvent::Type type, QList<QTouchEvent::TouchPoint>& points, ulong timestamp)
+{
+ ASSERT(window);
+
+ static QTouchDevice* device = 0;
+ if (!device) {
+ device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ }
+
+ Qt::TouchPointStates touchPointStates = 0;
+ foreach (const QTouchEvent::TouchPoint& touchPoint, points)
+ touchPointStates |= touchPoint.state();
+
+ QTouchEvent event(type, device, Qt::NoModifier, touchPointStates, points);
+ event.setTimestamp(timestamp);
+ event.setAccepted(false);
+
+ window->touchEvent(&event);
+
+ // Get rid of touch-points that are no longer valid.
+ QMutableListIterator<QTouchEvent::TouchPoint> it(points);
+ while (it.hasNext()) {
+ QTouchEvent::TouchPoint point = it.next();
+ if (point.state() == Qt::TouchPointReleased)
+ it.remove();
+ }
+
+ return event.isAccepted();
+}
+
bool QWebKitTest::touchTap(QObject* item, qreal x, qreal y, int delay)
{
- if (!qobject_cast<QQuickWebView*>(item)) {
- // FIXME: We only support the actual web view for now.
- qWarning("Touch event \"DoubleTap\" not accepted by receiving item");
+ QQuickWebView* window = qobject_cast<QQuickWebView*>(item);
+
+ if (!window) {
+ qWarning("Touch event \"TouchBegin\" not accepted by receiving item");
return false;
}
// FIXME: implement delay using QTest::qWait() or similar.
Q_UNUSED(delay);
- m_webViewPrivate->pageView->eventHandler()->handleSingleTapEvent(touchPoint(x, y));
+
+ QList<QTouchEvent::TouchPoint> points;
+ points.append(touchPoint(x, y));
+
+ points[0].setState(Qt::TouchPointPressed);
+ sendTouchEvent(window, QEvent::TouchBegin, points, QDateTime::currentMSecsSinceEpoch());
+
+ points[0].setState(Qt::TouchPointReleased);
+ sendTouchEvent(window, QEvent::TouchEnd, points, QDateTime::currentMSecsSinceEpoch());
return true;
}
bool QWebKitTest::touchDoubleTap(QObject* item, qreal x, qreal y, int delay)
{
- if (!qobject_cast<QQuickWebView*>(item)) {
- // FIXME: We only support the actual web view for now.
- qWarning("Touch event \"DoubleTap\" not accepted by receiving item");
+ if (!touchTap(item, x, y, delay))
return false;
- }
- // FIXME: implement delay using QTest::qWait() or similar.
- Q_UNUSED(delay);
-
- m_webViewPrivate->pageView->eventHandler()->handleDoubleTapEvent(touchPoint(x, y));
+ if (!touchTap(item, x, y, delay))
+ return false;
return true;
}
diff --git a/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h b/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h
index 6134864..2310894 100644
--- a/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h
@@ -29,6 +29,7 @@
#include <QtCore/QVariant>
#include <QtQml/QtQml>
#include <QtQuick/qquickitem.h>
+#include "qquickwebview_p.h"
class QQuickWebViewPrivate;
@@ -60,6 +61,8 @@ public:
QWebKitTest(QQuickWebViewPrivate* webviewPrivate, QObject* parent = 0);
virtual ~QWebKitTest();
+ bool sendTouchEvent(QQuickWebView* window, QEvent::Type type, QList<QTouchEvent::TouchPoint>& points, ulong timestamp);
+
QSize contentsSize() const;
QVariant contentsScale() const;
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml
index 904f60f..b2a860e 100644
--- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml
+++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml
@@ -46,15 +46,6 @@ Item {
property variant test: webView.experimental.test
- // Delayed windowShown to workaround problems with Qt5 in debug mode.
- when: false
- Timer {
- running: parent.windowShown
- repeat: false
- interval: 1
- onTriggered: parent.when = true
- }
-
function init() {
resultSpy.clear()
scaleSpy.clear()
@@ -92,15 +83,15 @@ Item {
webView.url = webView.content
verify(webView.waitForLoadSucceeded())
- compare("480x720", documentSize())
+ compare(documentSize(), "480x720")
- compare(1.0, test.contentsScale)
+ compare(test.contentsScale, 1.0)
var rect = elementRect("target");
var newScale = webView.width / (rect.width + 2 * 10) // inflated by 10px
doubleTapAtPoint(rect.left + rect.height / 2, rect.top + rect.width / 2)
- compare(newScale, test.contentsScale)
+ compare(test.contentsScale, newScale)
}
}
}
diff --git a/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp b/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp
index b2cadf7..cd4f36a 100644
--- a/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp
@@ -85,7 +85,7 @@ public:
// Make sure that tiles all around the viewport will be requested.
- emit engine->contentViewportChanged(QPointF());
+ emit engine->informVisibleContentChange(QPointF());
}
private:
@@ -170,6 +170,9 @@ qreal QtViewportInteractionEngine::outerBoundedCSSScale(qreal cssScale) const
void QtViewportInteractionEngine::setItemRectVisible(const QRectF& itemRect)
{
+ ASSERT_WITH_MESSAGE(m_suspendCount,
+ "setItemRectVisible has to be guarded using a ViewportUpdateDeferrer.");
+
if (itemRect.isEmpty())
return;
@@ -182,6 +185,9 @@ void QtViewportInteractionEngine::setItemRectVisible(const QRectF& itemRect)
QPointF newPosition(m_content->pos() + (itemRect.topLeft() * itemScale));
m_viewport->setContentPos(newPosition);
+
+ // Make sure that tiles all around the viewport will be requested.
+ //emit informVisibleContentChange(QPointF());
}
// Ease out overshoot of 1.25 combined with ease in correction of 0.25. Both quadratic to have physical motion.
@@ -202,13 +208,6 @@ void QtViewportInteractionEngine::animateItemRectVisible(const QRectF& itemRect)
if (itemRect == currentItemRectVisible)
return;
- // FIXME: Investigate why that animation doesn't run when we are unfocused.
- if (!m_viewport->isVisible() || !m_viewport->hasFocus()) {
- // Apply the end result immediately when we are non-visible.
- setItemRectVisible(itemRect);
- return;
- }
-
QEasingCurve easingCurve;
easingCurve.setCustomType(physicalOvershoot);
@@ -246,7 +245,7 @@ void QtViewportInteractionEngine::flickableMovingPositionUpdate()
{
QPointF newPosition = m_viewport->contentPos();
- emit contentViewportChanged(m_lastScrollPosition - newPosition);
+ emit informVisibleContentChange(m_lastScrollPosition - newPosition);
m_lastScrollPosition = newPosition;
}
@@ -286,11 +285,14 @@ void QtViewportInteractionEngine::pagePositionRequest(const QPoint& pagePosition
QRectF endVisibleContentRect(endPosition / endItemScale, m_viewport->boundingRect().size() / endItemScale);
+ ViewportUpdateDeferrer(this);
setItemRectVisible(endVisibleContentRect);
}
void QtViewportInteractionEngine::touchBegin()
{
+ m_hadUserInteraction = true;
+
// Prevents resuming the page between the user's flicks of the page while the animation is running.
if (scrollAnimationActive())
m_touchUpdateDeferrer = adoptPtr(new ViewportUpdateDeferrer(this, ViewportUpdateDeferrer::DeferUpdateAndSuspendContent));
@@ -314,6 +316,9 @@ QRectF QtViewportInteractionEngine::computePosRangeForItemAtScale(qreal itemScal
void QtViewportInteractionEngine::focusEditableArea(const QRectF& caretArea, const QRectF& targetArea)
{
+ // This can only happen as a result of a user interaction.
+ ASSERT(m_hadUserInteraction);
+
QRectF endArea = itemRectFromCSS(targetArea);
qreal endItemScale = itemScaleFromCSS(innerBoundedCSSScale(2.0));
@@ -348,6 +353,9 @@ void QtViewportInteractionEngine::focusEditableArea(const QRectF& caretArea, con
void QtViewportInteractionEngine::zoomToAreaGestureEnded(const QPointF& touchPoint, const QRectF& targetArea)
{
+ // This can only happen as a result of a user interaction.
+ ASSERT(m_hadUserInteraction);
+
if (!targetArea.isValid())
return;
@@ -539,6 +547,7 @@ void QtViewportInteractionEngine::cancelScrollAnimation()
// immediately positioned back to valid boundaries.
m_viewport->cancelFlick();
+ ViewportUpdateDeferrer(this);
setItemRectVisible(nearestValidBounds());
}
@@ -566,9 +575,6 @@ void QtViewportInteractionEngine::pinchGestureStarted(const QPointF& pinchCenter
m_lastPinchCenterInViewportCoordinates = pinchCenterInViewportCoordinates;
m_pinchStartScale = m_content->contentsScale();
-
- // Reset the tiling look-ahead vector so that tiles all around the viewport will be requested on pinch-end.
- emit contentViewportChanged(QPointF());
}
void QtViewportInteractionEngine::pinchGestureRequestUpdate(const QPointF& pinchCenterInViewportCoordinates, qreal totalScaleFactor)
@@ -623,6 +629,7 @@ void QtViewportInteractionEngine::itemSizeChanged()
if (m_suspendCount)
return;
+ ViewportUpdateDeferrer(this);
setItemRectVisible(nearestValidBounds());
}
diff --git a/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h b/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h
index 22e6941..ba540d5 100644
--- a/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h
+++ b/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h
@@ -96,9 +96,8 @@ Q_SIGNALS:
void contentSuspendRequested();
void contentResumeRequested();
- void contentViewportChanged(const QPointF& trajectory = QPointF());
+ void informVisibleContentChange(const QPointF& trajectory = QPointF());
- void viewportTrajectoryVectorChanged(const QPointF&);
void visibleContentRectAndScaleChanged();
private Q_SLOTS:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment