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> | 2019-05-08 18:04:22 +0000 |
commit | 7cdb24f8818a3cfa81bc43ac6f7ce09683f36639 (patch) | |
tree | 1d4b6be512f5977d57ce5007dcef5f38391902cb /src | |
parent | 27357fb962d97a12c20f6969f8cba6044fbfa9d0 (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>
(cherry picked from commit 15b6ab6a20ff7305f2b3558f8450e388148a0312)
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index b301622d4..8568a536c 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -90,6 +90,7 @@ #include <QPageLayout> #include <QStringList> #include <QStyleHints> +#include <QTimer> #include <QVariant> #include <QtCore/qelapsedtimer.h> #include <QtCore/qmimedata.h> @@ -583,8 +584,26 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request) params.extra_headers += (*it).toStdString() + ": " + request.header(*it).toStdString(); } - d->webContents->GetController().LoadURLWithParams(params); - 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); + 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) |