1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 04:36:34 +01:00

Workaround QWebEnginePage not scrolling to anchors when opened in background tab

Closes #2242
This commit is contained in:
David Rosca 2017-03-15 13:11:27 +01:00
parent 8940609a00
commit 486b8f4c7d
2 changed files with 14 additions and 2 deletions

View File

@ -90,6 +90,16 @@ WebPage::WebPage(QObject* parent)
connect(this, &QWebEnginePage::proxyAuthenticationRequired, this, [this](const QUrl &, QAuthenticator *auth, const QString &proxyHost) {
mApp->networkManager()->proxyAuthentication(proxyHost, auth, view());
});
// Workaround QWebEnginePage not scrolling to anchors when opened in background tab
m_contentsResizedConnection = connect(this, &QWebEnginePage::contentsSizeChanged, this, [this]() {
const QString fragment = url().fragment();
if (!fragment.isEmpty()) {
const QString src = QSL("var els = document.querySelectorAll(\"[name='%1']\"); if (els.length) els[0].scrollIntoView();");
runJavaScript(src.arg(fragment));
}
disconnect(m_contentsResizedConnection);
});
}
WebPage::~WebPage()

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* QupZilla - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -115,6 +115,8 @@ private:
bool m_blockAlerts;
bool m_secureStatus;
bool m_adjustingScheduled;
QMetaObject::Connection m_contentsResizedConnection;
};
#endif // WEBPAGE_H