1 #include <Elementary.h>
3 # include "elementary_config.h"
5 #ifndef ELM_LIB_QUICKLAUNCH
10 Evas_Object *btn_back;
12 Evas_Object *url_entry;
14 Eina_Bool js_hooks : 1;
18 _btn_back_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
20 Evas_Object *web = data;
26 _btn_fwd_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
28 Evas_Object *web = data;
34 _btn_reload_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
36 Evas_Object *web = data;
42 _url_change_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
44 Evas_Object *web = data;
45 const char *uri = elm_object_text_get(obj);
47 elm_web_uri_set(web, uri);
51 _toggle_inwin_mode_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
53 elm_web_inwin_mode_set(data, !elm_web_inwin_mode_get(data));
57 _title_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
60 snprintf(buf, sizeof(buf), "Web - %s", (const char *)event_info);
61 elm_win_title_set(data, buf);
65 _uri_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
69 elm_entry_entry_set(wt->url_entry, event_info);
71 elm_object_disabled_set(wt->btn_back, !elm_web_back_possible(wt->web));
72 elm_object_disabled_set(wt->btn_fwd, !elm_web_forward_possible(wt->web));
76 _new_win_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
79 wt->sub_wins = eina_list_remove(wt->sub_wins, obj);
83 _web_win_close_request_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
85 evas_object_del(data);
89 _new_window_hook(void *data, Evas_Object *obj __UNUSED__, Eina_Bool js __UNUSED__, const Elm_Web_Window_Features *wf __UNUSED__)
92 Evas_Object *new_win, *new_web, *bg;
94 new_win = elm_win_add(NULL, "elm-web-test-popup", ELM_WIN_BASIC);
95 elm_win_autodel_set(new_win, EINA_TRUE);
96 evas_object_resize(new_win, 300, 300);
97 evas_object_show(new_win);
99 bg = elm_bg_add(new_win);
100 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101 elm_win_resize_object_add(new_win, bg);
102 evas_object_show(bg);
104 new_web = elm_web_add(new_win);
105 evas_object_size_hint_weight_set(new_web, EVAS_HINT_EXPAND,
107 elm_win_resize_object_add(new_win, new_web);
108 evas_object_show(new_web);
110 evas_object_smart_callback_add(new_win, "delete,request", _new_win_del_cb,
112 evas_object_smart_callback_add(new_web, "windows,close,request",
113 _web_win_close_request_cb, new_win);
114 wt->sub_wins = eina_list_append(wt->sub_wins, new_win);
120 _alert_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
122 evas_object_del(obj);
126 _alert_hook(void *data __UNUSED__, Evas_Object *obj, const char *message)
128 Evas_Object *popup, *label;
130 popup = elm_notify_add(obj);
131 elm_notify_orient_set(popup, ELM_NOTIFY_ORIENT_CENTER);
132 // Using the timeout doesn't seem to go well with the second main loop
133 //elm_notify_timeout_set(popup, 2.0);
134 elm_notify_repeat_events_set(popup, EINA_FALSE);
135 evas_object_show(popup);
137 evas_object_smart_callback_add(popup, "block,clicked", _alert_del, NULL);
139 label = elm_label_add(obj);
140 elm_object_text_set(label, message);
141 elm_object_content_set(popup, label);
142 evas_object_show(label);
148 _confirm_ok_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
150 Eina_Bool *response = data;
151 *response = EINA_TRUE;
155 _confirm_cancel_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
157 Eina_Bool *response = data;
158 *response = EINA_FALSE;
162 _confirm_dismiss_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
164 evas_object_del(data);
168 _confirm_hook(void *data __UNUSED__, Evas_Object *obj, const char *message, Eina_Bool *response)
170 Evas_Object *popup, *box, *box2, *label, *btn_ok, *btn_cancel;
172 popup = elm_notify_add(obj);
173 elm_notify_orient_set(popup, ELM_NOTIFY_ORIENT_CENTER);
174 elm_notify_repeat_events_set(popup, EINA_FALSE);
175 evas_object_show(popup);
177 box = elm_box_add(obj);
178 elm_object_content_set(popup, box);
179 evas_object_show(box);
181 label = elm_label_add(obj);
182 elm_object_text_set(label, message);
183 elm_box_pack_end(box, label);
184 evas_object_show(label);
186 box2 = elm_box_add(obj);
187 elm_box_horizontal_set(box2, EINA_TRUE);
188 elm_box_pack_end(box, box2);
189 evas_object_show(box2);
191 btn_ok = elm_button_add(obj);
192 elm_object_text_set(btn_ok, "Ok");
193 elm_box_pack_end(box2, btn_ok);
194 evas_object_show(btn_ok);
196 btn_cancel = elm_button_add(obj);
197 elm_object_text_set(btn_cancel, "Cancel");
198 elm_box_pack_end(box2, btn_cancel);
199 evas_object_show(btn_cancel);
201 evas_object_smart_callback_add(btn_ok, "clicked", _confirm_dismiss_cb,
203 evas_object_smart_callback_add(btn_cancel, "clicked", _confirm_dismiss_cb,
205 evas_object_smart_callback_add(btn_ok, "clicked", _confirm_ok_cb, response);
206 evas_object_smart_callback_add(btn_cancel, "clicked", _confirm_cancel_cb,
213 _prompt_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *message __UNUSED__, const char *default_value, char **value, Eina_Bool *response)
215 *response = EINA_TRUE;
216 *value = default_value ? strdup(default_value) : "No default!";
221 _file_selector_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Eina_Bool allow_multiple __UNUSED__, Eina_List *accept_types __UNUSED__, Eina_List **selected_files, Eina_Bool *response)
223 *selected_files = eina_list_append(NULL,
224 strdup("/path/to/non_existing_file"));
225 *response = EINA_TRUE;
230 _console_message_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *message, unsigned int line_number, const char *source_id)
232 printf("CONSOLE: %s:%d:%s\n", source_id, line_number, message);
236 _js_popup_hooks_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
240 wt->js_hooks = !wt->js_hooks;
243 elm_web_dialog_alert_hook_set(wt->web, _alert_hook, NULL);
244 elm_web_dialog_confirm_hook_set(wt->web, _confirm_hook, NULL);
245 elm_web_dialog_prompt_hook_set(wt->web, _prompt_hook, NULL);
246 elm_web_dialog_file_selector_hook_set(wt->web, _file_selector_hook,
248 elm_web_console_message_hook_set(wt->web, _console_message_hook, NULL);
252 elm_web_dialog_alert_hook_set(wt->web, NULL, NULL);
253 elm_web_dialog_confirm_hook_set(wt->web, NULL, NULL);
254 elm_web_dialog_prompt_hook_set(wt->web, NULL, NULL);
255 elm_web_dialog_file_selector_hook_set(wt->web, NULL, NULL);
256 elm_web_console_message_hook_set(wt->web, NULL, NULL);
261 _zoom_out_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
266 zoom = elm_web_zoom_get(wt->web);
273 elm_web_zoom_set(wt->web, zoom);
277 _zoom_in_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
282 zoom = elm_web_zoom_get(wt->web);
290 elm_web_zoom_set(wt->web, zoom);
294 _zoom_mode_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
297 Elm_Object_Item *hoversel_it = event_info;
298 const char *lbl = elm_object_item_text_get(hoversel_it);
300 if (!strcmp(lbl, "Manual"))
301 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_MANUAL);
302 else if (!strcmp(lbl, "Fit"))
303 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_AUTO_FIT);
305 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_AUTO_FILL);
309 _show_region_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
312 elm_web_region_show(wt->web, 300, 300, 1, 1);
316 _bring_in_region_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
319 elm_web_region_bring_in(wt->web, 50, 0, 1, 1);
323 _main_web_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
326 Evas_Object *sub_win;
328 EINA_LIST_FREE(wt->sub_wins, sub_win)
329 evas_object_del(sub_win);
335 test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
337 Evas_Object *win, *bg, *bx, *bx2, *bt, *web, *url;
342 wt = calloc(1, sizeof(*wt));
344 win = elm_win_add(NULL, "web", ELM_WIN_BASIC);
345 elm_win_title_set(win, "Web");
346 elm_win_autodel_set(win, EINA_TRUE);
348 bg = elm_bg_add(win);
349 elm_win_resize_object_add(win, bg);
350 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351 evas_object_show(bg);
353 bx = elm_box_add(win);
354 elm_win_resize_object_add(win, bx);
355 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
356 evas_object_show(bx);
358 bx2 = elm_box_add(win);
359 elm_box_horizontal_set(bx2, EINA_TRUE);
360 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
361 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0.0);
362 elm_box_pack_end(bx, bx2);
363 evas_object_show(bx2);
365 web = elm_web_add(win);
366 evas_object_size_hint_weight_set(web, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
367 evas_object_size_hint_align_set(web, EVAS_HINT_FILL, EVAS_HINT_FILL);
368 elm_box_pack_end(bx, web);
369 evas_object_show(web);
371 bt = elm_button_add(win);
372 elm_object_text_set(bt, "<");
373 elm_box_pack_end(bx2, bt);
374 evas_object_show(bt);
376 evas_object_smart_callback_add(bt, "clicked", _btn_back_cb, web);
379 bt = elm_button_add(win);
380 elm_object_text_set(bt, "R");
381 elm_box_pack_end(bx2, bt);
382 evas_object_show(bt);
384 evas_object_smart_callback_add(bt, "clicked", _btn_reload_cb, web);
386 bt = elm_button_add(win);
387 elm_object_text_set(bt, ">");
388 elm_box_pack_end(bx2, bt);
389 evas_object_show(bt);
391 evas_object_smart_callback_add(bt, "clicked", _btn_fwd_cb, web);
394 url = elm_entry_add(win);
395 elm_entry_single_line_set(url, EINA_TRUE);
396 elm_entry_scrollable_set(url, EINA_TRUE);
397 evas_object_size_hint_weight_set(url, EVAS_HINT_EXPAND, 0);
398 evas_object_size_hint_align_set(url, EVAS_HINT_FILL, EVAS_HINT_FILL);
399 elm_box_pack_end(bx2, url);
400 evas_object_show(url);
402 evas_object_smart_callback_add(url, "activated", _url_change_cb, web);
405 bx2 = elm_box_add(win);
406 elm_box_horizontal_set(bx2, EINA_TRUE);
407 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
408 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0);
409 elm_box_pack_end(bx, bx2);
410 evas_object_show(bx2);
412 bt = elm_button_add(win);
413 elm_object_text_set(bt, "Inwin Mode");
414 elm_box_pack_end(bx2, bt);
415 evas_object_show(bt);
417 evas_object_smart_callback_add(bt, "clicked", _toggle_inwin_mode_cb, web);
419 bt = elm_button_add(win);
420 elm_object_text_set(bt, "Custom Hooks");
421 elm_box_pack_end(bx2, bt);
422 evas_object_show(bt);
424 evas_object_smart_callback_add(bt, "clicked", _js_popup_hooks_set, wt);
426 bt = elm_button_add(win);
427 elm_object_text_set(bt, "-");
428 elm_box_pack_end(bx2, bt);
429 evas_object_show(bt);
431 evas_object_smart_callback_add(bt, "clicked", _zoom_out_cb, wt);
433 bt = elm_button_add(win);
434 elm_object_text_set(bt, "+");
435 elm_box_pack_end(bx2, bt);
436 evas_object_show(bt);
438 evas_object_smart_callback_add(bt, "clicked", _zoom_in_cb, wt);
440 bt = elm_hoversel_add(win);
441 elm_object_text_set(bt, "Zoom Mode");
442 elm_box_pack_end(bx2, bt);
443 evas_object_show(bt);
445 elm_hoversel_item_add(bt, "Manual", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
446 elm_hoversel_item_add(bt, "Fit", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
447 elm_hoversel_item_add(bt, "Fill", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
449 bx2 = elm_box_add(win);
450 elm_box_horizontal_set(bx2, EINA_TRUE);
451 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
452 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0);
453 elm_box_pack_end(bx, bx2);
454 evas_object_show(bx2);
456 bt = elm_button_add(win);
457 elm_object_text_set(bt, "Show 300, 300");
458 elm_box_pack_end(bx2, bt);
459 evas_object_show(bt);
461 evas_object_smart_callback_add(bt, "clicked", _show_region_cb, wt);
463 bt = elm_button_add(win);
464 elm_object_text_set(bt, "Bring in 50, 0");
465 elm_box_pack_end(bx2, bt);
466 evas_object_show(bt);
468 evas_object_smart_callback_add(bt, "clicked", _bring_in_region_cb, wt);
470 evas_object_smart_callback_add(web, "title,changed", _title_changed_cb, win);
471 evas_object_smart_callback_add(web, "uri,changed", _uri_changed_cb, wt);
473 evas_object_event_callback_add(web, EVAS_CALLBACK_DEL, _main_web_del_cb, wt);
477 elm_web_uri_set(web, "http://www.enlightenment.org");
479 elm_web_window_create_hook_set(web, _new_window_hook, wt);
481 evas_object_resize(win, 320, 480);
482 evas_object_show(win);