diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2017-11-10 10:51:18 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2017-11-30 10:42:46 +0000 |
commit | 15b6ab6a20ff7305f2b3558f8450e388148a0312 (patch) | |
tree | 6f2e860f9faf6b2fcc58fd2b2feca70057434960 /src/core/web_contents_adapter.cpp | |
parent | 3f4daf02723b16e83dfb9bcee654b5c803de1ae8 (diff) |
Process pending resize of view before scroll to anchor by URL fragment
The size of the WebEngineView must be set before navigating to an URL
with fragment for scrolling to the correct position. In some cases the
resizing is scheduled on the event loop and Blink uses wrong size to
calculate position to scroll. Schedule the navigation on the event loop
if the viewport's size is 0 thus it is performed after the potential
resizing is done.
Task-number: QTBUG-54172
Change-Id: I9acbc33748755606082278585c121dd66b4aa02c
Reviewed-by: Viktor Engelmann <viktor.engelmann@qt.io>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 812a6f1c0..e2aedc9bb 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -91,6 +91,7 @@ #include <QPageLayout> #include <QStringList> #include <QStyleHints> +#include <QTimer> #include <QVariant> #include <QtCore/qelapsedtimer.h> #include <QtCore/qmimedata.h> @@ -593,10 +594,28 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request) params.extra_headers += (*it).toStdString() + ": " + request.header(*it).toStdString(); } - d->webContents->GetController().LoadURLWithParams(params); - // Follow chrome::Navigate and invalidate the URL immediately. - d->webContentsDelegate->NavigationStateChanged(d->webContents.get(), content::INVALIDATE_TYPE_URL); - focusIfNecessary(); + bool resizeNeeded = false; + if (request.url().hasFragment()) { + if (content::RenderWidgetHostView *rwhv = webContents()->GetRenderWidgetHostView()) { + const gfx::Size &viewportSize = rwhv->GetVisibleViewportSize(); + resizeNeeded = (viewportSize.width() == 0 || viewportSize.height() == 0); + } + } + + auto navigate = [this, params]() { + Q_D(WebContentsAdapter); + webContents()->GetController().LoadURLWithParams(params); + // Follow chrome::Navigate and invalidate the URL immediately. + d->webContentsDelegate->NavigationStateChanged(webContents(), content::INVALIDATE_TYPE_URL); + focusIfNecessary(); + }; + + if (resizeNeeded) { + // Schedule navigation on the event loop. + QTimer::singleShot(0, navigate); + } else { + navigate(); + } } void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) |