[Qt] Add infra for testing double-tap to zoom functionality etc
authorkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2012 13:55:26 +0000 (13:55 +0000)
committerkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2012 13:55:26 +0000 (13:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86474

Reviewed by Simon Hausmann.

Source/WebKit/qt:

The WebViewportInfo class was renamed to QWebKitTest in preparation
of becoming a separate module. Adapt the use API.

* declarative/experimental/plugin.cpp:

Source/WebKit2:

Rename the WebViewportInfo class to QWebKitTest in preparation
of becoming a separate module. Adapt the use API.

Modify the API to work better for testing and make sure the
signals are emitted the right places. Also add a method for
simulating a double tap.

Work around issue with animations not running when the item
doesn't have focus.

Create an example test for double-tap to zoom, showing how we can
now create UI tests using QML.

* Target.pri:
* UIProcess/API/qt/qquickwebpage.cpp:
(QQuickWebPage::setContentsSize):
(QQuickWebPage::setContentsScale):
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewFlickablePrivate::didChangeViewportProperties):
(QQuickWebViewFlickablePrivate::_q_contentViewportChanged):
(QQuickWebViewFlickablePrivate::didChangeContentsSize):
(QQuickWebViewExperimental::QQuickWebViewExperimental):
(QQuickWebViewExperimental::test):
(QQuickWebView::mouseDoubleClickEvent):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
* UIProcess/API/qt/qwebkittest.cpp: Renamed from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp.
(QWebKitTest::QWebKitTest):
(QWebKitTest::~QWebKitTest):
(QWebKitTest::touchDoubleTap):
(QWebKitTest::contentsSize):
(QWebKitTest::contentsScale):
(QWebKitTest::devicePixelRatio):
(QWebKitTest::initialScale):
(QWebKitTest::minimumScale):
(QWebKitTest::maximumScale):
(QWebKitTest::isScalable):
(QWebKitTest::layoutSize):
* UIProcess/API/qt/qwebkittest_p.h: Renamed from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h.
* UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml: Added.
* UIProcess/qt/QtViewportInteractionEngine.cpp:
(WebKit::QtViewportInteractionEngine::animateItemRectVisible):
* UIProcess/qt/QtViewportInteractionEngine.h:
(QtViewportInteractionEngine):

Tools:

The WebViewportInfo class was renamed to QWebKitTest in preparation
of becoming a separate module. Adapt the use API.

* MiniBrowser/qt/qml/BrowserWindow.qml:
* MiniBrowser/qt/qml/ViewportInfoItem.qml:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@117061 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/declarative/experimental/plugin.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/API/qt/qwebkittest.cpp [moved from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp with 64% similarity]
Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h [moved from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h with 70% similarity]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp
Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h
Tools/ChangeLog
Tools/MiniBrowser/qt/qml/BrowserWindow.qml
Tools/MiniBrowser/qt/qml/ViewportInfoItem.qml

index 6881af4..1dad791 100644 (file)
@@ -1,3 +1,15 @@
+2012-05-15  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Add infra for testing double-tap to zoom functionality etc
+        https://bugs.webkit.org/show_bug.cgi?id=86474
+
+        Reviewed by Simon Hausmann.
+
+        The WebViewportInfo class was renamed to QWebKitTest in preparation
+        of becoming a separate module. Adapt the use API.
+
+        * declarative/experimental/plugin.cpp:
+
 2012-05-10  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Move resumeAnimations to use Internals interface
index d33a479..495b308 100644 (file)
 #include "private/qquickwebview_p.h"
 #include "private/qtwebsecurityorigin_p.h"
 #include "private/qwebdownloaditem_p.h"
+#include "private/qwebkittest_p.h"
 #include "private/qwebnavigationhistory_p.h"
 #include "private/qwebpermissionrequest_p.h"
 #include "private/qwebpreferences_p.h"
-#include "private/qwebviewportinfo_p.h"
 
 #include <QtQml/qqml.h>
 #include <QtQml/qqmlextensionplugin.h>
