From 7717f941a349140497d5e689530a2bf31e8397da Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Mon, 18 Aug 2014 14:11:06 +0200 Subject: Propagate the page's screen coordinates when the top-level window moved This fixes a regression after the 37 upgrade where the select popups would have the wrong position. Adjust to the new behavior and also avoid doing a mapToGlobal of the position received in InitAsPopup. RWHV::SetBounds has been giving us screen coordinates since the Chromium 33 update, but popup locations somehow managed to work properly through some side-effect sorcery. This also fixes the value of window.screen[XY] in JavaScript which wasn't updated when the window was moved. Change-Id: I544499bafedccfb7d389b4abc48f1386c398473f Reviewed-by: Pierre Rossi --- src/core/render_widget_host_view_qt.cpp | 31 ++++++++++++---------- src/core/render_widget_host_view_qt.h | 5 ++-- src/core/render_widget_host_view_qt_delegate.h | 3 ++- src/core/web_contents_adapter_client.h | 1 - src/webengine/api/qquickwebengineview.cpp | 6 ----- src/webengine/api/qquickwebengineview_p_p.h | 1 - .../render_widget_host_view_qt_delegate_quick.cpp | 19 +++++++++++-- .../render_widget_host_view_qt_delegate_quick.h | 4 +++ src/webenginewidgets/api/qwebenginepage.cpp | 5 ---- src/webenginewidgets/api/qwebenginepage_p.h | 1 - .../render_widget_host_view_qt_delegate_widget.cpp | 21 +++++++++++++++ .../render_widget_host_view_qt_delegate_widget.h | 13 ++++++--- 12 files changed, 73 insertions(+), 37 deletions(-) diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 9365020a0..d0c8f1482 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -216,9 +216,7 @@ void RenderWidgetHostViewQt::InitAsChild(gfx::NativeView) void RenderWidgetHostViewQt::InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect& rect) { - QRect screenRect = toQt(rect); - screenRect.moveTo(m_adapterClient->mapToGlobal(screenRect.topLeft())); - m_delegate->initAsPopup(screenRect); + m_delegate->initAsPopup(toQt(rect)); } void RenderWidgetHostViewQt::InitAsFullscreen(content::RenderWidgetHostView*) @@ -238,12 +236,12 @@ void RenderWidgetHostViewQt::SetSize(const gfx::Size& size) m_delegate->resize(width,height); } -void RenderWidgetHostViewQt::SetBounds(const gfx::Rect& rect) +void RenderWidgetHostViewQt::SetBounds(const gfx::Rect& screenRect) { // This is called when webkit has sent us a Move message. - if (IsPopup()) - m_delegate->move(m_adapterClient->mapToGlobal(toQt(rect.origin()))); - SetSize(rect.size()); + if (IsPopup()) + m_delegate->move(toQt(screenRect.origin())); + SetSize(screenRect.size()); } gfx::Size RenderWidgetHostViewQt::GetPhysicalBackingSize() const @@ -659,7 +657,18 @@ QSGNode *RenderWidgetHostViewQt::updatePaintNode(QSGNode *oldNode) void RenderWidgetHostViewQt::notifyResize() { - GetRenderWidgetHost()->WasResized(); + m_host->WasResized(); +} + +void RenderWidgetHostViewQt::windowBoundsChanged() +{ + m_host->SendScreenRects(); +} + +void RenderWidgetHostViewQt::windowChanged() +{ + if (m_delegate->window()) + m_host->NotifyScreenInfoChanged(); } bool RenderWidgetHostViewQt::forwardEvent(QEvent *event) @@ -729,12 +738,6 @@ QVariant RenderWidgetHostViewQt::inputMethodQuery(Qt::InputMethodQuery query) co } } -void RenderWidgetHostViewQt::windowChanged() -{ - if (m_delegate->window()) - m_host->NotifyScreenInfoChanged(); -} - void RenderWidgetHostViewQt::ProcessAckedTouchEvent(const content::TouchEventWithLatencyInfo &touch, content::InputEventAckState ack_result) { Q_UNUSED(touch); const bool eventConsumed = ack_result == content::INPUT_EVENT_ACK_STATE_CONSUMED; diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index acb1948a8..90a6ef87c 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -109,7 +109,7 @@ public: virtual void InitAsFullscreen(content::RenderWidgetHostView*) Q_DECL_OVERRIDE; virtual content::RenderWidgetHost* GetRenderWidgetHost() const Q_DECL_OVERRIDE; virtual void SetSize(const gfx::Size& size) Q_DECL_OVERRIDE; - virtual void SetBounds(const gfx::Rect& rect) Q_DECL_OVERRIDE; + virtual void SetBounds(const gfx::Rect&) Q_DECL_OVERRIDE; virtual gfx::Size GetPhysicalBackingSize() const Q_DECL_OVERRIDE; virtual gfx::NativeView GetNativeView() const Q_DECL_OVERRIDE; virtual gfx::NativeViewId GetNativeViewId() const Q_DECL_OVERRIDE; @@ -161,9 +161,10 @@ public: // Overridden from RenderWidgetHostViewQtDelegateClient. virtual QSGNode *updatePaintNode(QSGNode *) Q_DECL_OVERRIDE; virtual void notifyResize() Q_DECL_OVERRIDE; + virtual void windowBoundsChanged() Q_DECL_OVERRIDE; + virtual void windowChanged() Q_DECL_OVERRIDE; virtual bool forwardEvent(QEvent *) Q_DECL_OVERRIDE; virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE; - virtual void windowChanged() Q_DECL_OVERRIDE; void handleMouseEvent(QMouseEvent*); void handleKeyEvent(QKeyEvent*); diff --git a/src/core/render_widget_host_view_qt_delegate.h b/src/core/render_widget_host_view_qt_delegate.h index d83f14235..d636e1d37 100644 --- a/src/core/render_widget_host_view_qt_delegate.h +++ b/src/core/render_widget_host_view_qt_delegate.h @@ -64,9 +64,10 @@ public: virtual ~RenderWidgetHostViewQtDelegateClient() { } virtual QSGNode *updatePaintNode(QSGNode *) = 0; virtual void notifyResize() = 0; + virtual void windowBoundsChanged() = 0; + virtual void windowChanged() = 0; virtual bool forwardEvent(QEvent *) = 0; virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const = 0; - virtual void windowChanged() = 0; }; class QWEBENGINE_EXPORT RenderWidgetHostViewQtDelegate { diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index e0ff25124..d4f3f6e0b 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -150,7 +150,6 @@ public: virtual void didUpdateTargetURL(const QUrl&) = 0; virtual void selectionChanged() = 0; virtual QRectF viewportRect() const = 0; - virtual QPoint mapToGlobal(const QPoint &posInView) const = 0; virtual qreal dpiScale() const = 0; virtual void loadStarted(const QUrl &provisionalUrl) = 0; virtual void loadCommitted() = 0; diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index e9c5232ab..9e0f5ad50 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -265,12 +265,6 @@ QRectF QQuickWebEngineViewPrivate::viewportRect() const return QRectF(q->x(), q->y(), q->width(), q->height()); } -QPoint QQuickWebEngineViewPrivate::mapToGlobal(const QPoint &posInView) const -{ - Q_Q(const QQuickWebEngineView); - return q->window() ? q->window()->mapToGlobal(posInView) : QPoint(); -} - qreal QQuickWebEngineViewPrivate::dpiScale() const { return m_dpiScale; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 332d9e280..6b61fb950 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -155,7 +155,6 @@ public: virtual void didUpdateTargetURL(const QUrl&) Q_DECL_OVERRIDE; virtual void selectionChanged() Q_DECL_OVERRIDE { } virtual QRectF viewportRect() const Q_DECL_OVERRIDE; - virtual QPoint mapToGlobal(const QPoint &posInView) const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; virtual void loadStarted(const QUrl &provisionalUrl) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; 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 daca44071..5b37d9653 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -224,11 +224,26 @@ void RenderWidgetHostViewQtDelegateQuick::geometryChanged(const QRectF &newGeome void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const ItemChangeData &value) { QQuickItem::itemChange(change, value); - if (m_initialized && change == QQuickItem::ItemSceneChange) - m_client->windowChanged(); + if (change == QQuickItem::ItemSceneChange) { + foreach (const QMetaObject::Connection &c, m_windowConnections) + disconnect(c); + m_windowConnections.clear(); + if (value.window) { + m_windowConnections.append(connect(value.window, SIGNAL(xChanged(int)), SLOT(onWindowPosChanged()))); + m_windowConnections.append(connect(value.window, SIGNAL(yChanged(int)), SLOT(onWindowPosChanged()))); + } + + if (m_initialized) + m_client->windowChanged(); + } } QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { return m_client->updatePaintNode(oldNode); } + +void RenderWidgetHostViewQtDelegateQuick::onWindowPosChanged() +{ + m_client->windowBoundsChanged(); +} diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h index 1d79a101c..a6dfe1719 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h @@ -86,8 +86,12 @@ protected: virtual void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE; virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE; +private slots: + void onWindowPosChanged(); + private: RenderWidgetHostViewQtDelegateClient *m_client; + QList m_windowConnections; bool m_isPopup; bool m_initialized; }; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 3d4906390..e8f34a1ea 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -227,11 +227,6 @@ QRectF QWebEnginePagePrivate::viewportRect() const return view ? view->rect() : QRectF(); } -QPoint QWebEnginePagePrivate::mapToGlobal(const QPoint &posInView) const -{ - return view ? view->mapToGlobal(posInView) : QPoint(); -} - qreal QWebEnginePagePrivate::dpiScale() const { return 1.0; diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 12f888064..f2f038e41 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -118,7 +118,6 @@ public: virtual void didUpdateTargetURL(const QUrl&) Q_DECL_OVERRIDE; virtual void selectionChanged() Q_DECL_OVERRIDE; virtual QRectF viewportRect() const Q_DECL_OVERRIDE; - virtual QPoint mapToGlobal(const QPoint &posInView) const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; virtual void loadStarted(const QUrl &provisionalUrl) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; 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 2fb03f02e..36ea5015f 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp @@ -201,6 +201,22 @@ void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent m_client->notifyResize(); } +void RenderWidgetHostViewQtDelegateWidget::showEvent(QShowEvent *event) +{ + QOpenGLWidget::showEvent(event); + // We don't have a way to catch a top-level window change with QWidget + // but a widget will most likely be shown again if it changes, so do + // the reconnection at this point. + foreach (const QMetaObject::Connection &c, m_windowConnections) + disconnect(c); + m_windowConnections.clear(); + if (QWindow *w = window()) { + m_windowConnections.append(connect(w, SIGNAL(xChanged(int)), SLOT(onWindowPosChanged()))); + m_windowConnections.append(connect(w, SIGNAL(yChanged(int)), SLOT(onWindowPosChanged()))); + } + m_client->windowChanged(); +} + bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) { bool handled = false; @@ -248,3 +264,8 @@ void RenderWidgetHostViewQtDelegateWidget::paintGL() m_sgRenderer->renderScene(defaultFramebufferObject()); } + +void RenderWidgetHostViewQtDelegateWidget::onWindowPosChanged() +{ + m_client->windowBoundsChanged(); +} diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h index 68553b8e8..756ad3c14 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h @@ -58,8 +58,8 @@ class QSGRootNode; class QWindow; QT_END_NAMESPACE -class RenderWidgetHostViewQtDelegateWidget : public QOpenGLWidget, public RenderWidgetHostViewQtDelegate -{ +class RenderWidgetHostViewQtDelegateWidget : public QOpenGLWidget, public RenderWidgetHostViewQtDelegate { + Q_OBJECT public: RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent = 0); @@ -81,13 +81,17 @@ public: virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; protected: - bool event(QEvent *event); - void resizeEvent(QResizeEvent *resizeEvent); + bool event(QEvent *event) Q_DECL_OVERRIDE; + void resizeEvent(QResizeEvent *resizeEvent) Q_DECL_OVERRIDE; + void showEvent(QShowEvent *) Q_DECL_OVERRIDE; void initializeGL() Q_DECL_OVERRIDE; void paintGL() Q_DECL_OVERRIDE; QVariant inputMethodQuery(Qt::InputMethodQuery query) const; +private slots: + void onWindowPosChanged(); + private: RenderWidgetHostViewQtDelegateClient *m_client; // Put the root node first to make sure it gets destroyed after the SG renderer. @@ -95,6 +99,7 @@ private: QScopedPointer m_sgEngine; QScopedPointer m_sgRenderer; bool m_isPopup; + QList m_windowConnections; }; #endif -- cgit v1.2.3