[Qt][WK2] Implement loadHtml API for QQuickWebView
authorjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Nov 2011 17:15:52 +0000 (17:15 +0000)
committerjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Nov 2011 17:15:52 +0000 (17:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72161

Reviewed by Simon Hausmann.

Implement QQuickWebView::loadHtml that calls QtWebPageProxy::loadHTMLString.
This function will use WKPageLoadHTMLString in order to load HTML from a given string.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebView::loadHtml):
* UIProcess/API/qt/qquickwebview.h:
* UIProcess/API/qt/tests/qmltests/WebView/tst_loadHtml.qml: Added.
* UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml: Added.
* UIProcess/API/qt/tests/qmltests/qmltests.pro:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::loadHTMLString):
* UIProcess/qt/QtWebPageProxy.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_loadHtml.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h

index 4632930..2829dac 100644 (file)
@@ -1,3 +1,23 @@
+2011-11-21  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
+
+        [Qt][WK2] Implement loadHtml API for QQuickWebView
+        https://bugs.webkit.org/show_bug.cgi?id=72161
+
+        Reviewed by Simon Hausmann.
+
+        Implement QQuickWebView::loadHtml that calls QtWebPageProxy::loadHTMLString.
+        This function will use WKPageLoadHTMLString in order to load HTML from a given string.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebView::loadHtml):
+        * UIProcess/API/qt/qquickwebview.h:
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_loadHtml.qml: Added.
+        * UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml: Added.
+        * UIProcess/API/qt/tests/qmltests/qmltests.pro:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::loadHTMLString):
+        * UIProcess/qt/QtWebPageProxy.h:
+
 2011-11-21  Igor Oliveira  <igor.oliveira@openbossa.org>
 
         [WK2][Qt] Move Accelerated Composite animations to UIProcess
index 82a9e19..bf83f5a 100644 (file)
@@ -622,4 +622,18 @@ WKPageRef QQuickWebView::pageRef() const
     return d->pageProxy->pageRef();
 }
 
+/*!
+    Loads the specified \a html as the content of the web view.
+
+    External objects such as stylesheets or images referenced in the HTML
+    document are located relative to \a baseUrl.
+
+    \sa load()
+*/
+void QQuickWebView::loadHtml(const QString& html, const QUrl& baseUrl)
+{
+    Q_D(QQuickWebView);
+    d->pageProxy->loadHTMLString(html, baseUrl);
+}
+
 #include "moc_qquickwebview_p.cpp"
index b0bad94..5eab75a 100644 (file)
@@ -92,6 +92,7 @@ public:
 public Q_SLOTS:
     void load(const QUrl&);
     void postMessage(const QString&);
+    void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
 
     void goBack();
     void goForward();
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml
new file mode 100644 (file)
index 0000000..2dc6242
--- /dev/null
@@ -0,0 +1,52 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit 3.0
+import QtWebKitTest 1.0
+
+DesktopWebView {
+    id: webView
+    width: 200
+    height: 400
+
+    property string lastUrl
+
+    SignalSpy {
+        id: loadSpy
+        target: webView
+        signalName: "loadSucceeded"
+    }
+
+    SignalSpy {
+        id: linkHoveredSpy
+        target: webView
+        signalName: "linkHovered"
+    }
+
+    onLinkHovered: {
+        webView.lastUrl = url
+    }
+
+    TestCase {
+        name: "DesktopWebViewLoadHtml"
+
+        function init() {
+            webView.lastUrl = ""
+            linkHoveredSpy.clear()
+            loadSpy.clear()
+        }
+
+        function test_baseUrlAfterLoadHtml() {
+            skip("Link Hovered is currently not working")
+            loadSpy.clear()
+            linkHoveredSpy.clear()
+            compare(linkHoveredSpy.count, 0)
+            webView.loadHtml("<html><head><title>Test page with huge link area</title></head><body><a title=\"A title\" href=\"test1.html\"><img width=200 height=200></a></body></html>", "http://www.example.foo.com")
+            loadSpy.wait()
+            compare("http://www.example.foo.com/", webView.url)
+            mouseMove(webView, 100, 100)
+            linkHoveredSpy.wait()
+            compare(linkHoveredSpy.count, 1)
+            compare(webView.lastUrl, "http://www.example.foo.com/test1.html")
+        }
+    }
+}
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_loadHtml.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_loadHtml.qml
new file mode 100644 (file)
index 0000000..b57df66
--- /dev/null
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit 3.0
+
+WebView {
+    id: webView
+    width: 200
+    height: 400
+
+    SignalSpy {
+        id: loadSpy
+        target: webView
+        signalName: "loadSucceeded"
+    }
+
+    TestCase {
+        name: "WebViewLoadHtml"
+
+        function test_loadProgressAfterLoadHtml() {
+            loadSpy.clear()
+            compare(loadSpy.count, 0)
+            compare(webView.loadProgress, 0)
+            webView.loadHtml("<html><head><title>Test page 1</title></head><body>Hello.</body></html>")
+            loadSpy.wait()
+            compare(webView.loadProgress, 100)
+        }
+    }
+}
index 536d858..7535fb8 100644 (file)
@@ -23,7 +23,9 @@ OTHER_FILES += \
     WebView/tst_loadProgressSignal.qml \
     WebView/tst_loadZeroSizeView.qml \
     WebView/tst_preferences.qml \
+    WebView/tst_loadHtml.qml \
     DesktopBehavior/tst_linkHovered.qml \
     DesktopBehavior/tst_messaging.qml \
     DesktopBehavior/tst_download.qml \
-    DesktopBehavior/tst_navigationPolicyForUrl.qml
+    DesktopBehavior/tst_navigationPolicyForUrl.qml \
+    DesktopBehavior/tst_loadHtml.qml
index c07ebd0..537b5a6 100644 (file)
@@ -804,6 +804,14 @@ void QtWebPageProxy::postMessageToNavigatorQtObject(const QString& message)
     m_context->postMessageToInjectedBundle(messageName, body.get());
 }
 
+void QtWebPageProxy::loadHTMLString(const QString& html, const QUrl& baseUrl)
+{
+    WKRetainPtr<WKURLRef> wkUrl(WKURLCreateWithQUrl(baseUrl));
+    WKRetainPtr<WKStringRef> wkHtmlString(WKStringCreateWithQString(html));
+
+    WKPageLoadHTMLString(pageRef(), wkHtmlString.get(), wkUrl.get());
+}
+
 void QtWebPageProxy::load(const QUrl& url)
 {
     WKRetainPtr<WKURLRef> wkurl(WKURLCreateWithQUrl(url));
index 2234ad4..67cd055 100644 (file)
@@ -167,6 +167,7 @@ public:
     WKPageRef pageRef() const;
 
     void load(const QUrl& url);
+    void loadHTMLString(const QString& html, const QUrl& baseUrl);
     QUrl url() const;
 
     void setDrawingAreaSize(const QSize&);