@@ -63,8 +63,8 @@ public:
         qmlRegisterExtendedType<QQuickWebView, QQuickWebViewExperimentalExtension>(uri, 1, 0, "WebView");
         qmlRegisterUncreatableType<QQuickWebViewExperimental>(uri, 1, 0, "WebViewExperimental",
             QObject::tr("Cannot create separate instance of WebViewExperimental"));
-        qmlRegisterUncreatableType<QWebViewportInfo>(uri, 1, 0, "QWebViewportInfo",
-            QObject::tr("Cannot create separate instance of QWebViewportInfo"));
+        qmlRegisterUncreatableType<QWebKitTest>(uri, 1, 0, "QWebKitTest",
+            QObject::tr("Cannot create separate instance of QWebKitTest"));
         qmlRegisterType<QQuickUrlSchemeDelegate>(uri, 1, 0, "UrlSchemeDelegate");
         qmlRegisterUncreatableType<QQuickNetworkRequest>(uri, 1, 0, "NetworkRequest",
             QObject::tr("NetworkRequest should not be created from QML"));
index 2bff1fb..2094976 100644 (file)
@@ -1,3 +1,56 @@
+2012-05-15  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Add infra for testing double-tap to zoom functionality etc
+        https://bugs.webkit.org/show_bug.cgi?id=86474
+
+        Reviewed by Simon Hausmann.
+
+        Rename the WebViewportInfo class to QWebKitTest in preparation
+        of becoming a separate module. Adapt the use API.
+
+        Modify the API to work better for testing and make sure the
+        signals are emitted the right places. Also add a method for
+        simulating a double tap.
+
+        Work around issue with animations not running when the item
+        doesn't have focus.
+
+        Create an example test for double-tap to zoom, showing how we can
+        now create UI tests using QML.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebpage.cpp:
+        (QQuickWebPage::setContentsSize):
+        (QQuickWebPage::setContentsScale):
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewFlickablePrivate::didChangeViewportProperties):
+        (QQuickWebViewFlickablePrivate::_q_contentViewportChanged):
+        (QQuickWebViewFlickablePrivate::didChangeContentsSize):
+        (QQuickWebViewExperimental::QQuickWebViewExperimental):
+        (QQuickWebViewExperimental::test):
+        (QQuickWebView::mouseDoubleClickEvent):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        * UIProcess/API/qt/qwebkittest.cpp: Renamed from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp.
+        (QWebKitTest::QWebKitTest):
+        (QWebKitTest::~QWebKitTest):
+        (QWebKitTest::touchDoubleTap):
+        (QWebKitTest::contentsSize):
+        (QWebKitTest::contentsScale):
+        (QWebKitTest::devicePixelRatio):
+        (QWebKitTest::initialScale):
+        (QWebKitTest::minimumScale):
+        (QWebKitTest::maximumScale):
+        (QWebKitTest::isScalable):
+        (QWebKitTest::layoutSize):
+        * UIProcess/API/qt/qwebkittest_p.h: Renamed from Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h.
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml: Added.
+        * UIProcess/qt/QtViewportInteractionEngine.cpp:
+        (WebKit::QtViewportInteractionEngine::animateItemRectVisible):
+        * UIProcess/qt/QtViewportInteractionEngine.h:
+        (QtViewportInteractionEngine):
+
 2012-05-15  Michael Brüning  <michael.bruning@nokia.com>
 
         [Qt][WK2] http/tests/navigation/https-in-page-cache.html fails with timeout
index d96a852..a4b9a4f 100644 (file)
@@ -195,7 +195,7 @@ HEADERS += \
     UIProcess/API/qt/qquicknetworkreply_p.h \
     UIProcess/API/qt/qquicknetworkrequest_p.h \
     UIProcess/API/qt/qquickurlschemedelegate_p.h \
