wiki:EFLWebKitCodingStyle

Version 5 (modified by gyuyoung.kim@samsung.com, 12 years ago) (diff)

--

Summary

  • EFL port should adhere to the WebKit Coding Style basically.(http://www.webkit.org/coding/coding-style.html)
  • Do not use abbreviation except for public APIs
  • Do not use Eina_Bool type except for public APIs
  • Place '*' operator to data type
  • Use C++ casting for type casting. For example, static_cast<...>, const_cast<...>, reinterpret_cast<...>
  • Use smart pointers
  • Use c++ new/delete operators
  • Use const keyword instead of #define when you define constant variable.

Example

Do not use abbreviation except for public APIs

Public APIs

 EAPI void ewk_view_bg_color_set(Evas_Object *o, int r, int g, int b, int a);

Implementation

 void ewk_view_bg_color_set(Evas_Object* ewkView, int red, int green, int blue, int alpha)
 {
     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
     EINA_SAFETY_ON_NULL_RETURN(smartData->api->bg_color_set);
 
     if (alpha < 0) {
         WRN("Alpha less than zero (%d).", alpha);
         alpha = 0;
     } else if (alpha > 255) {
         WRN("Alpha is larger than 255 (%d).", alpha);
         alpha = 255;
     }
  ...
 }

Do not use Eina_Bool type except for public APIs

Public APIs

EAPI Eina_Bool ewk_view_scale_set(Evas_Object *o, float scale_factor, Evas_Coord cx, Evas_Coord cy);

Implementation

Eina_Bool ewk_view_scale_set(Evas_Object* ewkView, float scaleFactor, Evas_Coord centerX, Evas_Coord centerY)
{
    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
 
    float currentScaleFactor = ewk_view_scale_get(ewkView);
    if (currentScaleFactor == -1)
        return false;
    int x, y;
    ewk_frame_scroll_pos_get(smartData->main_frame, &x, &y);
 
    x = static_cast<int>(((x + centerX) / currentScaleFactor) * scaleFactor) - centerX;
    y = static_cast<int>(((y + centerY) / currentScaleFactor) * scaleFactor) - centerY;
    priv->page->setPageScaleFactor(scaleFactor, WebCore::LayoutPoint(x, y));
    return true;
}

Place '*' operator to data type

static void _ewk_view_smart_show(Evas_Object* ewkView)

Wrong

static void _ewk_view_smart_show(Evas_Object *ewkView)

Use C++ casting for type casting

Right

 Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);

Wrong

 Ewk_View_Smart_Data* smartData = (Ewk_View_Smart_Data*)data;

Use smart pointers

Right

 RefPtr<cairo_region_t> dirtyRegion = adoptRef(cairo_region_create_rectangle(&rect));

 or 

 OwnPtr<WebCore::Page> page = adoptPtr(new WebCore::Page(pageClients));

Wrong

 cairo_region_t* dirtyRegion = cairo_region_create_rectangle(&rect);
 ...
 cairo_region_destroy(dirtyRegion);

 or

 WebCore::Page* page = new WebCore::Page(pageClients);
 ...
 delete page;

Use c++ new/delete operators

Right

Where it is not possible to use smart pointers. Use new/delete operators.

 unusedCacheEntry = new Ewk_Tile_Unused_Cache_Entry;
 ...
 delete unusedCacheEntry;

Wrong

 unusedCacheEntry = static_cast<Ewk_Tile_Unused_Cache_Entry*>(malloc(sizeof(Ewk_Tile_Unused_Cache_Entry)));
 ...
 free(unusedCacheEntry);

Use const keyword instead of #define when you define constant variable

Right

 const int defaultTileWidth = 256;
 const int defaultTileHeigth = 256;

Wrong

 #define DEFAULT_TILE_W (256) 
 #define DEFAULT_TILE_H (256)