[Qt] Add WebView.view attached property support for dialogs in QML
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Nov 2011 13:28:27 +0000 (13:28 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Nov 2011 13:28:27 +0000 (13:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72825

Reviewed by Simon Hausmann.

.:

Export QQuickWebViewAttached.

* Source/qtwebkit-export.map:

Source/WebKit2:

When creating new dialogs, fill their WebView.view attached property
with the WebView that's creating them. This follows the same pattern
as QtQuick's ListView, enabling the usage of the same dialog component
for different WebViews.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::runJavaScriptAlert):
(QQuickWebViewPrivate::runJavaScriptConfirm):
(QQuickWebViewPrivate::runJavaScriptPrompt):
(QQuickWebViewPrivate::setViewInAttachedProperties):
(QQuickWebViewAttached::QQuickWebViewAttached):
(QQuickWebViewAttached::setView):
(QQuickWebView::qmlAttachedProperties):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
* UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml:
* UIProcess/qt/QtDialogRunner.h:
(QtDialogRunner::dialog):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml
Source/WebKit2/UIProcess/qt/QtDialogRunner.h
Source/qtwebkit-export.map

index 97b8f7c..06a7aa8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-21  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] Add WebView.view attached property support for dialogs in QML
+        https://bugs.webkit.org/show_bug.cgi?id=72825
+
+        Reviewed by Simon Hausmann.
+
+        Export QQuickWebViewAttached.
+
+        * Source/qtwebkit-export.map:
+
 2011-11-21  Noel Gordon  <noel.gordon@gmail.com>
 
         Update .gitignore for latest WebKitLibraries
index a2bde7c..2d41253 100644 (file)
@@ -1,3 +1,29 @@
+2011-11-21  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] Add WebView.view attached property support for dialogs in QML
+        https://bugs.webkit.org/show_bug.cgi?id=72825
+
+        Reviewed by Simon Hausmann.
+
+        When creating new dialogs, fill their WebView.view attached property
+        with the WebView that's creating them. This follows the same pattern
+        as QtQuick's ListView, enabling the usage of the same dialog component
+        for different WebViews.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::runJavaScriptAlert):
+        (QQuickWebViewPrivate::runJavaScriptConfirm):
+        (QQuickWebViewPrivate::runJavaScriptPrompt):
+        (QQuickWebViewPrivate::setViewInAttachedProperties):
+        (QQuickWebViewAttached::QQuickWebViewAttached):
+        (QQuickWebViewAttached::setView):
+        (QQuickWebView::qmlAttachedProperties):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml:
+        * UIProcess/qt/QtDialogRunner.h:
+        (QtDialogRunner::dialog):
+
 2011-11-21  Jochen Eisinger  <jochen@chromium.org>
 
         Implement Meta referrer
index cd9f28d..82a9e19 100644 (file)
@@ -231,6 +231,7 @@ void QQuickWebViewPrivate::runJavaScriptAlert(const QString& alertText)
     QtDialogRunner dialogRunner;
     if (!dialogRunner.initForAlert(alertDialog, q, alertText))
         return;
+    setViewInAttachedProperties(dialogRunner.dialog());
 
     disableMouseEvents();
     dialogRunner.exec();
@@ -246,6 +247,7 @@ bool QQuickWebViewPrivate::runJavaScriptConfirm(const QString& message)
     QtDialogRunner dialogRunner;
     if (!dialogRunner.initForConfirm(confirmDialog, q, message))
         return true;
+    setViewInAttachedProperties(dialogRunner.dialog());
 
     disableMouseEvents();
     dialogRunner.exec();
@@ -267,6 +269,7 @@ QString QQuickWebViewPrivate::runJavaScriptPrompt(const QString& message, const
         ok = true;
         return defaultValue;
     }
+    setViewInAttachedProperties(dialogRunner.dialog());
 
     disableMouseEvents();
     dialogRunner.exec();
@@ -337,6 +340,13 @@ void QQuickWebViewPrivate::setUseTraditionalDesktopBehaviour(bool enable)
         initializeTouch(q);
 }
 