-    UIProcess/API/qt/qwebviewportinfo_p.h \
+    UIProcess/API/qt/qwebkittest_p.h \
     UIProcess/Authentication/AuthenticationChallengeProxy.h \
     UIProcess/Authentication/AuthenticationDecisionListener.h \
     UIProcess/Authentication/WebCredential.h \
@@ -535,7 +535,7 @@ SOURCES += \
     UIProcess/API/qt/qquicknetworkrequest.cpp \
     UIProcess/API/qt/qquickurlschemedelegate.cpp \
     UIProcess/API/qt/qwebpreferences.cpp \
-    UIProcess/API/qt/qwebviewportinfo.cpp \
+    UIProcess/API/qt/qwebkittest.cpp \
     UIProcess/Authentication/AuthenticationChallengeProxy.cpp \
     UIProcess/Authentication/AuthenticationDecisionListener.cpp \
     UIProcess/Authentication/WebCredential.cpp \
index 203c72b..e02ccc9 100644 (file)
@@ -29,6 +29,7 @@
 #include "WebPageProxy.h"
 #include "qquickwebpage_p_p.h"
 #include "qquickwebview_p.h"
+#include "qwebkittest_p.h"
 #include <QtQuick/QQuickCanvas>
 
 using namespace WebKit;
@@ -110,6 +111,7 @@ void QQuickWebPage::setContentsSize(const QSizeF& size)
 
     d->contentsSize = size;
     d->updateSize();
+    emit d->viewportItem->experimental()->test()->contentsSizeChanged();
 }
 
 const QSizeF& QQuickWebPage::contentsSize() const
@@ -122,6 +124,7 @@ void QQuickWebPage::setContentsScale(qreal scale)
     ASSERT(scale > 0);
     d->contentsScale = scale;
     d->updateSize();
+    emit d->viewportItem->experimental()->test()->contentsScaleCommitted();
 }
 
 qreal QQuickWebPage::contentsScale() const
index 7163a7e..9358421 100644 (file)
 #endif
 #include "WebPageGroup.h"
 #include "WebPreferences.h"
-
 #include "qquicknetworkreply_p.h"
 #include "qquicknetworkrequest_p.h"
 #include "qquickwebpage_p_p.h"
 #include "qquickwebview_p_p.h"
 #include "qwebdownloaditem_p_p.h"
+#include "qwebkittest_p.h"
 #include "qwebloadrequest_p.h"
 #include "qwebnavigationhistory_p.h"
 #include "qwebnavigationhistory_p_p.h"
 #include "qwebpreferences_p.h"
 #include "qwebpreferences_p_p.h"
-#include "qwebviewportinfo_p.h"
-
 #include <JavaScriptCore/InitializeThreading.h>
 #include <JavaScriptCore/JSBase.h>
 #include <JavaScriptCore/JSRetainPtr.h>
