[Qt] [WK2] Expose web view classes to QML
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 14:25:23 +0000 (14:25 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 14:25:23 +0000 (14:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65339

Reviewed by Benjamin Poulain.

.:

* Source/WebKit.pro: Include QML plugin subdir in the build system for WK2.

Source/WebKit2:

This patch also uses QuickTest from QtDeclarative to provide the basic autotest
infrastructure for the exposed elements.

* UIProcess/API/qt/qmlplugin/plugin.cpp: Added.
(WebKit2QmlPlugin::registerTypes):
* UIProcess/API/qt/qmlplugin/qmldir: Added.
* UIProcess/API/qt/qmlplugin/qmlplugin.pro: Added.
* UIProcess/API/qt/qtouchwebpage.h: Expose load() to QML environment.
* UIProcess/API/qt/qtouchwebview.h: Since QTouchWebPage* doesn't change once set
in the constructor, we mark the page property as CONSTANT. This avoid QML
warnings for not having a NOTIFY signal for the property change.

* UIProcess/API/qt/tests/tests.pro:
* UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_properties.qml: Added.
* UIProcess/API/qt/tests/qmltests/TouchWebView/tst_properties.qml: Added.
* UIProcess/API/qt/tests/qmltests/common/test1.html: Added.
* UIProcess/API/qt/tests/qmltests/qmltests.pro: Added.
* UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp: Added.

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

14 files changed:
ChangeLog
Source/WebKit.pro
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qmlplugin/plugin.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qmlplugin/qmldir [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qmlplugin/qmlplugin.pro [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qtouchwebpage.h
Source/WebKit2/UIProcess/API/qt/qtouchwebview.h
Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_properties.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/TouchWebView/tst_properties.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test1.html [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/tests.pro

index 6cd8f60..6efdeca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-08-02  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] [WK2] Expose web view classes to QML
+        https://bugs.webkit.org/show_bug.cgi?id=65339
+
+        Reviewed by Benjamin Poulain.
+
+        * Source/WebKit.pro: Include QML plugin subdir in the build system for WK2.
+
 2011-08-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Install web and plugin processes in libexecdir instead of bindir
index 46b10f3..741d476 100644 (file)
@@ -23,6 +23,7 @@ SUBDIRS += WebKit/qt/QtWebKit.pro
 webkit2 {
     exists($$PWD/WebKit2/WebProcess.pro): SUBDIRS += WebKit2/WebProcess.pro
     exists($$PWD/WebKit2/UIProcess/API/qt/tests): SUBDIRS += WebKit2/UIProcess/API/qt/tests
+    SUBDIRS += WebKit2/UIProcess/API/qt/qmlplugin
 }
 
 exists($$PWD/WebKit/qt/declarative) {
index 066dfb8..85ad620 100644 (file)
@@ -1,3 +1,29 @@
+2011-08-02  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] [WK2] Expose web view classes to QML
+        https://bugs.webkit.org/show_bug.cgi?id=65339
+
+        Reviewed by Benjamin Poulain.
+
+        This patch also uses QuickTest from QtDeclarative to provide the basic autotest
+        infrastructure for the exposed elements.
+
+        * UIProcess/API/qt/qmlplugin/plugin.cpp: Added.
+        (WebKit2QmlPlugin::registerTypes):
+        * UIProcess/API/qt/qmlplugin/qmldir: Added.
+        * UIProcess/API/qt/qmlplugin/qmlplugin.pro: Added.
+        * UIProcess/API/qt/qtouchwebpage.h: Expose load() to QML environment.
+        * UIProcess/API/qt/qtouchwebview.h: Since QTouchWebPage* doesn't change once set
+        in the constructor, we mark the page property as CONSTANT. This avoid QML
+        warnings for not having a NOTIFY signal for the property change.
+
+        * UIProcess/API/qt/tests/tests.pro:
+        * UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_properties.qml: Added.
+        * UIProcess/API/qt/tests/qmltests/TouchWebView/tst_properties.qml: Added.
+        * UIProcess/API/qt/tests/qmltests/common/test1.html: Added.
+        * UIProcess/API/qt/tests/qmltests/qmltests.pro: Added.
+        * UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp: Added.
+
 2011-08-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Install web and plugin processes in libexecdir instead of bindir
diff --git a/Source/WebKit2/UIProcess/API/qt/qmlplugin/plugin.cpp b/Source/WebKit2/UIProcess/API/qt/qmlplugin/plugin.cpp
new file mode 100644 (file)
index 0000000..41ea7fd
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "qdesktopwebview.h"
+#include "qtouchwebpage.h"
+#include "qtouchwebview.h"
+
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/qdeclarativeextensionplugin.h>
+
+QT_BEGIN_NAMESPACE
+
+class WebKit2QmlPlugin : public QDeclarativeExtensionPlugin {
+    Q_OBJECT
+public:
+    virtual void registerTypes(const char* uri)
+    {
+        Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWebKit.experimental"));
+        qmlRegisterType<QDesktopWebView>(uri, 5, 0, "DesktopWebView");
+        qmlRegisterType<QTouchWebView>(uri, 5, 0, "TouchWebView");
+        qmlRegisterUncreatableType<QTouchWebPage>(uri, 5, 0, "TouchWebPage", QObject::tr("Cannot create separate instance of TouchWebPage, use TouchWebView"));
+    }
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(webkit2qmlplugin, QT_PREPEND_NAMESPACE(WebKit2QmlPlugin));
+
diff --git a/Source/WebKit2/UIProcess/API/qt/qmlplugin/qmldir b/Source/WebKit2/UIProcess/API/qt/qmlplugin/qmldir
new file mode 100644 (file)
index 0000000..ca53c38
--- /dev/null
@@ -0,0 +1 @@
+plugin webkit2qmlplugin
diff --git a/Source/WebKit2/UIProcess/API/qt/qmlplugin/qmlplugin.pro b/Source/WebKit2/UIProcess/API/qt/qmlplugin/qmlplugin.pro
new file mode 100644 (file)
index 0000000..b424f73
--- /dev/null
@@ -0,0 +1,40 @@
+TEMPLATE = lib
+TARGET = webkit2qmlplugin
+TARGETPATH = QtWebKit/experimental
+CONFIG += qt plugin
+
+SOURCES += plugin.cpp
+
+include(../../../../../WebKit.pri)
+QT += declarative
+
+QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
+
+
+# From WK1 qml module. Copies the qmldir file to the build directory,
+# so we can use it in place without installing.
+QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir
+copy2build.input = QMLDIRFILE
+CONFIG(QTDIR_build) {
+    copy2build.output = $$QT_BUILD_TREE/imports/$$TARGETPATH/qmldir
+} else {
+    copy2build.output = $$OUTPUT_DIR/imports/$$TARGETPATH/qmldir
+}
+!contains(TEMPLATE_PREFIX, vc):copy2build.variable_out = PRE_TARGETDEPS
+copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+copy2build.name = COPY ${QMAKE_FILE_IN}
+copy2build.CONFIG += no_link
+QMAKE_EXTRA_COMPILERS += copy2build
+
+
+CONFIG(QTDIR_build) {
+    DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH
+} else {
+    DESTDIR = $$OUTPUT_DIR/imports/$$TARGETPATH
+}
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path +=  $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+INSTALLS += target qmldir
index d3a1abc..4cb5ea7 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     virtual ~QTouchWebPage();
 
-    void load(const QUrl&);
+    Q_INVOKABLE void load(const QUrl&);
     Q_INVOKABLE QUrl url() const;
 
     Q_INVOKABLE QString title() const;
index 6eacbd4..4519dc8 100644 (file)
@@ -35,7 +35,7 @@ class TouchViewInterface;
 class QWEBKIT_EXPORT QTouchWebView : public QSGItem
 {
     Q_OBJECT
-    Q_PROPERTY(QTouchWebPage* page READ page)
+    Q_PROPERTY(QTouchWebPage* page READ page CONSTANT)
 
 public:
     QTouchWebView(QSGItem* parent = 0);
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_properties.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_properties.qml
new file mode 100644 (file)
index 0000000..7d570cc
--- /dev/null
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit.experimental 5.0
+
+DesktopWebView {
+    id: webView
+
+    SignalSpy {
+        id: spy
+        target: webView
+        signalName: "loadSucceeded"
+    }
+
+    TestCase {
+        name: "DesktopWebViewProperties"
+
+        function test_title() {
+            compare(spy.count, 0)
+            webView.load(Qt.resolvedUrl("../common/test1.html"))
+            spy.wait()
+            compare(webView.title, "Test page 1")
+        }
+    }
+}
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/TouchWebView/tst_properties.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/TouchWebView/tst_properties.qml
new file mode 100644 (file)
index 0000000..605c7e8
--- /dev/null
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit.experimental 5.0
+
+TouchWebView {
+    id: webView
+
+    SignalSpy {
+        id: spy
+        target: webView.page
+        signalName: "loadSucceeded"
+    }
+
+    TestCase {
+        name: "TouchWebViewProperties"
+
+        function test_title() {
+            compare(spy.count, 0)
+            webView.page.load(Qt.resolvedUrl("../common/test1.html"))
+            spy.wait()
+            compare(webView.page.title, "Test page 1")
+        }
+    }
+}
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test1.html b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test1.html
new file mode 100644 (file)
index 0000000..5c09f06
--- /dev/null
@@ -0,0 +1,6 @@
+<html>
+<head><title>Test page 1</title></head>
+<body>
+Hello.
+</body>
+</html>
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro
new file mode 100644 (file)
index 0000000..1c301ea
--- /dev/null
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = tst_qmltests
+CONFIG += warn_on testcase
+SOURCES += tst_qmltests.cpp
+
+QT += declarative qmltest
+
+# QML files tested are the ones in WebKit source repository.
+DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD\\\"\"
+
+message($$PWD)
+
+OTHER_FILES += \
+    DesktopWebView/tst_properties.qml \
+    TouchWebView/tst_properties.qml
+
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp
new file mode 100644 (file)
index 0000000..a4755f3
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include <QtQuickTest/quicktest.h>
+QUICK_TEST_MAIN(qmltests)
index fab8df8..f229705 100644 (file)
@@ -1,2 +1,2 @@
 TEMPLATE = subdirs
-SUBDIRS = qtouchwebview qdesktopwebview commonviewtests
+SUBDIRS = qtouchwebview qdesktopwebview commonviewtests qmltests