summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2020-12-18 20:02:02 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2021-06-04 18:41:46 +0200
commit742b9db0e34c8fc08e9f50c3053aed5f501f08d2 (patch)
tree81265ca9b3bee9f78389b8855c7cf565769e15ce
parent881339e9d9054c46f2621119246de7a13c83761a (diff)
Merge WebEngineHistory's quick implementation into QWebEngineHistory
[ChangeLog][QWebEngineCore][QWebEngineHistory] New methods to access navigation history as a model through new class QWebEngineHistoryModel. [ChangeLog][QWebEngineQuick] QQuickWebEngineHistory is merged into QWebEngineHistory. Task-number: QTBUG-74585 Change-Id: I9f9a73bbaf3954282dfc220cfc2c4cb08a37fb73 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/api/qwebenginehistory.cpp256
-rw-r--r--src/core/api/qwebenginehistory.h56
-rw-r--r--src/core/api/qwebenginehistory_p.h60
-rw-r--r--src/core/api/qwebenginepage.cpp6
-rw-r--r--src/core/doc/src/qwebenginehistory_lgpl.qdoc (renamed from src/webenginewidgets/doc/src/qwebenginehistory_lgpl.qdoc)61
-rw-r--r--src/webenginequick/CMakeLists.txt1
-rw-r--r--src/webenginequick/api/qquickwebenginehistory.cpp355
-rw-r--r--src/webenginequick/api/qquickwebenginehistory_p.h124
-rw-r--r--src/webenginequick/api/qquickwebenginehistory_p_p.h107
-rw-r--r--src/webenginequick/api/qquickwebengineview.cpp8
-rw-r--r--src/webenginequick/api/qquickwebengineview_p.h6
-rw-r--r--src/webenginequick/api/qquickwebengineview_p_p.h3
-rw-r--r--src/webenginequick/doc/src/navigation_history.qdoc137
-rw-r--r--src/webenginequick/plugin/plugin.cpp10
-rw-r--r--src/webenginequick/plugin/plugins.qmltypes14
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp16
16 files changed, 548 insertions, 672 deletions
diff --git a/src/core/api/qwebenginehistory.cpp b/src/core/api/qwebenginehistory.cpp
index 08119d78c..bf2813bfb 100644
--- a/src/core/api/qwebenginehistory.cpp
+++ b/src/core/api/qwebenginehistory.cpp
@@ -50,50 +50,45 @@ QT_BEGIN_NAMESPACE
*/
QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(
- QtWebEngineCore::WebContentsAdapterClient *adapter, int index)
- : m_adapter(adapter), index(index)
+ QtWebEngineCore::WebContentsAdapterClient *client, int index)
+ : client(client), index(index)
{
}
-QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d) : d(d) { }
-
-QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other) : d(other.d) { }
-
-QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other)
+QtWebEngineCore::WebContentsAdapter *QWebEngineHistoryItemPrivate::adapter() const
{
- d = other.d;
- return *this;
+ return client ? client->webContentsAdapter() : nullptr;
}
-QWebEngineHistoryItem::~QWebEngineHistoryItem() { }
+QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d) : d(d) { }
+QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other) = default;
+QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItem &&other) = default;
+QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other) = default;
+QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(QWebEngineHistoryItem &&other) = default;
+QWebEngineHistoryItem::~QWebEngineHistoryItem() = default;
QUrl QWebEngineHistoryItem::originalUrl() const
{
Q_D(const QWebEngineHistoryItem);
- return d->m_adapter
- ? d->m_adapter->webContentsAdapter()->getNavigationEntryOriginalUrl(d->index)
- : QUrl();
+ return d->adapter() ? d->adapter()->getNavigationEntryOriginalUrl(d->index) : QUrl();
}
QUrl QWebEngineHistoryItem::url() const
{
Q_D(const QWebEngineHistoryItem);
- return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryUrl(d->index)
- : QUrl();
+ return d->adapter() ? d->adapter()->getNavigationEntryUrl(d->index) : QUrl();
}
QString QWebEngineHistoryItem::title() const
{
Q_D(const QWebEngineHistoryItem);
- return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryTitle(d->index)
- : QString();
+ return d->adapter() ? d->adapter()->getNavigationEntryTitle(d->index) : QString();
}
QDateTime QWebEngineHistoryItem::lastVisited() const
{
Q_D(const QWebEngineHistoryItem);
- return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryTimestamp(d->index)
- : QDateTime();
+ return d->adapter() ? d->adapter()->getNavigationEntryTimestamp(d->index) : QDateTime();
}
/*!
@@ -104,22 +99,22 @@ QDateTime QWebEngineHistoryItem::lastVisited() const
QUrl QWebEngineHistoryItem::iconUrl() const
{
Q_D(const QWebEngineHistoryItem);
- return d->m_adapter ? d->m_adapter->webContentsAdapter()->getNavigationEntryIconUrl(d->index)
- : QUrl();
+ return d->adapter() ? d->adapter()->getNavigationEntryIconUrl(d->index) : QUrl();
}
bool QWebEngineHistoryItem::isValid() const
{
Q_D(const QWebEngineHistoryItem);
- if (!d->m_adapter)
+ if (!d->client)
return false;
- return d->index >= 0 && d->index < d->m_adapter->webContentsAdapter()->navigationEntryCount();
+ return d->index >= 0 && d->index < d->adapter()->navigationEntryCount();
}
-QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(
- QtWebEngineCore::WebContentsAdapterClient *adapter)
- : m_adapter(adapter)
+QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(QtWebEngineCore::WebContentsAdapterClient *client,
+ const ImageProviderUrl &imageProviderUrl)
+ : client(client), imageProviderUrl(imageProviderUrl)
{
+ Q_ASSERT(client);
}
QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate()
@@ -127,33 +122,175 @@ QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate()
// Invalidate shared item references possibly still out there.
QList<QWebEngineHistoryItem>::iterator it, end;
for (it = items.begin(), end = items.end(); it != end; ++it)
- it->d->m_adapter = nullptr;
+ it->d->client = nullptr;
}
void QWebEngineHistoryPrivate::updateItems() const
{
// Keep track of items we return to be able to invalidate them
- // and avoid dangling references to our m_adapter.
- int entryCount = m_adapter->webContentsAdapter()->navigationEntryCount();
+ // and avoid dangling references to our client.
+ int entryCount = adapter()->navigationEntryCount();
while (items.size() > entryCount) {
- items.last().d->m_adapter = nullptr;
+ items.last().d->client = nullptr;
items.removeLast();
}
while (items.size() < entryCount) {
int nextIndex = items.size();
- items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(m_adapter, nextIndex)));
+ items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(client, nextIndex)));
+ }
+}
+
+QtWebEngineCore::WebContentsAdapter *QWebEngineHistoryPrivate::adapter() const
+{
+ Q_ASSERT(client->webContentsAdapter());
+ return client->webContentsAdapter();
+}
+
+QWebEngineHistoryModelPrivate::QWebEngineHistoryModelPrivate(const QWebEngineHistoryPrivate *history)
+ : history(history)
+{
+ Q_ASSERT(history);
+}
+
+QWebEngineHistoryModelPrivate::~QWebEngineHistoryModelPrivate()
+{
+}
+
+QtWebEngineCore::WebContentsAdapter *QWebEngineHistoryModelPrivate::adapter() const
+{
+ Q_ASSERT(history->adapter());
+ return history->adapter();
+}
+
+int QWebEngineHistoryModelPrivate::count() const
+{
+ return adapter()->navigationEntryCount();
+}
+
+int QWebEngineHistoryModelPrivate::index(int index) const
+{
+ return index;
+}
+
+int QWebEngineHistoryModelPrivate::offsetForIndex(int index) const
+{
+ return index - adapter()->currentNavigationEntryIndex();
+}
+
+int QWebEngineBackHistoryModelPrivate::count() const
+{
+ return adapter()->currentNavigationEntryIndex();
+}
+
+int QWebEngineBackHistoryModelPrivate::index(int i) const
+{
+ Q_ASSERT(i >= 0 && i < count());
+ return count() - 1 - i;
+}
+
+int QWebEngineBackHistoryModelPrivate::offsetForIndex(int index) const
+{
+ return - index - 1;
+}
+
+int QWebEngineForwardHistoryModelPrivate::count() const
+{
+ if (!adapter()->isInitialized())
+ return 0;
+ return adapter()->navigationEntryCount() - adapter()->currentNavigationEntryIndex() - 1;
+}
+
+int QWebEngineForwardHistoryModelPrivate::index(int i) const
+{
+ return adapter()->currentNavigationEntryIndex() + i + 1;
+}
+
+int QWebEngineForwardHistoryModelPrivate::offsetForIndex(int index) const
+{
+ return index + 1;
+}
+
+QWebEngineHistoryModel::QWebEngineHistoryModel(QWebEngineHistoryModelPrivate *d)
+ : d_ptr(d)
+{
+}
+
+QWebEngineHistoryModel::~QWebEngineHistoryModel()
+{
+}
+
+QHash<int, QByteArray> QWebEngineHistoryModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[Qt::DisplayRole] = "display";
+ roles[Qt::ToolTipRole] = "toolTip";
+ roles[UrlRole] = "url";
+ roles[TitleRole] = "title";
+ roles[OffsetRole] = "offset";
+ roles[IconUrlRole] = "icon";
+ return roles;
+}
+
+int QWebEngineHistoryModel::rowCount(const QModelIndex &index) const
+{
+ Q_UNUSED(index);
+ Q_D(const QWebEngineHistoryModel);
+ return d->count();
+}
+
+QVariant QWebEngineHistoryModel::data(const QModelIndex &index, int role) const
+{
+ Q_D(const QWebEngineHistoryModel);
+
+ if (!index.isValid())
+ return QVariant();
+
+ switch (role) {
+ case Qt::DisplayRole:
+ case TitleRole:
+ return d->adapter()->getNavigationEntryTitle(d->index(index.row()));
+
+ case Qt::ToolTipRole:
+ case UrlRole:
+ return d->adapter()->getNavigationEntryUrl(d->index(index.row()));
+
+ case OffsetRole:
+ return d->offsetForIndex(index.row());
+
+ case IconUrlRole: {
+ QUrl url = QUrl(d->adapter()->getNavigationEntryIconUrl(d->index(index.row())));
+ return d->history->urlOrImageProviderUrl(url);
+ }
+ default:
+ break;
}
+
+ return QVariant();
+}
+
+void QWebEngineHistoryModel::reset()
+{
+ beginResetModel();
+ endResetModel();
}
QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d) : d_ptr(d) { }
QWebEngineHistory::~QWebEngineHistory() { }
+/*!
+ \qmlmethod void WebEngineHistory::clear()
+ \since QtWebEngine 1.11
+
+ Clears the history.
+*/
+
void QWebEngineHistory::clear()
{
Q_D(const QWebEngineHistory);
- d->m_adapter->webContentsAdapter()->clearNavigationHistory();
- d->m_adapter->updateNavigationActions();
+ d->adapter()->clearNavigationHistory();
+ d->client->updateNavigationActions();
+ reset();
}
QList<QWebEngineHistoryItem> QWebEngineHistory::items() const
@@ -184,32 +321,32 @@ QList<QWebEngineHistoryItem> QWebEngineHistory::forwardItems(int maxItems) const
bool QWebEngineHistory::canGoBack() const
{
Q_D(const QWebEngineHistory);
- return d->m_adapter->webContentsAdapter()->canGoToOffset(-1);
+ return d->adapter()->canGoToOffset(-1);
}
bool QWebEngineHistory::canGoForward() const
{
Q_D(const QWebEngineHistory);
- return d->m_adapter->webContentsAdapter()->canGoToOffset(1);
+ return d->adapter()->canGoToOffset(1);
}
void QWebEngineHistory::back()
{
Q_D(const QWebEngineHistory);
- d->m_adapter->webContentsAdapter()->navigateToOffset(-1);
+ d->adapter()->navigateToOffset(-1);
}
void QWebEngineHistory::forward()
{
Q_D(const QWebEngineHistory);
- d->m_adapter->webContentsAdapter()->navigateToOffset(1);
+ d->adapter()->navigateToOffset(1);
}
void QWebEngineHistory::goToItem(const QWebEngineHistoryItem &item)
{
Q_D(const QWebEngineHistory);
- Q_ASSERT(item.d->m_adapter == d->m_adapter);
- d->m_adapter->webContentsAdapter()->navigateToIndex(item.d->index);
+ Q_ASSERT(item.d->client == d->client);
+ d->adapter()->navigateToIndex(item.d->index);
}
QWebEngineHistoryItem QWebEngineHistory::backItem() const
@@ -244,15 +381,50 @@ QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const
int QWebEngineHistory::currentItemIndex() const
{
Q_D(const QWebEngineHistory);
- return d->m_adapter->webContentsAdapter()->currentNavigationEntryIndex();
+ return d->adapter()->currentNavigationEntryIndex();
}
int QWebEngineHistory::count() const
{
Q_D(const QWebEngineHistory);
- if (!d->m_adapter->webContentsAdapter()->isInitialized())
+ if (!d->adapter()->isInitialized())
return 0;
- return d->m_adapter->webContentsAdapter()->navigationEntryCount();
+ return d->adapter()->navigationEntryCount();
+}
+
+QWebEngineHistoryModel *QWebEngineHistory::itemsModel() const
+{
+ Q_D(const QWebEngineHistory);
+ if (!d->navigationModel)
+ d->navigationModel.reset(new QWebEngineHistoryModel(new QWebEngineHistoryModelPrivate(d)));
+ return d->navigationModel.data();
+}
+
+QWebEngineHistoryModel *QWebEngineHistory::backItemsModel() const
+{
+ Q_D(const QWebEngineHistory);
+ if (!d->backNavigationModel)
+ d->backNavigationModel.reset(new QWebEngineHistoryModel(new QWebEngineBackHistoryModelPrivate(d)));
+ return d->backNavigationModel.data();
+}
+
+QWebEngineHistoryModel *QWebEngineHistory::forwardItemsModel() const
+{
+ Q_D(const QWebEngineHistory);
+ if (!d->forwardNavigationModel)
+ d->forwardNavigationModel.reset(new QWebEngineHistoryModel(new QWebEngineForwardHistoryModelPrivate(d)));
+ return d->forwardNavigationModel.data();
+}
+
+void QWebEngineHistory::reset()
+{
+ Q_D(QWebEngineHistory);
+ if (d->navigationModel)
+ d->navigationModel->reset();
+ if (d->backNavigationModel)
+ d->backNavigationModel->reset();
+ if (d->forwardNavigationModel)
+ d->forwardNavigationModel->reset();
}
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginehistory.h b/src/core/api/qwebenginehistory.h
index f7e591e38..f572ba011 100644
--- a/src/core/api/qwebenginehistory.h
+++ b/src/core/api/qwebenginehistory.h
@@ -41,6 +41,7 @@
#define QWEBENGINEHISTORY_H
#include <QtWebEngineCore/qtwebenginecoreglobal.h>
+#include <QtCore/QAbstractListModel>
#include <QtCore/qurl.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
@@ -50,15 +51,20 @@
QT_BEGIN_NAMESPACE
class QWebEngineHistory;
+class QWebEngineHistoryPrivate;
class QWebEngineHistoryItemPrivate;
+class QWebEngineHistoryModelPrivate;
class QWebEnginePage;
class QWebEnginePagePrivate;
+class QQuickWebEngineViewPrivate;
class Q_WEBENGINECORE_EXPORT QWebEngineHistoryItem
{
public:
QWebEngineHistoryItem(const QWebEngineHistoryItem &other);
+ QWebEngineHistoryItem(QWebEngineHistoryItem &&other);
QWebEngineHistoryItem &operator=(const QWebEngineHistoryItem &other);
+ QWebEngineHistoryItem &operator=(QWebEngineHistoryItem &&other);
~QWebEngineHistoryItem();
QUrl originalUrl() const;
@@ -80,13 +86,47 @@ private:
friend class QWebEngineHistoryPrivate;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QWebEngineHistoryItem)
+Q_DECLARE_SHARED(QWebEngineHistoryItem)
-class QWebEngineHistoryPrivate;
-class Q_WEBENGINECORE_EXPORT QWebEngineHistory
+class Q_WEBENGINECORE_EXPORT QWebEngineHistoryModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ enum Roles {
+ UrlRole = Qt::UserRole,
+ TitleRole,
+ OffsetRole,
+ IconUrlRole,
+ };
+
+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
+ QHash<int, QByteArray> roleNames() const override;
+ void reset();
+
+private:
+ QWebEngineHistoryModel(QWebEngineHistoryModelPrivate *);
+ virtual ~QWebEngineHistoryModel();
+
+ Q_DISABLE_COPY(QWebEngineHistoryModel)
+ Q_DECLARE_PRIVATE(QWebEngineHistoryModel)
+ QScopedPointer<QWebEngineHistoryModelPrivate> d_ptr;
+
+ friend class QWebEngineHistory;
+ friend class QWebEngineHistoryPrivate;
+ friend void QScopedPointerDeleter<QWebEngineHistoryModel>::cleanup(QWebEngineHistoryModel *) noexcept;
+};
+
+class Q_WEBENGINECORE_EXPORT QWebEngineHistory : public QObject
{
+ Q_OBJECT
+ Q_PROPERTY(QWebEngineHistoryModel *items READ itemsModel CONSTANT FINAL)
+ Q_PROPERTY(QWebEngineHistoryModel *backItems READ backItemsModel CONSTANT FINAL)
+ Q_PROPERTY(QWebEngineHistoryModel *forwardItems READ forwardItemsModel CONSTANT FINAL)
+
public:
- void clear();
+ Q_REVISION(1) Q_INVOKABLE void clear();
QList<QWebEngineHistoryItem> items() const;
QList<QWebEngineHistoryItem> backItems(int maxItems) const;
@@ -108,6 +148,10 @@ public:
int count() const;
+ QWebEngineHistoryModel *itemsModel() const;
+ QWebEngineHistoryModel *backItemsModel() const;
+ QWebEngineHistoryModel *forwardItemsModel() const;
+
private:
QWebEngineHistory(QWebEngineHistoryPrivate *d);
~QWebEngineHistory();
@@ -116,10 +160,14 @@ private:
Q_DECLARE_PRIVATE(QWebEngineHistory)
QScopedPointer<QWebEngineHistoryPrivate> d_ptr;
+ void reset();
+
friend Q_WEBENGINECORE_EXPORT QDataStream &operator>>(QDataStream &, QWebEngineHistory &);
friend Q_WEBENGINECORE_EXPORT QDataStream &operator<<(QDataStream &, const QWebEngineHistory &);
friend class QWebEnginePage;
friend class QWebEnginePagePrivate;
+ friend class QQuickWebEngineViewPrivate;
+ friend void QScopedPointerDeleter<QWebEngineHistory>::cleanup(QWebEngineHistory *) noexcept;
};
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginehistory_p.h b/src/core/api/qwebenginehistory_p.h
index 2ca944e5b..fb52f799c 100644
--- a/src/core/api/qwebenginehistory_p.h
+++ b/src/core/api/qwebenginehistory_p.h
@@ -51,33 +51,83 @@
// We mean it.
//
#include "qtwebenginecoreglobal_p.h"
+#include "qwebenginehistory.h"
#include <QtCore/qshareddata.h>
namespace QtWebEngineCore {
+class WebContentsAdapter;
class WebContentsAdapterClient;
}
QT_BEGIN_NAMESPACE
+
class QWebEnginePagePrivate;
class QWebEngineHistoryItemPrivate : public QSharedData
{
public:
- QWebEngineHistoryItemPrivate(QtWebEngineCore::WebContentsAdapterClient *adapter = nullptr,
- int index = 0);
- QtWebEngineCore::WebContentsAdapterClient *m_adapter;
+ QWebEngineHistoryItemPrivate(QtWebEngineCore::WebContentsAdapterClient *client = nullptr, int index = 0);
+ QtWebEngineCore::WebContentsAdapter *adapter() const;
+ QtWebEngineCore::WebContentsAdapterClient *client;
int index;
};
+class QWebEngineHistoryModelPrivate
+{
+public:
+ QWebEngineHistoryModelPrivate(const QWebEngineHistoryPrivate *history);
+ virtual ~QWebEngineHistoryModelPrivate();
+
+ virtual int count() const;
+ virtual int index(int) const;
+ virtual int offsetForIndex(int) const;
+
+ QtWebEngineCore::WebContentsAdapter *adapter() const;
+ const QWebEngineHistoryPrivate *history;
+};
+
+class QWebEngineBackHistoryModelPrivate : public QWebEngineHistoryModelPrivate
+{
+public:
+ QWebEngineBackHistoryModelPrivate(const QWebEngineHistoryPrivate *history)
+ : QWebEngineHistoryModelPrivate(history) { }
+
+ int count() const override;
+ int index(int) const override;
+ int offsetForIndex(int) const override;
+};
+
+class QWebEngineForwardHistoryModelPrivate : public QWebEngineHistoryModelPrivate
+{
+public:
+ QWebEngineForwardHistoryModelPrivate(const QWebEngineHistoryPrivate *history)
+ : QWebEngineHistoryModelPrivate(history) { }
+
+ int count() const override;
+ int index(int) const override;
+ int offsetForIndex(int) const override;
+};
+
class Q_WEBENGINECORE_PRIVATE_EXPORT QWebEngineHistoryPrivate
{
public:
- QWebEngineHistoryPrivate(QtWebEngineCore::WebContentsAdapterClient *adapter);
+ typedef std::function<QUrl (const QUrl &)> ImageProviderUrl;
+ QWebEngineHistoryPrivate(QtWebEngineCore::WebContentsAdapterClient *client,
+ const ImageProviderUrl &imageProviderUrl = ImageProviderUrl());
~QWebEngineHistoryPrivate();
+
void updateItems() const;
+ QtWebEngineCore::WebContentsAdapter *adapter() const;
+
+ QtWebEngineCore::WebContentsAdapterClient *client;
+
+ ImageProviderUrl imageProviderUrl;
+ QUrl urlOrImageProviderUrl(const QUrl &url) const { return imageProviderUrl ? imageProviderUrl(url) : url; }
- QtWebEngineCore::WebContentsAdapterClient *m_adapter;
mutable QList<QWebEngineHistoryItem> items;
+ mutable QScopedPointer<QWebEngineHistoryModel> navigationModel;
+ mutable QScopedPointer<QWebEngineHistoryModel> backNavigationModel;
+ mutable QScopedPointer<QWebEngineHistoryModel> forwardNavigationModel;
};
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp
index 64b4f4d99..460b5a351 100644
--- a/src/core/api/qwebenginepage.cpp
+++ b/src/core/api/qwebenginepage.cpp
@@ -2389,8 +2389,7 @@ QWebEnginePage* QWebEnginePage::fromDownloadRequest(QWebEngineDownloadRequest *r
QDataStream &operator<<(QDataStream &stream, const QWebEngineHistory &history)
{
- QtWebEngineCore::WebContentsAdapter *adapter =
- history.d_func()->m_adapter->webContentsAdapter();
+ auto adapter = history.d_func()->adapter();
if (!adapter->isInitialized())
adapter->loadDefault();
adapter->serializeNavigationHistory(stream);
@@ -2399,8 +2398,7 @@ QDataStream &operator<<(QDataStream &stream, const QWebEngineHistory &history)
QDataStream &operator>>(QDataStream &stream, QWebEngineHistory &history)
{
- static_cast<QWebEnginePagePrivate *>(history.d_func()->m_adapter)
- ->recreateFromSerializedHistory(stream);
+ static_cast<QWebEnginePagePrivate *>(history.d_func()->client)->recreateFromSerializedHistory(stream);
return stream;
}
diff --git a/src/webenginewidgets/doc/src/qwebenginehistory_lgpl.qdoc b/src/core/doc/src/qwebenginehistory_lgpl.qdoc
index 5e3ebecb1..c2c9d69c6 100644
--- a/src/webenginewidgets/doc/src/qwebenginehistory_lgpl.qdoc
+++ b/src/core/doc/src/qwebenginehistory_lgpl.qdoc
@@ -26,7 +26,7 @@
\class QWebEngineHistoryItem
\brief The QWebEngineHistoryItem class represents one item in the history of a web engine page.
\since 5.4
- \inmodule QtWebEngineWidgets
+ \inmodule QtWebEngineCore
Each web engine history item represents an entry in the history stack of a web page,
containing information about the page, its location, and the time when it was last visited.
@@ -87,10 +87,40 @@
*/
/*!
+ \class QWebEngineHistoryModel
+ \inqmlmodule QtWebEngineCore
+ \since 6.2
+
+ \brief A data model that represents the history of a web engine page.
+
+ The QWebEngineHistoryModel type exposes the \e title, \e url, \e icon, and \e offset roles.
+ The \e title, \e url and \e icon specify the title, URL, and favicon of the visited page.
+ The \e offset specifies the position of the page in respect to the current page (0).
+ A positive number indicates that the page was visited after the current page, whereas a
+ negative number indicates that the page was visited before the current page.
+
+ This type is uncreatable, but it can be accessed by using the QWebEngineHistory::itemsModel,
+ QWebEngineHistory::backItemsModel, QWebEngineHistory::forwardItemsModel methods.
+
+ \sa QWebEngineHistory
+*/
+
+/*!
+ \enum QWebEngineHistoryModel::Roles
+
+ This enum describes specific roles, which history data model supports.
+
+ \value UrlRole URL of the visited page
+ \value TitleRole Title of the visited page
+ \value OffsetRole The offset of the page in respect to the current page (0)
+ \value IconUrlRole Favicon of the visited page
+*/
+
+/*!
\class QWebEngineHistory
\brief The QWebEngineHistory class represents the history of a web engine page.
\since 5.4
- \inmodule QtWebEngineWidgets
+ \inmodule QtWebEngineCore
Each web engine page contains a history of visited pages that can be accessed
by QWebEnginePage::history().
@@ -106,6 +136,16 @@
pages ahead of the current page can be obtained with the forwardItems() function.
The total list of items is obtained with the items() function.
+ Also, the following QWebEngineHistoryModel data model objects are provided:
+
+ \list
+ \li \c backItemsModel(), which contains the URLs of visited pages.
+ \li \c forwardItemsModel(), which contains the URLs of the pages that were visited after visiting
+ the current page.
+ \li \c itemsModel(), which contains the URLs of the back and forward items, as well as the URL of
+ the current page.
+ \endlist
+
Just as with containers, functions are available to examine the history in terms
of a list. Arbitrary items in the history can be obtained with itemAt(), the total
number of items is given by count(), and the history can be cleared with the
@@ -148,6 +188,23 @@
*/
/*!
+ \fn QWebEngineHistoryModel *QWebEngineHistory::itemsModel
+ Returns the data model, which represents URLs of back items, forward items,
+ and the current item in the history.
+*/
+
+/*!
+ \fn QWebEngineHistoryModel *QWebEngineHistory::backItemsModel
+ Return the data model, which represents URLs of visited pages.
+*/
+
+/*!
+ \fn QWebEngineHistoryModel *QWebEngineHistory::forwardItemsModel
+ Return the data model, which represents URLs of the pages
+ that were visited after visiting the current page.
+*/
+
+/*!
\fn bool QWebEngineHistory::canGoBack() const
Returns \c true if there is an item preceding the current item in the history;
otherwise returns \c false.
diff --git a/src/webenginequick/CMakeLists.txt b/src/webenginequick/CMakeLists.txt
index f133c0a42..9434d6908 100644
--- a/src/webenginequick/CMakeLists.txt
+++ b/src/webenginequick/CMakeLists.txt
@@ -13,7 +13,6 @@ qt_internal_add_module(WebEngineQuick
api/qquickwebenginedialogrequests.cpp api/qquickwebenginedialogrequests_p.h
api/qquickwebenginefaviconprovider.cpp
api/qquickwebenginefaviconprovider_p_p.h
- api/qquickwebenginehistory.cpp api/qquickwebenginehistory_p.h
api/qquickwebengineprofile.cpp api/qquickwebengineprofile.h api/qquickwebengineprofile_p.h
api/qquickwebenginescriptcollection.cpp api/qquickwebenginescriptcollection.h
api/qquickwebenginesettings.cpp api/qquickwebenginesettings_p.h
diff --git a/src/webenginequick/api/qquickwebenginehistory.cpp b/src/webenginequick/api/qquickwebenginehistory.cpp
deleted file mode 100644
index 50feb067c..000000000
--- a/src/webenginequick/api/qquickwebenginehistory.cpp
+++ /dev/null
@@ -1,355 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qquickwebenginehistory_p.h"
-#include "qquickwebenginehistory_p_p.h"
-
-#include "qquickwebenginefaviconprovider_p_p.h"
-#include "qquickwebengineview_p_p.h"
-#include "web_contents_adapter.h"
-
-QT_BEGIN_NAMESPACE
-
-QQuickWebEngineHistoryListModelPrivate::QQuickWebEngineHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
- : view(view)
-{
-}
-
-QQuickWebEngineHistoryListModelPrivate::~QQuickWebEngineHistoryListModelPrivate()
-{
-}
-
-int QQuickWebEngineHistoryListModelPrivate::count() const
-{
- return adapter()->navigationEntryCount();
-}
-
-int QQuickWebEngineHistoryListModelPrivate::index(int index) const
-{
- return index;
-}
-
-int QQuickWebEngineHistoryListModelPrivate::offsetForIndex(int index) const
-{
- return index - adapter()->currentNavigationEntryIndex();
-}
-
-QtWebEngineCore::WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const
-{
- return view->adapter.data();
-}
-
-QQuickWebEngineBackHistoryListModelPrivate::QQuickWebEngineBackHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
- : QQuickWebEngineHistoryListModelPrivate(view)
-{
-}
-
-int QQuickWebEngineBackHistoryListModelPrivate::count() const
-{
- return adapter()->currentNavigationEntryIndex();
-}
-
-int QQuickWebEngineBackHistoryListModelPrivate::index(int i) const
-{
- Q_ASSERT(i >= 0 && i < count());
- return count() - 1 - i;
-}
-
-int QQuickWebEngineBackHistoryListModelPrivate::offsetForIndex(int index) const
-{
- return - index - 1;
-}
-
-QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
- : QQuickWebEngineHistoryListModelPrivate(view)
-{
-}
-
-int QQuickWebEngineForwardHistoryListModelPrivate::count() const
-{
- if (!adapter()->isInitialized())
- return 0;
- return adapter()->navigationEntryCount() - adapter()->currentNavigationEntryIndex() - 1;
-}
-
-int QQuickWebEngineForwardHistoryListModelPrivate::index(int i) const
-{
- return adapter()->currentNavigationEntryIndex() + i + 1;
-}
-
-int QQuickWebEngineForwardHistoryListModelPrivate::offsetForIndex(int index) const
-{
- return index + 1;
-}
-
-/*!
- \qmltype WebEngineHistoryListModel
- \instantiates QQuickWebEngineHistoryListModel
- \inqmlmodule QtWebEngine
- \since QtWebEngine 1.1
-
- \brief A data model that represents the history of a web engine page.
-
- The WebEngineHistoryListModel type exposes the \e title, \e url, \e icon, and \e offset roles.
- The \e title, \e url and \e icon specify the title, URL, and favicon of the visited page.
- The \e offset specifies
- the position of the page in respect to the current page (0). A positive number indicates that
- the page was visited after the current page, whereas a negative number indicates that the page
- was visited before the current page.
-
- This type is uncreatable, but it can be accessed by using the
- \l{WebEngineView::navigationHistory}{WebEngineView.navigationHistory} property.
-
- \sa WebEngineHistory
-*/
-
-QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel()
- : QAbstractListModel()
-{
-}
-
-QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel(QQuickWebEngineHistoryListModelPrivate *d)
- : QAbstractListModel()
- , d_ptr(d)
-{
-}
-
-QQuickWebEngineHistoryListModel::~QQuickWebEngineHistoryListModel()
-{
-}
-
-QHash<int, QByteArray> QQuickWebEngineHistoryListModel::roleNames() const
-{
- QHash<int, QByteArray> roles;
- roles[QQuickWebEngineHistory::UrlRole] = "url";
- roles[QQuickWebEngineHistory::TitleRole] = "title";
- roles[QQuickWebEngineHistory::OffsetRole] = "offset";
- roles[QQuickWebEngineHistory::IconUrlRole] = "icon";
- return roles;
-}
-
-int QQuickWebEngineHistoryListModel::rowCount(const QModelIndex &index) const
-{
- Q_UNUSED(index);
- Q_D(const QQuickWebEngineHistoryListModel);
- return d->count();
-}
-
-QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int role) const
-{
- Q_D(const QQuickWebEngineHistoryListModel);
-
- if (!index.isValid())
- return QVariant();
-
- if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::IconUrlRole)
- return QVariant();
-
- if (role == QQuickWebEngineHistory::UrlRole)
- return QUrl(d->adapter()->getNavigationEntryUrl(d->index(index.row())));
-
- if (role == QQuickWebEngineHistory::TitleRole)
- return QString(d->adapter()->getNavigationEntryTitle(d->index(index.row())));
-
- if (role == QQuickWebEngineHistory::OffsetRole)
- return d->offsetForIndex(index.row());
-
- if (role == QQuickWebEngineHistory::IconUrlRole) {
- QUrl iconUrl = QUrl(d->adapter()->getNavigationEntryIconUrl(d->index(index.row())));
- return QQuickWebEngineFaviconProvider::faviconProviderUrl(iconUrl);
- }
-
- return QVariant();
-}
-
-void QQuickWebEngineHistoryListModel::reset()
-{
- beginResetModel();
- endResetModel();
-}
-
-QQuickWebEngineHistoryPrivate::QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate *view)
- : m_view(view)
-{
-}
-
-QQuickWebEngineHistoryPrivate::~QQuickWebEngineHistoryPrivate()
-{
-}
-
-/*!
- \qmltype WebEngineHistory
- \instantiates QQuickWebEngineHistory
- \inqmlmodule QtWebEngine
- \since QtWebEngine 1.1
-
- \brief Provides data models that represent the history of a web engine page.
-
- The WebEngineHistory type can be accessed by using the
- \l{WebEngineView::navigationHistory}{WebEngineView.navigationHistory} property.
-
- The WebEngineHistory type provides the following WebEngineHistoryListModel data model objects:
-
- \list
- \li \c backItems, which contains the URLs of visited pages.
- \li \c forwardItems, which contains the URLs of the pages that were visited after visiting
- the current page.
- \li \c items, which contains the URLs of the back and forward items, as well as the URL of
- the current page.
- \endlist
-
- The easiest way to use these models is to use them in a ListView as illustrated by the
- following code snippet:
-
- \code
- ListView {
- id: historyItemsList
- anchors.fill: parent
- model: webEngineView.navigationHistory.items
- delegate:
- Text {
- color: "black"
- text: model.title + " - " + model.url + " (" + model.offset + ")"
- }
- }
- \endcode
-
- The ListView shows the content of the corresponding model. The delegate is responsible for the
- format of the list items. The appearance of each item of the list in the delegate can be defined
- separately (it is not web engine specific).
-
- The model roles \e title, \e url, and \e icon specify the title, URL, and favicon of the
- visited page. The \e offset
- role specifies the position of the page in respect to the current page (0). A positive number
- indicates that the page was visited after the current page, whereas a negative number indicates
- that the page was visited before the current page.
-
- The data models can also be used to create a menu, as illustrated by the following code
- snippet:
-
- \quotefromfile webengine/quicknanobrowser/BrowserWindow.qml
- \skipto ToolBar
- \printuntil onObjectRemoved
- \printuntil }
- \printuntil }
- \printuntil }
-
- For the complete example, see \l{WebEngine Quick Nano Browser}.
-
- \sa WebEngineHistoryListModel
-*/
-
-QQuickWebEngineHistory::QQuickWebEngineHistory(QQuickWebEngineViewPrivate *view)
- : d_ptr(new QQuickWebEngineHistoryPrivate(view))
-{
-}
-
-QQuickWebEngineHistory::~QQuickWebEngineHistory()
-{
-}
-
-/*!
- \qmlproperty WebEngineHistoryListModel WebEngineHistory::items
- \readonly
-
- URLs of back items, forward items, and the current item in the history.
-*/
-QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::items() const
-{
- Q_D(const QQuickWebEngineHistory);
- if (!d->m_navigationModel)
- d->m_navigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineHistoryListModelPrivate(d->m_view)));
- return d->m_navigationModel.data();
-}
-
-/*!
- \qmlproperty WebEngineHistoryListModel WebEngineHistory::backItems
- \readonly
-
- URLs of visited pages.
-*/
-QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::backItems() const
-{
- Q_D(const QQuickWebEngineHistory);
- if (!d->m_backNavigationModel)
- d->m_backNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(d->m_view)));
- return d->m_backNavigationModel.data();
-}
-
-/*!
- \qmlproperty WebEngineHistoryListModel WebEngineHistory::forwardItems
- \readonly
-
- URLs of the pages that were visited after visiting the current page.
-*/
-QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::forwardItems() const
-{
- Q_D(const QQuickWebEngineHistory);
- if (!d->m_forwardNavigationModel)
- d->m_forwardNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(d->m_view)));
- return d->m_forwardNavigationModel.data();
-}
-
-/*!
- \qmlmethod void WebEngineHistory::clear()
- \since QtWebEngine 1.11
-
- Clears the history.
-*/
-void QQuickWebEngineHistory::clear()
-{
- Q_D(QQuickWebEngineHistory);
- d->m_view->adapter->clearNavigationHistory();
- d->m_view->updateNavigationActions();
- reset();
-}
-
-void QQuickWebEngineHistory::reset()
-{
- Q_D(QQuickWebEngineHistory);
- if (d->m_navigationModel)
- d->m_navigationModel->reset();
- if (d->m_backNavigationModel)
- d->m_backNavigationModel->reset();
- if (d->m_forwardNavigationModel)
- d->m_forwardNavigationModel->reset();
-}
-
-
-QT_END_NAMESPACE
diff --git a/src/webenginequick/api/qquickwebenginehistory_p.h b/src/webenginequick/api/qquickwebenginehistory_p.h
deleted file mode 100644
index 8433e8dd5..000000000
--- a/src/webenginequick/api/qquickwebenginehistory_p.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKWEBENGINEHISTORY_P_H
-#define QQUICKWEBENGINEHISTORY_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 <QtWebEngineQuick/qtwebengineglobal.h>
-#include <QAbstractListModel>
-#include <QtCore/qshareddata.h>
-#include <QQuickItem>
-#include <QUrl>
-#include <QVariant>
-
-QT_BEGIN_NAMESPACE
-
-class QQuickWebEngineHistory;
-class QQuickWebEngineHistoryPrivate;
-class QQuickWebEngineHistoryListModelPrivate;
-class QQuickWebEngineViewPrivate;
-
-class Q_WEBENGINE_EXPORT QQuickWebEngineHistoryListModel : public QAbstractListModel {
- Q_OBJECT
-
-public:
- QQuickWebEngineHistoryListModel(QQuickWebEngineHistoryListModelPrivate*);
- virtual ~QQuickWebEngineHistoryListModel();
-
- int rowCount(const QModelIndex& parent = QModelIndex()) const override;
- QVariant data(const QModelIndex& index, int role) const override;
- QHash<int, QByteArray> roleNames() const override;
- void reset();
-
-private:
- QQuickWebEngineHistoryListModel();
-
- Q_DECLARE_PRIVATE(QQuickWebEngineHistoryListModel)
- QScopedPointer<QQuickWebEngineHistoryListModelPrivate> d_ptr;
-
- friend class QQuickWebEngineHistory;
-};
-
-class Q_WEBENGINE_EXPORT QQuickWebEngineHistory : public QQuickItem {
- Q_OBJECT
- Q_PROPERTY(QQuickWebEngineHistoryListModel *items READ items CONSTANT FINAL)
- Q_PROPERTY(QQuickWebEngineHistoryListModel *backItems READ backItems CONSTANT FINAL)
- Q_PROPERTY(QQuickWebEngineHistoryListModel *forwardItems READ forwardItems CONSTANT FINAL)
-
-public:
- QQuickWebEngineHistory(QQuickWebEngineViewPrivate*);
- virtual ~QQuickWebEngineHistory();
-
- enum NavigationHistoryRoles {
- UrlRole = Qt::UserRole + 1,
- TitleRole = Qt::UserRole + 2,
- OffsetRole = Qt::UserRole + 3,
- IconUrlRole = Qt::UserRole + 4,
- };
-
- QQuickWebEngineHistoryListModel *items() const;
- QQuickWebEngineHistoryListModel *backItems() const;
- QQuickWebEngineHistoryListModel *forwardItems() const;
- Q_REVISION(1,1) Q_INVOKABLE void clear();
-
- void reset();
-
-private:
- QQuickWebEngineHistory();
-
- Q_DECLARE_PRIVATE(QQuickWebEngineHistory)
- QScopedPointer<QQuickWebEngineHistoryPrivate> d_ptr;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QQuickWebEngineHistory)
-
-#endif // QQUICKWEBENGINEHISTORY_P_H
diff --git a/src/webenginequick/api/qquickwebenginehistory_p_p.h b/src/webenginequick/api/qquickwebenginehistory_p_p.h
deleted file mode 100644
index 019c6f0ad..000000000
--- a/src/webenginequick/api/qquickwebenginehistory_p_p.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKWEBENGINEHISTORY_P_P_H
-#define QQUICKWEBENGINEHISTORY_P_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.
-//
-
-namespace QtWebEngineCore {
-class WebContentsAdapter;
-}
-
-QT_BEGIN_NAMESPACE
-class QQuickWebEngineHistoryListModel;
-class QQuickWebEngineViewPrivate;
-
-class QQuickWebEngineHistoryListModelPrivate {
-public:
- QQuickWebEngineHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
- virtual ~QQuickWebEngineHistoryListModelPrivate();
-
- virtual int count() const;
- virtual int index(int) const;
- virtual int offsetForIndex(int) const;
-
- QtWebEngineCore::WebContentsAdapter *adapter() const;
-
- QQuickWebEngineViewPrivate *view;
-};
-
-class QQuickWebEngineBackHistoryListModelPrivate : public QQuickWebEngineHistoryListModelPrivate {
-public:
- QQuickWebEngineBackHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
-
- int count() const override;
- int index(int) const override;
- int offsetForIndex(int) const override;
-};
-
-class QQuickWebEngineForwardHistoryListModelPrivate : public QQuickWebEngineHistoryListModelPrivate {
-public:
- QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate*);
-
- int count() const override;
- int index(int) const override;
- int offsetForIndex(int) const override;
-};
-
-class QQuickWebEngineHistoryPrivate {
-public:
- QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate*);
- ~QQuickWebEngineHistoryPrivate();
-
- QQuickWebEngineViewPrivate *m_view;
- mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_navigationModel;
- mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_backNavigationModel;
- mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_forwardNavigationModel;
-};
-
-QT_END_NAMESPACE
-
-#endif // QQUICKWEBENGINEHISTORY_P_P_H
diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp
index 2e6a2f428..1d65ad3ac 100644
--- a/src/webenginequick/api/qquickwebengineview.cpp
+++ b/src/webenginequick/api/qquickwebengineview.cpp
@@ -48,7 +48,6 @@
#include "qquickwebengineaction_p.h"
#include "qquickwebengineaction_p_p.h"
-#include "qquickwebenginehistory_p.h"
#include "qquickwebengineclientcertificateselection_p.h"
#include "qquickwebenginedialogrequests_p.h"
#include "qquickwebenginefaviconprovider_p_p.h"
@@ -63,6 +62,7 @@
#include "qwebenginenewwindowrequest.h"
#include "qwebenginequotarequest.h"
#include "qwebenginescriptcollection.h"
+#include <QtWebEngineCore/private/qwebenginehistory_p.h>
#include <QtWebEngineCore/private/qwebenginescriptcollection_p.h>
#include "qwebengineregisterprotocolhandlerrequest.h"
#if QT_CONFIG(webenginequick_testsupport)
@@ -127,7 +127,9 @@ static QLatin1String defaultMimeType("text/html;charset=UTF-8");
QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
: m_profile(nullptr)
, adapter(QSharedPointer<WebContentsAdapter>::create())
- , m_history(new QQuickWebEngineHistory(this))
+ , m_history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this, [] (const QUrl &url) {
+ return QQuickWebEngineFaviconProvider::faviconProviderUrl(url);
+ })))
#if QT_CONFIG(webenginequick_testsupport)
, m_testSupport(0)
#endif
@@ -1521,7 +1523,7 @@ void QQuickWebEngineView::findText(const QString &subString, FindFlags options,
d->adapter->findTextHelper()->startFinding(subString, options & FindCaseSensitively, options & FindBackward, callback);
}
-QQuickWebEngineHistory *QQuickWebEngineView::navigationHistory() const
+QWebEngineHistory *QQuickWebEngineView::navigationHistory() const
{
Q_D(const QQuickWebEngineView);
return d->m_history.data();
diff --git a/src/webenginequick/api/qquickwebengineview_p.h b/src/webenginequick/api/qquickwebengineview_p.h
index 5b8231cbf..74fe13c25 100644
--- a/src/webenginequick/api/qquickwebengineview_p.h
+++ b/src/webenginequick/api/qquickwebengineview_p.h
@@ -71,7 +71,6 @@ class QQuickWebEngineAuthenticationDialogRequest;
class QQuickWebEngineClientCertificateSelection;
class QQuickWebEngineColorDialogRequest;
class QQuickWebEngineFileDialogRequest;
-class QQuickWebEngineHistory;
class QQuickWebEngineJavaScriptDialogRequest;
class QQuickWebEngineSettings;
class QQuickWebEngineTooltipRequest;
@@ -81,6 +80,7 @@ class QWebEngineCertificateError;
class QWebEngineContextMenuRequest;
class QWebEngineFindTextResult;
class QWebEngineFullScreenRequest;
+class QWebEngineHistory;
class QWebEngineLoadRequest;
class QWebEngineNavigationRequest;
class QWebEngineNewWindowRequest;
@@ -106,7 +106,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged REVISION(1,1) FINAL)
Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile NOTIFY profileChanged FINAL REVISION(1,1))
Q_PROPERTY(QQuickWebEngineSettings *settings READ settings REVISION(1,1) CONSTANT FINAL)
- Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL REVISION(1,1))
+ Q_PROPERTY(QWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL REVISION(1,1))
#if QT_CONFIG(webengine_webchannel)
Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel NOTIFY webChannelChanged REVISION(1,1) FINAL)
#endif
@@ -443,7 +443,7 @@ public:
QQuickWebEngineSettings *settings();
QQmlWebChannel *webChannel();
void setWebChannel(QQmlWebChannel *);
- QQuickWebEngineHistory *navigationHistory() const;
+ QWebEngineHistory *navigationHistory() const;
uint webChannelWorld() const;
void setWebChannelWorld(uint);
Q_REVISION(1,8) Q_INVOKABLE QQuickWebEngineAction *action(WebAction action);
diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h
index 1b50de26a..f8bcadeb6 100644
--- a/src/webenginequick/api/qquickwebengineview_p_p.h
+++ b/src/webenginequick/api/qquickwebengineview_p_p.h
@@ -82,6 +82,7 @@ class QQuickWebEngineFaviconProvider;
class QQuickWebEngineProfilePrivate;
class QQuickWebEngineTouchHandleProvider;
class QWebEngineFindTextResult;
+class QWebEngineHistory;
#if QT_CONFIG(webenginequick_testsupport)
class QQuickWebEngineTestSupport;
@@ -187,7 +188,7 @@ public:
QQuickWebEngineProfile *m_profile;
QSharedPointer<QtWebEngineCore::WebContentsAdapter> adapter;
- QScopedPointer<QQuickWebEngineHistory> m_history;
+ QScopedPointer<QWebEngineHistory> m_history;
QScopedPointer<QQuickWebEngineSettings> m_settings;
#if QT_CONFIG(webenginequick_testsupport)
QQuickWebEngineTestSupport *m_testSupport;
diff --git a/src/webenginequick/doc/src/navigation_history.qdoc b/src/webenginequick/doc/src/navigation_history.qdoc
new file mode 100644
index 000000000..cdee9ffa0
--- /dev/null
+++ b/src/webenginequick/doc/src/navigation_history.qdoc
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \qmltype WebEngineHistoryModel
+ \instantiates QWebEngineHistoryModel
+ \inqmlmodule QtWebEngine
+ \since QtWebEngine 1.1
+
+ \brief A data model that represents the history of a web engine page.
+
+ The WebEngineHistoryModel type exposes the \e title, \e url, \e icon, and \e offset roles.
+ The \e title, \e url and \e icon specify the title, URL, and favicon of the visited page.
+ The \e offset specifies
+ the position of the page in respect to the current page (0). A positive number indicates that
+ the page was visited after the current page, whereas a negative number indicates that the page
+ was visited before the current page.
+
+ This type is uncreatable, but it can be accessed by using the
+ \l{WebEngineView::navigationHistory}{WebEngineView.navigationHistory} property.
+
+ \sa WebEngineHistory
+*/
+
+/*!
+ \qmltype WebEngineHistory
+ \instantiates QWebEngineHistory
+ \inqmlmodule QtWebEngine
+ \since QtWebEngine 1.1
+
+ \brief Provides data models that represent the history of a web engine page.
+
+ The WebEngineHistory type can be accessed by using the
+ \l{WebEngineView::navigationHistory}{WebEngineView.navigationHistory} property.
+
+ The WebEngineHistory type provides the following WebEngineHistoryModel data model objects:
+
+ \list
+ \li \c backItems, which contains the URLs of visited pages.
+ \li \c forwardItems, which contains the URLs of the pages that were visited after visiting
+ the current page.
+ \li \c items, which contains the URLs of the back and forward items, as well as the URL of
+ the current page.
+ \endlist
+
+ The easiest way to use these models is to use them in a ListView as illustrated by the
+ following code snippet:
+
+ \code
+ ListView {
+ id: historyItemsList
+ anchors.fill: parent
+ model: webEngineView.navigationHistory.items
+ delegate:
+ Text {
+ color: "black"
+ text: model.title + " - " + model.url + " (" + model.offset + ")"
+ }
+ }
+ \endcode
+
+ The ListView shows the content of the corresponding model. The delegate is responsible for the
+ format of the list items. The appearance of each item of the list in the delegate can be defined
+ separately (it is not web engine specific).
+
+ The model roles \e title, \e url, and \e icon specify the title, URL, and favicon of the
+ visited page. The \e offset
+ role specifies the position of the page in respect to the current page (0). A positive number
+ indicates that the page was visited after the current page, whereas a negative number indicates
+ that the page was visited before the current page.
+
+ The data models can also be used to create a menu, as illustrated by the following code
+ snippet:
+
+ \quotefromfile webengine/quicknanobrowser/BrowserWindow.qml
+ \skipto ToolBar
+ \printuntil onObjectRemoved
+ \printuntil }
+ \printuntil }
+ \printuntil }
+
+ For the complete example, see \l{WebEngine Quick Nano Browser}.
+
+ \sa WebEngineHistoryModel
+*/
+
+/*!
+ \qmlproperty WebEngineHistoryModel WebEngineHistory::items
+ \readonly
+
+ URLs of back items, forward items, and the current item in the history.
+*/
+
+/*!
+ \qmlproperty WebEngineHistoryModel WebEngineHistory::backItems
+ \readonly
+
+ URLs of visited pages.
+*/
+
+/*!
+ \qmlproperty WebEngineHistoryModel WebEngineHistory::forwardItems
+ \readonly
+
+ URLs of the pages that were visited after visiting the current page.
+*/
+
+/*!
+ \qmlmethod void WebEngineHistory::clear()
+ \since QtWebEngine 1.11
+
+ Clears the history.
+*/
diff --git a/src/webenginequick/plugin/plugin.cpp b/src/webenginequick/plugin/plugin.cpp
index 7865f9863..c044a08be 100644
--- a/src/webenginequick/plugin/plugin.cpp
+++ b/src/webenginequick/plugin/plugin.cpp
@@ -42,7 +42,6 @@
#include <QtWebEngineQuick/private/qquickwebengineclientcertificateselection_p.h>
#include <QtWebEngineQuick/private/qquickwebenginedialogrequests_p.h>
-#include <QtWebEngineQuick/private/qquickwebenginehistory_p.h>
#include <QtWebEngineQuick/private/qquickwebenginefaviconprovider_p_p.h>
#include <QtWebEngineQuick/private/qquickwebenginesettings_p.h>
#include <QtWebEngineQuick/private/qquickwebenginesingleton_p.h>
@@ -52,6 +51,7 @@
#include <QtWebEngineCore/qwebenginecertificateerror.h>
#include <QtWebEngineCore/qwebenginefindtextresult.h>
#include <QtWebEngineCore/qwebenginefullscreenrequest.h>
+#include <QtWebEngineCore/qwebenginehistory.h>
#include <QtWebEngineCore/qwebengineloadrequest.h>
#include <QtWebEngineCore/qwebenginenavigationrequest.h>
#include <QtWebEngineCore/qwebenginenewwindowrequest.h>
@@ -124,11 +124,9 @@ public:
qmlRegisterUncreatableType<QQuickWebEngineSettings, 7>(uri, 1, 8, "WebEngineSettings", msgUncreatableType("WebEngineSettings"));
qmlRegisterUncreatableType<QQuickWebEngineSettings, 8>(uri, 1, 9, "WebEngineSettings", msgUncreatableType("WebEngineSettings"));
qmlRegisterSingletonType<QQuickWebEngineSingleton>(uri, 1, 1, "WebEngine", webEngineSingletonProvider);
- qmlRegisterUncreatableType<QQuickWebEngineHistory>(uri, 1, 1, "NavigationHistory",
- msgUncreatableType("NavigationHistory"));
- qmlRegisterUncreatableType<QQuickWebEngineHistory, 1>(uri, 1, 11, "NavigationHistory", msgUncreatableType("NavigationHistory"));
- qmlRegisterUncreatableType<QQuickWebEngineHistoryListModel>(uri, 1, 1, "NavigationHistoryListModel",
- msgUncreatableType("NavigationHistory"));
+ qmlRegisterUncreatableType<QWebEngineHistory>(uri, 1, 1, "WebEngineHistory", msgUncreatableType("WebEngineHistory"));
+ qmlRegisterUncreatableType<QWebEngineHistory, 1>(uri, 1, 11, "WebEngineHistory", msgUncreatableType("WebEngineHistory"));
+ qmlRegisterUncreatableType<QWebEngineHistoryModel>(uri, 1, 1, "WebEngineHistoryModel", msgUncreatableType("WebEngineHistoryModel"));
qmlRegisterUncreatableType<QWebEngineFullScreenRequest>(uri, 1, 1, "FullScreenRequest",
msgUncreatableType("FullScreenRequest"));
diff --git a/src/webenginequick/plugin/plugins.qmltypes b/src/webenginequick/plugin/plugins.qmltypes
index 6c96e2678..7e0652c09 100644
--- a/src/webenginequick/plugin/plugins.qmltypes
+++ b/src/webenginequick/plugin/plugins.qmltypes
@@ -641,7 +641,7 @@ Module {
Method { name: "reject" }
}
Component {
- name: "QQuickWebEngineHistory"
+ name: "QWebEngineHistory"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["QtWebEngine/NavigationHistory 1.1"]
@@ -649,27 +649,27 @@ Module {
exportMetaObjectRevisions: [0]
Property {
name: "items"
- type: "QQuickWebEngineHistoryListModel"
+ type: "QWebEngineHistoryModel"
isReadonly: true
isPointer: true
}
Property {
name: "backItems"
- type: "QQuickWebEngineHistoryListModel"
+ type: "QWebEngineHistoryModel"
isReadonly: true
isPointer: true
}
Property {
name: "forwardItems"
- type: "QQuickWebEngineHistoryListModel"
+ type: "QWebEngineHistoryModel"
isReadonly: true
isPointer: true
}
}
Component {
- name: "QQuickWebEngineHistoryListModel"
+ name: "QWebEngineHistoryModel"
prototype: "QAbstractListModel"
- exports: ["QtWebEngine/NavigationHistoryListModel 1.1"]
+ exports: ["QtWebEngine/NavigationHistoryModel 1.1"]
isCreatable: false
exportMetaObjectRevisions: [0]
}
@@ -1324,7 +1324,7 @@ Module {
Property {
name: "navigationHistory"
revision: 1
- type: "QQuickWebEngineHistory"
+ type: "QWebEngineHistory"
isReadonly: true
isPointer: true
}
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index a125d84f3..4ea079b63 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -37,6 +37,7 @@
#include <QtWebEngineCore/QWebEngineCertificateError>
#include <QtWebEngineCore/QWebEngineFindTextResult>
#include <QtWebEngineCore/QWebEngineFullScreenRequest>
+#include <QtWebEngineCore/QWebEngineHistory>
#include <QtWebEngineCore/QWebEngineNavigationRequest>
#include <QtWebEngineCore/QWebEngineNewWindowRequest>
#include <QtWebEngineCore/QWebEngineNotification>
@@ -50,7 +51,6 @@
#include <private/qquickwebengineaction_p.h>
#include <private/qquickwebengineclientcertificateselection_p.h>
#include <private/qquickwebenginedialogrequests_p.h>
-#include <private/qquickwebenginehistory_p.h>
#include <private/qquickwebenginesettings_p.h>
#include <private/qquickwebenginesingleton_p.h>
@@ -66,8 +66,8 @@ static const QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *
<< &QQuickWebEngineClientCertificateOption::staticMetaObject
<< &QQuickWebEngineClientCertificateSelection::staticMetaObject
<< &QWebEngineDownloadRequest::staticMetaObject
- << &QQuickWebEngineHistory::staticMetaObject
- << &QQuickWebEngineHistoryListModel::staticMetaObject
+ << &QWebEngineHistory::staticMetaObject
+ << &QWebEngineHistoryModel::staticMetaObject
<< &QQuickWebEngineProfile::staticMetaObject
<< &QQuickWebEngineSettings::staticMetaObject
<< &QWebEngineFullScreenRequest::staticMetaObject
@@ -294,10 +294,10 @@ static const QStringList expectedAPI = QStringList()
<< "QWebEngineFullScreenRequest.origin --> QUrl"
<< "QWebEngineFullScreenRequest.reject() --> void"
<< "QWebEngineFullScreenRequest.toggleOn --> bool"
- << "QQuickWebEngineHistory.backItems --> QQuickWebEngineHistoryListModel*"
- << "QQuickWebEngineHistory.clear() --> void"
- << "QQuickWebEngineHistory.forwardItems --> QQuickWebEngineHistoryListModel*"
- << "QQuickWebEngineHistory.items --> QQuickWebEngineHistoryListModel*"
+ << "QWebEngineHistory.backItems --> QWebEngineHistoryModel*"
+ << "QWebEngineHistory.clear() --> void"
+ << "QWebEngineHistory.forwardItems --> QWebEngineHistoryModel*"
+ << "QWebEngineHistory.items --> QWebEngineHistoryModel*"
<< "QQuickWebEngineJavaScriptDialogRequest.DialogTypeAlert --> DialogType"
<< "QQuickWebEngineJavaScriptDialogRequest.DialogTypeBeforeUnload --> DialogType"
<< "QQuickWebEngineJavaScriptDialogRequest.DialogTypeConfirm --> DialogType"
@@ -721,7 +721,7 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.loadProgressChanged() --> void"
<< "QQuickWebEngineView.loading --> bool"
<< "QQuickWebEngineView.loadingChanged(QWebEngineLoadRequest) --> void"
- << "QQuickWebEngineView.navigationHistory --> QQuickWebEngineHistory*"
+ << "QQuickWebEngineView.navigationHistory --> QWebEngineHistory*"
<< "QQuickWebEngineView.navigationRequested(QWebEngineNavigationRequest*) --> void"
<< "QQuickWebEngineView.newViewRequested(QWebEngineNewWindowRequest*) --> void"
<< "QQuickWebEngineView.pdfPrintingFinished(QString,bool) --> void"