[elm_webview] add EWEBKIT_SUPPORT for glib and implement els_webview_add (1)
[framework/uifw/elementary.git] / src / lib / els_webview.c
1 /*
2  *
3  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4  */
5 #include <Elementary.h>
6 #include "elm_priv.h"
7
8 #ifdef ELM_EWEBKIT
9 #include <EWebKit.h>
10 #include <glib-object.h>
11
12 static Ewk_View_Smart_Class _parent_sc = EWK_VIEW_SMART_CLASS_INIT_NULL;
13 #endif
14
15 Evas_Object*
16 _els_webview_add(Evas_Object *parent, Eina_Bool tiled)
17 {
18 #ifdef ELM_EWEBKIT
19    static Evas_Smart* smart = NULL;
20    Evas_Object *obj;
21    Evas *e;
22    int (*ewk_init)(void);
23    Eina_Bool (*ewk_view_single_smart_set)(Ewk_View_Smart_Class *);
24    Eina_Bool (*ewk_view_tiled_smart_set)(Ewk_View_Smart_Class *);
25
26    if (!smart)
27      {
28         g_type_init();
29         if (!g_thread_get_initialized())
30              g_thread_init(NULL);
31
32         void *ewk_handle = dlopen("/usr/lib/libewebkit.so", RTLD_LAZY);//FIXME
33         ewk_init = (int (*)())dlsym(ewk_handle, "ewk_init");
34         ewk_init();
35         static Ewk_View_Smart_Class api = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("ELM_WEBVIEW");
36
37         if (tiled)
38           {
39              ewk_view_tiled_smart_set = (Eina_Bool (*)(Ewk_View_Smart_Class *))dlsym(ewk_handle, "ewk_view_tiled_smart_set");
40              ewk_view_tiled_smart_set(&api);
41              if (EINA_UNLIKELY(!_parent_sc.sc.add))
42                ewk_view_tiled_smart_set(&_parent_sc);
43           }
44         else
45           {
46              ewk_view_single_smart_set = (Eina_Bool (*)(Ewk_View_Smart_Class *))dlsym(ewk_handle, "ewk_view_single_smart_set");
47              ewk_view_single_smart_set(&api);
48              if (EINA_UNLIKELY(!_parent_sc.sc.add))
49                ewk_view_single_smart_set(&_parent_sc);
50           }
51         //TODO: add apis
52         dlclose(ewk_handle);
53      }
54
55    if (!smart)
56      return NULL;
57
58    obj = evas_object_smart_add(e, smart);
59    if (!obj)
60      return NULL;
61
62    /*TODO:
63    View_Smart_Data *sd = evas_object_smart_data_get(obj);
64    if (sd)
65      sd->tiled = tiled;
66    */
67    /*
68       ewk_init = (int (*)())dlsym(ewk_handle, "ewk_init");
69       ewk_view_add = (Evas_Object *(*)(Evas *))dlsym(ewk_handle, "ewk_view_tiled_add");
70       ewk_view_uri_set = (Eina_Bool (*)(Evas_Object *, const char *))dlsym(ewk_handle, "ewk_view_uri_set");
71
72       e = evas_object_evas_get(parent);
73       ewk_init();
74       obj = ewk_view_add(e);
75       ewk_view_uri_set(obj, "file:///a.html");
76       evas_object_show(obj);
77       */
78    return obj;
79 #else
80    return NULL;
81 #endif
82 }