summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2016-04-01 16:32:56 +0200
committerChristian Stromme <christian.stromme@theqtcompany.com>2016-04-15 13:33:52 +0000
commit87cc3318cbd0aba2388e9c2623eb085b48db4e6c (patch)
treea1904f7021dd95ec17c342c95f7334604b831bcc
parentdd99ce27b73923823dc19a4a3273cd8bce5193e3 (diff)
Fix geometry updates in the view controller.
Move the common, and QtQuick specific code, into the view controller to make the behavior more consistent across all platforms. Change-Id: I89cc383fb92ee6755e8fba9baf48e3e756d04cca Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
-rw-r--r--src/webview/qquickviewcontroller.cpp34
-rw-r--r--src/webview/qwebview_android.cpp8
-rw-r--r--src/webview/qwebview_ios.mm25
-rw-r--r--src/webview/webview.pro2
4 files changed, 38 insertions, 31 deletions
diff --git a/src/webview/qquickviewcontroller.cpp b/src/webview/qquickviewcontroller.cpp
index f6dae31..0295d1f 100644
--- a/src/webview/qquickviewcontroller.cpp
+++ b/src/webview/qquickviewcontroller.cpp
@@ -41,6 +41,7 @@
#include <QtQuick/QQuickWindow>
#include <QtCore/QDebug>
+#include <QtQuick/qquickrendercontrol.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickitemchangelistener_p.h>
@@ -182,8 +183,33 @@ void QQuickViewController::updatePolish()
if (m_view == 0)
return;
- const QRectF &cr = clipRect();
- m_view->setGeometry(cr.isValid() ? mapRectToScene(cr).toRect() : QRect(-1, -1, 1, 1));
+ QSize itemSize = QSize(width(), height());
+ if (!itemSize.isValid())
+ return;
+
+ QQuickWindow *w = window();
+ if (w == 0)
+ return;
+
+ // Find this item's geometry in the scene.
+ QRect itemGeometry = mapRectToScene(QRect(QPoint(0, 0), itemSize)).toRect();
+ // Check if we should be clipped to our parent's shape
+ // Note: This is crude but it should give an acceptable result on all platforms.
+ QQuickItem *p = parentItem();
+ const bool clip = p != 0 ? p->clip() : false;
+ if (clip) {
+ const QSize &parentSize = QSize(p->width(), p->height());
+ const QRect &parentGeometry = p->mapRectToScene(QRect(QPoint(0, 0), parentSize)).toRect();
+ itemGeometry &= parentGeometry;
+ itemSize = itemGeometry.size();
+ }
+
+ // Find the top left position of this item, in global coordinates.
+ const QPoint &tl = w->mapToGlobal(itemGeometry.topLeft());
+ // Get the actual render window, in case we're rendering into a off-screen window.
+ QWindow *rw = QQuickRenderControl::renderWindowFor(w);
+
+ m_view->setGeometry(rw ? QRect(rw->mapFromGlobal(tl), itemSize) : itemGeometry);
m_view->setVisible(isVisible());
}
@@ -220,7 +246,9 @@ void QQuickViewController::onWindowChanged(QQuickWindow* window)
connect(window, &QQuickWindow::sceneGraphInvalidated, this, &QQuickViewController::onSceneGraphInvalidated);
}
- m_view->setParentView(window);
+ // Check if there's an actual window available.
+ QWindow *rw = QQuickRenderControl::renderWindowFor(window);
+ m_view->setParentView(rw ? rw : window);
}
void QQuickViewController::onVisibleChanged()
diff --git a/src/webview/qwebview_android.cpp b/src/webview/qwebview_android.cpp
index 7050173..54f6a3d 100644
--- a/src/webview/qwebview_android.cpp
+++ b/src/webview/qwebview_android.cpp
@@ -175,13 +175,7 @@ void QAndroidWebViewPrivate::setGeometry(const QRect &geometry)
if (m_window == 0)
return;
- QRect newGeometry = geometry;
- const QWindow *parent = m_window->parent();
-
- if (parent != 0)
- newGeometry.moveTo(parent->mapToGlobal(geometry.topLeft()));
-
- m_window->setGeometry(newGeometry);
+ m_window->setGeometry(geometry);
}
void QAndroidWebViewPrivate::setVisibility(QWindow::Visibility visibility)
diff --git a/src/webview/qwebview_ios.mm b/src/webview/qwebview_ios.mm
index ef0865b..3936eb4 100644
--- a/src/webview/qwebview_ios.mm
+++ b/src/webview/qwebview_ios.mm
@@ -38,9 +38,8 @@
#include "qwebview_p.h"
#include "qwebviewloadrequest_p.h"
-#include <QtQuick/qquickwindow.h>
-#include <QtQuick/qquickrendercontrol.h>
#include <QtCore/qmap.h>
+#include <QtCore/qvariant.h>
#include <CoreFoundation/CoreFoundation.h>
#include <UIKit/UIKit.h>
@@ -253,11 +252,9 @@ void QIosWebViewPrivate::setParentView(QObject *view)
if (!uiWebView)
return;
- 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());
+ QWindow *w = qobject_cast<QWindow *>(view);
+ if (w) {
+ UIView *parentView = reinterpret_cast<UIView *>(w->winId());
[parentView addSubview:uiWebView];
} else {
[uiWebView removeFromSuperview];
@@ -274,19 +271,7 @@ void QIosWebViewPrivate::setGeometry(const QRect &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)];
+ [uiWebView setFrame:toCGRect(geometry)];
}
void QIosWebViewPrivate::setVisibility(QWindow::Visibility visibility)
diff --git a/src/webview/webview.pro b/src/webview/webview.pro
index 83ef4c0..452a3cc 100644
--- a/src/webview/webview.pro
+++ b/src/webview/webview.pro
@@ -1,7 +1,7 @@
TARGET = QtWebView
QT =
-QT_FOR_PRIVATE = quick-private
+QT_FOR_PRIVATE = quick-private gui-private
include($$PWD/webview-lib.pri)