From dae47317c1089a438a92d8080109bde43f14b540 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 14 Jul 2021 11:08:33 +0200 Subject: Add QWebEngineNewWindowRequest::openIn(QWebEnginePage *) Makes for a nicer API Change-Id: I15e72d526e9cf6cf9ca8bd3e24f5dd7e7b2e9fa5 Reviewed-by: Kirill Burtsev (cherry picked from commit 9285872b0dd4da8c0ba1dd8ef6c6822f85622f4e) Reviewed-by: Qt Cherry-pick Bot --- src/core/api/qwebenginenewwindowrequest.cpp | 16 ++++++++++++++++ src/core/api/qwebenginenewwindowrequest.h | 3 +++ src/core/api/qwebenginepage.cpp | 8 +++----- 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src/core/api') diff --git a/src/core/api/qwebenginenewwindowrequest.cpp b/src/core/api/qwebenginenewwindowrequest.cpp index 7d2762e1c..1322bb4dd 100644 --- a/src/core/api/qwebenginenewwindowrequest.cpp +++ b/src/core/api/qwebenginenewwindowrequest.cpp @@ -40,6 +40,8 @@ #include "qwebenginenewwindowrequest.h" #include "qwebenginenewwindowrequest_p.h" +#include "qwebenginepage.h" + #include "web_contents_adapter.h" QT_BEGIN_NAMESPACE @@ -172,4 +174,18 @@ bool QWebEngineNewWindowRequest::isUserInitiated() const return d_ptr->isUserInitiated; } +/*! + Opens the requested window in the view represented by \a page. + + \sa QWebEnginePage::newWindowRequested +*/ +void QWebEngineNewWindowRequest::openIn(QWebEnginePage *page) +{ + if (!page) { + qWarning("Trying to open a QWebEngineNewWindowRequest in an invalid QWebEnginePage."); + return; + } + page->acceptAsNewWindow(*this); +} + QT_END_NAMESPACE diff --git a/src/core/api/qwebenginenewwindowrequest.h b/src/core/api/qwebenginenewwindowrequest.h index 4066f1a65..8fd35ad6f 100644 --- a/src/core/api/qwebenginenewwindowrequest.h +++ b/src/core/api/qwebenginenewwindowrequest.h @@ -53,6 +53,7 @@ class WebContentsAdapter; QT_BEGIN_NAMESPACE +class QWebEnginePage; struct QWebEngineNewWindowRequestPrivate; class Q_WEBENGINECORE_EXPORT QWebEngineNewWindowRequest : public QObject @@ -78,6 +79,8 @@ public: QRect requestedGeometry() const; bool isUserInitiated() const; + void openIn(QWebEnginePage *); + protected: QWebEngineNewWindowRequest(DestinationType, const QRect &, const QUrl &, bool, QSharedPointer, diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index 17a790d9f..b69fdfb92 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -2225,18 +2225,16 @@ QSizeF QWebEnginePage::contentsSize() const while holding Shift, Ctrl, or a built-in combination that triggers the page to open in a new window. - The signal is handled by calling acceptAsNewWindow() on the destination page. + The signal is handled by calling openIn() with the new page on the request. If this signal is not handled, the requested load will fail. \note This signal is not emitted if \l createWindow() handled the request first. - \sa createWindow() + \sa createWindow(), QWebEngineNewWindowRequest::openIn() */ /*! - Handles the newWindowRequested() signal by opening the \a request in this page. - \since 6.2 - \sa newWindowRequested() + \internal */ void QWebEnginePage::acceptAsNewWindow(QWebEngineNewWindowRequest &request) { -- cgit v1.2.3