wiki:EFLWebKitCodingStyle

Version 1 (modified by gyuyoung.kim@samsung.com, 10 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 static_cast<...> for type casting

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 static_cast 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;