[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.21-584-g1e41756

eric at webkit.org eric at webkit.org
Fri Feb 26 22:19:57 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit f8ed7725debf862fcf6471b5c0be96a22df1961c
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Feb 15 15:36:00 2010 +0000

    2010-02-15  Noam Rosenthal  <noam.rosenthal at nokia.com>
    
            Reviewed by Simon Hausmann.
    
            [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
            https://bugs.webkit.org/show_bug.cgi?id=34901
    
            When a signal/slot/property is of type QWebElement, it can seamlessly
            connect with JS objects that hold a WebCore element.
    
            New tests, see WebKit/qt/ChangeLog
    
            * bridge/qt/qt_runtime.cpp:
            (JSC::Bindings::QtWebElementRuntime::create): A proxy to QWebElement
            constructor
            (JSC::Bindings::QtWebElementRuntime::get): A proxy to
            QWebElement::element
            (JSC::Bindings::convertValueToQVariant): handle QWebElement
            (JSC::Bindings::convertQVariantToValue): handle QWebElement
    2010-02-15  Noam Rosenthal  <noam.rosenthal at nokia.com>
    
            Reviewed by Simon Hausmann.
    
            [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
            Add Q_DECLARE_METATYPE to QWebElement, add relevant tests to
            tst_qwebframe
            https://bugs.webkit.org/show_bug.cgi?id=34901
    
            * Api/qwebelement.h: declare metatype
            * tests/qwebframe/tst_qwebframe.cpp:
            (MyQObject::webElementProperty): new test for QWebElement
            (MyQObject::setWebElementProperty): new test for QWebElement
            (MyQObject::myOverloadedSlot): new test for QWebElement
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54775 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 71a4c2c..1c7acc0 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2010-02-15  Noam Rosenthal  <noam.rosenthal at nokia.com>
+
+        Reviewed by Simon Hausmann.
+
+        [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
+        https://bugs.webkit.org/show_bug.cgi?id=34901
+
+        When a signal/slot/property is of type QWebElement, it can seamlessly
+        connect with JS objects that hold a WebCore element.
+
+        New tests, see WebKit/qt/ChangeLog
+
+        * bridge/qt/qt_runtime.cpp:
+        (JSC::Bindings::QtWebElementRuntime::create): A proxy to QWebElement
+        constructor
+        (JSC::Bindings::QtWebElementRuntime::get): A proxy to
+        QWebElement::element
+        (JSC::Bindings::convertValueToQVariant): handle QWebElement
+        (JSC::Bindings::convertQVariantToValue): handle QWebElement
+
 2010-02-15  Pavel Feldman  <pfeldman at chromium.org>
 
         Not reviewed, Chromium build fix (force conversion of property names to
diff --git a/WebCore/bridge/qt/qt_runtime.cpp b/WebCore/bridge/qt/qt_runtime.cpp
index 9601a4a..ada9f01 100644
--- a/WebCore/bridge/qt/qt_runtime.cpp
+++ b/WebCore/bridge/qt/qt_runtime.cpp
@@ -29,7 +29,10 @@
 #include "JSArray.h"
 #include "JSByteArray.h"
 #include "JSDOMBinding.h"
+#include "JSDOMWindow.h"
+#include <JSFunction.h>
 #include "JSGlobalObject.h"
+#include "JSHTMLElement.h"
 #include "JSLock.h"
 #include "JSObject.h"
 #include "ObjectPrototype.h"
@@ -45,7 +48,7 @@
 #include "qt_instance.h"
 #include "qt_pixmapruntime.h"
 #include "qvarlengtharray.h"
-#include <JSFunction.h>
+#include "qwebelement.h"
 #include <limits.h>
 #include <runtime/Error.h>
 #include <runtime_array.h>
@@ -114,6 +117,21 @@ QDebug operator<<(QDebug dbg, const JSRealType &c)
 }
 #endif
 
+// this is here as a proxy, so we'd have a class to friend in QWebElement,
+// as getting/setting a WebCore in QWebElement is private
+class QtWebElementRuntime {
+public:
+    static QWebElement create(Element* element)
+    {
+        return QWebElement(element);
+    }
+
+    static Element* get(const QWebElement& element)
+    {
+        return element.m_element;
+    }
+};
+
 static JSRealType valueRealType(ExecState* exec, JSValue val)
 {
     if (val.isNumber())
@@ -722,6 +740,11 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
                 break;
             } else if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(hint))) {
                 ret = QtPixmapInstance::variantFromObject(object, static_cast<QMetaType::Type>(hint));
+            } else if (hint == (QMetaType::Type) qMetaTypeId<QWebElement>()) {
+                if (object && object->inherits(&JSHTMLElement::s_info))
+                    ret = QVariant::fromValue<QWebElement>(QtWebElementRuntime::create((static_cast<JSHTMLElement*>(object))->impl()));
+                else
+                    ret = QVariant::fromValue<QWebElement>(QWebElement());
             } else if (hint == (QMetaType::Type) qMetaTypeId<QVariant>()) {
                 if (value.isUndefinedOrNull()) {
                     if (distance)
@@ -854,6 +877,17 @@ JSValue convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, con
     if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(variant.type())))
         return QtPixmapInstance::createRuntimeObject(exec, root, variant);
 
+    if (type == qMetaTypeId<QWebElement>()) {
+        if (!root->globalObject()->inherits(&JSDOMWindow::s_info))
+            return jsUndefined();
+
+        Document* document = (static_cast<JSDOMWindow*>(root->globalObject()))->impl()->document();
+        if (!document)
+            return jsUndefined();
+
+        return toJS(exec, toJSDOMGlobalObject(document, exec), QtWebElementRuntime::get(variant.value<QWebElement>()));
+    }
+
     if (type == QMetaType::QVariantMap) {
         // create a new object, and stuff properties into it
         JSObject* ret = constructEmptyObject(exec);
diff --git a/WebKit/qt/Api/qwebelement.h b/WebKit/qt/Api/qwebelement.h
index 3833070..156d24b 100644
--- a/WebKit/qt/Api/qwebelement.h
+++ b/WebKit/qt/Api/qwebelement.h
@@ -32,6 +32,12 @@ namespace WebCore {
     class Node;
 }
 
+namespace JSC {
+namespace Bindings {
+    class QtWebElementRuntime;
+}
+}
+
 QT_BEGIN_NAMESPACE
 class QPainter;
 QT_END_NAMESPACE
@@ -153,6 +159,7 @@ private:
     friend class QWebHitTestResult;
     friend class QWebHitTestResultPrivate;
     friend class QWebPage;
+    friend class JSC::Bindings::QtWebElementRuntime;
 
     QWebElementPrivate* d;
     WebCore::Element* m_element;
@@ -255,4 +262,6 @@ private:
     QExplicitlySharedDataPointer<QWebElementCollectionPrivate> d;
 };
 
+Q_DECLARE_METATYPE(QWebElement)
+
 #endif // QWEBELEMENT_H
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index 4d33f7b..45a24d0 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,18 @@
+2010-02-15  Noam Rosenthal  <noam.rosenthal at nokia.com>
+
+        Reviewed by Simon Hausmann.
+
+        [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
+        Add Q_DECLARE_METATYPE to QWebElement, add relevant tests to
+        tst_qwebframe
+        https://bugs.webkit.org/show_bug.cgi?id=34901
+
+        * Api/qwebelement.h: declare metatype
+        * tests/qwebframe/tst_qwebframe.cpp:
+        (MyQObject::webElementProperty): new test for QWebElement
+        (MyQObject::setWebElementProperty): new test for QWebElement
+        (MyQObject::myOverloadedSlot): new test for QWebElement
+
 2010-02-15  Robert Hogan  <robert at roberthogan.net>, Jocelyn Turcotte  <jocelyn.turcotte at nokia.com>
 
         Reviewed by Simon Hausmann.
diff --git a/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp b/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
index 0fb0bd6..f5c0efb 100644
--- a/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
+++ b/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
@@ -66,6 +66,7 @@ class MyQObject : public QObject
     Q_PROPERTY(int readOnlyProperty READ readOnlyProperty)
     Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
     Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType)
+    Q_PROPERTY(QWebElement webElementProperty READ webElementProperty WRITE setWebElementProperty)
     Q_ENUMS(Policy Strategy)
     Q_FLAGS(Ability)
 
@@ -181,6 +182,14 @@ public:
         m_shortcut = seq;
     }
 
+    QWebElement webElementProperty() const {
+        return m_webElement;
+    }
+
+    void setWebElementProperty(const QWebElement& element) {
+        m_webElement = element;
+    }
+
     CustomType propWithCustomType() const {
         return m_customType;
     }
@@ -433,6 +442,10 @@ public Q_SLOTS:
         m_qtFunctionInvoked = 35;
         m_actuals << arg;
     }
