From fd61d752e313bf91a09c85020b3fb50067c610c8 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Tue, 19 Nov 2013 17:55:49 +0100 Subject: Moving sources to src part 1: Move files. This only move files without adjusting any paths. This moves: - lib/quick -> src/webengine/api (API files) lib/quick -> src/webengine (other files) This contains the main QtWebEngine module library since . - lib/widgets -> src/webenginewidgets Also rename this directory to match its module name and rename Api to api. - lib -> src/core - process -> src/process - resources -> src/core/resources - tools/* -> tools/scripts/ The build directory is spread as follow: - build/build.pro -> src/core/gyp_run.pro - build/qmake_extras/* -> src/core/ (for the host and target .pro files) - build/qmake -> tools/qmake - Build related scripts -> tools/buildscripts Change-Id: I0cded1de772c99c0c1da6536c9afea353236b4a1 Reviewed-by: Zeno Albisser Reviewed-by: Pierre Rossi Reviewed-by: Andras Becsi --- .../api/qtwebenginewidgetsglobal.h | 60 +++ src/webenginewidgets/api/qwebenginehistory.cpp | 288 ++++++++++ src/webenginewidgets/api/qwebenginehistory.h | 112 ++++ src/webenginewidgets/api/qwebenginehistory_p.h | 73 +++ .../api/qwebenginehistoryinterface.h | 46 ++ src/webenginewidgets/api/qwebengineinspector.h | 43 ++ src/webenginewidgets/api/qwebenginepage.cpp | 494 +++++++++++++++++ src/webenginewidgets/api/qwebenginepage.h | 592 +++++++++++++++++++++ src/webenginewidgets/api/qwebenginepage_p.h | 95 ++++ .../api/qwebenginesecurityorigin.h | 52 ++ src/webenginewidgets/api/qwebenginesettings.h | 170 ++++++ src/webenginewidgets/api/qwebengineview.cpp | 211 ++++++++ src/webenginewidgets/api/qwebengineview.h | 145 +++++ src/webenginewidgets/api/qwebengineview_p.h | 67 +++ 14 files changed, 2448 insertions(+) create mode 100644 src/webenginewidgets/api/qtwebenginewidgetsglobal.h create mode 100644 src/webenginewidgets/api/qwebenginehistory.cpp create mode 100644 src/webenginewidgets/api/qwebenginehistory.h create mode 100644 src/webenginewidgets/api/qwebenginehistory_p.h create mode 100644 src/webenginewidgets/api/qwebenginehistoryinterface.h create mode 100644 src/webenginewidgets/api/qwebengineinspector.h create mode 100644 src/webenginewidgets/api/qwebenginepage.cpp create mode 100644 src/webenginewidgets/api/qwebenginepage.h create mode 100644 src/webenginewidgets/api/qwebenginepage_p.h create mode 100644 src/webenginewidgets/api/qwebenginesecurityorigin.h create mode 100644 src/webenginewidgets/api/qwebenginesettings.h create mode 100644 src/webenginewidgets/api/qwebengineview.cpp create mode 100644 src/webenginewidgets/api/qwebengineview.h create mode 100644 src/webenginewidgets/api/qwebengineview_p.h (limited to 'src/webenginewidgets/api') diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.h b/src/webenginewidgets/api/qtwebenginewidgetsglobal.h new file mode 100644 index 000000000..d875c1cbe --- /dev/null +++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QTWEBENGINEWIDGETSGLOBAL_H +#define QTWEBENGINEWIDGETSGLOBAL_H + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_WEBENGINEWIDGETS_LIB) +# define QWEBENGINEWIDGETS_EXPORT Q_DECL_EXPORT +# else +# define QWEBENGINEWIDGETS_EXPORT Q_DECL_IMPORT +# endif +#else +# define QWEBENGINEWIDGETS_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTWEBENGINEWIDGETSGLOBAL_H diff --git a/src/webenginewidgets/api/qwebenginehistory.cpp b/src/webenginewidgets/api/qwebenginehistory.cpp new file mode 100644 index 000000000..2dd69dcff --- /dev/null +++ b/src/webenginewidgets/api/qwebenginehistory.cpp @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebenginehistory.h" +#include "qwebenginehistory_p.h" + +#include "qwebenginepage_p.h" +#include "web_contents_adapter.h" + +QT_BEGIN_NAMESPACE + +QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(WebContentsAdapter *adapter, int index) + : adapter(adapter) + , index(index) +{ +} + +QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d) + : d(d) +{ +} + +QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other) + : d(other.d) +{ +} + +QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other) +{ + d = other.d; + return *this; +} + +QWebEngineHistoryItem::~QWebEngineHistoryItem() +{ +} + +QUrl QWebEngineHistoryItem::originalUrl() const +{ + Q_D(const QWebEngineHistoryItem); + return d->adapter ? d->adapter->getNavigationEntryOriginalUrl(d->index) : QUrl(); +} + +QUrl QWebEngineHistoryItem::url() const +{ + Q_D(const QWebEngineHistoryItem); + return d->adapter ? d->adapter->getNavigationEntryUrl(d->index) : QUrl(); +} + +QString QWebEngineHistoryItem::title() const +{ + Q_D(const QWebEngineHistoryItem); + return d->adapter ? d->adapter->getNavigationEntryTitle(d->index) : QString(); +} + +QDateTime QWebEngineHistoryItem::lastVisited() const +{ + qWarning("Not implemented: %s", __func__); + return QDateTime(); +} + +QIcon QWebEngineHistoryItem::icon() const +{ + qWarning("Not implemented: %s", __func__); + return QIcon(); +} + +QVariant QWebEngineHistoryItem::userData() const +{ + return QVariant(); +} + +void QWebEngineHistoryItem::setUserData(const QVariant& userData) +{ + qWarning("Not implemented: %s", __func__); +} + +bool QWebEngineHistoryItem::isValid() const +{ + Q_D(const QWebEngineHistoryItem); + if (!d->adapter) + return false; + return d->index >= 0 && d->index < d->adapter->navigationEntryCount(); +} + +QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(WebContentsAdapter *adapter) + : adapter(adapter) +{ +} + +QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate() +{ + // Invalidate shared item references possibly still out there. + QList::iterator it, end; + for (it = items.begin(), end = items.end(); it != end; ++it) + it->d->adapter = 0; +} + +void QWebEngineHistoryPrivate::updateItems() const +{ + // Keep track of items we return to be able to invalidate them + // and avoid dangling references to our adapter. + int entryCount = adapter->navigationEntryCount(); + while (items.size() > entryCount) { + items.last().d->adapter = 0; + items.removeLast(); + } + while (items.size() < entryCount) { + int nextIndex = items.size(); + items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(adapter, nextIndex))); + } +} + +QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d) + : d_ptr(d) +{ +} + +QWebEngineHistory::~QWebEngineHistory() +{ +} + +void QWebEngineHistory::clear() +{ + Q_D(const QWebEngineHistory); + d->adapter->clearNavigationHistory(); +} + +QList QWebEngineHistory::items() const +{ + Q_D(const QWebEngineHistory); + d->updateItems(); + return d->items; +} + +QList QWebEngineHistory::backItems(int maxItems) const +{ + Q_D(const QWebEngineHistory); + d->updateItems(); + const int end = currentItemIndex(); + const int start = std::max(0, end - maxItems); + return d->items.mid(start, end - start); +} + +QList QWebEngineHistory::forwardItems(int maxItems) const +{ + Q_D(const QWebEngineHistory); + d->updateItems(); + const int start = currentItemIndex() + 1; + const int end = std::min(count(), start + maxItems); + return d->items.mid(start, end - start); +} + +bool QWebEngineHistory::canGoBack() const +{ + Q_D(const QWebEngineHistory); + return d->adapter->canGoBack(); +} + +bool QWebEngineHistory::canGoForward() const +{ + Q_D(const QWebEngineHistory); + return d->adapter->canGoForward(); +} + +void QWebEngineHistory::back() +{ + Q_D(const QWebEngineHistory); + d->adapter->navigateToOffset(-1); +} + +void QWebEngineHistory::forward() +{ + Q_D(const QWebEngineHistory); + d->adapter->navigateToOffset(1); +} + +void QWebEngineHistory::goToItem(const QWebEngineHistoryItem &item) +{ + Q_D(const QWebEngineHistory); + Q_ASSERT(item.d->adapter == d->adapter); + d->adapter->navigateToIndex(item.d->index); +} + +QWebEngineHistoryItem QWebEngineHistory::backItem() const +{ + return itemAt(currentItemIndex() - 1); +} + +QWebEngineHistoryItem QWebEngineHistory::currentItem() const +{ + Q_D(const QWebEngineHistory); + d->updateItems(); + return d->items[currentItemIndex()]; +} + +QWebEngineHistoryItem QWebEngineHistory::forwardItem() const +{ + return itemAt(currentItemIndex() + 1); +} + +QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const +{ + Q_D(const QWebEngineHistory); + if (i >= 0 && i < count()) { + d->updateItems(); + return d->items[i]; + } else { + // Return an invalid item right away. + QWebEngineHistoryItem item(new QWebEngineHistoryItemPrivate(0, i)); + Q_ASSERT(!item.isValid()); + return item; + } +} + +int QWebEngineHistory::currentItemIndex() const +{ + Q_D(const QWebEngineHistory); + return d->adapter->currentNavigationEntryIndex(); +} + +int QWebEngineHistory::count() const +{ + Q_D(const QWebEngineHistory); + return d->adapter->navigationEntryCount(); +} + +int QWebEngineHistory::maximumItemCount() const +{ + return 100; +} + +void QWebEngineHistory::setMaximumItemCount(int count) +{ + qWarning("Not implemented: %s", __func__); +} + +QDataStream& operator<<(QDataStream& stream, const QWebEngineHistory& history) +{ + qWarning("Not implemented: %s", __func__); + return stream; +} + +QDataStream& operator>>(QDataStream& stream, QWebEngineHistory& history) +{ + qWarning("Not implemented: %s", __func__); + return stream; +} + +QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginehistory.h b/src/webenginewidgets/api/qwebenginehistory.h new file mode 100644 index 000000000..b8ea6b863 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginehistory.h @@ -0,0 +1,112 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008 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. +*/ + +#ifndef QWEBENGINEHISTORY_H +#define QWEBENGINEHISTORY_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QWebEngineHistory; +class QWebEngineHistoryItemPrivate; +class QWebEnginePage; +class QWebEnginePagePrivate; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineHistoryItem { +public: + QWebEngineHistoryItem(const QWebEngineHistoryItem &other); + QWebEngineHistoryItem &operator=(const QWebEngineHistoryItem &other); + ~QWebEngineHistoryItem(); + + QUrl originalUrl() const; + QUrl url() const; + + QString title() const; + QDateTime lastVisited() const; + + QIcon icon() const; + + QVariant userData() const; + void setUserData(const QVariant& userData); + + bool isValid() const; +private: + QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *priv); + Q_DECLARE_PRIVATE_D(d.data(), QWebEngineHistoryItem); + QExplicitlySharedDataPointer d; + friend class QWebEngineHistory; + friend class QWebEngineHistoryPrivate; +}; + + +class QWebEngineHistoryPrivate; +class QWEBENGINEWIDGETS_EXPORT QWebEngineHistory { +public: + void clear(); + + QList items() const; + QList backItems(int maxItems) const; + QList forwardItems(int maxItems) const; + + bool canGoBack() const; + bool canGoForward() const; + + void back(); + void forward(); + void goToItem(const QWebEngineHistoryItem &item); + + QWebEngineHistoryItem backItem() const; + QWebEngineHistoryItem currentItem() const; + QWebEngineHistoryItem forwardItem() const; + QWebEngineHistoryItem itemAt(int i) const; + + int currentItemIndex() const; + + int count() const; + + int maximumItemCount() const; + void setMaximumItemCount(int count); + +private: + QWebEngineHistory(QWebEngineHistoryPrivate *d); + ~QWebEngineHistory(); + + Q_DISABLE_COPY(QWebEngineHistory) + Q_DECLARE_PRIVATE(QWebEngineHistory); + QScopedPointer d_ptr; + + friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator>>(QDataStream&, QWebEngineHistory&); + friend QWEBENGINEWIDGETS_EXPORT QDataStream& operator<<(QDataStream&, const QWebEngineHistory&); + friend class QWebEnginePage; + friend class QWebEnginePagePrivate; +}; + +QWEBENGINEWIDGETS_EXPORT QDataStream& operator<<(QDataStream& stream, const QWebEngineHistory& history); +QWEBENGINEWIDGETS_EXPORT QDataStream& operator>>(QDataStream& stream, QWebEngineHistory& history); + +QT_END_NAMESPACE + +#endif // QWEBENGINEHISTORY_H diff --git a/src/webenginewidgets/api/qwebenginehistory_p.h b/src/webenginewidgets/api/qwebenginehistory_p.h new file mode 100644 index 000000000..42f3ff73c --- /dev/null +++ b/src/webenginewidgets/api/qwebenginehistory_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEHISTORY_P_H +#define QWEBENGINEHISTORY_P_H + +#include + +class WebContentsAdapter; + +QT_BEGIN_NAMESPACE + +class QWebEngineHistoryItemPrivate : public QSharedData +{ +public: + QWebEngineHistoryItemPrivate(WebContentsAdapter *adapter = 0, int index = 0); + + WebContentsAdapter *adapter; + int index; +}; + +class QWebEngineHistoryPrivate +{ +public: + QWebEngineHistoryPrivate(WebContentsAdapter *adapter); + ~QWebEngineHistoryPrivate(); + void updateItems() const; + + WebContentsAdapter *adapter; + mutable QList items; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEHISTORY_P_H diff --git a/src/webenginewidgets/api/qwebenginehistoryinterface.h b/src/webenginewidgets/api/qwebenginehistoryinterface.h new file mode 100644 index 000000000..b8108c516 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginehistoryinterface.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2007 Staikos Computing Services, Inc. + + 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. + + This class provides all functionality needed for tracking global history. +*/ + +#ifndef QWEBENGINEHISTORYINTERFACE_H +#define QWEBENGINEHISTORYINTERFACE_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QWEBENGINEWIDGETS_EXPORT QWebEngineHistoryInterface : public QObject { + Q_OBJECT +public: + QWebEngineHistoryInterface(QObject *parent = 0); + ~QWebEngineHistoryInterface(); + + static void setDefaultInterface(QWebEngineHistoryInterface *defaultInterface); + static QWebEngineHistoryInterface *defaultInterface(); + + virtual bool historyContains(const QString &url) const = 0; + virtual void addHistoryEntry(const QString &url) = 0; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEHISTORYINTERFACE_H diff --git a/src/webenginewidgets/api/qwebengineinspector.h b/src/webenginewidgets/api/qwebengineinspector.h new file mode 100644 index 000000000..9427b4e5c --- /dev/null +++ b/src/webenginewidgets/api/qwebengineinspector.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2009 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. +*/ + +#ifndef QWEBENGINEINSPECTOR_H +#define QWEBENGINEINSPECTOR_H + +#include + +QT_BEGIN_NAMESPACE + +class QWebEnginePage; +class QWebEngineInspectorPrivate; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineInspector : public QWidget { + Q_OBJECT +public: + QWebEngineInspector(QWidget* parent = 0); + ~QWebEngineInspector(); + + void setPage(QWebEnginePage* page); + QWebEnginePage* page() const; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEINSPECTOR_H diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp new file mode 100644 index 000000000..106e46949 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -0,0 +1,494 @@ +/* + Copyright (C) 2012, 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008, 2009, 2012 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2007 Staikos Computing Services Inc. + Copyright (C) 2007 Apple Inc. + + 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 "qwebenginepage.h" +#include "qwebenginepage_p.h" + +#include "qwebenginehistory.h" +#include "qwebenginehistory_p.h" +#include "qwebengineview.h" +#include "qwebengineview_p.h" +#include "render_widget_host_view_qt_delegate_widget.h" +#include "web_contents_adapter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QWebEnginePagePrivate::QWebEnginePagePrivate() + : QObjectPrivate(QObjectPrivateVersion) + , adapter(new WebContentsAdapter(SoftwareRenderingMode)) + , history(new QWebEngineHistory(new QWebEngineHistoryPrivate(adapter.data()))) + , view(0) + , m_isLoading(false) +{ + adapter->initialize(this); + memset(actions, 0, sizeof(actions)); +} + +QWebEnginePagePrivate::~QWebEnginePagePrivate() +{ + delete history; +} + +RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) +{ + Q_UNUSED(mode); + return new RenderWidgetHostViewQtDelegateWidget(client); +} + +void QWebEnginePagePrivate::titleChanged(const QString &title) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->titleChanged(title); +} + +void QWebEnginePagePrivate::urlChanged(const QUrl &url) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->urlChanged(url); +} + +void QWebEnginePagePrivate::iconChanged(const QUrl &url) +{ + Q_UNUSED(url) +} + +void QWebEnginePagePrivate::loadingStateChanged() +{ + Q_Q(QWebEnginePage); + const bool wasLoading = m_isLoading; + m_isLoading = adapter->isLoading(); + if (m_isLoading != wasLoading) { + if (m_isLoading) + Q_EMIT q->loadStarted(); + } + updateNavigationActions(); +} + +void QWebEnginePagePrivate::loadProgressChanged(int progress) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->loadProgress(progress); +} + +QRectF QWebEnginePagePrivate::viewportRect() const +{ + return view ? view->geometry() : QRectF(); +} + +void QWebEnginePagePrivate::loadFinished(bool success) +{ + Q_Q(QWebEnginePage); + m_isLoading = adapter->isLoading(); + Q_EMIT q->loadFinished(success); +} + +void QWebEnginePagePrivate::focusContainer() +{ + if (view) + view->setFocus(); +} + +void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect &initialGeometry) +{ + Q_Q(QWebEnginePage); + QWebEnginePage *newPage = q->createWindow(disposition == WebContentsAdapterClient::NewPopupDisposition ? QWebEnginePage::WebModalDialog : QWebEnginePage::WebBrowserWindow); + // Overwrite the new page's WebContents with ours. + if (newPage) { + newPage->d_func()->adapter = newWebContents; + newWebContents->initialize(newPage->d_func()); + if (!initialGeometry.isEmpty()) + emit newPage->geometryChangeRequested(initialGeometry); + } +} + +void QWebEnginePagePrivate::close() +{ + Q_Q(QWebEnginePage); + Q_EMIT q->windowCloseRequested(); +} + +void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const +{ +#ifdef QT_NO_ACTION + Q_UNUSED(action) +#else + QAction *a = actions[action]; + if (!a) + return; + + bool enabled = false; + + switch (action) { + case QWebEnginePage::Back: + enabled = adapter->canGoBack(); + break; + case QWebEnginePage::Forward: + enabled = adapter->canGoForward(); + break; + case QWebEnginePage::Stop: + enabled = adapter->isLoading(); + break; + case QWebEnginePage::Reload: + case QWebEnginePage::ReloadAndBypassCache: + enabled = !adapter->isLoading(); + break; + default: + break; + } + + a->setEnabled(enabled); +#endif // QT_NO_ACTION +} + +void QWebEnginePagePrivate::updateNavigationActions() +{ + updateAction(QWebEnginePage::Back); + updateAction(QWebEnginePage::Forward); + updateAction(QWebEnginePage::Stop); + updateAction(QWebEnginePage::Reload); + updateAction(QWebEnginePage::ReloadAndBypassCache); +} + +#ifndef QT_NO_ACTION +void QWebEnginePagePrivate::_q_webActionTriggered(bool checked) +{ + Q_Q(QWebEnginePage); + QAction *a = qobject_cast(q->sender()); + if (!a) + return; + QWebEnginePage::WebAction action = static_cast(a->data().toInt()); + q->triggerAction(action, checked); +} +#endif // QT_NO_ACTION + +QWebEnginePage::QWebEnginePage(QObject* parent) + : QObject(*new QWebEnginePagePrivate, parent) +{ +} + +QWebEnginePage::~QWebEnginePage() +{ +} + +QWebEngineHistory *QWebEnginePage::history() const +{ + Q_D(const QWebEnginePage); + return d->history; +} + +void QWebEnginePage::setView(QWidget *view) +{ + QWebEngineViewPrivate::bind(qobject_cast(view), this); +} + +QWidget *QWebEnginePage::view() const +{ + Q_D(const QWebEnginePage); + return d->view; +} + +#ifndef QT_NO_ACTION +QAction *QWebEnginePage::action(WebAction action) const +{ + Q_D(const QWebEnginePage); + if (action == QWebEnginePage::NoWebAction) + return 0; + if (d->actions[action]) + return d->actions[action]; + + QString text; + QIcon icon; + QStyle *style = d->view ? d->view->style() : qApp->style(); + + switch (action) { + case Back: + text = tr("Back"); + icon = style->standardIcon(QStyle::SP_ArrowBack); + break; + case Forward: + text = tr("Forward"); + icon = style->standardIcon(QStyle::SP_ArrowForward); + break; + case Stop: + text = tr("Stop"); + icon = style->standardIcon(QStyle::SP_BrowserStop); + break; + case Reload: + text = tr("Reload"); + icon = style->standardIcon(QStyle::SP_BrowserReload); + break; + default: + break; + } + + QAction *a = new QAction(const_cast(this)); + a->setText(text); + a->setData(action); + a->setIcon(icon); + + connect(a, SIGNAL(triggered(bool)), this, SLOT(_q_webActionTriggered(bool))); + + d->actions[action] = a; + d->updateAction(action); + return a; +} +#endif // QT_NO_ACTION + +void QWebEnginePage::triggerAction(WebAction action, bool) +{ + Q_D(QWebEnginePage); + switch (action) { + case Back: + d->adapter->navigateToOffset(-1); + break; + case Forward: + d->adapter->navigateToOffset(1); + break; + case Stop: + d->adapter->stop(); + break; + case Reload: + d->adapter->reload(); + break; + default: + Q_UNREACHABLE(); + } +} + +bool QWebEnginePagePrivate::contextMenuRequested(const WebEngineContextMenuData &data) +{ + if (!view) + return false; + + QContextMenuEvent event(QContextMenuEvent::Mouse, data.pos, view->mapToGlobal(data.pos)); + switch (view->contextMenuPolicy()) { + case Qt::PreventContextMenu: + return false; + case Qt::DefaultContextMenu: + m_menuData = data; + view->contextMenuEvent(&event); + break; + case Qt::CustomContextMenu: + Q_EMIT view->customContextMenuRequested(data.pos); + break; + case Qt::ActionsContextMenu: + if (view->actions().count()) { + QMenu::exec(view->actions(), event.globalPos(), 0, view); + break; + } + // fall through + default: + event.ignore(); + return false; + break; + } + Q_ASSERT(view->d_func()->m_pendingContextMenuEvent); + view->d_func()->m_pendingContextMenuEvent = false; + m_menuData = WebEngineContextMenuData(); + return true; +} + +bool QWebEnginePagePrivate::javascriptDialog(JavascriptDialogType type, const QString &message, const QString &defaultValue, QString *result) +{ + Q_Q(QWebEnginePage); + switch (type) { + case AlertDialog: + q->javaScriptAlert(0, message); + return true; + case ConfirmDialog: + return q->javaScriptConfirm(0, message); + case PromptDialog: + return q->javaScriptPrompt(0, message, defaultValue, result); + } + Q_UNREACHABLE(); + return false; +} + +namespace { +class SaveToClipboardFunctor +{ + QString m_text; +public: + SaveToClipboardFunctor(const QString &text) + : m_text(text) + {} + void operator()() const + { + qApp->clipboard()->setText(m_text); + } +}; + +class LoadUrlFunctor +{ + QWebEnginePage *m_page; + QUrl m_url; +public: + LoadUrlFunctor(QWebEnginePage *page, const QUrl &url) + : m_page(page) + , m_url(url) + {} + void operator()() const + { + m_page->load(m_url); + } +}; +} + +QMenu *QWebEnginePage::createStandardContextMenu() +{ + Q_D(QWebEnginePage); + QMenu *menu = new QMenu(d->view); + QAction *action = 0; + WebEngineContextMenuData contextMenuData(d->m_menuData); + if (contextMenuData.selectedText.isEmpty()) { + action = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), tr("&Back"), menu); + connect(action, &QAction::triggered, d->view, &QWebEngineView::back); + action->setEnabled(d->adapter->canGoBack()); + menu->addAction(action); + + action = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), tr("&Forward"), menu); + connect(action, &QAction::triggered, d->view, &QWebEngineView::forward); + action->setEnabled(d->adapter->canGoForward()); + menu->addAction(action); + + action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), tr("&Reload"), menu); + connect(action, &QAction::triggered, d->view, &QWebEngineView::reload); + menu->addAction(action); + } else { + action = new QAction(tr("Copy..."), menu); + connect(action, &QAction::triggered, SaveToClipboardFunctor(contextMenuData.selectedText)); + menu->addAction(action); + } + + if (!contextMenuData.linkText.isEmpty() && contextMenuData.linkUrl.isValid()) { + menu->addSeparator(); + action = new QAction(tr("Navigate to..."), menu); + connect(action, &QAction::triggered, LoadUrlFunctor(this, contextMenuData.linkUrl)); + menu->addAction(action); + action = new QAction(tr("Copy link address"), menu); + connect(action, &QAction::triggered, SaveToClipboardFunctor(contextMenuData.linkUrl.toString())); + menu->addAction(action); + } + return menu; +} + +void QWebEnginePage::load(const QUrl& url) +{ + Q_D(QWebEnginePage); + d->adapter->load(url); +} + +QString QWebEnginePage::title() const +{ + Q_D(const QWebEnginePage); + return d->adapter->pageTitle(); +} + +void QWebEnginePage::setUrl(const QUrl &url) +{ + load(url); +} + +QUrl QWebEnginePage::url() const +{ + Q_D(const QWebEnginePage); + return d->adapter->activeUrl(); +} + +qreal QWebEnginePage::zoomFactor() const +{ + Q_D(const QWebEnginePage); + return d->adapter->currentZoomFactor(); +} + +void QWebEnginePage::setZoomFactor(qreal factor) +{ + Q_D(QWebEnginePage); + d->adapter->setZoomFactor(factor); +} + +void QWebEnginePage::runJavaScript(const QString &scriptSource, const QString &xPath) +{ + Q_D(QWebEnginePage); + d->adapter->runJavaScript(scriptSource, xPath); +} + +namespace { +struct JSCallbackFunctor : public JSCallbackBase { + JSCallbackFunctor(QtWebEnginePrivate::FunctorBase *functor) : m_func(functor) { } + ~JSCallbackFunctor() { delete m_func; } + void call(const QVariant &value) { (*m_func)(value); } +private: + QtWebEnginePrivate::FunctorBase *m_func; +}; +} + +void QWebEnginePage::runJavaScriptHelper(const QString &source, QtWebEnginePrivate::FunctorBase *functor, const QString &xPath) +{ + Q_D(QWebEnginePage); + d->adapter->runJavaScript(source, xPath, new JSCallbackFunctor(functor)); +} + +QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type) +{ + Q_D(QWebEnginePage); + if (d->view) { + QWebEngineView *newView = d->view->createWindow(type); + if (newView) + return newView->page(); + } + return 0; +} + +void QWebEnginePage::javaScriptAlert(QWebEngineFrame *originatingFrame, const QString &msg) +{ + Q_UNUSED(originatingFrame); + QMessageBox::information(view(), QStringLiteral("Javascript Alert - %1").arg(url().toString()), msg); +} + +bool QWebEnginePage::javaScriptConfirm(QWebEngineFrame *originatingFrame, const QString &msg) +{ + Q_UNUSED(originatingFrame); + return (QMessageBox::information(view(), QStringLiteral("Javascript Confirm - %1").arg(url().toString()), msg, QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok); +} + +bool QWebEnginePage::javaScriptPrompt(QWebEngineFrame *originatingFrame, const QString &msg, const QString &defaultValue, QString *result) +{ + Q_UNUSED(originatingFrame); + bool ret = false; + if (result) + *result = QInputDialog::getText(view(), QStringLiteral("Javascript Prompt - %1").arg(url().toString()), msg, QLineEdit::Normal, defaultValue, &ret); + return ret; +} +QT_END_NAMESPACE + +#include "moc_qwebenginepage.cpp" diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h new file mode 100644 index 000000000..a613f4a27 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -0,0 +1,592 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2007 Staikos Computing Services Inc. + + 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. +*/ + +#ifndef QWEBENGINEPAGE_H +#define QWEBENGINEPAGE_H + +#include +#include + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QUndoStack; +class QMenu; +class QPrinter; + +// FIXME: Just forward-declare the to-be-removed frame and element classes for now. +// Referencing calls should be ported to be page-friendly or removed individually. +class QWebEngineFrame; +class QWebEngineElement; +class QWebEngineElementCollection; + +class QWebEngineHistory; +class QWebEngineHistoryItem; +class QWebEnginePagePrivate; +class QWebEnginePluginFactory; +class QWebEngineSecurityOrigin; +class QtViewportAttributesPrivate; +class QWebEngineHitTestResultPrivate; + +namespace QtWebEnginePrivate { + +struct FunctorBase { + virtual ~FunctorBase() {} + virtual void operator()(const QVariant &) = 0; +}; + +template +struct FunctorCallback : public FunctorBase { + FunctorCallback(F callback) : m_callback(callback) {} + virtual void operator()(const QVariant &value) Q_DECL_OVERRIDE { m_callback(value); } +private: + F m_callback; +}; +} + +class QWEBENGINEWIDGETS_EXPORT QWebEngineHitTestResult { +public: + QWebEngineHitTestResult(); + QWebEngineHitTestResult(const QWebEngineHitTestResult &other); + QWebEngineHitTestResult &operator=(const QWebEngineHitTestResult &other); + ~QWebEngineHitTestResult(); + + bool isNull() const; + + QPoint pos() const; + QRect boundingRect() const; + QWebEngineElement enclosingBlockElement() const; + QString title() const; + + QString linkText() const; + QUrl linkUrl() const; + QUrl linkTitle() const; + QWebEngineFrame *linkTargetFrame() const; + QWebEngineElement linkElement() const; + + QString alternateText() const; // for img, area, input and applet + + QUrl imageUrl() const; + QPixmap pixmap() const; + + bool isContentEditable() const; + bool isContentSelected() const; + + QWebEngineElement element() const; + + QWebEngineFrame *frame() const; +}; + +class QWEBENGINEWIDGETS_EXPORT QWebEnginePage : public QObject { + Q_OBJECT +// Hack to avoid undefined symbols with properties until we have them implemented. +#ifndef Q_MOC_RUN + Q_PROPERTY(bool modified READ isModified) + Q_PROPERTY(QString selectedText READ selectedText) + Q_PROPERTY(QString selectedHtml READ selectedHtml) + Q_PROPERTY(bool hasSelection READ hasSelection) + Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize) + Q_PROPERTY(QSize preferredContentsSize READ preferredContentsSize WRITE setPreferredContentsSize) + Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent) + Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy) + Q_PROPERTY(QPalette palette READ palette WRITE setPalette) + Q_PROPERTY(bool contentEditable READ isContentEditable WRITE setContentEditable) + Q_ENUMS(LinkDelegationPolicy NavigationType WebAction) + + // Ex-QWebFrame properties + Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) + Q_PROPERTY(QUrl requestedUrl READ requestedUrl) + Q_PROPERTY(QUrl baseUrl READ baseUrl) + Q_PROPERTY(QIcon icon READ icon) + Q_PROPERTY(QSize contentsSize READ contentsSize) + Q_PROPERTY(QPoint scrollPosition READ scrollPosition WRITE setScrollPosition) + Q_PROPERTY(bool focus READ hasFocus) +#endif + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor) + Q_PROPERTY(QString title READ title) + Q_PROPERTY(QUrl url READ url WRITE setUrl) + +public: + enum NavigationType { + NavigationTypeLinkClicked, + NavigationTypeFormSubmitted, + NavigationTypeBackOrForward, + NavigationTypeReload, + NavigationTypeFormResubmitted, + NavigationTypeOther + }; + + enum WebAction { + NoWebAction = - 1, + + OpenLink, + + OpenLinkInNewWindow, + OpenFrameInNewWindow, + + DownloadLinkToDisk, + CopyLinkToClipboard, + + OpenImageInNewWindow, + DownloadImageToDisk, + CopyImageToClipboard, + + Back, + Forward, + Stop, + Reload, + + Cut, + Copy, + Paste, + + Undo, + Redo, + MoveToNextChar, + MoveToPreviousChar, + MoveToNextWord, + MoveToPreviousWord, + MoveToNextLine, + MoveToPreviousLine, + MoveToStartOfLine, + MoveToEndOfLine, + MoveToStartOfBlock, + MoveToEndOfBlock, + MoveToStartOfDocument, + MoveToEndOfDocument, + SelectNextChar, + SelectPreviousChar, + SelectNextWord, + SelectPreviousWord, + SelectNextLine, + SelectPreviousLine, + SelectStartOfLine, + SelectEndOfLine, + SelectStartOfBlock, + SelectEndOfBlock, + SelectStartOfDocument, + SelectEndOfDocument, + DeleteStartOfWord, + DeleteEndOfWord, + + SetTextDirectionDefault, + SetTextDirectionLeftToRight, + SetTextDirectionRightToLeft, + + ToggleBold, + ToggleItalic, + ToggleUnderline, + + InspectElement, + + InsertParagraphSeparator, + InsertLineSeparator, + + SelectAll, + ReloadAndBypassCache, + + PasteAndMatchStyle, + RemoveFormat, + + ToggleStrikethrough, + ToggleSubscript, + ToggleSuperscript, + InsertUnorderedList, + InsertOrderedList, + Indent, + Outdent, + + AlignCenter, + AlignJustified, + AlignLeft, + AlignRight, + + StopScheduledPageRefresh, + + CopyImageUrlToClipboard, + + OpenLinkInThisWindow, + + WebActionCount + }; + + enum FindFlag { + FindBackward = 1, + FindCaseSensitively = 2, + FindWrapsAroundDocument = 4, + HighlightAllOccurrences = 8 + }; + Q_DECLARE_FLAGS(FindFlags, FindFlag) + + enum LinkDelegationPolicy { + DontDelegateLinks, + DelegateExternalLinks, + DelegateAllLinks + }; + + enum WebWindowType { + WebBrowserWindow, + WebModalDialog + }; + + enum PermissionPolicy { + PermissionUnknown, + PermissionGrantedByUser, + PermissionDeniedByUser + }; + + enum Feature { + Notifications, + Geolocation + }; + + // Ex-QWebFrame enum + enum ValueOwnership { + QtOwnership, + ScriptOwnership, + AutoOwnership + }; + + class QWEBENGINEWIDGETS_EXPORT ViewportAttributes { + public: + ViewportAttributes(); + ViewportAttributes(const QWebEnginePage::ViewportAttributes& other); + + ~ViewportAttributes(); + + QWebEnginePage::ViewportAttributes& operator=(const QWebEnginePage::ViewportAttributes& other); + + inline qreal initialScaleFactor() const { return m_initialScaleFactor; } + inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; } + inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; } + inline qreal devicePixelRatio() const { return m_devicePixelRatio; } + inline bool isUserScalable() const { return m_isUserScalable; } + inline bool isValid() const { return m_isValid; } + inline QSizeF size() const { return m_size; } + + private: + QSharedDataPointer d; + qreal m_initialScaleFactor; + qreal m_minimumScaleFactor; + qreal m_maximumScaleFactor; + qreal m_devicePixelRatio; + bool m_isUserScalable; + bool m_isValid; + QSizeF m_size; + + friend class QWebEnginePage; + }; + + + explicit QWebEnginePage(QObject *parent = 0); + ~QWebEnginePage(); + + QWebEngineFrame *mainFrame() const; + QWebEngineFrame *currentFrame() const; + QWebEngineFrame* frameAt(const QPoint& pos) const; + + QWebEngineHistory *history() const; + QWebEngineSettings *settings() const; + + void setView(QWidget *view); + QWidget *view() const; + + bool isModified() const; +#ifndef QT_NO_UNDOSTACK + QUndoStack *undoStack() const; +#endif + + void setNetworkAccessManager(QNetworkAccessManager *manager); + QNetworkAccessManager *networkAccessManager() const; + + void setPluginFactory(QWebEnginePluginFactory *factory); + QWebEnginePluginFactory *pluginFactory() const; + + quint64 totalBytes() const; + quint64 bytesReceived() const; + + bool hasSelection() const; + QString selectedText() const; + QString selectedHtml() const; + +#ifndef QT_NO_ACTION + QAction *action(WebAction action) const; +#endif + virtual void triggerAction(WebAction action, bool checked = false); + + QSize viewportSize() const; + void setViewportSize(const QSize &size) const; + ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const; + + QSize preferredContentsSize() const; + void setPreferredContentsSize(const QSize &size) const; + void setActualVisibleContentRect(const QRect& rect) const; + + bool focusNextPrevChild(bool next); + + QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + + bool findText(const QString &subString, FindFlags options = 0); + + void setForwardUnsupportedContent(bool forward); + bool forwardUnsupportedContent() const; + + void setLinkDelegationPolicy(LinkDelegationPolicy policy); + LinkDelegationPolicy linkDelegationPolicy() const; + + void setPalette(const QPalette &palette); + QPalette palette() const; + + void setContentEditable(bool editable); + bool isContentEditable() const; + +#ifndef QT_NO_CONTEXTMENU + bool swallowContextMenuEvent(QContextMenuEvent *event); +#endif + void updatePositionDependentActions(const QPoint &pos); + + QMenu *createStandardContextMenu(); + + void setFeaturePermission(QWebEngineFrame* frame, Feature feature, PermissionPolicy policy); + + QStringList supportedContentTypes() const; + bool supportsContentType(const QString& mimeType) const; + + enum Extension { + ChooseMultipleFilesExtension, + ErrorPageExtension + }; + class ExtensionOption + {}; + class ExtensionReturn + {}; + + class ChooseMultipleFilesExtensionOption : public ExtensionOption { + public: + QWebEngineFrame *parentFrame; + QStringList suggestedFileNames; + }; + + class ChooseMultipleFilesExtensionReturn : public ExtensionReturn { + public: + QStringList fileNames; + }; + + enum ErrorDomain { QtNetwork, Http, WebKit }; + class ErrorPageExtensionOption : public ExtensionOption { + public: + QUrl url; + QWebEngineFrame* frame; + ErrorDomain domain; + int error; + QString errorString; + }; + + class ErrorPageExtensionReturn : public ExtensionReturn { + public: + ErrorPageExtensionReturn() : contentType(QLatin1String("text/html")), encoding(QLatin1String("utf-8")) {}; + QString contentType; + QString encoding; + QUrl baseUrl; + QByteArray content; + }; + + + virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) { Q_UNUSED(extension); Q_UNUSED(option); Q_UNUSED(output); Q_UNREACHABLE(); return false; } + virtual bool supportsExtension(Extension extension) const { Q_UNUSED(extension); Q_UNREACHABLE(); return false; } + + virtual bool shouldInterruptJavaScript() { Q_UNREACHABLE(); return false; } + + // Ex-QWebFrame methods + void load(const QUrl &url); + void load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray()); + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + void addToJavaScriptWindowObject(const QString &name, QObject *object, ValueOwnership ownership = QtOwnership); + QString toHtml() const; + QString toPlainText() const; + + QString title() const; + void setUrl(const QUrl &url); + QUrl url() const; + QUrl requestedUrl() const; + QUrl baseUrl() const; + QIcon icon() const; + QMultiMap metaData() const; + + QString frameName() const; + + QWebEngineFrame *parentFrame() const; + QList childFrames() const; + + Qt::ScrollBarPolicy scrollBarPolicy(Qt::Orientation orientation) const; + void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy); + + void setScrollBarValue(Qt::Orientation orientation, int value); + int scrollBarValue(Qt::Orientation orientation) const; + int scrollBarMinimum(Qt::Orientation orientation) const; + int scrollBarMaximum(Qt::Orientation orientation) const; + QRect scrollBarGeometry(Qt::Orientation orientation) const; + + void scroll(int, int); + QPoint scrollPosition() const; + void setScrollPosition(const QPoint &pos); + + void scrollToAnchor(const QString& anchor); + + enum RenderLayer { + ContentsLayer = 0x10, + ScrollBarLayer = 0x20, + PanIconLayer = 0x40, + + AllLayers = 0xff + }; + Q_DECLARE_FLAGS(RenderLayers, RenderLayer) + + void render(QPainter*, const QRegion& clip = QRegion()); + void render(QPainter*, RenderLayers layer, const QRegion& clip = QRegion()); + + void setTextSizeMultiplier(qreal factor); + qreal textSizeMultiplier() const; + + qreal zoomFactor() const; + void setZoomFactor(qreal factor); + + bool hasFocus() const; + void setFocus(); + + QPoint pos() const; + QRect geometry() const; + QSize contentsSize() const; + + QWebEngineElement documentElement() const; + QWebEngineElementCollection findAllElements(const QString &selectorQuery) const; + QWebEngineElement findFirstElement(const QString &selectorQuery) const; + + QWebEngineHitTestResult hitTestContent(const QPoint &pos) const; + + QWebEngineSecurityOrigin securityOrigin() const; + + void runJavaScript(const QString& scriptSource, const QString &xPath = QString()); + + template + void runJavaScript(const QString& scriptSource, F func, const QString &xPath = QString()); + +public Q_SLOTS: + // Ex-QWebFrame slot +#ifndef QT_NO_PRINTER + void print(QPrinter *printer) const { Q_UNUSED(printer); Q_UNREACHABLE(); } +#endif + + +Q_SIGNALS: + void loadStarted(); + void loadProgress(int progress); + void loadFinished(bool ok); + + void linkHovered(const QString &link, const QString &title, const QString &textContent); + void statusBarMessage(const QString& text); + void selectionChanged(); + void frameCreated(QWebEngineFrame *frame); + void geometryChangeRequested(const QRect& geom); + void repaintRequested(const QRect& dirtyRect); + void scrollRequested(int dx, int dy, const QRect& scrollViewRect); + void windowCloseRequested(); + void printRequested(QWebEngineFrame *frame); + void linkClicked(const QUrl &url); + + void toolBarVisibilityChangeRequested(bool visible); + void statusBarVisibilityChangeRequested(bool visible); + void menuBarVisibilityChangeRequested(bool visible); + + void unsupportedContent(QNetworkReply *reply); + void downloadRequested(const QNetworkRequest &request); + + void microFocusChanged(); + void contentsChanged(); + void databaseQuotaExceeded(QWebEngineFrame* frame, QString databaseName); + void applicationCacheQuotaExceeded(QWebEngineSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded); + + void saveFrameStateRequested(QWebEngineFrame* frame, QWebEngineHistoryItem* item); + void restoreFrameStateRequested(QWebEngineFrame* frame); + + void viewportChangeRequested(); + + void featurePermissionRequested(QWebEngineFrame* frame, QWebEnginePage::Feature feature); + void featurePermissionRequestCanceled(QWebEngineFrame* frame, QWebEnginePage::Feature feature); + + // Ex-QWebFrame signals + void javaScriptWindowObjectCleared(); + + void provisionalLoad(); + void titleChanged(const QString &title); + void urlChanged(const QUrl &url); + + void initialLayoutCompleted(); + + void iconChanged(); + + void contentsSizeChanged(const QSize &size); + + void pageChanged(); + +protected: + virtual QWebEnginePage *createWindow(WebWindowType type); + virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) { Q_UNUSED(classid); Q_UNUSED(url); Q_UNUSED(paramNames); Q_UNUSED(paramValues); Q_UNREACHABLE(); return 0; } + + virtual bool acceptNavigationRequest(QWebEngineFrame *frame, const QNetworkRequest &request, NavigationType type) { Q_UNUSED(frame); Q_UNUSED(request); Q_UNUSED(type); Q_UNREACHABLE(); return false; } + virtual QString chooseFile(QWebEngineFrame *originatingFrame, const QString& oldFile) { Q_UNUSED(originatingFrame); Q_UNUSED(oldFile); Q_UNREACHABLE(); return QString(); } + virtual void javaScriptAlert(QWebEngineFrame *originatingFrame, const QString& msg); + virtual bool javaScriptConfirm(QWebEngineFrame *originatingFrame, const QString& msg); + virtual bool javaScriptPrompt(QWebEngineFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); + virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) { Q_UNUSED(message); Q_UNUSED(lineNumber); Q_UNUSED(sourceID); Q_UNREACHABLE(); } + + virtual QString userAgentForUrl(const QUrl& url) const { Q_UNUSED(url); Q_UNREACHABLE(); return QString(); } + +private: + Q_DECLARE_PRIVATE(QWebEnginePage); +#ifndef QT_NO_ACTION + Q_PRIVATE_SLOT(d_func(), void _q_webActionTriggered(bool checked)) +#endif + void runJavaScriptHelper(const QString &source, QtWebEnginePrivate::FunctorBase *, const QString &xPath); + + friend class QWebEngineView; + friend class QWebEngineViewPrivate; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QWebEnginePage::FindFlags); +Q_DECLARE_OPERATORS_FOR_FLAGS(QWebEnginePage::RenderLayers); + + +template +inline void QWebEnginePage::runJavaScript(const QString &scriptSource, F func, const QString &xPath) +{ + runJavaScriptHelper(scriptSource, new QtWebEnginePrivate::FunctorCallback(func), xPath); +} + +QT_END_NAMESPACE + +#endif // QWEBENGINEPAGE_H diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h new file mode 100644 index 000000000..0e654e6c9 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEPAGE_P_H +#define QWEBENGINEPAGE_P_H + +#include "qwebenginepage.h" + +#include "web_contents_adapter_client.h" +#include +#include + +class RenderWidgetHostViewQtDelegate; +class WebContentsAdapter; + +QT_BEGIN_NAMESPACE +class QWebEngineHistory; +class QWebEnginePage; +class QWebEngineView; + +class QWebEnginePagePrivate : public QObjectPrivate, public WebContentsAdapterClient +{ +public: + Q_DECLARE_PUBLIC(QWebEnginePage) + + QWebEnginePagePrivate(); + ~QWebEnginePagePrivate(); + + virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) Q_DECL_OVERRIDE; + virtual void titleChanged(const QString&) Q_DECL_OVERRIDE; + virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE; + virtual void iconChanged(const QUrl&) Q_DECL_OVERRIDE; + virtual void loadingStateChanged() Q_DECL_OVERRIDE; + virtual void loadProgressChanged(int progress) Q_DECL_OVERRIDE; + virtual QRectF viewportRect() const Q_DECL_OVERRIDE; + virtual void loadFinished(bool success) Q_DECL_OVERRIDE; + virtual void focusContainer() Q_DECL_OVERRIDE; + virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect &initialGeometry) Q_DECL_OVERRIDE; + virtual void close() Q_DECL_OVERRIDE; + virtual bool contextMenuRequested(const WebEngineContextMenuData &data) Q_DECL_OVERRIDE; + virtual bool javascriptDialog(JavascriptDialogType type, const QString &message, const QString &defaultValue = QString(), QString *result = 0) Q_DECL_OVERRIDE; + + void updateAction(QWebEnginePage::WebAction) const; + void updateNavigationActions(); + void _q_webActionTriggered(bool checked); + + QExplicitlySharedDataPointer adapter; + QWebEngineHistory *history; + QWebEngineView *view; + mutable QAction *actions[QWebEnginePage::WebActionCount]; + bool m_isLoading; + WebEngineContextMenuData m_menuData; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEPAGE_P_H diff --git a/src/webenginewidgets/api/qwebenginesecurityorigin.h b/src/webenginewidgets/api/qwebenginesecurityorigin.h new file mode 100644 index 000000000..c943bec84 --- /dev/null +++ b/src/webenginewidgets/api/qwebenginesecurityorigin.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008 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. +*/ + +#ifndef QWEBENGINESECURITYORIGIN_H_ +#define QWEBENGINESECURITYORIGIN_H_ + +#include + +QT_BEGIN_NAMESPACE +class QWebEngineDatabase; +class QWebEngineSecurityOriginPrivate; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineSecurityOrigin { +public: + static QList allOrigins(); + static void addLocalScheme(const QString& scheme); + static void removeLocalScheme(const QString& scheme); + static QStringList localSchemes(); + + ~QWebEngineSecurityOrigin(); + + QString scheme() const; + QString host() const; + int port() const; + + qint64 databaseUsage() const; + qint64 databaseQuota() const; + void setDatabaseQuota(qint64 quota); + void setApplicationCacheQuota(qint64 quota); + QList databases() const; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINESECURITYORIGIN_H_ diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h new file mode 100644 index 000000000..177a975fd --- /dev/null +++ b/src/webenginewidgets/api/qwebenginesettings.h @@ -0,0 +1,170 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008 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. +*/ + +#ifndef QWEBENGINESETTINGS_H +#define QWEBENGINESETTINGS_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QIcon; +class QPixmap; +class QUrl; +class QWebEngineSettingsPrivate; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineSettings { +public: + enum FontFamily { + StandardFont, + FixedFont, + SerifFont, + SansSerifFont, + CursiveFont, + FantasyFont + }; + enum WebAttribute { + AutoLoadImages, + JavascriptEnabled, + JavaEnabled, + PluginsEnabled, + PrivateBrowsingEnabled, + JavascriptCanOpenWindows, + JavascriptCanAccessClipboard, + DeveloperExtrasEnabled, + LinksIncludedInFocusChain, + ZoomTextOnly, + PrintElementBackgrounds, + OfflineStorageDatabaseEnabled, + OfflineWebApplicationCacheEnabled, + LocalStorageEnabled, +#if defined(QT_DEPRECATED) || defined(qdoc) + LocalStorageDatabaseEnabled = LocalStorageEnabled, +#endif + LocalContentCanAccessRemoteUrls, + DnsPrefetchEnabled, + XSSAuditingEnabled, + AcceleratedCompositingEnabled, + SpatialNavigationEnabled, + LocalContentCanAccessFileUrls, + TiledBackingStoreEnabled, + FrameFlatteningEnabled, + SiteSpecificQuirksEnabled, + JavascriptCanCloseWindows, + WebGLEnabled, + CSSRegionsEnabled, + HyperlinkAuditingEnabled, + CSSGridLayoutEnabled, + ScrollAnimatorEnabled, + CaretBrowsingEnabled, + NotificationsEnabled + }; + enum WebGraphic { + MissingImageGraphic, + MissingPluginGraphic, + DefaultFrameIconGraphic, + TextAreaSizeGripCornerGraphic, + DeleteButtonGraphic, + InputSpeechButtonGraphic, + SearchCancelButtonGraphic, + SearchCancelButtonPressedGraphic + }; + enum FontSize { + MinimumFontSize, + MinimumLogicalFontSize, + DefaultFontSize, + DefaultFixedFontSize + }; + enum ThirdPartyCookiePolicy { + AlwaysAllowThirdPartyCookies, + AlwaysBlockThirdPartyCookies, + AllowThirdPartyWithExistingCookies + }; + + static QWebEngineSettings *globalSettings(); + + void setFontFamily(FontFamily which, const QString &family); + QString fontFamily(FontFamily which) const; + void resetFontFamily(FontFamily which); + + void setFontSize(FontSize type, int size); + int fontSize(FontSize type) const; + void resetFontSize(FontSize type); + + void setAttribute(WebAttribute attr, bool on); + bool testAttribute(WebAttribute attr) const; + void resetAttribute(WebAttribute attr); + + void setUserStyleSheetUrl(const QUrl &location); + QUrl userStyleSheetUrl() const; + + void setDefaultTextEncoding(const QString &encoding); + QString defaultTextEncoding() const; + + static void setIconDatabasePath(const QString &location); + static QString iconDatabasePath(); + static void clearIconDatabase(); + static QIcon iconForUrl(const QUrl &url); + + //static QWebEnginePluginDatabase *pluginDatabase(); + + static void setWebGraphic(WebGraphic type, const QPixmap &graphic); + static QPixmap webGraphic(WebGraphic type); + + static void setMaximumPagesInCache(int pages); + static int maximumPagesInCache(); + static void setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity); + + static void setOfflineStoragePath(const QString& path); + static QString offlineStoragePath(); + static void setOfflineStorageDefaultQuota(qint64 maximumSize); + static qint64 offlineStorageDefaultQuota(); + + static void setOfflineWebApplicationCachePath(const QString& path); + static QString offlineWebApplicationCachePath(); + static void setOfflineWebApplicationCacheQuota(qint64 maximumSize); + static qint64 offlineWebApplicationCacheQuota(); + + void setLocalStoragePath(const QString& path); + QString localStoragePath() const; + + static void clearMemoryCaches(); + + static void enablePersistentStorage(const QString& path = QString()); + + void setThirdPartyCookiePolicy(ThirdPartyCookiePolicy); + QWebEngineSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy() const; + + void setCSSMediaType(const QString&); + QString cssMediaType() const; + +private: + Q_DISABLE_COPY(QWebEngineSettings) + + QWebEngineSettings(); + ~QWebEngineSettings(); + + QWebEngineSettingsPrivate *d; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINESETTINGS_H diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp new file mode 100644 index 000000000..4dea036b1 --- /dev/null +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineview.h" +#include "qwebengineview_p.h" + +#include "qwebenginepage_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +void QWebEngineViewPrivate::bind(QWebEngineView *view, QWebEnginePage *page) +{ + if (view && page == view->d_func()->page) + return; + + if (page) { + // Un-bind page from its current view. + if (QWebEngineView *oldView = page->d_func()->view) { + page->disconnect(oldView); + oldView->d_func()->page = 0; + } + page->d_func()->view = view; + } + + if (view) { + // Un-bind view from its current page. + if (QWebEnginePage *oldPage = view->d_func()->page) { + oldPage->disconnect(view); + oldPage->d_func()->view = 0; + } + view->d_func()->page = page; + } + + if (view && page) { + QObject::connect(page, &QWebEnginePage::titleChanged, view, &QWebEngineView::titleChanged); + QObject::connect(page, &QWebEnginePage::urlChanged, view, &QWebEngineView::urlChanged); + QObject::connect(page, &QWebEnginePage::loadStarted, view, &QWebEngineView::loadStarted); + QObject::connect(page, &QWebEnginePage::loadProgress, view, &QWebEngineView::loadProgress); + QObject::connect(page, &QWebEnginePage::loadFinished, view, &QWebEngineView::loadFinished); + } +} + +QWebEngineViewPrivate::QWebEngineViewPrivate() + : QWidgetPrivate(QObjectPrivateVersion) + , page(0) +{ +} + +QWebEngineView::QWebEngineView(QWidget *parent) + : QWidget(*(new QWebEngineViewPrivate), parent, 0) +{ + // This causes the child RenderWidgetHostViewQtDelegateWidgets to fill this widget. + setLayout(new QStackedLayout); +} + +QWebEngineView::~QWebEngineView() +{ +} + +QWebEnginePage* QWebEngineView::page() const +{ + Q_D(const QWebEngineView); + if (!d->page) { + QWebEngineView *that = const_cast(this); + that->setPage(new QWebEnginePage(that)); + } + return d->page; +} + +void QWebEngineView::setPage(QWebEnginePage* page) +{ + QWebEngineViewPrivate::bind(this, page); +} + +void QWebEngineView::load(const QUrl& url) +{ + page()->load(url); +} + +QWebEngineHistory* QWebEngineView::history() const +{ + return page()->history(); +} + +QString QWebEngineView::title() const +{ + return page()->title(); +} + +void QWebEngineView::setUrl(const QUrl &url) +{ + page()->setUrl(url); +} + +QUrl QWebEngineView::url() const +{ + return page()->url(); +} + +#ifndef QT_NO_ACTION +QAction* QWebEngineView::pageAction(QWebEnginePage::WebAction action) const +{ + return page()->action(action); +} +#endif + +void QWebEngineView::triggerPageAction(QWebEnginePage::WebAction action, bool checked) +{ + page()->triggerAction(action, checked); +} + +void QWebEngineView::stop() +{ + page()->triggerAction(QWebEnginePage::Stop); +} + +void QWebEngineView::back() +{ + page()->triggerAction(QWebEnginePage::Back); +} + +void QWebEngineView::forward() +{ + page()->triggerAction(QWebEnginePage::Forward); +} + +void QWebEngineView::reload() +{ + page()->triggerAction(QWebEnginePage::Reload); +} + +QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type) +{ + Q_UNUSED(type) + return 0; +} + + +qreal QWebEngineView::zoomFactor() const +{ + return page()->zoomFactor(); +} + +void QWebEngineView::setZoomFactor(qreal factor) +{ + page()->setZoomFactor(factor); +} + +bool QWebEngineView::event(QEvent *ev) +{ + // We swallow spontaneous contextMenu events and synthethize those back later on when we get the + // HandleContextMenu callback from chromium + if (ev->type() == QEvent::ContextMenu) { + ev->accept(); + return true; + } + return QWidget::event(ev); +} + +void QWebEngineView::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu *menu = page()->createStandardContextMenu(); + menu->popup(event->globalPos()); +} + +QT_END_NAMESPACE + +#include "moc_qwebengineview.cpp" diff --git a/src/webenginewidgets/api/qwebengineview.h b/src/webenginewidgets/api/qwebengineview.h new file mode 100644 index 000000000..2c649d46f --- /dev/null +++ b/src/webenginewidgets/api/qwebengineview.h @@ -0,0 +1,145 @@ +/* + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2007 Staikos Computing Services Inc. + + 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. +*/ + +#ifndef QWEBENGINEVIEW_H +#define QWEBENGINEVIEW_H + +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QContextMenuEvent; +class QIcon; +class QNetworkRequest; +class QPrinter; +class QUrl; +class QWebEnginePage; +class QWebEngineViewPrivate; +class QWebEngineNetworkRequest; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineView : public QWidget { + Q_OBJECT +// Hack to avoid undefined symbols with properties until we have them implemented. +#ifndef Q_MOC_RUN + Q_PROPERTY(QString title READ title) + Q_PROPERTY(QUrl url READ url WRITE setUrl) + Q_PROPERTY(QIcon icon READ icon) + Q_PROPERTY(QString selectedText READ selectedText) + Q_PROPERTY(QString selectedHtml READ selectedHtml) + Q_PROPERTY(bool hasSelection READ hasSelection) + Q_PROPERTY(bool modified READ isModified) + //Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) + Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor) + + Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints) + Q_FLAGS(QPainter::RenderHints) +#endif + +public: + explicit QWebEngineView(QWidget* parent = 0); + virtual ~QWebEngineView(); + + QWebEnginePage* page() const; + void setPage(QWebEnginePage* page); + + void load(const QUrl& url); + void load(const QNetworkRequest& request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray()); + void setHtml(const QString& html, const QUrl& baseUrl = QUrl()); + void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl()); + + QWebEngineHistory* history() const; + QWebEngineSettings* settings() const; + + QString title() const; + void setUrl(const QUrl &url); + QUrl url() const; + QIcon icon() const; + + bool hasSelection() const; + QString selectedText() const; + QString selectedHtml() const; + +#ifndef QT_NO_ACTION + QAction* pageAction(QWebEnginePage::WebAction action) const; +#endif + void triggerPageAction(QWebEnginePage::WebAction action, bool checked = false); + + bool isModified() const; + + /* + Qt::TextInteractionFlags textInteractionFlags() const; + void setTextInteractionFlags(Qt::TextInteractionFlags flags); + void setTextInteractionFlag(Qt::TextInteractionFlag flag); + */ + + qreal zoomFactor() const; + void setZoomFactor(qreal factor); + + void setTextSizeMultiplier(qreal factor); + qreal textSizeMultiplier() const; + + QPainter::RenderHints renderHints() const; + void setRenderHints(QPainter::RenderHints hints); + void setRenderHint(QPainter::RenderHint hint, bool enabled = true); + + bool findText(const QString& subString, QWebEnginePage::FindFlags options = 0); + + virtual QSize sizeHint() const { return QSize(800, 600); } + +public Q_SLOTS: + void stop(); + void back(); + void forward(); + void reload(); + + void print(QPrinter*) const { } + +Q_SIGNALS: + void loadStarted(); + void loadProgress(int progress); + void loadFinished(bool); + void titleChanged(const QString& title); + void statusBarMessage(const QString& text); + void linkClicked(const QUrl&); + void selectionChanged(); + void iconChanged(); + void urlChanged(const QUrl&); + +protected: + virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type); + virtual void contextMenuEvent(QContextMenuEvent*) Q_DECL_OVERRIDE; + virtual bool event(QEvent*) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QWebEngineView); + + friend class QWebEnginePage; + friend class QWebEnginePagePrivate; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEVIEW_H diff --git a/src/webenginewidgets/api/qwebengineview_p.h b/src/webenginewidgets/api/qwebengineview_p.h new file mode 100644 index 000000000..774386a21 --- /dev/null +++ b/src/webenginewidgets/api/qwebengineview_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEVIEW_P_H +#define QWEBENGINEVIEW_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QWebEngineView; + +class QWebEngineViewPrivate : public QWidgetPrivate +{ +public: + Q_DECLARE_PUBLIC(QWebEngineView) + + static void bind(QWebEngineView *view, QWebEnginePage *page); + + QWebEngineViewPrivate(); + + QWebEnginePage *page; + bool m_pendingContextMenuEvent; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEVIEW_P_H -- cgit v1.2.3