summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-08-28 04:54:46 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-08-28 04:54:46 (GMT)
commit1a742b1a1c646d7941f3f714b21c2ef927a0390b (patch)
tree27415deffc45d6c6cfc9d4ac6fdd9ea276b7b79a
parent9f5ab512b6293c28367052c46b12413f2f70b181 (diff)
downloadQt-1a742b1a1c646d7941f3f714b21c2ef927a0390b.zip
Qt-1a742b1a1c646d7941f3f714b21c2ef927a0390b.tar.gz
Qt-1a742b1a1c646d7941f3f714b21c2ef927a0390b.tar.bz2
New window creation in WebView.
-rw-r--r--examples/declarative/webview/newwindows.html3
-rw-r--r--examples/declarative/webview/newwindows.qml28
-rw-r--r--src/declarative/fx/qfxwebview.cpp103
-rw-r--r--src/declarative/fx/qfxwebview.h12
4 files changed, 145 insertions, 1 deletions
diff --git a/examples/declarative/webview/newwindows.html b/examples/declarative/webview/newwindows.html
new file mode 100644
index 0000000..f169599
--- /dev/null
+++ b/examples/declarative/webview/newwindows.html
@@ -0,0 +1,3 @@
+<h1>Multiple windows...</h1>
+
+<a target="_blank" href="newwindows.html">Popup!</a>
diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml
new file mode 100644
index 0000000..7fd9d63
--- /dev/null
+++ b/examples/declarative/webview/newwindows.qml
@@ -0,0 +1,28 @@
+// Demonstrates opening new WebViews from HTML
+//
+// Note that to open windows from JavaScript, you will need to
+// allow it with WebView.settings.javascriptCanOpenWindows: true
+
+import Qt 4.6
+
+Row {
+ id: Pages
+ height: 200
+ resources: [
+ Component {
+ id: WebViewPage
+ Rectangle {
+ width: WV.width
+ height: WV.height
+ WebView {
+ id: WV
+ newWindowComponent: WebViewPage
+ newWindowParent: Pages
+ url: "newwindows.html"
+ }
+ }
+ }
+ ]
+ width: 500
+ ComponentInstance { component: WebViewPage }
+}
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index 46f1c1a..b150ca0 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -167,7 +167,9 @@ class QFxWebViewPrivate : public QFxPaintedItemPrivate
public:
QFxWebViewPrivate()
: QFxPaintedItemPrivate(), page(0), idealwidth(0), idealheight(0),
- progress(1.0), status(QFxWebView::Null), pending(PendingNone), windowObjects(this)
+ progress(1.0), status(QFxWebView::Null), pending(PendingNone),
+ newWindowComponent(0), newWindowParent(0),
+ windowObjects(this)
{
}
@@ -184,6 +186,8 @@ public:
QString pending_string;
QByteArray pending_data;
mutable QFxWebSettings settings;
+ QmlComponent *newWindowComponent;
+ QFxItem *newWindowParent;
void updateWindowObjects();
class WindowObjectList : public QmlConcreteList<QObject *>
@@ -1099,6 +1103,95 @@ QWebSettings *QFxWebView::settings() const
return page()->settings();
}
+QFxWebView *QFxWebView::createWindow(QWebPage::WebWindowType type)
+{
+ Q_D(QFxWebView);
+ switch (type) {
+ case QWebPage::WebBrowserWindow: {
+ if (!d->newWindowComponent && d->newWindowParent)
+ qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored");
+ else if (d->newWindowComponent && !d->newWindowParent)
+ qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored");
+ else if (d->newWindowComponent && d->newWindowParent) {
+ QFxWebView *webview = 0;
+ QmlContext *windowContext = new QmlContext(qmlContext(this));
+
+ QObject *nobj = d->newWindowComponent->create(windowContext);
+ if (nobj) {
+ windowContext->setParent(nobj);
+ QFxItem *item = qobject_cast<QFxItem *>(nobj);
+ if (!item) {
+ delete nobj;
+ } else {
+ webview = item->findChild<QFxWebView*>();
+ if (!webview) {
+ delete item;
+ } else {
+ item->setParent(d->newWindowParent);
+ }
+ }
+ } else {
+ delete windowContext;
+ }
+
+ return webview;
+ }
+ }
+ break;
+ case QWebPage::WebModalDialog: {
+ // Not supported
+ }
+ }
+ return 0;
+}
+
+/*!
+ \qmlproperty component WebView::newWindowComponent
+
+ This property holds the component to use for new windows.
+ The component must have a WebView somewhere in its structure.
+
+ When the web engine requests a new window, it will be an instance of
+ this component.
+
+ The parent of the new window is set by newWindowParent. It must be set.
+*/
+QmlComponent *QFxWebView::newWindowComponent() const
+{
+ Q_D(const QFxWebView);
+ return d->newWindowComponent;
+}
+
+void QFxWebView::setNewWindowComponent(QmlComponent *newWindow)
+{
+ Q_D(QFxWebView);
+ delete d->newWindowComponent;
+ d->newWindowComponent = newWindow;
+}
+
+
+/*!
+ \qmlproperty item WebView::newWindowParent
+
+ The parent item for new windows.
+
+ \sa newWindowComponent
+*/
+QFxItem *QFxWebView::newWindowParent() const
+{
+ Q_D(const QFxWebView);
+ return d->newWindowParent;
+}
+
+void QFxWebView::setNewWindowParent(QFxItem *parent)
+{
+ Q_D(QFxWebView);
+ delete d->newWindowParent;
+ d->newWindowParent = parent;
+}
+
+
+
/*!
\internal
\class QFxWebPage
@@ -1206,6 +1299,14 @@ QObject *QFxWebPage::createPlugin(const QString &, const QUrl &url, const QStrin
return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues);
}
+QWebPage *QFxWebPage::createWindow(WebWindowType type)
+{
+ QFxWebView *newView = viewItem()->createWindow(type);
+ if (newView)
+ return newView->page();
+ return 0;
+}
+
QT_END_NAMESPACE
#include "qfxwebview.moc"
diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h
index 5a42ec4..c8fd7a0 100644
--- a/src/declarative/fx/qfxwebview.h
+++ b/src/declarative/fx/qfxwebview.h
@@ -69,6 +69,8 @@ public:
~QFxWebPage();
protected:
QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
+ QWebPage *createWindow(WebWindowType type);
+
private:
QFxWebView *viewItem();
};
@@ -111,6 +113,9 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem
Q_PROPERTY(QmlList<QObject *>* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT)
+ Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent)
+ Q_PROPERTY(QFxItem* newWindowParent READ newWindowParent WRITE setNewWindowParent)
+
public:
QFxWebView(QFxItem *parent=0);
~QFxWebView();
@@ -166,6 +171,11 @@ public:
static QFxWebViewAttached *qmlAttachedProperties(QObject *);
+ QmlComponent *newWindowComponent() const;
+ void setNewWindowComponent(QmlComponent *newWindow);
+ QFxItem *newWindowParent() const;
+ void setNewWindowParent(QFxItem *newWindow);
+
Q_SIGNALS:
void preferredWidthChanged();
void preferredHeightChanged();
@@ -212,12 +222,14 @@ protected:
const QRectF &oldGeometry);
virtual void focusChanged(bool);
virtual bool sceneEvent(QEvent *event);
+ QFxWebView *createWindow(QWebPage::WebWindowType type);
private:
void init();
virtual void componentComplete();
Q_DISABLE_COPY(QFxWebView)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxWebView)
+ friend class QFxWebPage;
};
QT_END_NAMESPACE