summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-24 20:02:56 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-24 20:02:56 +0200
commit44b7e5650ab0627bb86274930c8f62f8f312a3d6 (patch)
treea03e5340af5ae47c1db323c2142b79a7e6f07122
parent4a97b966218165cbce0fbacf544961f7add76033 (diff)
parent8618811a5220f5456f012179abc743e08120adf3 (diff)
Merge remote-tracking branch 'origin/5.7' into dev
-rw-r--r--examples/webview/minibrowser/minibrowser.pro2
-rw-r--r--src/webview/doc/qtwebview.qdocconf2
-rw-r--r--src/webview/qquickviewcontroller.cpp34
-rw-r--r--src/webview/qwebview_android.cpp39
-rw-r--r--src/webview/qwebview_ios.mm25
-rw-r--r--src/webview/webview.pro2
6 files changed, 39 insertions, 65 deletions
diff --git a/examples/webview/minibrowser/minibrowser.pro b/examples/webview/minibrowser/minibrowser.pro
index be7a348..4460e6a 100644
--- a/examples/webview/minibrowser/minibrowser.pro
+++ b/examples/webview/minibrowser/minibrowser.pro
@@ -3,8 +3,6 @@ TARGET = minibrowser
QT += qml quick webview
-winrt: WINRT_MANIFEST.capabilities += internetClient
-
SOURCES += main.cpp
RESOURCES += qml.qrc
diff --git a/src/webview/doc/qtwebview.qdocconf b/src/webview/doc/qtwebview.qdocconf
index 90a4170..ae7e25c 100644
--- a/src/webview/doc/qtwebview.qdocconf
+++ b/src/webview/doc/qtwebview.qdocconf
@@ -34,7 +34,7 @@ sourcedirs += ../ ../../imports/ ../
exampledirs += ../../../examples/webview
imagedirs += images
-examplesinstallpath = qtwebview/webview
+examplesinstallpath = webview
depends = qtcore qtdoc qtquick qtqml
Cpp.ignoretokens += Q_WEBVIEW_EXPORT
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 d47e61d..54f6a3d 100644
--- a/src/webview/qwebview_android.cpp
+++ b/src/webview/qwebview_android.cpp
@@ -47,26 +47,9 @@
#include <QtCore/qjsonobject.h>
#include <QtCore/qurl.h>
#include <QtCore/qdebug.h>
-#include <QtCore/qrunnable.h>
QT_BEGIN_NAMESPACE
-static inline bool setClipRect(const QJNIObjectPrivate &view, const QRect &clipRect)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 18)
- return false;
-
- if (!view.isValid())
- return false;
-
- QtAndroidPrivate::runOnAndroidThread([view, clipRect] {
- QJNIObjectPrivate cr("android/graphics/Rect", "(IIII)V", 0, 0, clipRect.width(), clipRect.height());
- view.callMethod<void>("setClipBounds", "(Landroid/graphics/Rect;)V", cr.object());
- }, QJNIEnvironmentPrivate());
-
- return true;
-}
-
QWebViewPrivate *QWebViewPrivate::create(QWebView *q)
{
return new QAndroidWebViewPrivate(q);
@@ -192,27 +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()));
- const QRect parentGlobalRect(parent->mapToGlobal(QPoint(0, 0)), parent->geometry().size());
- const QRect clipRect = parentGlobalRect & newGeometry;
- if (clipRect != newGeometry) {
- const bool clipIsSet = setClipRect(m_webView, clipRect);
- const bool topLeftChanged = newGeometry.topLeft() != clipRect.topLeft();
- if (topLeftChanged && clipIsSet)
- newGeometry.moveTo(clipRect.topLeft());
-
- // If setting the clip rect fails, e.g., if the API level is lower then 18, then we'll
- // cheat by simply re-sizing the view.
- if (!clipIsSet)
- newGeometry = clipRect;
- }
- }
-
- 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)