diff options
author | Christian Strømme <[email protected]> | 2015-04-20 16:46:31 +0200 |
---|---|---|
committer | Christian Stromme <[email protected]> | 2015-04-24 15:58:52 +0000 |
commit | 463265940da7df5c1a972b039bf3ec937039ea34 (patch) | |
tree | ba12df2982748d9841e01b10a9daaf94d4da7b79 | |
parent | 7cc9a00b1bb3f2341894c54b248a742285e37463 (diff) |
Update the geometry of the native view when the scene changes.
This is need to correctly position the native view when we have a scene
that might change its position or size, e.g., in a Widget application
where a QQuickWidget is the scene.
Task-number: QTBUG-43391
Change-Id: I3dca2401ddae06d8c65e69fbfec20bdd205c0937
Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
-rw-r--r-- | src/webview/qnativeviewcontroller_p.h | 2 | ||||
-rw-r--r-- | src/webview/qquickviewcontroller.cpp | 20 | ||||
-rw-r--r-- | src/webview/qquickviewcontroller_p.h | 3 | ||||
-rw-r--r-- | src/webview/qwebview.cpp | 6 | ||||
-rw-r--r-- | src/webview/qwebview_android.cpp | 5 | ||||
-rw-r--r-- | src/webview/qwebview_android_p.h | 1 | ||||
-rw-r--r-- | src/webview/qwebview_ios.mm | 7 | ||||
-rw-r--r-- | src/webview/qwebview_ios_p.h | 2 | ||||
-rw-r--r-- | src/webview/qwebview_osx.mm | 5 | ||||
-rw-r--r-- | src/webview/qwebview_osx_p.h | 1 | ||||
-rw-r--r-- | src/webview/qwebview_p.h | 1 |
11 files changed, 50 insertions, 3 deletions
diff --git a/src/webview/qnativeviewcontroller_p.h b/src/webview/qnativeviewcontroller_p.h index d7c49fd..92c9d96 100644 --- a/src/webview/qnativeviewcontroller_p.h +++ b/src/webview/qnativeviewcontroller_p.h @@ -40,6 +40,7 @@ #include "qwebview_global.h" #include <QtCore/qrect.h> #include <QtGui/qwindow.h> +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE @@ -48,6 +49,7 @@ class QNativeViewController public: virtual ~QNativeViewController() {} virtual void setParentView(QObject *view) = 0; + virtual QObject *parentView() const = 0; virtual void setGeometry(const QRect &geometry) = 0; virtual void setVisibility(QWindow::Visibility visibility) = 0; virtual void setVisible(bool visible) = 0; diff --git a/src/webview/qquickviewcontroller.cpp b/src/webview/qquickviewcontroller.cpp index 35e6017..d2415c1 100644 --- a/src/webview/qquickviewcontroller.cpp +++ b/src/webview/qquickviewcontroller.cpp @@ -184,17 +184,31 @@ void QQuickViewController::setView(QNativeViewController *view) m_view = view; } +void QQuickViewController::scheduleUpdatePolish() +{ + polish(); +} + void QQuickViewController::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { QQuickItem::geometryChanged(newGeometry, oldGeometry); if (newGeometry.isValid()) - m_view->setGeometry(mapRectToScene(clipRect()).toRect()); - else - qWarning() << __FUNCTION__ << "Invalid geometry: " << newGeometry; + polish(); } void QQuickViewController::onWindowChanged(QQuickWindow* window) { + QQuickWindow *oldParent = qobject_cast<QQuickWindow *>(m_view->parentView()); + if (oldParent != 0) + oldParent->disconnect(this); + + if (window != 0) { + connect(window, &QQuickWindow::widthChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::heightChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::xChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::yChanged, this, &QQuickViewController::scheduleUpdatePolish); + } + m_view->setParentView(window); } diff --git a/src/webview/qquickviewcontroller_p.h b/src/webview/qquickviewcontroller_p.h index fd20bfd..7d1b371 100644 --- a/src/webview/qquickviewcontroller_p.h +++ b/src/webview/qquickviewcontroller_p.h @@ -80,6 +80,9 @@ private: friend class QQuickWebView; QNativeViewController *m_view; QScopedPointer<QQuickViewChangeListener> m_changeListener; + +private Q_SLOTS: + void scheduleUpdatePolish(); }; QT_END_NAMESPACE diff --git a/src/webview/qwebview.cpp b/src/webview/qwebview.cpp index 88d35fa..43f79f3 100644 --- a/src/webview/qwebview.cpp +++ b/src/webview/qwebview.cpp @@ -127,6 +127,12 @@ void QWebView::setParentView(QObject *view) d->setParentView(view); } +QObject *QWebView::parentView() const +{ + Q_D(const QWebView); + return d->parentView(); +} + void QWebView::setGeometry(const QRect &geometry) { Q_D(QWebView); diff --git a/src/webview/qwebview_android.cpp b/src/webview/qwebview_android.cpp index 505b827..fb880ee 100644 --- a/src/webview/qwebview_android.cpp +++ b/src/webview/qwebview_android.cpp @@ -212,6 +212,11 @@ void QAndroidWebViewPrivate::setParentView(QObject *view) m_window->setParent(qobject_cast<QWindow *>(view)); } +QObject *QAndroidWebViewPrivate::parentView() const +{ + return m_window->parent(); +} + void QAndroidWebViewPrivate::stop() { m_viewController.callMethod<void>("stopLoading"); diff --git a/src/webview/qwebview_android_p.h b/src/webview/qwebview_android_p.h index 4a799e9..9290289 100644 --- a/src/webview/qwebview_android_p.h +++ b/src/webview/qwebview_android_p.h @@ -73,6 +73,7 @@ public: bool isLoading() const Q_DECL_OVERRIDE; void setParentView(QObject *view) Q_DECL_OVERRIDE; + QObject *parentView() const Q_DECL_OVERRIDE; void setGeometry(const QRect &geometry) Q_DECL_OVERRIDE; void setVisibility(QWindow::Visibility visibility) Q_DECL_OVERRIDE; void setVisible(bool visible) Q_DECL_OVERRIDE; diff --git a/src/webview/qwebview_ios.mm b/src/webview/qwebview_ios.mm index 0b3ec43..f5984b2 100644 --- a/src/webview/qwebview_ios.mm +++ b/src/webview/qwebview_ios.mm @@ -247,6 +247,8 @@ bool QIosWebViewPrivate::isLoading() const void QIosWebViewPrivate::setParentView(QObject *view) { + m_parentView = view; + if (!uiWebView) return; @@ -259,6 +261,11 @@ void QIosWebViewPrivate::setParentView(QObject *view) } } +QObject *QIosWebViewPrivate::parentView() const +{ + return m_parentView; +} + void QIosWebViewPrivate::setGeometry(const QRect &geometry) { [uiWebView setFrame:toCGRect(geometry)]; diff --git a/src/webview/qwebview_ios_p.h b/src/webview/qwebview_ios_p.h index 0345426..840e358 100644 --- a/src/webview/qwebview_ios_p.h +++ b/src/webview/qwebview_ios_p.h @@ -75,6 +75,7 @@ public: bool isLoading() const Q_DECL_OVERRIDE; void setParentView(QObject *view) Q_DECL_OVERRIDE; + QObject *parentView() const Q_DECL_OVERRIDE; void setGeometry(const QRect &geometry) Q_DECL_OVERRIDE; void setVisibility(QWindow::Visibility visibility) Q_DECL_OVERRIDE; void setVisible(bool visible) Q_DECL_OVERRIDE; @@ -95,6 +96,7 @@ public: UIWebView *uiWebView; UIGestureRecognizer *m_recognizer; int requestFrameCount; + QPointer<QObject> m_parentView; }; QT_END_NAMESPACE diff --git a/src/webview/qwebview_osx.mm b/src/webview/qwebview_osx.mm index 2b7fdb5..9668064 100644 --- a/src/webview/qwebview_osx.mm +++ b/src/webview/qwebview_osx.mm @@ -212,6 +212,11 @@ void QOsxWebViewPrivate::setParentView(QObject *view) m_window->setParent(qobject_cast<QWindow *>(view)); } +QObject *QOsxWebViewPrivate::parentView() const +{ + return m_window->parent(); +} + void QOsxWebViewPrivate::setGeometry(const QRect &geometry) { m_window->setGeometry(geometry); diff --git a/src/webview/qwebview_osx_p.h b/src/webview/qwebview_osx_p.h index 7ee0b2e..bacd70b 100644 --- a/src/webview/qwebview_osx_p.h +++ b/src/webview/qwebview_osx_p.h @@ -75,6 +75,7 @@ public: void runJavaScriptPrivate(const QString& script, int callbackId); void setParentView(QObject *view) Q_DECL_OVERRIDE; + QObject *parentView() const Q_DECL_OVERRIDE; void setGeometry(const QRect &geometry) Q_DECL_OVERRIDE; void setVisibility(QWindow::Visibility visibility) Q_DECL_OVERRIDE; void setVisible(bool visible) Q_DECL_OVERRIDE; diff --git a/src/webview/qwebview_p.h b/src/webview/qwebview_p.h index 68ae4ad..baeda60 100644 --- a/src/webview/qwebview_p.h +++ b/src/webview/qwebview_p.h @@ -86,6 +86,7 @@ public: bool isLoading() const Q_DECL_OVERRIDE; void setParentView(QObject *view) Q_DECL_OVERRIDE; + QObject *parentView() const Q_DECL_OVERRIDE; void setGeometry(const QRect &geometry) Q_DECL_OVERRIDE; void setVisibility(QWindow::Visibility visibility) Q_DECL_OVERRIDE; void setVisible(bool visible) Q_DECL_OVERRIDE; |