[rkward/work/qtwebengine] /: Start porting to QWebEngine (optional)

Thomas Friedrichsmeier null at kde.org
Sun Apr 22 09:17:02 UTC 2018


Git commit a568ba392dfb9b95ee46af4638287326c890c785 by Thomas Friedrichsmeier.
Committed on 14/08/2016 at 18:49.
Pushed by tfry into branch 'work/qtwebengine'.

Start porting to QWebEngine (optional)

M  +14   -2    CMakeLists.txt
M  +33   -16   rkward/windows/rkhtmlwindow.cpp
M  +19   -2    rkward/windows/rkhtmlwindow.h

https://commits.kde.org/rkward/a568ba392dfb9b95ee46af4638287326c890c785

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 99e01c8c..3889e956 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,8 +19,20 @@ INCLUDE(KDECompilerSettings)
 INCLUDE(ECMInstallIcons)
 INCLUDE(FeatureSummary)
 
-FIND_PACKAGE(Qt5 5.2 CONFIG REQUIRED COMPONENTS Widgets Core Xml Network WebKit Script PrintSupport)
-FIND_PACKAGE(KF5 5.2 REQUIRED COMPONENTS CoreAddons DocTools I18n XmlGui TextEditor WidgetsAddons WebKit Parts Config Notifications WindowSystem)
+FIND_PACKAGE(Qt5 5.2 CONFIG REQUIRED COMPONENTS Widgets Core Xml Network Script PrintSupport)
+FIND_PACKAGE(KF5 5.2 REQUIRED COMPONENTS CoreAddons DocTools I18n XmlGui TextEditor WidgetsAddons Parts Config Notifications WindowSystem)
+IF(NOT NO_QT_WEBENGINE)
+	FIND_PACKAGE(Qt5 OPTIONAL_COMPONENTS WebEngine)
+ENDIF(NOT NoQtWebEngine)
+IF(NOT Qt5WebEngine_FOUND)
+	FIND_PACKAGE(KF5 5.2 OPTIONAL_COMPONENTS WebKit)
+	IF(NOT KF5_WebKit_FOUND)
+		MESSAGE(FATAL_ERROR "At least one of KF5WebKit or QtWebEngine is required. Neither was found on this system.")
+	ENDIF(NOT KF5_WebKit_FOUND)
+	ADD_DEFINITIONS(-DNO_QT_WEBENGINE)  # TODO: rather set it for rkhtmlwindow, only
+ELSE(Qt5WebEngine_FOUND)
+	MESSAGE(STATUS "QtWebEngine will be used for rendering HTML. To use KF5WebKit, instead (if available), pass -DNO_QT_WEBENGINE in your call to cmake.")
+ENDIF(Qt5WebEngine_FOUND)
 FIND_PACKAGE(Gettext REQUIRED)
 
 # FindIntl in cmake is broken for MSVC on Windows, (and only included from 3.2.3 upwards).
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index ebc13d37..42636db2 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -23,7 +23,6 @@
 #include <kdirwatch.h>
 #include <kio/job.h>
 #include <kservice.h>
-#include <kwebview.h>
 #include <kcodecaction.h>
 
 #include <qfileinfo.h>
@@ -33,8 +32,6 @@
 #include <qdir.h>
 #include <QHBoxLayout>
 #include <QHostInfo>
-#include <QNetworkRequest>
-#include <QWebFrame>
 #include <QPrintDialog>
 #include <QMenu>
 #include <QTextCodec>
@@ -65,9 +62,16 @@
 #include "../windows/rkworkplaceview.h"
 #include "../debug.h"
 
