diff options
35 files changed, 2033 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 0000000..38985c5 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += webview diff --git a/examples/webview/webview.pro b/examples/webview/webview.pro new file mode 100644 index 0000000..38985c5 --- /dev/null +++ b/examples/webview/webview.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += webview diff --git a/examples/webview/webview/deployment.pri b/examples/webview/webview/deployment.pri new file mode 100644 index 0000000..5441b63 --- /dev/null +++ b/examples/webview/webview/deployment.pri @@ -0,0 +1,27 @@ +android-no-sdk { + target.path = /data/user/qt + export(target.path) + INSTALLS += target +} else:android { + x86 { + target.path = /libs/x86 + } else: armeabi-v7a { + target.path = /libs/armeabi-v7a + } else { + target.path = /libs/armeabi + } + export(target.path) + INSTALLS += target +} else:unix { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/examples/webview/webview/doc/images/qtwebview-example.png b/examples/webview/webview/doc/images/qtwebview-example.png Binary files differnew file mode 100644 index 0000000..40f2611 --- /dev/null +++ b/examples/webview/webview/doc/images/qtwebview-example.png diff --git a/examples/webview/webview/doc/src/webview.qdoc b/examples/webview/webview/doc/src/webview.qdoc new file mode 100644 index 0000000..034be45 --- /dev/null +++ b/examples/webview/webview/doc/src/webview.qdoc @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \title Qt WebView Examples - WebView + \example qtwebview + \brief WebView is an example that demonstrates how to use the Qt WebView module with Qt Quick. + \image qtwebview-example.png + \ingroup qtwebview-examples + + The WebView example creates a simple browser using Qt Quick Controls + and Qt WebView. +*/ diff --git a/examples/webview/webview/main.cpp b/examples/webview/webview/main.cpp new file mode 100644 index 0000000..8525bc2 --- /dev/null +++ b/examples/webview/webview/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/examples/webview/webview/main.qml b/examples/webview/webview/main.qml new file mode 100644 index 0000000..5b1e951 --- /dev/null +++ b/examples/webview/webview/main.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Dialogs 1.2 +import QtWebView 1.0 + +ApplicationWindow { + id: topLevel + visible: true + width: 640 + height: 480 + title: qsTr("QtWebView Browser") + + Label { + id: title + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + horizontalAlignment: Label.AlignHCenter + text: webView.title + } + + Rectangle { + id: addressBar + anchors.top: title.bottom + anchors.left: parent.left + anchors.right: parent.right + height: parent.height / 10 + color: "black" + + Button { + id: goButton + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.margins: topLevel.width / 30 + text: qsTr("Go") + onClicked: { + webView.url = addressField.text + } + } + + TextField { + id: addressField + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: goButton.left + anchors.margins: topLevel.width / 30 + } + } + + WebView { + id: webView + anchors.top: addressBar.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + url: "http://qt-project.org" + onUrlChanged: { + addressField.text = url + } + } +} diff --git a/examples/webview/webview/qml.qrc b/examples/webview/webview/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/examples/webview/webview/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/examples/webview/webview/webview.pro b/examples/webview/webview/webview.pro new file mode 100644 index 0000000..77cbe78 --- /dev/null +++ b/examples/webview/webview/webview.pro @@ -0,0 +1,13 @@ +TEMPLATE = app + +QT += qml quick + +SOURCES += main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/qtwebview.pro b/qtwebview.pro new file mode 100644 index 0000000..58c33f2 --- /dev/null +++ b/qtwebview.pro @@ -0,0 +1 @@ +load(qt_parts) diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 0000000..88e4c3b --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,18 @@ +CXX_MODULE = webview +TARGET = declarative_webview +TARGETPATH = QtWebView +IMPORT_VERSION = 1.0 + +QT += qml quick webview webview-private +SOURCES += \ + $$PWD/webview.cpp + +!android: qtHaveModule(webengine) { + QT += webengine webengine-private + DEFINES += QT_WEBVIEW_WEBENGINE_BACKEND +} + + +load(qml_plugin) + +OTHER_FILES += qmldir diff --git a/src/imports/qmldir b/src/imports/qmldir new file mode 100644 index 0000000..d8d92f3 --- /dev/null +++ b/src/imports/qmldir @@ -0,0 +1,4 @@ +module QtWebView +plugin declarative_webview +typeinfo plugins.qmltypes +classname QWebViewModule diff --git a/src/imports/webview.cpp b/src/imports/webview.cpp new file mode 100644 index 0000000..6c6d145 --- /dev/null +++ b/src/imports/webview.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> + +#include <QtWebView/private/qwebview_p.h> + +QT_BEGIN_NAMESPACE + +class QWebViewModule : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") +public: + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWebView")); + + // @uri QtWebView + qmlRegisterType<QWebView>(uri, 1, 0, "WebView"); + } + + void initializeEngine(QQmlEngine *engine, const char *uri) + { + Q_UNUSED(uri); + Q_UNUSED(engine); + } +}; + +QT_END_NAMESPACE + +#include "webview.moc" + + + diff --git a/src/jar/bundledjar.pro b/src/jar/bundledjar.pro new file mode 100644 index 0000000..abe173b --- /dev/null +++ b/src/jar/bundledjar.pro @@ -0,0 +1,3 @@ +TARGET = QtAndroidWebView-bundled +CONFIG += bundled_jar_file +include(jar.pri) diff --git a/src/jar/distributedjar.pro b/src/jar/distributedjar.pro new file mode 100644 index 0000000..710983e --- /dev/null +++ b/src/jar/distributedjar.pro @@ -0,0 +1,2 @@ +TARGET = QtAndroidWebView +include(jar.pri) diff --git a/src/jar/jar.pri b/src/jar/jar.pri new file mode 100644 index 0000000..0c4f499 --- /dev/null +++ b/src/jar/jar.pri @@ -0,0 +1,11 @@ +load(qt_build_paths) +CONFIG += java +DESTDIR = $$MODULE_BASE_OUTDIR/jar + +JAVACLASSPATH += $$PWD/src + +JAVASOURCES += $$PWD/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java + +# install +target.path = $$[QT_INSTALL_PREFIX]/jar +INSTALLS += target diff --git a/src/jar/jar.pro b/src/jar/jar.pro new file mode 100644 index 0000000..6a4fcd3 --- /dev/null +++ b/src/jar/jar.pro @@ -0,0 +1,3 @@ +TEMPLATE=subdirs +SUBDIRS += distributedjar.pro bundledjar.pro + diff --git a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java new file mode 100644 index 0000000..de3d374 --- /dev/null +++ b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java @@ -0,0 +1,253 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +package org.qtproject.qt5.android.view; + +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.webkit.WebChromeClient; +import java.lang.Runnable; +import android.app.Activity; +import java.lang.String; +import android.webkit.WebSettings; +import android.webkit.URLUtil; +import android.util.Log; +import android.webkit.WebSettings.PluginState; +import android.graphics.Bitmap; +import java.util.concurrent.Semaphore; + +public class QtAndroidWebViewController +{ + private final Activity m_activity; + private final long m_id; + private WebView m_webView = null; + private static final String TAG = "QtAndroidWebViewController"; + // Native callbacks + private native void c_onPageFinished(long id, String url); + private native void c_onPageStarted(long id, String url, Bitmap icon); + private native void c_onProgressChanged(long id, int newProgress); + private native void c_onReceivedIcon(long id, Bitmap icon); + private native void c_onReceivedTitle(long id, String title); + + private class QtAndroidWebViewClient extends WebViewClient + { + QtAndroidWebViewClient() { super(); } + + @Override + public void onLoadResource(WebView view, String url) + { + super.onLoadResource(view, url); + } + + @Override + public void onPageFinished(WebView view, String url) + { + super.onPageFinished(view, url); + c_onPageFinished(m_id, url); + } + + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) + { + super.onPageStarted(view, url, favicon); + c_onPageStarted(m_id, url, favicon); + } + } + + private class QtAndroidWebChromeClient extends WebChromeClient + { + QtAndroidWebChromeClient() { super(); } + @Override + public void onProgressChanged(WebView view, int newProgress) + { + super.onProgressChanged(view, newProgress); + c_onProgressChanged(m_id, newProgress); + } + + @Override + public void onReceivedIcon(WebView view, Bitmap icon) + { + super.onReceivedIcon(view, icon); + c_onReceivedIcon(m_id, icon); + } + + @Override + public void onReceivedTitle(WebView view, String title) + { + super.onReceivedTitle(view, title); + c_onReceivedTitle(m_id, title); + } + } + + public QtAndroidWebViewController(final Activity activity, final long id) + { + m_activity = activity; + m_id = id; + final Semaphore sem = new Semaphore(0); + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { + m_webView = new WebView(m_activity); + WebSettings webSettings = m_webView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setBuiltInZoomControls(true); + webSettings.setPluginState(PluginState.ON); + m_webView.setWebViewClient((WebViewClient)new QtAndroidWebViewClient()); + m_webView.setWebChromeClient((WebChromeClient)new QtAndroidWebChromeClient()); + sem.release(); + } + }); + + try { + sem.acquire(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadUrl(final String url) + { + if (url == null) { + return; + } + + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { m_webView.loadUrl(URLUtil.guessUrl(url)); } + }); + } + + public void goBack() + { + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { m_webView.goBack(); } + }); + } + + public boolean canGoBack() + { + final boolean[] back = {false}; + final Semaphore sem = new Semaphore(0); + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { back[0] = m_webView.canGoBack(); sem.release(); } + }); + + try { + sem.acquire(); + } catch (Exception e) { + e.printStackTrace(); + } + + return back[0]; + } + + public void goForward() + { + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { m_webView.goForward(); } + }); + } + + public boolean canGoForward() + { + final boolean[] forward = {false}; + final Semaphore sem = new Semaphore(0); + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { forward[0] = m_webView.canGoForward(); sem.release(); } + }); + + try { + sem.acquire(); + } catch (Exception e) { + e.printStackTrace(); + } + + return forward[0]; + } + + public void stopLoading() + { + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { m_webView.stopLoading(); } + }); + } + + public String getTitle() + { + final String[] title = {""}; + final Semaphore sem = new Semaphore(0); + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { title[0] = m_webView.getTitle(); sem.release(); } + }); + + try { + sem.acquire(); + } catch (Exception e) { + e.printStackTrace(); + } + + return title[0]; + } + + public String getUrl() + { + final String[] url = {""}; + final Semaphore sem = new Semaphore(0); + m_activity.runOnUiThread(new Runnable() { + @Override + public void run() { url[0] = m_webView.getUrl(); sem.release(); } + }); + + try { + sem.acquire(); + } catch (Exception e) { + e.printStackTrace(); + } + + return url[0]; + } + + public WebView getWebView() + { + return m_webView; + } +} diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..6b79cb3 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS += webview imports +android: SUBDIRS += jar diff --git a/src/webview/doc/qtwebview-examples.qdoc b/src/webview/doc/qtwebview-examples.qdoc new file mode 100644 index 0000000..b0f918a --- /dev/null +++ b/src/webview/doc/qtwebview-examples.qdoc @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group qtwebview-examples + \title Qt WebView Examples + \brief Examples for the Qt WebView module + + These are the Qt WebView examples. + +*/ + diff --git a/src/webview/doc/src/qtwebview-overview.qdoc b/src/webview/doc/src/qtwebview-overview.qdoc new file mode 100644 index 0000000..95fb775 --- /dev/null +++ b/src/webview/doc/src/qtwebview-overview.qdoc @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page index.html + \title Qt WebView + \brief A light-weight web view. + + Qt WebView provides a way to display web content in an application without + necessarily including a full web browser stack by using native APIs where + this makes sense. + + This is especially important on platforms such as iOS, where policy dictates + that all web content is displayed using the operating system's web view. + + The WebView is currently supported on the following platforms: Android. + + \section1 QML types + + The module provides a single QML component for displaying web content in + the application: \l{WebView}. + + \section1 Limitations + + Due to platform limitations, overlapping the WebView with other QML components + is not supported. Doing this will have unpredictable results which may differ + from platform to platform. + + \section1 Examples + + Take a look at the \l{Qt WebView Examples} for a demonstration on + how the APIs can be used in applications. + + \section1 API Reference + + \list + \li \l{Qt WebView QML Types} + \endlist + +*/ diff --git a/src/webview/doc/src/qtwebview-qmltypes.qdoc b/src/webview/doc/src/qtwebview-qmltypes.qdoc new file mode 100644 index 0000000..8c7990f --- /dev/null +++ b/src/webview/doc/src/qtwebview-qmltypes.qdoc @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule QtWebView 1.0 + \title Qt WebView QML Types + \ingroup qmlmodules + \brief Provides QML types for Qt WebView. + + The Qt WebView module provides a QML type that can be used to include + web content in an application. + + The QML type can be imported into your application using the following + import statement: + + \code + import QtWebView 1.0 + \endcode + +*/ diff --git a/src/webview/doc/webview.qdocconf b/src/webview/doc/webview.qdocconf new file mode 100644 index 0000000..ec6a99c --- /dev/null +++ b/src/webview/doc/webview.qdocconf @@ -0,0 +1,46 @@ +include($QT_INSTALL_DOCS/global/macros.qdocconf) +include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf) +include($QT_INSTALL_DOCS/global/compat.qdocconf) +include($QT_INSTALL_DOCS/global/fileextensions.qdocconf) +include($QT_INSTALL_DOCS/global/qt-html-templates-offline.qdocconf) + +project = QtWebView +description = Qt WebView Reference Documentation +url = http://qt-project.org/doc/qt-$QT_VER +version = $QT_VERSION + +qhp.projects = QtWebView + +qhp.QtPurchasing.file = qtwebview.qhp +qhp.QtPurchasing.namespace = org.qt-project.qtmultimedia.$QT_VERSION_TAG +qhp.QtPurchasing.virtualFolder = qtwebview +qhp.QtPurchasing.indexTitle = Qt WebView +qhp.QtPurchasing.indexRoot = +qhp.QtPurchasing.filterAttributes = qtwebview 1.0 qtrefdoc +qhp.QtPurchasing.customFilters.Qt.name = QtWebView 1.0 +qhp.QtPurchasing.customFilters.Qt.filterAttributes = qtwebview 1.0 + +qhp.QtPurchasing.subprojects = qmltypes classes examples +qhp.QtPurchasing.subprojects.qmltypes.title = QML Types +qhp.QtPurchasing.subprojects.qmltypes.indexTitle = Qt WebView QML Types +qhp.QtPurchasing.subprojects.qmltypes.selectors = fake:qmlclass +qhp.QtPurchasing.subprojects.qmltypes.sortPages = true +qhp.QtPurchasing.subprojects.examples.title = Examples +qhp.QtPurchasing.subprojects.examples.indexTitle = Qt WebView Examples +qhp.QtPurchasing.subprojects.examples.selectors = fake:example + +indexes += $QT_INSTALL_DOCS/qtqml/qtqml.index \ + $QT_INSTALL_DOCS/qtquick/qtquick.index \ + $QT_INSTALL_DOCS/qtdoc/qtdoc.index \ + $QT_INSTALL_DOCS/qtquickcontrols/qtquickcontrols.index + +headerdirs += ../ ../../imports/ ../ +sourcedirs += ../ ../../imports/ ../ +exampledirs += ../../../examples/webview +imagedirs += images + +examplesinstallpath = webview +depends = qtcore qtdoc qtquick qtqml + +navigation.landingpage = "Qt WebView" +navigation.qmltypespage = "Qt WebView QML Types" diff --git a/src/webview/qwebview.cpp b/src/webview/qwebview.cpp new file mode 100644 index 0000000..f37f99e --- /dev/null +++ b/src/webview/qwebview.cpp @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebview_p.h" + +QT_BEGIN_NAMESPACE + +QWebViewPrivate::QWebViewPrivate(QWebView *q) + : m_loadProgress(0) + , m_loading(false) + , q_ptr(q) +{ + connect(this,SIGNAL(pageStarted(QString)),SLOT(onPageStartedPrivate(QString))); + connect(this,SIGNAL(pageFinished(QString)),SLOT(onPageFinishedPrivate(QString))); + connect(this,SIGNAL(titleChanged(QString)),SLOT(onTitleChangedPrivate(QString))); + connect(this,SIGNAL(progressChanged(int)),SLOT(onProgressChangedPrivate(int))); +} + +QWebViewPrivate::~QWebViewPrivate() +{ +} + +void QWebViewPrivate::onPageStartedPrivate(QString url) +{ + Q_Q(QWebView); + const QUrl newUrl = QUrl::fromUserInput(url); + if (m_url != newUrl) { + m_url = newUrl; + Q_EMIT q->urlChanged(); + } + + if (!m_loading) { + m_loading = true; + Q_EMIT q->loadingChanged(); + } +} + +void QWebViewPrivate::onPageFinishedPrivate(QString url) +{ + Q_Q(QWebView); + const QUrl newUrl = QUrl::fromUserInput(url); + if (m_url != newUrl) { + m_url = newUrl; + Q_EMIT q->urlChanged(); + } + + if (m_loading) { + m_loading = false; + Q_EMIT q->loadingChanged(); + } +} + +void QWebViewPrivate::onTitleChangedPrivate(QString title) +{ + Q_Q(QWebView); + if (m_title == title) + return; + + m_title = title; + Q_EMIT q->titleChanged(); +} + +void QWebViewPrivate::onProgressChangedPrivate(int progress) +{ + Q_Q(QWebView); + if (m_loadProgress == progress) + return; + + m_loadProgress = progress; + Q_EMIT q->loadProgressChanged(); +} + +/*! + \qmltype WebView + \inqmlmodule QtWebView + \ingroup qtwebview + \brief A component for displaying web content + + WebView is a component for displaying web content which is implemented using native + APIs on the platforms where this is available, thus it does not necessarily require + including a full web browser stack as part of the application. + + WebView is currently supported on the following platforms: Android. + + \note Due to platform limitations overlapping the WebView and other QML components + is not supported. +*/ + +QWebView::QWebView(QQuickItem *parent) + : QWindowControllerItem(parent) + , d_ptr(QWebViewPrivate::create(this)) +{ + WId id(WId(d_ptr->nativeWebView())); + if (id != 0) + setNativeWindow(id); + else + qWarning("No native web view. Missing platform support?"); +} + +QWebView::~QWebView() +{ +} + +/*! + \qmlproperty url QtWebView::WebView::url + + The url of currently loaded web page. Changing this will trigger + loading new content. +*/ + +void QWebView::setUrl(const QUrl &url) +{ + Q_D(QWebView); + if (d->m_url == url) + return; + + d->loadUrl(url.toString()); +} + +/*! + \qmlproperty string QtWebView::WebView::title + + The title of the currently loaded web page. +*/ + +QString QWebView::title() const +{ + Q_D(const QWebView); + return d->m_title; +} + +QUrl QWebView::url() const +{ + Q_D(const QWebView); + return d->m_url; +} + +/*! + \qmlproperty bool QtWebView::WebView::canGoBack + + True if it's currently possible to navigate back in the web history. +*/ + +bool QWebView::canGoBack() const +{ + Q_D(const QWebView); + return d->canGoBack(); +} + +/*! + \qmlproperty bool QtWebView::WebView::canGoForward + + True if it's currently possible to navigate forward in the web history. +*/ + +bool QWebView::canGoForward() const +{ + Q_D(const QWebView); + return d->canGoForward(); +} + +/*! + \qmlproperty int QtWebView::WebView::loadProgress + + The current load progress of the web content, represented as + an integer between 0 and 100. +*/ +int QWebView::loadProgress() const +{ + Q_D(const QWebView); + return d->m_loadProgress; +} + +/*! + \qmlproperty bool QtWebView::WebView::loading + + True if the WebView is currently in the process of loading + new content, and false if not. +*/ +bool QWebView::isLoading() const +{ + Q_D(const QWebView); + return d->m_loading; +} + +/*! + Navigates back in the web history. +*/ +void QWebView::goBack() +{ + Q_D(QWebView); + d->goBack(); +} + +/*! + Navigates forward in the web history. +*/ +void QWebView::goForward() +{ + Q_D(QWebView); + d->goForward(); +} + +/*! + Reloads the current url. +*/ +void QWebView::reload() +{ + Q_D(QWebView); + if (d->m_url.isValid()) + d->loadUrl(d->m_url.toString()); +} + +/*! + Stops loading the current url. +*/ +void QWebView::stop() +{ + Q_D(QWebView); + d->stopLoading(); +} + +QT_END_NAMESPACE diff --git a/src/webview/qwebview_android.cpp b/src/webview/qwebview_android.cpp new file mode 100644 index 0000000..81cedb3 --- /dev/null +++ b/src/webview/qwebview_android.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebview_p.h" +#include "qwebview_android_p.h" +#include <QtAndroidExtras/QtAndroid> + +#include <QtQuick/qquickitem.h> +#include <QtCore/qmap.h> +#include <android/bitmap.h> + +QT_BEGIN_NAMESPACE + +QWebViewPrivate *QWebViewPrivate::create(QWebView *q) +{ + return new QAndroidWebViewPrivate(q); +} + +//static bool favIcon(JNIEnv *env, jobject icon, QImage *image) +//{ +// // TODO: +// AndroidBitmapInfo bitmapInfo; +// if (AndroidBitmap_getInfo(env, icon, &bitmapInfo) != ANDROID_BITMAP_RESULT_SUCCESS) +// return false; + +// void *pixelData; +// if (AndroidBitmap_lockPixels(env, icon, &pixelData) != ANDROID_BITMAP_RESULT_SUCCESS) +// return false; + +// *image = QImage::fromData(static_cast<const uchar *>(pixelData), bitmapInfo.width * bitmapInfo.height); +// AndroidBitmap_unlockPixels(env, icon); + +// return true; +//} + +typedef QMap<quintptr, QWebViewPrivate *> WebViews; +Q_GLOBAL_STATIC(WebViews, g_webViews) + +QAndroidWebViewPrivate::QAndroidWebViewPrivate(QWebView *q) + : QWebViewPrivate(q) + , m_id(reinterpret_cast<quintptr>(this)) +{ + m_viewController = QAndroidJniObject("org/qtproject/qt5/android/view/QtAndroidWebViewController", + "(Landroid/app/Activity;J)V", + QtAndroid::androidActivity().object(), + m_id); + m_webView = m_viewController.callObjectMethod("getWebView", + "()Landroid/webkit/WebView;"); + g_webViews->insert(m_id, this); +} + +QAndroidWebViewPrivate::~QAndroidWebViewPrivate() +{ + g_webViews->take(m_id); +} + +QString QAndroidWebViewPrivate::getUrl() const +{ + return m_viewController.callObjectMethod<jstring>("getUrl").toString(); +} + +void QAndroidWebViewPrivate::loadUrl(const QString &url) +{ + m_viewController.callMethod<void>("loadUrl", + "(Ljava/lang/String;)V", + QAndroidJniObject::fromString(url).object()); +} + +bool QAndroidWebViewPrivate::canGoBack() const +{ + return m_viewController.callMethod<jboolean>("canGoBack"); +} + +void QAndroidWebViewPrivate::goBack() const +{ + m_viewController.callMethod<void>("goBack"); +} + +bool QAndroidWebViewPrivate::canGoForward() const +{ + return m_viewController.callMethod<jboolean>("canGoForward"); +} + +void QAndroidWebViewPrivate::goForward() const +{ + m_viewController.callMethod<void>("goForward"); +} + +QString QAndroidWebViewPrivate::getTitle() const +{ + return m_viewController.callObjectMethod<jstring>("getTitle").toString(); +} + +void QAndroidWebViewPrivate::stopLoading() const +{ + m_viewController.callMethod<void>("stopLoading"); +} + +void *QAndroidWebViewPrivate::nativeWebView() const +{ + return m_webView.object(); +} + +QT_END_NAMESPACE + +static void c_onPageFinished(JNIEnv *env, + jobject thiz, + jlong id, + jstring url) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + const WebViews &wv = (*g_webViews); + QWebViewPrivate *wc = wv[id]; + if (!wc) + return; + + Q_EMIT wc->pageFinished(QAndroidJniObject(url).toString()); +} + +static void c_onPageStarted(JNIEnv *env, + jobject thiz, + jlong id, + jstring url, + jobject icon) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + Q_UNUSED(icon) + const WebViews &wv = (*g_webViews); + QWebViewPrivate *wc = wv[id]; + if (!wc) + return; + + Q_EMIT wc->pageStarted(QAndroidJniObject(url).toString()); + +// if (!icon) +// return; + +// QImage image; +// if (favIcon(env, icon, &image)) +// Q_EMIT wc->iconChanged(image); +} + +static void c_onProgressChanged(JNIEnv *env, + jobject thiz, + jlong id, + jint newProgress) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + const WebViews &wv = (*g_webViews); + QWebViewPrivate *wc = wv[id]; + if (!wc) + return; + + Q_EMIT wc->progressChanged(newProgress); +} + +static void c_onReceivedIcon(JNIEnv *env, + jobject thiz, + jlong id, + jobject icon) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + Q_UNUSED(id) + Q_UNUSED(icon) + + const WebViews &wv = (*g_webViews); + QWebViewPrivate *wc = wv[id]; + if (!wc) + return; + + if (!icon) + return; + +// QImage image; +// if (favIcon(env, icon, &image)) +// Q_EMIT wc->iconChanged(image); +} + +static void c_onReceivedTitle(JNIEnv *env, + jobject thiz, + jlong id, + jstring title) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + const WebViews &wv = (*g_webViews); + QWebViewPrivate *wc = wv[id]; + if (!wc) + return; + + Q_EMIT wc->titleChanged(QAndroidJniObject(title).toString()); +} + +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) +{ + typedef union { + JNIEnv *nativeEnvironment; + void *venv; + } UnionJNIEnvToVoid; + + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) + return JNI_ERR; + + JNIEnv *jniEnv = uenv.nativeEnvironment; + + jclass clazz = jniEnv->FindClass("org/qtproject/qt5/android/view/QtAndroidWebViewController"); + if (!clazz) + return JNI_ERR; + + JNINativeMethod methods[] = { + {"c_onPageFinished", "(JLjava/lang/String;)V", reinterpret_cast<void *>(c_onPageFinished)}, + {"c_onPageStarted", "(JLjava/lang/String;Landroid/graphics/Bitmap;)V", reinterpret_cast<void *>(c_onPageStarted)}, + {"c_onProgressChanged", "(JI)V", reinterpret_cast<void *>(c_onProgressChanged)}, + {"c_onReceivedIcon", "(JLandroid/graphics/Bitmap;)V", reinterpret_cast<void *>(c_onReceivedIcon)}, + {"c_onReceivedTitle", "(JLjava/lang/String;)V", reinterpret_cast<void *>(c_onReceivedTitle)} + }; + + const int nMethods = sizeof(methods) / sizeof(methods[0]); + + if (jniEnv->RegisterNatives(clazz, methods, nMethods) != JNI_OK) + return JNI_ERR; + + return JNI_VERSION_1_4; +} diff --git a/src/webview/qwebview_android_p.h b/src/webview/qwebview_android_p.h new file mode 100644 index 0000000..1ab2709 --- /dev/null +++ b/src/webview/qwebview_android_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBVIEW_ANDROID_P_H +#define QWEBVIEW_ANDROID_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobject.h> +#include <QtCore/qurl.h> +#include <QtGui/qwindow.h> +#include <QtAndroidExtras/qandroidjniobject.h> + +#include "qwebview_p.h" + +QT_BEGIN_NAMESPACE + +class QAndroidWebViewPrivate : public QWebViewPrivate +{ + Q_OBJECT +public: + QAndroidWebViewPrivate(QWebView *q); + virtual ~QAndroidWebViewPrivate(); + + QString getUrl() const; + bool canGoBack() const; + bool canGoForward() const; + QString getTitle() const; + + void *nativeWebView() const; + +public Q_SLOTS: + void loadUrl(const QString &url); + void goBack() const; + void goForward() const; + void stopLoading() const; + +private: + quintptr m_id; + QAndroidJniObject m_viewController; + QAndroidJniObject m_webView; +}; + +QT_END_NAMESPACE + +#endif // QWEBVIEW_ANDROID_P_H diff --git a/src/webview/qwebview_default.cpp b/src/webview/qwebview_default.cpp new file mode 100644 index 0000000..b2517e6 --- /dev/null +++ b/src/webview/qwebview_default.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebview_p.h" +#include "qwebview_default_p.h" + +QT_BEGIN_NAMESPACE + +QWebViewPrivate *QWebViewPrivate::create(QWebView *q) +{ + return new QDefaultWebViewPrivate(q); +} + +QDefaultWebViewPrivate::QDefaultWebViewPrivate(QWebView *q) + : QWebViewPrivate(q) +{ +} + +QDefaultWebViewPrivate::~QDefaultWebViewPrivate() +{ +} + +QString QDefaultWebViewPrivate::getUrl() const +{ + return QString(); +} + +void QDefaultWebViewPrivate::loadUrl(const QString &url) +{ + Q_UNUSED(url); +} + +bool QDefaultWebViewPrivate::canGoBack() const +{ + return false; +} + +void QDefaultWebViewPrivate::goBack() const +{ +} + +bool QDefaultWebViewPrivate::canGoForward() const +{ + return false; +} + +void QDefaultWebViewPrivate::goForward() const +{ +} + +QString QDefaultWebViewPrivate::getTitle() const +{ + return QString(); +} + +void QDefaultWebViewPrivate::stopLoading() const +{ +} + +void *QDefaultWebViewPrivate::nativeWebView() const +{ + return 0; +} + +QT_END_NAMESPACE diff --git a/src/webview/qwebview_default_p.h b/src/webview/qwebview_default_p.h new file mode 100644 index 0000000..9231e4e --- /dev/null +++ b/src/webview/qwebview_default_p.h @@ -0,0 +1,78 @@ +#ifndef QWEBVIEW_DEFAULT_P_H +#define QWEBVIEW_DEFAULT_P_H + +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qwebview_p.h" + +QT_BEGIN_NAMESPACE + +class QDefaultWebViewPrivate : public QWebViewPrivate +{ + Q_OBJECT +public: + QDefaultWebViewPrivate(QWebView *q); + ~QDefaultWebViewPrivate(); + + QString getUrl() const; + bool canGoBack() const; + bool canGoForward() const; + QString getTitle() const; + + void *nativeWebView() const; + +public Q_SLOTS: + void loadUrl(const QString &url); + void goBack() const; + void goForward() const; + void stopLoading() const; +}; + +QT_END_NAMESPACE + +#endif // QWEBVIEW_DEFAULT_P_H diff --git a/src/webview/qwebview_p.h b/src/webview/qwebview_p.h new file mode 100644 index 0000000..268aba0 --- /dev/null +++ b/src/webview/qwebview_p.h @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBVIEW_H +#define QWEBVIEW_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#if !defined(QT_WEBVIEW_WEBENGINE_BACKEND) + +#include "qwindowcontrolleritem_p.h" +#include <QtCore/qobject.h> +#include <QtCore/qurl.h> +#include <QtGui/qimage.h> + + +QT_BEGIN_NAMESPACE + +class QWebView; +class QWebViewPrivate : public QObject +{ + Q_OBJECT +public: + QWebViewPrivate(QWebView *q); + ~QWebViewPrivate(); + + virtual QString getUrl() const = 0; + virtual bool canGoBack() const = 0; + virtual bool canGoForward() const = 0; + virtual QString getTitle() const = 0; + virtual void *nativeWebView() const = 0; + + static QWebViewPrivate *create(QWebView *q); + +public Q_SLOTS: + virtual void loadUrl(const QString &url) = 0; + virtual void goBack() const = 0; + virtual void goForward() const = 0; + virtual void stopLoading() const = 0; + +private Q_SLOTS: + void onPageStartedPrivate(QString url); + void onPageFinishedPrivate(QString url); + void onTitleChangedPrivate(QString title); + void onProgressChangedPrivate(int progress); + +Q_SIGNALS: + void pageStarted(QString url); + void pageFinished(QString url); + void progressChanged(int progress); + void titleChanged(QString title); + +private: + Q_DECLARE_PUBLIC(QWebView) + int m_loadProgress; + bool m_loading; + QString m_title; + QUrl m_url; + QWebView *q_ptr; +}; + +class Q_DECL_EXPORT QWebView : public QWindowControllerItem +{ + Q_OBJECT + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged) + Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged) + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged) + Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged) + +public: + QWebView(QQuickItem *parent = 0); + ~QWebView(); + + QUrl url() const; + void setUrl(const QUrl &url); + int loadProgress() const; + QString title() const; + bool canGoBack() const; + bool isLoading() const; + bool canGoForward() const; + +public Q_SLOTS: + void goBack(); + void goForward(); + void reload(); + void stop(); + +Q_SIGNALS: + void titleChanged(); + void urlChanged(); + void loadingChanged(); + void loadProgressChanged(); + +private: + void load(const QUrl &url); + + Q_DECLARE_PRIVATE(QWebView) + QScopedPointer<QWebViewPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#else + +# include <QtWebEngine/private/qquickwebengineview_p.h> + +QT_BEGIN_NAMESPACE + +class Q_DECL_EXPORT QWebView : public QQuickWebEngineView +{ + Q_OBJECT +}; + +QT_END_NAMESPACE + +#endif + + +#endif diff --git a/src/webview/qwindowcontrolleritem.cpp b/src/webview/qwindowcontrolleritem.cpp new file mode 100644 index 0000000..9af72c2 --- /dev/null +++ b/src/webview/qwindowcontrolleritem.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwindowcontrolleritem_p.h" + +#include <QtGui/QWindow> +#include <QtQuick/QQuickWindow> + +QWindowControllerItem::QWindowControllerItem(QQuickItem *parent) + : QQuickItem(parent) + , m_controlledWindow(0) +{ + connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(onWindowChanged(QQuickWindow*))); + connect(this, SIGNAL(visibleChanged()), this, SLOT(onVisibleChanged())); +} + +void QWindowControllerItem::setNativeWindow(WId windowId) +{ + m_controlledWindow = QWindow::fromWinId(windowId); + m_controlledWindow->setVisibility(QWindow::Windowed); +} + +void QWindowControllerItem::componentComplete() +{ + QQuickItem::componentComplete(); +} + +void QWindowControllerItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QQuickItem::geometryChanged(newGeometry, oldGeometry); + m_controlledWindow->setGeometry(newGeometry.toRect()); +} + +void QWindowControllerItem::onWindowChanged(QQuickWindow* window) +{ + if (!m_controlledWindow) + return; + + m_controlledWindow->setParent(window); +} + +void QWindowControllerItem::onVisibleChanged() +{ + m_controlledWindow->setVisible(isVisible()); +} diff --git a/src/webview/qwindowcontrolleritem_p.h b/src/webview/qwindowcontrolleritem_p.h new file mode 100644 index 0000000..548d381 --- /dev/null +++ b/src/webview/qwindowcontrolleritem_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOWCONTROLLERITEM_H +#define QWINDOWCONTROLLERITEM_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuick/QQuickItem> + +class Q_DECL_EXPORT QWindowControllerItem : public QQuickItem +{ + Q_OBJECT +public: + explicit QWindowControllerItem(QQuickItem *parent = 0); + void setNativeWindow(WId windowId); + void componentComplete(); + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + +public slots: + void onWindowChanged(QQuickWindow* window); + void onVisibleChanged(); + +private: + QWindow *m_controlledWindow; +}; + +#endif // QTWINDOWCONTROLLERITEM_H diff --git a/src/webview/webview.pro b/src/webview/webview.pro new file mode 100644 index 0000000..781bc43 --- /dev/null +++ b/src/webview/webview.pro @@ -0,0 +1,39 @@ +TARGET = QtWebView + +QT += quick qml + +load(qt_module) + +ANDROID_BUNDLED_JAR_DEPENDENCIES = \ + jar/QtAndroidWebView-bundled.jar +ANDROID_JAR_DEPENDENCIES = \ + jar/QtAndroidWebView.jar + +HEADERS += \ + qwebview_p.h \ + +android { + QT += androidextras + LIBS += -ljnigraphics + SOURCES += \ + qwebview_android.cpp \ + qwebview.cpp \ + qwindowcontrolleritem.cpp + HEADERS += \ + qwebview_android_p.h \ + qwindowcontrolleritem_p.h + +} else { + qtHaveModule(webengine) { + QT += webengine webengine-private + DEFINES += QT_WEBVIEW_WEBENGINE_BACKEND + } else { + SOURCES += \ + qwebview_default.cpp \ + qwebview.cpp \ + qwindowcontrolleritem.cpp + HEADERS += \ + qwebview_default_p.h \ + qwindowcontrolleritem_p.h + } +} diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..09e41b1 --- /dev/null +++ b/sync.profile @@ -0,0 +1,17 @@ +%modules = ( # path to module name map + "QtWebView" => "$basedir/src/webview", +); +%moduleheaders = ( # restrict the module headers to those found in relative path +); +# Module dependencies. +# Every module that is required to build this module should have one entry. +# Each of the module version specifiers can take one of the following values: +# - A specific Git revision. +# - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch) +# - an empty string to use the same branch under test (dependencies will become "refs/heads/master" if we are in the master branch) +# +%dependencies = ( + "qtbase" => "", + "qtandroidextras" => "", + "qtdeclarative" => "", +); diff --git a/tests/auto/webview/qwebview/qwebview.pro b/tests/auto/webview/qwebview/qwebview.pro new file mode 100644 index 0000000..3cfaca9 --- /dev/null +++ b/tests/auto/webview/qwebview/qwebview.pro @@ -0,0 +1,12 @@ +CONFIG += testcase parallel_test +TARGET = tst_qwebview +osx:CONFIG -= app_bundle + +!android: qtHaveModule(webengine) { + QT += webengine webengine-private + DEFINES += QT_WEBVIEW_WEBENGINE_BACKEND +} + +QT += webview webview-private testlib +SOURCES += \ + tst_qwebview.cpp diff --git a/tests/auto/webview/qwebview/tst_qwebview.cpp b/tests/auto/webview/qwebview/tst_qwebview.cpp new file mode 100644 index 0000000..87b39a2 --- /dev/null +++ b/tests/auto/webview/qwebview/tst_qwebview.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtCore/qstandardpaths.h> +#include <QtWebView/private/qwebview_p.h> + +class tst_QWebView : public QObject +{ + Q_OBJECT +private slots: + void load(); +}; + +void tst_QWebView::load() +{ + QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + QString fileName(cacheLocation + QStringLiteral("/file.html")); + + { + QFile file(fileName); + QVERIFY(file.open(QIODevice::WriteOnly)); + file.write("<html><head><title>FooBar</title></head><body />"); + } + + QWebView view; + QCOMPARE(view.loadProgress(), 0); + view.setUrl(QUrl(QStringLiteral("file://") + fileName)); + QTRY_COMPARE(view.loadProgress(), 100); + QTRY_VERIFY(!view.isLoading()); + QCOMPARE(view.title(), QStringLiteral("FooBar")); + QVERIFY(!view.canGoBack()); + QVERIFY(!view.canGoForward()); + QCOMPARE(view.url(), QUrl(QStringLiteral("file://") + fileName)); +} + +QTEST_MAIN(tst_QWebView) + +#include "tst_qwebview.moc" |