summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2016-03-01 17:04:24 +0100
committerChristian Stromme <christian.stromme@theqtcompany.com>2016-03-03 15:50:17 +0000
commit10134cf8a9e0c89a016e1d31fd70377f174ab693 (patch)
tree242301468390cf45b62e2c3aa30c0daef90c1d37
parentd245351578234e0149604470aa326241c676ed17 (diff)
Make it possible to put a WebView inside a QQuickWidget on iOS
When setting the parent view of the WebvView we need to use the real window, and not the off-screen window provided by QQuickWidget. This change also improves the logic for setting the geometry, as extra care is needed to make sure the view is position correctly inside the scene when using a QQuickWidget. Task-number: QTBUG-48221 Change-Id: I476cac926df6c862cc3602b21e97003cc254726c Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
-rw-r--r--src/webview/qwebview_ios.mm28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/webview/qwebview_ios.mm b/src/webview/qwebview_ios.mm
index f622b6b..ef0865b 100644
--- a/src/webview/qwebview_ios.mm
+++ b/src/webview/qwebview_ios.mm
@@ -38,7 +38,8 @@
#include "qwebview_p.h"
#include "qwebviewloadrequest_p.h"
-#include <QtQuick/qquickitem.h>
+#include <QtQuick/qquickwindow.h>
+#include <QtQuick/qquickrendercontrol.h>
#include <QtCore/qmap.h>
#include <CoreFoundation/CoreFoundation.h>
@@ -252,9 +253,11 @@ void QIosWebViewPrivate::setParentView(QObject *view)
if (!uiWebView)
return;
- QWindow *window = qobject_cast<QWindow *>(view);
- if (window != 0) {
- UIView *parentView = reinterpret_cast<UIView *>(window->winId());
+ QQuickWindow *qw = qobject_cast<QQuickWindow *>(view);
+ if (qw) {
+ // Before setting the parent view, make sure we have the real window.
+ QWindow *rw = QQuickRenderControl::renderWindowFor(qw);
+ UIView *parentView = reinterpret_cast<UIView *>(rw ? rw->winId() : qw->winId());
[parentView addSubview:uiWebView];
} else {
[uiWebView removeFromSuperview];
@@ -268,7 +271,22 @@ QObject *QIosWebViewPrivate::parentView() const
void QIosWebViewPrivate::setGeometry(const QRect &geometry)
{
- [uiWebView setFrame:toCGRect(geometry)];
+ if (!uiWebView)
+ return;
+
+ QWindow *w = qobject_cast<QWindow *>(m_parentView);
+ if (w == 0)
+ return;
+
+ // Find the top left position of this item in global coordinates.
+ const QPoint &tl = w->mapToGlobal(geometry.topLeft());
+ // Map the top left position to the render windows coordinates.
+ QQuickWindow *qw = qobject_cast<QQuickWindow *>(m_parentView);
+ QWindow *rw = QQuickRenderControl::renderWindowFor(qw);
+ // New geometry
+ const QRect &newGeometry = rw ? QRect(rw->mapFromGlobal(tl), geometry.size()) : geometry;
+ // Sets location and size in the superviews coordinate system.
+ [uiWebView setFrame:toCGRect(newGeometry)];
}
void QIosWebViewPrivate::setVisibility(QWindow::Visibility visibility)