fb664cc3f2acb1207a8adb1cbdf64cca215306e6
[framework/uifw/elementary.git] / src / lib / elm_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 /**
9  * @defgroup WebView WebView
10  * @ingroup Elementary
11  *
12  * TODO
13  */
14 typedef struct _Widget_Data Widget_Data;
15
16 struct _Widget_Data
17 {
18    Evas_Object *webkit;
19 };
20
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _sizing_eval(Evas_Object *obj);
24 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
25 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
26
27 static void
28 _del_pre_hook(Evas_Object *obj)
29 {
30    Widget_Data *wd = elm_widget_data_get(obj);
31    if (!wd) return;
32    /*evas_object_event_callback_del_full
33         (wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
34    evas_object_box_remove_all(wd->box, 0);
35    */
36 }
37
38 static void
39 _del_hook(Evas_Object *obj)
40 {
41    Widget_Data *wd = elm_widget_data_get(obj);
42    if (!wd) return;
43    //_els_webview_del(wd->webkit);
44    free(wd);
45 }
46
47 static void
48 _sizing_eval(Evas_Object *obj)
49 {
50    Evas_Coord w, h;
51    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
52    printf("sizing eval : %d, %d\n", w, h);
53    //evas_object_resize(obj, w, h);
54 }
55
56 static void
57 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
58 {
59    _sizing_eval(data);
60 }
61
62 static void
63 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
64 {
65    _sizing_eval(obj);
66 }
67
68 static void
69 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
70 {
71    Widget_Data *wd = data;
72    if (!wd) return;
73    //_els_box_layout(o, priv, wd->horizontal, wd->homogeneous);
74 }
75
76 /**
77  * Add a new box to the parent
78  *
79  * @param parent The parent object
80  * @return The new object or NULL if it cannot be created
81  *
82  * @ingroup Box
83  */
84 #ifdef ELM_EWEBKIT
85 EAPI Evas_Object *
86 elm_webview_add(Evas_Object *parent, Eina_Bool tiled)
87 {
88    Evas_Object *obj;
89    Evas *e;
90    Widget_Data *wd;
91
92    wd = ELM_NEW(Widget_Data);
93    e = evas_object_evas_get(parent);
94    obj = elm_widget_add(e);
95    ELM_SET_WIDTYPE(widtype, "webview");
96    elm_widget_type_set(obj, "webview");
97    elm_widget_sub_object_add(parent, obj);
98    elm_widget_data_set(obj, wd);
99    elm_widget_del_hook_set(obj, _del_hook);
100
101    wd->webkit = _elm_smart_webview_add(e, tiled);
102    _elm_smart_webview_widget_set(wd->webkit, obj);
103    //TODO:evas_object_box_layout_set(wd->box, _layout, wd, NULL);
104    evas_object_event_callback_add(wd->webkit, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
105                                   _changed_size_hints, obj);
106
107    elm_widget_resize_object_set(obj, wd->webkit);
108    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
109    return obj;
110 }
111
112 EAPI Evas_Object *
113 elm_webview_webkit_get(Evas_Object *obj)
114 {
115    Widget_Data *wd = elm_widget_data_get(obj);
116    if (!wd) return;
117    return wd->webkit;
118 }
119
120 EAPI void
121 elm_webview_events_feed_set(Evas_Object *obj, Eina_Bool feed)
122 {
123    Widget_Data *wd = elm_widget_data_get(obj);
124    if (!wd) return;
125    _elm_smart_webview_events_feed_set(wd->webkit, feed);
126 }
127
128 EAPI Eina_Bool
129 elm_webview_events_feed_get(Evas_Object *obj)
130 {
131    Widget_Data *wd = elm_widget_data_get(obj);
132    if (!wd) return EINA_FALSE;
133    return _elm_smart_webview_events_feed_get(wd->webkit);
134 }
135
136 EAPI void
137 elm_webview_auto_fitting_set(Evas_Object *obj, Eina_Bool enable)
138 {
139    Widget_Data *wd = elm_widget_data_get(obj);
140    if (!wd) return;
141    _elm_smart_webview_auto_fitting_set(wd->webkit, enable);
142 }
143
144 EAPI Eina_Bool
145 elm_webview_auto_fitting_get(Evas_Object *obj)
146 {
147    Widget_Data *wd = elm_widget_data_get(obj);
148    if (!wd) return EINA_FALSE;
149    return _elm_smart_webview_auto_fitting_get(wd->webkit);
150 }
151
152 EAPI Evas_Object *
153 elm_webview_minimap_get(Evas_Object *obj)
154 {
155    Widget_Data *wd = elm_widget_data_get(obj);
156    if (!wd) return EINA_FALSE;
157    return _elm_smart_webview_minimap_get(wd->webkit);
158 }
159
160 EAPI void
161 elm_webview_uri_set(Evas_Object *obj, const char *uri)
162 {
163    Widget_Data *wd = elm_widget_data_get(obj);
164    if (!wd) return;
165    _elm_smart_webview_uri_set(wd->webkit, uri);
166 }
167
168 /**
169  * Set bouncing behavior(Not supported yet)
170  *
171  * When scrolling, the WebView may "bounce" when reaching an edge of contents
172  * This is a visual way to indicate the end has been reached. This is enabled
173  * by default for both axes. This will set if it is enabled for that axis with
174  * the boolean parameers for each axis.
175  *
176  * @param obj The WebView object
177  * @param h_bounce Will the WebView bounce horizontally or not
178  * @param v_bounce Will the WebView bounce vertically or not
179  *
180  * @ingroup WebView
181  */
182 EAPI void
183 elm_webview_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
184 {
185    Widget_Data *wd = elm_widget_data_get(obj);
186    if (!wd) return;
187    _elm_smart_webview_bounce_allow_set(wd->webkit, h_bounce, v_bounce);
188 }
189
190 /**
191  * Add callback to treat mime type
192  *
193  * When user click link, the WebView may have different action by mime type.
194  * This is a way to choose proper action each mime type.
195  *
196  * @param obj The WebView object
197  * @param mime mime type string
198  * @param mime_callback callback when user choose link which involved @mime
199  *
200  * @ingroup WebView
201  */
202 EAPI void
203 elm_webview_mime_callback_set(Evas_Object *obj, const char *mime, Elm_WebView_Mime_Cb func)
204 {
205    Widget_Data *wd = elm_widget_data_get(obj);
206    if (!wd) return;
207    _elm_smart_webview_mime_callback_set(wd->webkit, mime, func);
208 }
209
210 /**
211  * Set default layout width
212  *
213  * If you want to load webpage with specific layout width, you can set it using this API.
214  * If you do not set it, the default layout width will be 1024.
215  *
216  * @param obj Webview object
217  * @param width width size that you want to set
218  *
219  * @ingroup WebView
220  *
221  */
222 EAPI void
223 elm_webview_default_layout_width_set(Evas_Object *obj, int width)
224 {
225    Widget_Data *wd = elm_widget_data_get(obj);
226    if (!wd) return;
227    _elm_smart_webview_default_layout_width_set(wd->webkit, width);
228 }
229
230 #endif