Changes between Version 6 and Version 7 of WebKitGTK/AddingNewWebKit2API


Ignore:
Timestamp:
Nov 23, 2012 6:24:28 AM (9 years ago)
Author:
Carlos Garcia Campos
Comment:

Document WEBKIT_DEFINE_ macros

Legend:

Unmodified
Added
Removed
Modified
  • WebKitGTK/AddingNewWebKit2API

    v6 v7  
    2121  * Use WebKit coding style for all other code, including unit tests, See http://www.webkit.org/coding/coding-style.html
    2222  * You can use check-webkit-style script to make sure your patch follows the WebKit coding style
    23  * Use the placement new syntax for private structures
    24   * Let glib allocate the private structure using g_type_class_add_private() as usual
    25   * In the init method use the following syntax
     23 * Use WEBKIT_DEFINE_ macros instead of G_DEFINE_ ones. There some small differences:
     24  * The private struct is allocated by the macro using the placement new syntax, so you can use smart pointers in the private struct.
     25  * You only need to define a class_init method but not init() nor finalize().
     26  * Don't call g_type_class_add_private() in class_init() since it's already done by the macro.
     27  * If you need to add some initialization for instances, override GObjectClass::constructor() or use the private struct constructor
    2628  {{{
    27 static void webkit_foo_init(WebKitFoo* foo)
    28 {
    29     WebKitFooPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(foo, WEBKIT_TYPE_FOO, WebKitFooPrivate);
    30     foo->priv = priv;
    31     new (priv) WebKitFooPrivate();
    32 }
     29struct _WebKitSettingsPrivate {
     30    _WebKitSettingsPrivate()
     31        : preferences(WebPreferences::create())
     32    {
     33        defaultFontFamily = preferences->standardFontFamily().utf8();
     34        monospaceFontFamily = preferences->fixedFontFamily().utf8();
     35        serifFontFamily = preferences->serifFontFamily().utf8();
     36        sansSerifFontFamily = preferences->sansSerifFontFamily().utf8();
     37        cursiveFontFamily = preferences->cursiveFontFamily().utf8();
     38        fantasyFontFamily = preferences->fantasyFontFamily().utf8();
     39        pictographFontFamily = preferences->pictographFontFamily().utf8();
     40        defaultCharset = preferences->defaultTextEncodingName().utf8();
     41    }
     42
     43    RefPtr<WebPreferences> preferences;
     44    CString defaultFontFamily;
     45    CString monospaceFontFamily;
     46    CString serifFontFamily;
     47    CString sansSerifFontFamily;
     48    CString cursiveFontFamily;
     49    CString fantasyFontFamily;
     50    CString pictographFontFamily;
     51    CString defaultCharset;
     52    CString userAgent;
     53    bool allowModalDialogs;
     54    bool zoomTextOnly;
     55};
    3356  }}}
    34   * And in finalize method call the destructor manually
     57  * The same way, if you need to add destruction code, you can override GObjectClass::dispose() or use the private struct destructor. Note that dispose can be called multiple times, so if you want to make sure the destruction code is only called once, use the private struct destructor.
    3558  {{{
    36 static void webkitFooFinalize(GObject* object)
    37 {
    38     WEBKIT_FOO(object)->priv->~WebKitFooPrivate();
    39     G_OBJECT_CLASS(webkit_foo_parent_class)->finalize(object);
    40 }
     59struct _WebKitCookieManagerPrivate {
     60    ~_WebKitCookieManagerPrivate()
     61    {
     62        webCookieManager->stopObservingCookieChanges();
     63    }
     64
     65    RefPtr<WebCookieManagerProxy> webCookieManager;
     66};
    4167  }}}
    4268 * Use wtf classes (CString, HashMap, etc.) and GRefPtr/GOwnPtr for attributes so that they are automatically freed by the private structure destructor