[rkward/work/qtwebengine] /: Fix restoring scroll position in QtWebEngine
Thomas Friedrichsmeier
null at kde.org
Tue Mar 31 14:40:58 BST 2020
Git commit 514901c9592c44d45f0d5f4d4b944805795d1aab by Thomas Friedrichsmeier.
Committed on 31/03/2020 at 13:40.
Pushed by tfry into branch 'work/qtwebengine'.
Fix restoring scroll position in QtWebEngine
M +0 -1 ChangeLog
M +13 -12 rkward/windows/rkhtmlwindow.cpp
M +0 -1 rkward/windows/rkhtmlwindow.h
https://commits.kde.org/rkward/514901c9592c44d45f0d5f4d4b944805795d1aab
diff --git a/ChangeLog b/ChangeLog
index a5fcb91b..ea2bcca8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,6 @@
--- Version 0.7.2 - UNRELEASED
- Support using QWebEngine instead of QtWebKit (still supported)
- TODO:
- - Restore scroll position (needs to happen *after* page load)
- Should all KIO-schemes be supported (not too hard to do, help:/ already supported)?
- Support pdf
- <text> elements in plugins may now also contain clickable links, including rkward://-scheme links
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index f7926847..dd33c72a 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -184,7 +184,7 @@ protected:
/** reimplemented to schedule new window creation for the next page to load */
QWebPage* createWindow (QWebPage::WebWindowType) override {
#else
- QWebEnginePage* createWindow (QWebEnginePage::WebWindowType) {
+ QWebEnginePage* createWindow (QWebEnginePage::WebWindowType) override {
#endif
RK_TRACE (APP);
new_window = true; // Don't actually create the window, until we know which URL we're talking about.
@@ -228,7 +228,7 @@ protected:
class RKWebEngineKIOForwarder : public QWebEngineUrlSchemeHandler {
public:
RKWebEngineKIOForwarder (QObject *parent) : QWebEngineUrlSchemeHandler (parent) {}
- void requestStarted (QWebEngineUrlRequestJob *request) {
+ void requestStarted (QWebEngineUrlRequestJob *request) override {
KIO::StoredTransferJob *job = KIO::storedGet(request->requestUrl (), KIO::NoReload, KIO::HideProgressInfo);
connect (job, &KIO::StoredTransferJob::result, this, [this, job](){ kioJobFinished(job); });
jobs.insert (job, request);
@@ -400,12 +400,21 @@ void RKHTMLWindow::openLocationFromHistory (VisitedLocation &loc) {
int history_last = url_history.count () - 1;
RK_ASSERT (current_history_position >= 0);
RK_ASSERT (current_history_position <= history_last);
+ QPoint scroll_pos = loc.scroll_position.toPoint ();
if (loc.url == current_url) {
- restoreBrowserState (&loc);
+ page->setScrollPosition (scroll_pos);
} else {
url_change_is_from_history = true;
openURL (loc.url); // TODO: merge into restoreBrowserState()?
- restoreBrowserState (&loc);
+#ifndef NO_QT_WEBENGINE
+ QMetaObject::Connection * const connection = new QMetaObject::Connection;
+ *connection = connect(view, &QWebEngineView::loadFinished, [this, scroll_pos, connection](){
+ QObject::disconnect(*connection);
+ delete connection;
+ page->setScrollPosition (scroll_pos);
+ });
+#endif
+ page->setScrollPosition (scroll_pos);
url_change_is_from_history = false;
}
@@ -763,14 +772,6 @@ void RKHTMLWindow::saveBrowserState (VisitedLocation* state) {
}
}
-void RKHTMLWindow::restoreBrowserState (VisitedLocation* state) {
- RK_TRACE (APP);
-
- if (state->scroll_position.isNull ()) return;
- RK_ASSERT (page);
- page->setScrollPosition (state->scroll_position.toPoint ());
-}
-
RKHTMLWindowPart::RKHTMLWindowPart (RKHTMLWindow* window) : KParts::Part (window) {
RK_TRACE (APP);
setComponentName (QCoreApplication::applicationName (), QGuiApplication::applicationDisplayName ());
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index b701940c..e43662c3 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -132,7 +132,6 @@ friend class RKHTMLWindowPart;
void fileDoesNotExistMessage ();
void saveBrowserState (VisitedLocation *state);
- void restoreBrowserState (VisitedLocation *state);
};
class RKHTMLWindowPart : public KParts::Part {
More information about the rkward-tracker
mailing list