+void QQuickWebViewPrivate::setViewInAttachedProperties(QObject* object)
+{
+    Q_Q(QQuickWebView);
+    QQuickWebViewAttached* attached = static_cast<QQuickWebViewAttached*>(qmlAttachedPropertiesObject<QQuickWebView>(object));
+    attached->setView(q);
+}
+
 static QtPolicyInterface::PolicyAction toPolicyAction(QQuickWebView::NavigationPolicy policy)
 {
     switch (policy) {
@@ -385,6 +395,21 @@ void QQuickWebViewPrivate::setPageProxy(QtWebPageProxy* pageProxy)
     QObject::connect(pageProxy, SIGNAL(receivedMessageFromNavigatorQtObject(QVariantMap)), q, SIGNAL(messageReceived(QVariantMap)));
 }
 
+QQuickWebViewAttached::QQuickWebViewAttached(QObject* object)
+    : QObject(object)
+    , m_view(0)
+{
+
+}
+
+void QQuickWebViewAttached::setView(QQuickWebView* view)
+{
+    if (m_view == view)
+        return;
+    m_view = view;
+    emit viewChanged();
+}
+
 QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView)
     : QObject(webView)
     , q_ptr(webView)
@@ -567,6 +592,11 @@ QQuickWebViewExperimental* QQuickWebView::experimental() const
     return m_experimental;
 }
 
+QQuickWebViewAttached* QQuickWebView::qmlAttachedProperties(QObject* object)
+{
+    return new QQuickWebViewAttached(object);
+}
+
 void QQuickWebView::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
 {
     Q_D(QQuickWebView);
index 0ebb0aa..b0bad94 100644 (file)
@@ -26,6 +26,7 @@
 
 class QDeclarativeComponent;
 class QQuickWebPage;
+class QQuickWebViewAttached;
 class QQuickWebViewPrivate;
 class QQuickWebViewExperimental;
 class QWebDownloadItem;
@@ -86,6 +87,7 @@ public:
     QQuickWebPage* page();
 
     QQuickWebViewExperimental* experimental() const;
+    static QQuickWebViewAttached* qmlAttachedProperties(QObject*);
 
 public Q_SLOTS:
     void load(const QUrl&);
@@ -136,6 +138,24 @@ private:
 
 QML_DECLARE_TYPE(QQuickWebView)
 
+class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject {
+    Q_OBJECT
+    Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL)
+
+public:
+    QQuickWebViewAttached(QObject* object);
+    QQuickWebView* view() const { return m_view; }
+    void setView(QQuickWebView*);
+
+Q_SIGNALS:
+    void viewChanged();
+
+private:
+    QQuickWebView* m_view;
+};
+
+QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES)
+
 class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
     Q_OBJECT
     Q_PROPERTY(QDeclarativeComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged)
index 21872fe..e646c80 100644 (file)
@@ -109,6 +109,8 @@ private:
 
     bool isTransitioningToNewPage() const { return transitioningToNewPage; }
 
+    void setViewInAttachedProperties(QObject*);
+
     QScopedPointer<QQuickWebPage> pageView;
     QScopedPointer<QtViewportInteractionEngine> interactionEngine;
 
index bf0be41..d79d4f5 100644 (file)
@@ -16,7 +16,8 @@ WebView {
             running: true
             interval: 1
             onTriggered: {
-                webView.messageFromAlertDialog = message
+                // Testing both attached property and id defined in the Component context.
+                parent.WebView.view.messageFromAlertDialog = message
                 webView.modelMessageEqualsMessage = Boolean(model.message == message)
                 model.dismiss()
             }
@@ -28,7 +29,7 @@ WebView {
             running: true
             interval: 1
             onTriggered: {
-                webView.confirmCount += 1
+                parent.WebView.view.confirmCount += 1
                 if (message == "ACCEPT")
                     model.accept()
                 else
@@ -42,7 +43,7 @@ WebView {
             running: true
             interval: 1
             onTriggered: {
-                webView.promptCount += 1
+                parent.WebView.view.promptCount += 1
                 if (message == "REJECT")
                     model.reject()
                 else {
index fd1c9f3..bfa5302 100644 (file)
@@ -39,6 +39,8 @@ public:
     bool initForConfirm(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& message);
     bool initForPrompt(QDeclarativeComponent*, QQuickItem* dialogParent, const QString& message, const QString& defaultValue);
 
+    QQuickItem* dialog() const { return m_dialog.get(); }
+
     bool wasAccepted() const { return m_wasAccepted; }
     QString result() const { return m_result; }
 
index eca36bb..ad9ea4c 100644 (file)
@@ -108,6 +108,9 @@ qwk_1.0 {
         *QQuickWebViewPrivateExtension;
         non-virtual?thunk?to?QQuickWebViewPrivateExtension*;
         QQuickWebViewPrivateExtension::*;
+        *QQuickWebViewAttached;
+        non-virtual?thunk?to?QQuickWebViewAttached*;
+        QQuickWebViewAttached::*;
         *QQuickWebViewExperimental;
         non-virtual?thunk?to?QQuickWebViewExperimental*;
         QQuickWebViewExperimental::*;