Changeset 62004 in webkit


Ignore:
Timestamp:
Jun 28, 2010 7:39:17 AM (14 years ago)
Author:
xan@webkit.org
Message:

2010-06-28 Xan Lopez <xlopez@igalia.com>

Reviewed by Gustavo Noronha.

Until now we were adding the event listeners for a given object in
the wrap method, since that's the first moment we have accoss to
the core WebCore object. The problem is that we only install the
listeners that the topmost class in the class hierarchy needs (eg,
HTMLParagrahElement for a P element), when most of the actual
event attributes are defined in the base classes (Node, Element,
...).

To fix this set the core object as a construct/write-only property
on the wrapper GObject, and set the eventlisteners in the cGObject
'construct' method, chaining up through all the class hierarchy
until the end. This way we'll get all the eventlisteners defined
in all the superclasses of our object, which is what we want.

  • bindings/gobject/WebKitDOMObject.cpp: (webkit_dom_object_get_property): (webkit_dom_object_set_property): (webkit_dom_object_class_init):
  • bindings/scripts/CodeGeneratorGObject.pm:
  • dom/Node.idl:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r62003 r62004  
     12010-06-28  Xan Lopez  <xlopez@igalia.com>
     2
     3        Reviewed by Gustavo Noronha.
     4
     5        Until now we were adding the event listeners for a given object in
     6        the wrap method, since that's the first moment we have accoss to
     7        the core WebCore object. The problem is that we only install the
     8        listeners that the topmost class in the class hierarchy needs (eg,
     9        HTMLParagrahElement for a P element), when most of the actual
     10        event attributes are defined in the base classes (Node, Element,
     11        ...).
     12
     13        To fix this set the core object as a construct/write-only property
     14        on the wrapper GObject, and set the eventlisteners in the cGObject
     15        'construct' method, chaining up through all the class hierarchy
     16        until the end. This way we'll get all the eventlisteners defined
     17        in all the superclasses of our object, which is what we want.
     18
     19        * bindings/gobject/WebKitDOMObject.cpp:
     20        (webkit_dom_object_get_property):
     21        (webkit_dom_object_set_property):
     22        (webkit_dom_object_class_init):
     23        * bindings/scripts/CodeGeneratorGObject.pm:
     24        * dom/Node.idl:
     25
    1262010-06-28  Xan Lopez  <xlopez@igalia.com>
    227
  • trunk/WebCore/bindings/gobject/WebKitDOMObject.cpp

    r57985 r62004  
    1212#include "WebKitDOMBinding.h"
    1313
     14enum {
     15    PROP_0,
     16    PROP_CORE_OBJECT
     17};
     18
    1419G_DEFINE_TYPE(WebKitDOMObject, webkit_dom_object, G_TYPE_OBJECT);
    1520
     
    1823}
    1924
     25static void webkit_dom_object_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
     26{
     27    switch (prop_id) {
     28    default:
     29        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     30        break;
     31    }
     32}
     33
     34static void webkit_dom_object_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
     35{
     36    switch (prop_id) {
     37    case PROP_CORE_OBJECT:
     38        WEBKIT_DOM_OBJECT(object)->coreObject = g_value_get_pointer(value);
     39        break;
     40    default:
     41        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     42        break;
     43    }
     44}
     45
    2046static void webkit_dom_object_class_init(WebKitDOMObjectClass* klass)
    2147{
     48    GObjectClass* gobjectClass = G_OBJECT_CLASS(klass);
     49    gobjectClass->set_property = webkit_dom_object_set_property;
     50    gobjectClass->get_property = webkit_dom_object_get_property;
     51
     52    g_object_class_install_property(gobjectClass,
     53                                    PROP_CORE_OBJECT,
     54                                    g_param_spec_pointer("core-object",
     55                                                         "Core Object",
     56                                                         "The WebCore object the WebKitDOMObject wraps",
     57                                                         static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
    2258}
    2359
  • trunk/WebCore/bindings/scripts/CodeGeneratorGObject.pm

    r61428 r62004  
    505505
    506506    my $txtInstallEventListener = << "EOF";
    507     RefPtr<WebCore::GObjectEventListener> ${listenerName} = WebCore::GObjectEventListener::create(reinterpret_cast<GObject*>(wrapper), "${gobjectSignalName}");
     507    RefPtr<WebCore::GObjectEventListener> ${listenerName} = WebCore::GObjectEventListener::create(reinterpret_cast<GObject*>(object), "${gobjectSignalName}");
    508508    coreObject->addEventListener("${domSignalName}", ${listenerName}, false);
    509509EOF
     
    626626@txtGetProps
    627627
     628static void ${lowerCaseIfaceName}_constructed(GObject* object)
     629{
     630EOF
     631    push(@cBodyPriv, $implContent);
     632
     633    if (scalar @txtInstallEventListeners > 0) {
     634        $implContent = << "EOF";
     635    WebCore::${interfaceName}* coreObject = static_cast<WebCore::${interfaceName}*>(WEBKIT_DOM_OBJECT(object)->coreObject);
     636EOF
     637    push(@cBodyPriv, $implContent);
     638    }
     639
     640    $implContent = << "EOF";
     641@txtInstallEventListeners
     642    if (G_OBJECT_CLASS(${lowerCaseIfaceName}_parent_class)->constructed)
     643        G_OBJECT_CLASS(${lowerCaseIfaceName}_parent_class)->constructed(object);
     644}
     645
    628646static void ${lowerCaseIfaceName}_class_init(${className}Class* requestClass)
    629647{
     
    632650    gobjectClass->set_property = ${lowerCaseIfaceName}_set_property;
    633651    gobjectClass->get_property = ${lowerCaseIfaceName}_get_property;
     652    gobjectClass->constructed = ${lowerCaseIfaceName}_constructed;
    634653
    635654@txtInstallProps
     
    11021121{
    11031122    g_return_val_if_fail(coreObject, 0);
    1104    
    1105     ${className}* wrapper = WEBKIT_DOM_${clsCaps}(g_object_new(WEBKIT_TYPE_DOM_${clsCaps}, NULL));
    1106     g_return_val_if_fail(wrapper, 0);
    11071123
    11081124    /* We call ref() rather than using a C++ smart pointer because we can't store a C++ object
     
    11101126     * matching deref().
    11111127     */
    1112 
    11131128    coreObject->ref();
    1114     WEBKIT_DOM_OBJECT(wrapper)->coreObject = coreObject;
    1115 @txtInstallEventListeners
    1116 
    1117     return wrapper;
     1129
     1130    return  WEBKIT_DOM_${clsCaps}(g_object_new(WEBKIT_TYPE_DOM_${clsCaps},
     1131                                               "core-object", coreObject, NULL));
    11181132}
    11191133} // namespace WebKit
  • trunk/WebCore/dom/Node.idl

    r60784 r62004  
    135135#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP
    136136#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C
    137 #if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT
    138137        void addEventListener(in DOMString type,
    139138                              in EventListener listener,
     
    144143        boolean dispatchEvent(in Event event)
    145144            raises(EventException);
    146 #endif
    147145#endif
    148146#endif
Note: See TracChangeset for help on using the changeset viewer.