@@ -866,7 +864,7 @@ void QQuickWebViewFlickablePrivate::didChangeViewportProperties(const WebCore::V
         interactionEngine->setCSSScale(attr.initialScale);
 
     this->attributes = attr;
-    q->experimental()->viewportInfo()->didUpdateViewportConstraints();
+    emit q->experimental()->test()->viewportChanged();
 
     // If the web app successively changes the viewport on purpose
     // it wants to be in control and we should disable animations.
@@ -895,8 +893,6 @@ void QQuickWebViewFlickablePrivate::updateViewportSize()
 void QQuickWebViewFlickablePrivate::_q_contentViewportChanged(const QPointF& trajectoryVector)
 {
     Q_Q(QQuickWebView);
-    // This is only for our QML ViewportInfo debugging API.
-    q->experimental()->viewportInfo()->didUpdateCurrentScale();
 
     DrawingAreaProxy* drawingArea = webPageProxy->drawingArea();
     if (!drawingArea)
@@ -905,6 +901,8 @@ void QQuickWebViewFlickablePrivate::_q_contentViewportChanged(const QPointF& tra
     const QRect visibleRect(visibleContentsRect());
     float scale = pageView->contentsScale();
 
+    emit q->experimental()->test()->contentsScaleChanged();
+
     QRectF accurateVisibleRect(q->boundingRect());
     accurateVisibleRect.translate(contentPos());
     drawingArea->setVisibleContentsRect(visibleRect, scale, trajectoryVector, FloatPoint(accurateVisibleRect.x(), accurateVisibleRect.y()));
@@ -940,14 +938,13 @@ void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize)
     Q_Q(QQuickWebView);
     QSize viewportSize = q->boundingRect().size().toSize();
 
-    pageView->setContentsSize(newSize);
-    q->experimental()->viewportInfo()->didUpdateContentsSize();
+    pageView->setContentsSize(newSize); // emits contentsSizeChanged()
 
     float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(attributes, viewportSize, newSize);
 
     if (!qFuzzyCompare(minimumScale, attributes.minimumScale)) {
         interactionEngine->setCSSScaleBounds(minimumScale, attributes.maximumScale);
-        q->experimental()->viewportInfo()->didUpdateViewportConstraints();
+        emit q->experimental()->test()->viewportChanged();
 
         if (!interactionEngine->hadUserInteraction() && !pageIsSuspended)
             interactionEngine->setCSSScale(minimumScale);
@@ -975,7 +972,7 @@ QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView)
     , q_ptr(webView)
     , d_ptr(webView->d_ptr.data())
     , schemeParent(new QObject(this))
-    , m_viewportInfo(new QWebViewportInfo(webView->d_ptr.data(), this))
+    , m_test(new QWebKitTest(webView->d_ptr.data(), this))
 {
 }
 
@@ -1386,9 +1383,9 @@ void QQuickWebViewExperimental::goBackTo(int index)
     d_ptr->navigationHistory->d->goBackTo(index);
 }
 
-QWebViewportInfo* QQuickWebViewExperimental::viewportInfo()
+QWebKitTest* QQuickWebViewExperimental::test()
 {
-    return m_viewportInfo;
+    return m_test;
 }
 
 QQuickWebPage* QQuickWebViewExperimental::page()
@@ -1710,6 +1707,7 @@ void QQuickWebView::mouseReleaseEvent(QMouseEvent* event)
 void QQuickWebView::mouseDoubleClickEvent(QMouseEvent* event)
 {
     Q_D(QQuickWebView);
+
     // If a MouseButtonDblClick was received then we got a MouseButtonPress before
     // handleMousePressEvent will take care of double clicks.
     d->pageView->eventHandler()->handleMousePressEvent(event);
index 7bd45b6..773f735 100644 (file)
@@ -38,7 +38,7 @@ class QWebDownloadItem;
 class QWebNavigationHistory;
 class QWebPreferences;
 class QWebPermissionRequest;
-class QWebViewportInfo;
+class QWebKitTest;
 class QQuickNetworkReply;
 
 namespace WTR {
@@ -266,7 +266,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
     Q_PROPERTY(QQmlComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged)
     Q_PROPERTY(QQmlComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged)
     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
-    Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL)
+    Q_PROPERTY(QWebKitTest* test READ test CONSTANT FINAL)
     Q_PROPERTY(QQmlListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
     Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent NOTIFY userAgentChanged)
     Q_PROPERTY(double devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
@@ -303,7 +303,7 @@ public:
     double devicePixelRatio() const;
     void setDevicePixelRatio(double);
 
-    QWebViewportInfo* viewportInfo();
+    QWebKitTest* test();
 
     QWebPreferences* preferences() const;
     QWebNavigationHistory* navigationHistory() const;
@@ -360,7 +360,7 @@ private:
     QQuickWebView* q_ptr;
     QQuickWebViewPrivate* d_ptr;
     QObject* schemeParent;
-    QWebViewportInfo* m_viewportInfo;
+    QWebKitTest* m_test;
 
     friend class WebKit::QtWebPageUIClient;
 
index d3beca4..ebd06e3 100644 (file)
@@ -48,7 +48,7 @@ class WebPageProxy;
 }
 
 class QWebNavigationHistory;
-class QWebViewportInfo;
+class QWebKitTest;
 
 QT_BEGIN_NAMESPACE
 class QQmlComponent;
@@ -60,7 +60,7 @@ class QQuickWebViewPrivate {
     friend class QQuickWebViewExperimental;
     friend class QQuickWebPage;
     friend class QWebPreferencesPrivate;
-    friend class QWebViewportInfo;
+    friend class QWebKitTest;
 
 public:
     static QQuickWebViewPrivate* get(QQuickWebView* q) { return q->d_ptr.data(); }
  */
 
 #include "config.h"
-#include "QtViewportInteractionEngine.h"
-#include "qwebviewportinfo_p.h"
+#include "qwebkittest_p.h"
 
+#include "QtViewportInteractionEngine.h"
+#include "QtWebPageEventHandler.h"
 #include "qquickwebview_p.h"
 #include "qquickwebview_p_p.h"
 
 using namespace WebKit;
 
-QWebViewportInfo::QWebViewportInfo(QQuickWebViewPrivate* webViewPrivate, QObject* parent)
+QWebKitTest::QWebKitTest(QQuickWebViewPrivate* webViewPrivate, QObject* parent)
     : QObject(parent)
     , m_webViewPrivate(webViewPrivate)
 {
 }
 
-QWebViewportInfo::~QWebViewportInfo()
+QWebKitTest::~QWebKitTest()
+{
+}
+
+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");
+        return false;
+    }
+
+    // FIXME: implement delay using QTest::qWait() or similar.
+    Q_UNUSED(delay);
+
+    QPointF localPos(x, y);
+
+    QTouchEvent::TouchPoint point;
+    point.setLastPos(localPos);
+    QRectF touchRect(0, 0, 40, 40);
+    touchRect.moveCenter(localPos);
+    point.setRect(touchRect);
+
+    m_webViewPrivate->pageView->eventHandler()->handleDoubleTapEvent(point);
+
+    return true;
 }
 
-QSize QWebViewportInfo::contentsSize() const
+QSize QWebKitTest::contentsSize() const
 {
     return QSize(m_webViewPrivate->pageView->contentsSize().toSize());
 }
 
-QVariant QWebViewportInfo::currentScale() const
+QVariant QWebKitTest::contentsScale() const
 {
     if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine())
         return interactionEngine->currentCSSScale();
@@ -50,17 +75,17 @@ QVariant QWebViewportInfo::currentScale() const
     return m_webViewPrivate->attributes.initialScale;
 }
 