+    void myOverloadedSlot(const QWebElement &arg) {
+        m_qtFunctionInvoked = 36;
+        m_actuals << QVariant::fromValue<QWebElement>(arg);
+    }
 
     void qscript_call(int arg) {
         m_qtFunctionInvoked = 40;
@@ -467,6 +480,7 @@ private:
     int m_writeOnlyValue;
     int m_readOnlyValue;
     QKeySequence m_shortcut;
+    QWebElement m_webElement;
     CustomType m_customType;
     int m_qtFunctionInvoked;
     QVariantList m_actuals;
@@ -685,6 +699,7 @@ void tst_QWebFrame::cleanup()
 
 void tst_QWebFrame::getSetStaticProperty()
 {
+    m_page->mainFrame()->setHtml("<html><head><body></body></html>");
     QCOMPARE(evalJS("typeof myObject.noSuchProperty"), sUndefined);
 
     // initial value (set in MyQObject constructor)
@@ -824,6 +839,8 @@ void tst_QWebFrame::getSetStaticProperty()
     QCOMPARE(evalJS("myObject.stringListProperty[1]"), QLatin1String("two"));
     QCOMPARE(evalJS("typeof myObject.stringListProperty[2]"), sString);
     QCOMPARE(evalJS("myObject.stringListProperty[2]"), QLatin1String("true"));
+    evalJS("myObject.webElementProperty=document.body;");
+    QCOMPARE(evalJS("myObject.webElementProperty.tagName"), QLatin1String("BODY"));
 
     // try to delete
     QCOMPARE(evalJS("delete myObject.intProperty"), sFalse);
@@ -1886,6 +1903,12 @@ void tst_QWebFrame::overloadedSlots()
     f.call(QString(), QStringList() << m_engine->newVariant(QVariant("ciao")));
     QCOMPARE(m_myObject->qtFunctionInvoked(), 35);
     */
+
+    // should pick myOverloadedSlot(QRegExp)
+    m_myObject->resetQtFunctionInvoked();
+    evalJS("myObject.myOverloadedSlot(document.body)");
+    QCOMPARE(m_myObject->qtFunctionInvoked(), 36);
+
     // should pick myOverloadedSlot(QObject*)
     m_myObject->resetQtFunctionInvoked();
     evalJS("myObject.myOverloadedSlot(myObject)");

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list