+#ifdef NO_QT_WEBENGINE
+#	include <QWebFrame>
+#	include <QNetworkRequest>
+#	include <kwebview.h>
 // TODO: We used to have KioIntegration in addition to KPartsIntegration. But this is just buggy, buggy, buggy in KF5 5.9.0. (e.g. navigation to previous
 // // page in history just doesn't work).
 RKWebPage::RKWebPage (RKHTMLWindow* window): KWebPage (window, KPartsIntegration) {
+#else
+RKWebPage::RKWebPage (RKHTMLWindow* window): QWebEnginePage (window) {
+#endif
 	RK_TRACE (APP);
 	RKWebPage::window = window;
 	new_window = false;
@@ -76,46 +80,59 @@ RKWebPage::RKWebPage (RKHTMLWindow* window): KWebPage (window, KPartsIntegration
 	settings ()->setFontFamily (QWebSettings::FixedFont, QFontDatabase::systemFont(QFontDatabase::FixedFont).family ());
 }
 
+#ifdef NO_QT_WEBENGINE
 bool RKWebPage::acceptNavigationRequest (QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
+	QUrl navurl = request.url ();
+	QUrl cururl (mainFrame ()->url ());
+	bool is_main_frame = frame == mainFrame ();
+#else
+bool RKWebPage::acceptNavigationRequest (const QUrl &navurl, QWebEnginePage::NavigationType type, bool is_main_frame) override {
+	QUrl cururl (url ());
+#endif
 	Q_UNUSED (type);
 
 	RK_TRACE (APP);
-	RK_DEBUG (APP, DL_DEBUG, "Navigation request to %s", qPrintable (request.url ().toString ()));
-	if (direct_load && (frame == mainFrame ())) {
+	RK_DEBUG (APP, DL_DEBUG, "Navigation request to %s", qPrintable (navurl.toString ()));
+	if (direct_load && (is_main_frame)) {
 		direct_load = false;
 		return true;
 	}
 
 	if (new_window) {
-		frame = 0;
 		new_window = false;
-	}
-	if (!frame) {
-		RKWorkplace::mainWorkplace ()->openAnyUrl (request.url ());
+		RKWorkplace::mainWorkplace ()->openAnyUrl (navurl);
 		return false;
 	}
 
-	if (frame != mainFrame ()) {
-		if (request.url ().isLocalFile () && (QMimeDatabase ().mimeTypeForUrl (request.url ()).inherits ("text/html"))) return true;
+	if (!is_main_frame) {
+		if (navurl.isLocalFile () && (QMimeDatabase ().mimeTypeForUrl (navurl).inherits ("text/html"))) return true;
 	}
 
-	if (QUrl (mainFrame ()->url ()).matches (request.url (), QUrl::NormalizePathSegments | QUrl::StripTrailingSlash)) {
-		RK_DEBUG (APP, DL_DEBUG, "Page internal navigation request from %s to %s", qPrintable (mainFrame ()->url ().toString ()), qPrintable (request.url ().toString ()));
-		emit (pageInternalNavigation (request.url ()));
+	if (cururl.matches (navurl, QUrl::NormalizePathSegments | QUrl::StripTrailingSlash)) {
+		RK_DEBUG (APP, DL_DEBUG, "Page internal navigation request from %s to %s", qPrintable (cururl.toString ()), qPrintable (navurl.toString ()));
+		emit (pageInternalNavigation (navurl));
 		return true;
 	}
 
-	window->openURL (request.url ());
+	window->openURL (navurl);
 	return false;
 }
 
 void RKWebPage::load (const QUrl& url) {
 	RK_TRACE (APP);
 	direct_load = true;
+#ifdef NO_QT_WEBENGINE
 	mainFrame ()->load (url);
+#else
+	load (url);
+#endif
 }
 
+#ifdef NO_QT_WEBENGINE
 QWebPage* RKWebPage::createWindow (QWebPage::WebWindowType) {
+#else
+QWebEnginePage* RKWebPage::createWindow (QWebEnginePage::WebWindowType) {
+#endif
 	RK_TRACE (APP);
 	new_window = true;         // Don't actually create the window, until we know which URL we're talking about.
 	return (this);
@@ -149,7 +166,7 @@ RKHTMLWindow::RKHTMLWindow (QWidget *parent, WindowMode mode) : RKMDIWindow (par
 
 	// We have to connect this in order to allow browsing.
 	connect (page, &RKWebPage::pageInternalNavigation, this, &RKHTMLWindow::internalNavigation);
-	connect (page, &QWebPage::downloadRequested, this, &RKHTMLWindow::saveRequested);
+	connect (page, &QWebPage::downloadRequested, this, &RKHTMLWindow::saveRequested);  --> webengine: override triggerAction virtual
 	connect (page, &QWebPage::printRequested, this, &RKHTMLWindow::slotPrint);
 	connect (view, &QWidget::customContextMenuRequested, this, &RKHTMLWindow::makeContextMenu);
 
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index 7598b100..1e65ca24 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -21,7 +21,6 @@
 #include <QUrl>
 #include <kparts/part.h>
 #include <kio/jobclasses.h>
-#include <kwebpage.h>
 
 #include <QDomElement>
 
@@ -33,12 +32,19 @@ class QAction;
 class RKComponentHandle;
 class XMLHelper;
 class RKHTMLWindowPart;
-class KWebView;
 class QTemporaryFile;
 class RKHTMLWindow;
 class RKFindBar;
 
+#ifdef NO_QT_WEBENGINE
+#	include <kwebpage.h>
+class KWebView;
 class RKWebPage : public KWebPage {
+#else
+#	include <QWebEnginePage>
+class QWebEngineView;
+class RKWebPage : public QWebEnginePage {
+#endif
 	Q_OBJECT
 public:
 	explicit RKWebPage (RKHTMLWindow* window);
@@ -46,10 +52,17 @@ public:
 signals:
 	void pageInternalNavigation (const QUrl& url);
 protected:
+#ifdef NO_QT_WEBENGINE
 /** reimplemented to always emit linkClicked() for pages that need special handling (importantly, rkward://-urls). */
 	bool acceptNavigationRequest (QWebFrame* frame, const QNetworkRequest& request, NavigationType type) override;
 /** reimplemented to schedule new window creation for the next page to load */
 	QWebPage* createWindow (WebWindowType type) override;
+#else
+/** reimplemented to always emit linkClicked() for pages that need special handling (importantly, rkward://-urls). */
+	bool acceptNavigationRequest (const QUrl &url, NavigationType type, bool isMainFrame) override;
+/** reimplemented to schedule new window creation for the next page to load */
+	QWebEnginePage* createWindow (WebWindowType type) override;
+#endif
 private:
 	RKHTMLWindow *window;
 	bool new_window;
@@ -120,7 +133,11 @@ private slots:
 	void findRequest (const QString& text, bool backwards, const RKFindBar *findbar, bool* found);
 private:
 friend class RKHTMLWindowPart;
+#ifdef NO_QT_WEBENGINE
 	KWebView* view;
+#else
+	QWebEngineView* view;
+#endif
 	RKWebPage* page;
 	RKFindBar* findbar;
 	bool have_highlight;



More information about the rkward-tracker mailing list