-QVariant QWebViewportInfo::devicePixelRatio() const
+QVariant QWebKitTest::devicePixelRatio() const
 {
     return m_webViewPrivate->attributes.devicePixelRatio;
 }
 
-QVariant QWebViewportInfo::initialScale() const
+QVariant QWebKitTest::initialScale() const
 {
     return m_webViewPrivate->attributes.initialScale;
 }
 
-QVariant QWebViewportInfo::minimumScale() const
+QVariant QWebKitTest::minimumScale() const
 {
     if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine())
         return interactionEngine->m_minimumScale;
@@ -68,7 +93,7 @@ QVariant QWebViewportInfo::minimumScale() const
     return m_webViewPrivate->attributes.minimumScale;
 }
 
-QVariant QWebViewportInfo::maximumScale() const
+QVariant QWebKitTest::maximumScale() const
 {
     if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine())
         return interactionEngine->m_maximumScale;
@@ -76,28 +101,12 @@ QVariant QWebViewportInfo::maximumScale() const
     return m_webViewPrivate->attributes.maximumScale;
 }
 
-QVariant QWebViewportInfo::isScalable() const
+QVariant QWebKitTest::isScalable() const
 {
     return !!m_webViewPrivate->attributes.userScalable;
 }
 
-QVariant QWebViewportInfo::layoutSize() const
+QVariant QWebKitTest::layoutSize() const
 {
     return QSizeF(m_webViewPrivate->attributes.layoutSize.width(), m_webViewPrivate->attributes.layoutSize.height());
 }
