125 lines
5.0 KiB
Diff
125 lines
5.0 KiB
Diff
From 1c33a4a6ae07106513a8105ebbc2d0c65363b333 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?J=C3=BCri=20Valdmann?= <juri.valdmann@qt.io>
|
|
Date: Mon, 29 Jul 2019 13:10:14 +0200
|
|
Subject: Fix QWebEnginePage visibility state
|
|
|
|
Calling
|
|
|
|
view.show();
|
|
view.load(...);
|
|
view.hide();
|
|
|
|
results in a WebContents in visible state because the first call to show() is
|
|
delayed via a timer and never canceled so it takes effect after the hide().
|
|
|
|
Also, the page's visibility state is not updated when changing views, so that a
|
|
visible QWebEngineView can be set to display a hidden QWebEnginePage.
|
|
|
|
Fixes: QTBUG-77209
|
|
Change-Id: I0243c659f4039a35c36e04ea55c5972666170fd0
|
|
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
|
|
---
|
|
src/webenginewidgets/api/qwebenginepage.cpp | 4 ++-
|
|
src/webenginewidgets/api/qwebengineview.cpp | 3 ++
|
|
.../widgets/qwebengineview/tst_qwebengineview.cpp | 34 ++++++++++++++++++++++
|
|
3 files changed, 40 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
|
|
index f252137a..8451bab1 100644
|
|
--- a/src/webenginewidgets/api/qwebenginepage.cpp
|
|
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
|
|
@@ -175,7 +175,6 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
|
|
wasShownTimer.setSingleShot(true);
|
|
QObject::connect(&wasShownTimer, &QTimer::timeout, [this](){
|
|
ensureInitialized();
|
|
- wasShown();
|
|
});
|
|
|
|
profile->d_ptr->addWebContentsAdapterClient(this);
|
|
@@ -215,6 +214,9 @@ void QWebEnginePagePrivate::initializationFinished()
|
|
if (!qFuzzyCompare(adapter->currentZoomFactor(), defaultZoomFactor))
|
|
adapter->setZoomFactor(defaultZoomFactor);
|
|
|
|
+ if (view && view->isVisible())
|
|
+ adapter->wasShown();
|
|
+
|
|
scriptCollection.d->initializationFinished(adapter);
|
|
|
|
m_isBeingAdopted = false;
|
|
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp
|
|
index 6c08df34..6e113852 100644
|
|
--- a/src/webenginewidgets/api/qwebengineview.cpp
|
|
+++ b/src/webenginewidgets/api/qwebengineview.cpp
|
|
@@ -61,6 +61,7 @@ void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage
|
|
Q_Q(QWebEngineView);
|
|
|
|
if (oldPage) {
|
|
+ oldPage->d_ptr->wasHidden();
|
|
oldPage->disconnect(q);
|
|
}
|
|
|
|
@@ -74,6 +75,8 @@ void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage
|
|
QObject::connect(newPage, &QWebEnginePage::loadFinished, q, &QWebEngineView::loadFinished);
|
|
QObject::connect(newPage, &QWebEnginePage::selectionChanged, q, &QWebEngineView::selectionChanged);
|
|
QObject::connect(newPage, &QWebEnginePage::renderProcessTerminated, q, &QWebEngineView::renderProcessTerminated);
|
|
+ if (q->isVisible())
|
|
+ newPage->d_ptr->wasShown();
|
|
}
|
|
|
|
auto oldUrl = oldPage ? oldPage->url() : QUrl();
|
|
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
|
|
index a7ff05f5..1bb65d7d 100644
|
|
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
|
|
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
|
|
@@ -192,6 +192,8 @@ private Q_SLOTS:
|
|
void webUIURLs_data();
|
|
void webUIURLs();
|
|
void visibilityState();
|
|
+ void visibilityState2();
|
|
+ void visibilityState3();
|
|
void jsKeyboardEvent();
|
|
void deletePage();
|
|
void closeOpenerTab();
|
|
@@ -3106,6 +3108,38 @@ void tst_QWebEngineView::visibilityState()
|
|
QCOMPARE(evaluateJavaScriptSync(view.page(), "document.visibilityState").toString(), QStringLiteral("visible"));
|
|
}
|
|
|
|
+void tst_QWebEngineView::visibilityState2()
|
|
+{
|
|
+ QWebEngineView view;
|
|
+ QSignalSpy spy(&view, &QWebEngineView::loadFinished);
|
|
+ view.show();
|
|
+ view.load(QStringLiteral("about:blank"));
|
|
+ view.hide();
|
|
+ QVERIFY(spy.count() || spy.wait());
|
|
+ QVERIFY(spy.takeFirst().takeFirst().toBool());
|
|
+ QCOMPARE(evaluateJavaScriptSync(view.page(), "document.visibilityState").toString(), QStringLiteral("hidden"));
|
|
+}
|
|
+
|
|
+void tst_QWebEngineView::visibilityState3()
|
|
+{
|
|
+ QWebEnginePage page1;
|
|
+ QWebEnginePage page2;
|
|
+ QSignalSpy spy1(&page1, &QWebEnginePage::loadFinished);
|
|
+ QSignalSpy spy2(&page2, &QWebEnginePage::loadFinished);
|
|
+ page1.load(QStringLiteral("about:blank"));
|
|
+ page2.load(QStringLiteral("about:blank"));
|
|
+ QVERIFY(spy1.count() || spy1.wait());
|
|
+ QVERIFY(spy2.count() || spy2.wait());
|
|
+ QWebEngineView view;
|
|
+ view.setPage(&page1);
|
|
+ view.show();
|
|
+ QCOMPARE(evaluateJavaScriptSync(&page1, "document.visibilityState").toString(), QStringLiteral("visible"));
|
|
+ QCOMPARE(evaluateJavaScriptSync(&page2, "document.visibilityState").toString(), QStringLiteral("hidden"));
|
|
+ view.setPage(&page2);
|
|
+ QCOMPARE(evaluateJavaScriptSync(&page1, "document.visibilityState").toString(), QStringLiteral("hidden"));
|
|
+ QCOMPARE(evaluateJavaScriptSync(&page2, "document.visibilityState").toString(), QStringLiteral("visible"));
|
|
+}
|
|
+
|
|
void tst_QWebEngineView::jsKeyboardEvent()
|
|
{
|
|
QWebEngineView view;
|
|
--
|
|
cgit v1.2.1
|
|
|