Changeset 54775 in webkit


Ignore:
Timestamp:
Feb 15, 2010, 7:36:00 AM (16 years ago)
Author:
eric@webkit.org
Message:

2010-02-15 Noam Rosenthal <noam.rosenthal@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@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
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54774 r54775  
     12010-02-15  Noam Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
     6        https://bugs.webkit.org/show_bug.cgi?id=34901
     7
     8        When a signal/slot/property is of type QWebElement, it can seamlessly
     9        connect with JS objects that hold a WebCore element.
     10
     11        New tests, see WebKit/qt/ChangeLog
     12
     13        * bridge/qt/qt_runtime.cpp:
     14        (JSC::Bindings::QtWebElementRuntime::create): A proxy to QWebElement
     15        constructor
     16        (JSC::Bindings::QtWebElementRuntime::get): A proxy to
     17        QWebElement::element
     18        (JSC::Bindings::convertValueToQVariant): handle QWebElement
     19        (JSC::Bindings::convertQVariantToValue): handle QWebElement
     20
    1212010-02-15  Pavel Feldman  <pfeldman@chromium.org>
    222
  • trunk/WebCore/bridge/qt/qt_runtime.cpp

    r54060 r54775  
    3030#include "JSByteArray.h"
    3131#include "JSDOMBinding.h"
     32#include "JSDOMWindow.h"
     33#include <JSFunction.h>
    3234#include "JSGlobalObject.h"
     35#include "JSHTMLElement.h"
    3336#include "JSLock.h"
    3437#include "JSObject.h"
     
    4649#include "qt_pixmapruntime.h"
    4750#include "qvarlengtharray.h"
    48 #include <JSFunction.h>
     51#include "qwebelement.h"
    4952#include <limits.h>
    5053#include <runtime/Error.h>
     
    114117}
    115118#endif
     119
     120// this is here as a proxy, so we'd have a class to friend in QWebElement,
     121// as getting/setting a WebCore in QWebElement is private
     122class QtWebElementRuntime {
     123public:
     124    static QWebElement create(Element* element)
     125    {
     126        return QWebElement(element);
     127    }
     128
     129    static Element* get(const QWebElement& element)
     130    {
     131        return element.m_element;
     132    }
     133};
    116134
    117135static JSRealType valueRealType(ExecState* exec, JSValue val)
     
    723741            } else if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(hint))) {
    724742                ret = QtPixmapInstance::variantFromObject(object, static_cast<QMetaType::Type>(hint));
     743            } else if (hint == (QMetaType::Type) qMetaTypeId<QWebElement>()) {
     744                if (object && object->inherits(&JSHTMLElement::s_info))
     745                    ret = QVariant::fromValue<QWebElement>(QtWebElementRuntime::create((static_cast<JSHTMLElement*>(object))->impl()));
     746                else
     747                    ret = QVariant::fromValue<QWebElement>(QWebElement());
    725748            } else if (hint == (QMetaType::Type) qMetaTypeId<QVariant>()) {
    726749                if (value.isUndefinedOrNull()) {
     
    854877    if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(variant.type())))
    855878        return QtPixmapInstance::createRuntimeObject(exec, root, variant);
     879
     880    if (type == qMetaTypeId<QWebElement>()) {
     881        if (!root->globalObject()->inherits(&JSDOMWindow::s_info))
     882            return jsUndefined();
     883
     884        Document* document = (static_cast<JSDOMWindow*>(root->globalObject()))->impl()->document();
     885        if (!document)
     886            return jsUndefined();
     887
     888        return toJS(exec, toJSDOMGlobalObject(document, exec), QtWebElementRuntime::get(variant.value<QWebElement>()));
     889    }
    856890
    857891    if (type == QMetaType::QVariantMap) {
  • trunk/WebKit/qt/Api/qwebelement.h

    r50676 r54775  
    3131    class Element;
    3232    class Node;
     33}
     34
     35namespace JSC {
     36namespace Bindings {
     37    class QtWebElementRuntime;
     38}
    3339}
    3440
     
    154160    friend class QWebHitTestResultPrivate;
    155161    friend class QWebPage;
     162    friend class JSC::Bindings::QtWebElementRuntime;
    156163
    157164    QWebElementPrivate* d;
     
    256263};
    257264
     265Q_DECLARE_METATYPE(QWebElement)
     266
    258267#endif // QWEBELEMENT_H
  • trunk/WebKit/qt/ChangeLog

    r54772 r54775  
     12010-02-15  Noam Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] QtWebkit bridge: enable passing a QWebElement to a signal/slot/property
     6        Add Q_DECLARE_METATYPE to QWebElement, add relevant tests to
     7        tst_qwebframe
     8        https://bugs.webkit.org/show_bug.cgi?id=34901
     9
     10        * Api/qwebelement.h: declare metatype
     11        * tests/qwebframe/tst_qwebframe.cpp:
     12        (MyQObject::webElementProperty): new test for QWebElement
     13        (MyQObject::setWebElementProperty): new test for QWebElement
     14        (MyQObject::myOverloadedSlot): new test for QWebElement
     15
    1162010-02-15  Robert Hogan  <robert@roberthogan.net>, Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    217
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r53930 r54775  
    6767    Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
    6868    Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType)
     69    Q_PROPERTY(QWebElement webElementProperty READ webElementProperty WRITE setWebElementProperty)
    6970    Q_ENUMS(Policy Strategy)
    7071    Q_FLAGS(Ability)
     
    182183    }
    183184
     185    QWebElement webElementProperty() const {
     186        return m_webElement;
     187    }
     188
     189    void setWebElementProperty(const QWebElement& element) {
     190        m_webElement = element;
     191    }
     192
    184193    CustomType propWithCustomType() const {
    185194        return m_customType;
     
    433442        m_qtFunctionInvoked = 35;
    434443        m_actuals << arg;
     444    }
     445    void myOverloadedSlot(const QWebElement &arg) {
     446        m_qtFunctionInvoked = 36;
     447        m_actuals << QVariant::fromValue<QWebElement>(arg);
    435448    }
    436449
     
    468481    int m_readOnlyValue;
    469482    QKeySequence m_shortcut;
     483    QWebElement m_webElement;
    470484    CustomType m_customType;
    471485    int m_qtFunctionInvoked;
     
    686700void tst_QWebFrame::getSetStaticProperty()
    687701{
     702    m_page->mainFrame()->setHtml("<html><head><body></body></html>");
    688703    QCOMPARE(evalJS("typeof myObject.noSuchProperty"), sUndefined);
    689704
     
    825840    QCOMPARE(evalJS("typeof myObject.stringListProperty[2]"), sString);
    826841    QCOMPARE(evalJS("myObject.stringListProperty[2]"), QLatin1String("true"));
     842    evalJS("myObject.webElementProperty=document.body;");
     843    QCOMPARE(evalJS("myObject.webElementProperty.tagName"), QLatin1String("BODY"));
    827844
    828845    // try to delete
     
    18871904    QCOMPARE(m_myObject->qtFunctionInvoked(), 35);
    18881905    */
     1906
     1907    // should pick myOverloadedSlot(QRegExp)
     1908    m_myObject->resetQtFunctionInvoked();
     1909    evalJS("myObject.myOverloadedSlot(document.body)");
     1910    QCOMPARE(m_myObject->qtFunctionInvoked(), 36);
     1911
    18891912    // should pick myOverloadedSlot(QObject*)
    18901913    m_myObject->resetQtFunctionInvoked();
Note: See TracChangeset for help on using the changeset viewer.