-
-void QWebViewportInfo::didUpdateContentsSize()
-{
-    emit contentsSizeUpdated();
-}
-
-void QWebViewportInfo::didUpdateCurrentScale()
-{
-    emit currentScaleUpdated();
-}
-
-void QWebViewportInfo::didUpdateViewportConstraints()
-{
-    emit viewportConstraintsUpdated();
-    emit currentScaleUpdated();
-}
@@ -18,8 +18,8 @@
  *
  */
 
-#ifndef qwebviewportinfo_p_h
-#define qwebviewportinfo_p_h
+#ifndef qwebkittest_p_h
+#define qwebkittest_p_h
 
 #include "qwebkitglobal.h"
 
 #include <QtCore/QSize>
 #include <QtCore/QVariant>
 #include <QtQml/QtQml>
+#include <QtQuick/qquickitem.h>
 
 class QQuickWebViewPrivate;
 
-class QWEBKIT_EXPORT QWebViewportInfo : public QObject {
+class QWEBKIT_EXPORT QWebKitTest : public QObject {
     Q_OBJECT
-    Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeUpdated)
-    Q_PROPERTY(QVariant currentScale READ currentScale NOTIFY currentScaleUpdated)
-    Q_PROPERTY(QVariant devicePixelRatio READ devicePixelRatio NOTIFY viewportConstraintsUpdated)
-    Q_PROPERTY(QVariant initialScale READ initialScale NOTIFY viewportConstraintsUpdated)
-    Q_PROPERTY(QVariant isScalable READ isScalable NOTIFY viewportConstraintsUpdated)
-    Q_PROPERTY(QVariant maximumScale READ maximumScale NOTIFY viewportConstraintsUpdated)
-    Q_PROPERTY(QVariant minimumScale READ minimumScale NOTIFY viewportConstraintsUpdated)
-    Q_PROPERTY(QVariant layoutSize READ layoutSize NOTIFY viewportConstraintsUpdated)
+
+    Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
+
+    Q_PROPERTY(QVariant contentsScale READ contentsScale NOTIFY contentsScaleChanged)
+
+    Q_PROPERTY(QVariant devicePixelRatio READ devicePixelRatio NOTIFY viewportChanged)
+    Q_PROPERTY(QVariant initialScale READ initialScale NOTIFY viewportChanged)
+    Q_PROPERTY(QVariant isScalable READ isScalable NOTIFY viewportChanged)
+    Q_PROPERTY(QVariant maximumScale READ maximumScale NOTIFY viewportChanged)
+    Q_PROPERTY(QVariant minimumScale READ minimumScale NOTIFY viewportChanged)
+    Q_PROPERTY(QVariant layoutSize READ layoutSize NOTIFY viewportChanged)
 
 signals:
-    void contentsSizeUpdated();
-    void currentScaleUpdated();
-    void viewportConstraintsUpdated();
+    void contentsSizeChanged();
+    void contentsScaleChanged();
+    void contentsScaleCommitted();
+    void viewportChanged();
+
+public slots:
+    bool touchDoubleTap(QObject* item, qreal x, qreal y, int delay = -1);
 
 public:
-    QWebViewportInfo(QQuickWebViewPrivate* webviewPrivate, QObject* parent = 0);
-    virtual ~QWebViewportInfo();
+    QWebKitTest(QQuickWebViewPrivate* webviewPrivate, QObject* parent = 0);
+    virtual ~QWebKitTest();
 
     QSize contentsSize() const;
-    QVariant currentScale() const;
+    QVariant contentsScale() const;
+
     QVariant devicePixelRatio() const;
     QVariant initialScale() const;
     QVariant isScalable() const;
@@ -60,12 +69,8 @@ public:
     QVariant maximumScale() const;
     QVariant minimumScale() const;
 
-    void didUpdateContentsSize();
-    void didUpdateCurrentScale();
-    void didUpdateViewportConstraints();
-
 private:
     QQuickWebViewPrivate* m_webViewPrivate;
 };
 
