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