From d8d4666db2592b64b7e24aa896ecdac7e8f8bc1a Mon Sep 17 00:00:00 2001
From: Andras Becsi <andras.becsi@theqtcompany.com>
Date: Wed, 22 Apr 2015 11:40:11 +0200
Subject: [PATCH] WebEngineView does not load a url while invisible
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Notify the RenderWidgetHost about visibility changes so that we
receive updates with non-empty DelegatedFrameData when a page was
loaded in an invisible WebEngineView and then made visible.

Task-number: QTBUG-42789
Change-Id: I4856efcd9c0ce44b66a228d5a414198df46b95eb
Reviewed-by: Michael Brüning <michael.bruning@theqtcompany.com>
---
 src/core/render_widget_host_view_qt.cpp                | 10 ++++++++++
 src/core/render_widget_host_view_qt.h                  |  2 ++
 src/core/render_widget_host_view_qt_delegate.h         |  2 ++
 .../render_widget_host_view_qt_delegate_quick.cpp      |  2 ++
 ...render_widget_host_view_qt_delegate_quickwindow.cpp |  2 ++
 .../render_widget_host_view_qt_delegate_widget.cpp     |  5 ++++-
 6 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 0f9286252..572bc340c 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -715,6 +715,16 @@ void RenderWidgetHostViewQt::notifyResize()
     m_host->WasResized();
 }
 
+void RenderWidgetHostViewQt::notifyShown()
+{
+    WasShown();
+}
+
+void RenderWidgetHostViewQt::notifyHidden()
+{
+    WasHidden();
+}
+
 void RenderWidgetHostViewQt::windowBoundsChanged()
 {
     m_host->SendScreenRects();
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 68330a486..248c52f6e 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -159,6 +159,8 @@ public:
     // Overridden from RenderWidgetHostViewQtDelegateClient.
     virtual QSGNode *updatePaintNode(QSGNode *) Q_DECL_OVERRIDE;
     virtual void notifyResize() Q_DECL_OVERRIDE;
+    virtual void notifyShown() Q_DECL_OVERRIDE;
+    virtual void notifyHidden() Q_DECL_OVERRIDE;
     virtual void windowBoundsChanged() Q_DECL_OVERRIDE;
     virtual void windowChanged() Q_DECL_OVERRIDE;
     virtual bool forwardEvent(QEvent *) Q_DECL_OVERRIDE;
diff --git a/src/core/render_widget_host_view_qt_delegate.h b/src/core/render_widget_host_view_qt_delegate.h
index a12f3055e..da595b91f 100644
--- a/src/core/render_widget_host_view_qt_delegate.h
+++ b/src/core/render_widget_host_view_qt_delegate.h
@@ -64,6 +64,8 @@ public:
     virtual ~RenderWidgetHostViewQtDelegateClient() { }
     virtual QSGNode *updatePaintNode(QSGNode *) = 0;
     virtual void notifyResize() = 0;
+    virtual void notifyShown() = 0;
+    virtual void notifyHidden() = 0;
     virtual void windowBoundsChanged() = 0;
     virtual void windowChanged() = 0;
     virtual bool forwardEvent(QEvent *) = 0;
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
index 0a534ac2c..a3999ccab 100644
--- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
+++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
@@ -120,11 +120,13 @@ void RenderWidgetHostViewQtDelegateQuick::unlockMouse()
 void RenderWidgetHostViewQtDelegateQuick::show()
 {
     setVisible(true);
+    m_client->notifyShown();
 }
 
 void RenderWidgetHostViewQtDelegateQuick::hide()
 {
     setVisible(false);
+    m_client->notifyHidden();
 }
 
 bool RenderWidgetHostViewQtDelegateQuick::isVisible() const
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp
index 39c48ea5c..be240a8ae 100644
--- a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp
+++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp
@@ -79,11 +79,13 @@ QRectF RenderWidgetHostViewQtDelegateQuickWindow::contentsRect() const
 void RenderWidgetHostViewQtDelegateQuickWindow::show()
 {
     QQuickWindow::show();
+    m_realDelegate->show();
 }
 
 void RenderWidgetHostViewQtDelegateQuickWindow::hide()
 {
     QQuickWindow::hide();
+    m_realDelegate->hide();
 }
 
 bool RenderWidgetHostViewQtDelegateQuickWindow::isVisible() const
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
index 865d0f93f..d615b0f9c 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
@@ -136,13 +136,16 @@ void RenderWidgetHostViewQtDelegateWidget::show()
 {
     // Check if we're attached to a QWebEngineView, we don't
     // want to show anything else than popups as top-level.
-    if (parent() || m_isPopup)
+    if (parent() || m_isPopup) {
         QOpenGLWidget::show();
+        m_client->notifyShown();
+    }
 }
 
 void RenderWidgetHostViewQtDelegateWidget::hide()
 {
     QOpenGLWidget::hide();
+    m_client->notifyHidden();
 }
 
 bool RenderWidgetHostViewQtDelegateWidget::isVisible() const
-- 
GitLab