-#endif // qwebviewportinfo_p
+#endif // qwebkittest_p
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
new file mode 100644 (file)
index 0000000..904f60f
--- /dev/null
@@ -0,0 +1,106 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit 3.0
+import QtWebKit.experimental 1.0
+import Test 1.0
+import "../common"
+
+Item {
+    TestWebView {
+        id: webView
+        width: 480
+        height: 720
+
+        property variant result
+
+        experimental.test.onContentsScaleCommitted: scaleChanged()
+
+        property variant content: "data:text/html," +
+            "<head>" +
+            "    <meta name='viewport' content='width=device-width'>" +
+            "</head>" +
+            "<body>" +
+            "    <div id='target' " +
+            "         style='position:absolute; left:20; top:20; width:200; height:200;'>" +
+            "    </div>" +
+            "</body>"
+
+        signal resultReceived
+        signal scaleChanged
+    }
+
+    SignalSpy {
+        id: resultSpy
+        target: webView
+        signalName: "resultReceived"
+    }
+
+    SignalSpy {
+        id: scaleSpy
+        target: webView
+        signalName: "scaleChanged"
+    }
+
+    TestCase {
+        name: "DoubleTapToZoom"
+
+        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()
+        }
+
+        function documentSize() {
+            resultSpy.clear();
+            var result;
+
+             webView.experimental.evaluateJavaScript(
+                "window.innerWidth + 'x' + window.innerHeight",
+                function(size) { webView.resultReceived(); result = size });
+            resultSpy.wait();
+            return result;
+        }
+
+        function elementRect(id) {
+            resultSpy.clear();
+            var result;
+
+             webView.experimental.evaluateJavaScript(
+                "document.getElementById('" + id + "').getBoundingClientRect();",
+                function(rect) { webView.resultReceived(); result = rect });
+            resultSpy.wait();
+            return result;
+        }
+
+        function doubleTapAtPoint(x, y) {
+            scaleSpy.clear()
+            test.touchDoubleTap(webView, x, y)
+            scaleSpy.wait()
+        }
+
+        function test_basic() {
+            webView.url = webView.content
+            verify(webView.waitForLoadSucceeded())
+
+            compare("480x720", documentSize())
+
+            compare(1.0, test.contentsScale)
+
+            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)
+        }
+    }
+}
index 949a591..b8c85ef 100644 (file)
@@ -192,6 +192,13 @@ bool QtViewportInteractionEngine::animateItemRectVisible(const QRectF& itemRect)
     if (itemRect == currentItemRectVisible)
         return false;
 
+    // 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 true;
+    }
+
     m_scaleAnimation->setDuration(kScaleAnimationDurationMillis);
     m_scaleAnimation->setEasingCurve(QEasingCurve::OutCubic);
 
index 8a720f3..876ab69 100644 (file)
@@ -35,7 +35,7 @@ class QQuickWebView;
 class QWheelEvent;
 QT_END_NAMESPACE
 
-class QWebViewportInfo;
+class QWebKitTest;
 
 namespace WebKit {
 
@@ -116,7 +116,7 @@ private Q_SLOTS:
 
 private:
     friend class ViewportUpdateDeferrer;
-    friend class ::QWebViewportInfo;
+    friend class ::QWebKitTest;
 
     QQuickWebView* const m_viewport;
     QQuickWebPage* const m_content;
index 33a5c39..dc6ff09 100644 (file)
@@ -1,3 +1,16 @@
+2012-05-15  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Add infra for testing double-tap to zoom functionality etc
+        https://bugs.webkit.org/show_bug.cgi?id=86474
+
+        Reviewed by Simon Hausmann.
+
+        The WebViewportInfo class was renamed to QWebKitTest in preparation
+        of becoming a separate module. Adapt the use API.
+
+        * MiniBrowser/qt/qml/BrowserWindow.qml:
+        * MiniBrowser/qt/qml/ViewportInfoItem.qml:
+
 2012-05-15  Csaba Osztrogonác  <ossy@webkit.org>
 
         Introduce ENABLE_CSS_VARIABLES compile flag.
index 5513b9b..96d53d3 100644 (file)
@@ -356,6 +356,6 @@ Rectangle {
             bottom: parent.bottom
         }
         visible: false
-        viewportInfo : webView.experimental.viewportInfo
+        test : webView.experimental.test
     }
 }
index 77f734c..88ac012 100644 (file)
@@ -2,7 +2,7 @@ import QtQuick 2.0
 import QtWebKit 3.0
 
 Rectangle {
-    property var viewportInfo
+    property var test
 
     color: "black"
     opacity: 0.8
@@ -25,28 +25,28 @@ Rectangle {
             id: currentScaleLabel
             anchors.top: viewportInfoLabel.bottom
             anchors.topMargin: 30
-            text: "Current scale: " + parseFloat(viewportInfo.currentScale.toFixed(4))
+            text: "Current scale: " + parseFloat(test.contentsScale.toFixed(4))
             font.family: parent.fontFamily
             color: parent.fontColor
         }
         Text {
             id: initialScaleLabel
             anchors.top: currentScaleLabel.bottom
-            text: "Initial scale: " + parseFloat(viewportInfo.initialScale.toFixed(4))
+            text: "Initial scale: " + parseFloat(test.initialScale.toFixed(4))
             font.family: parent.fontFamily
             color: parent.fontColor
         }
         Text {
             id: minimumScaleLabel
             anchors.top: initialScaleLabel.bottom
-            text: "Minimum scale: " + parseFloat(viewportInfo.minimumScale.toFixed(4))
+            text: "Minimum scale: " + parseFloat(test.minimumScale.toFixed(4))
             font.family: parent.fontFamily
             color: parent.fontColor
         }
         Text {
             id: maximumScaleLabel
             anchors.top: minimumScaleLabel.bottom
-            text: "Maximum scale: " + parseFloat(viewportInfo.maximumScale.toFixed(4))
+            text: "Maximum scale: " + parseFloat(test.maximumScale.toFixed(4))
             font.family: parent.fontFamily
             color: parent.fontColor
         }
@@ -54,21 +54,21 @@ Rectangle {
             id: devicePixelRatioLabel
             anchors.top: maximumScaleLabel.bottom
             anchors.topMargin: 30
-            text: "Device pixel ratio: " + parseFloat(viewportInfo.devicePixelRatio.toFixed(4))
+            text: "Device pixel ratio: " + parseFloat(test.devicePixelRatio.toFixed(4))
             font.family: parent.fontFamily
             color: parent.fontColor
         }
         Text {
             id: contentsSizeLabel
             anchors.top: devicePixelRatioLabel.bottom
-            text: "Contents size: " + viewportInfo.contentsSize.width + "x" + viewportInfo.contentsSize.height
+            text: "Contents size: " + test.contentsSize.width + "x" + test.contentsSize.height
             font.family: parent.fontFamily
             color: parent.fontColor
         }
         Text {
             id: layoutSizeLabel
             anchors.top: contentsSizeLabel.bottom
-            text: "Viewport layout size: " + viewportInfo.layoutSize.width + "x" + viewportInfo.layoutSize.height
+            text: "Viewport layout size: " + test.layoutSize.width + "x" + test.layoutSize.height
             font.family: parent.fontFamily
             color: parent.fontColor
         }
@@ -76,7 +76,7 @@ Rectangle {
             id: scalableLabel
             anchors.top: layoutSizeLabel.bottom
             anchors.topMargin: 30
-            text: "View " + (viewportInfo.isScalable ? "is " : "is not " ) + "scalable."
+            text: "View " + (test.isScalable ? "is " : "is not " ) + "scalable."
             font.family: parent.fontFamily
             color: parent.fontColor
         }