2 # include "elementary_config.h"
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
10 Evas_Object *btn_back;
12 Evas_Object *url_entry;
14 const char* user_agent;
15 Eina_Bool js_hooks : 1;
19 _btn_back_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
21 Evas_Object *web = data;
27 _btn_fwd_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
29 Evas_Object *web = data;
35 _btn_reload_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
37 Evas_Object *web = data;
43 _url_change_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
45 Evas_Object *web = data;
46 const char *uri = elm_object_text_get(obj);
48 elm_web_uri_set(web, uri);
52 _toggle_inwin_mode_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
54 elm_web_inwin_mode_set(data, !elm_web_inwin_mode_get(data));
58 _title_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
61 snprintf(buf, sizeof(buf), "Web - %s", (const char *)event_info);
62 elm_win_title_set(data, buf);
66 _uri_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
70 elm_object_text_set(wt->url_entry, event_info);
72 elm_object_disabled_set(wt->btn_back, !elm_web_back_possible_get(wt->web));
73 elm_object_disabled_set(wt->btn_fwd, !elm_web_forward_possible_get(wt->web));
77 _new_win_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
80 wt->sub_wins = eina_list_remove(wt->sub_wins, obj);
84 _web_win_close_request_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
86 evas_object_del(data);
90 _new_window_hook(void *data, Evas_Object *obj __UNUSED__, Eina_Bool js __UNUSED__, const Elm_Web_Window_Features *wf __UNUSED__)
93 Evas_Object *new_win, *new_web;
95 new_win = elm_win_util_standard_add("elm-web-test-popup", "Elm Web Test Popup");
96 elm_win_autodel_set(new_win, EINA_TRUE);
97 evas_object_resize(new_win, 300, 300);
98 evas_object_show(new_win);
100 new_web = elm_web_add(new_win);
101 elm_web_useragent_set(new_web, wt->user_agent);
102 evas_object_size_hint_weight_set(new_web, EVAS_HINT_EXPAND,
104 elm_win_resize_object_add(new_win, new_web);
105 evas_object_show(new_web);
107 evas_object_smart_callback_add(new_win, "delete,request", _new_win_del_cb,
109 evas_object_smart_callback_add(new_web, "windows,close,request",
110 _web_win_close_request_cb, new_win);
111 wt->sub_wins = eina_list_append(wt->sub_wins, new_win);
117 _alert_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
119 evas_object_del(obj);
123 _alert_hook(void *data __UNUSED__, Evas_Object *obj, const char *message)
125 Evas_Object *popup, *label;
127 popup = elm_notify_add(obj);
128 elm_notify_orient_set(popup, ELM_NOTIFY_ORIENT_CENTER);
129 // Using the timeout doesn't seem to go well with the second main loop
130 //elm_notify_timeout_set(popup, 2.0);
131 elm_notify_allow_events_set(popup, EINA_FALSE);
132 evas_object_show(popup);
134 evas_object_smart_callback_add(popup, "block,clicked", _alert_del, NULL);
136 label = elm_label_add(obj);
137 elm_object_text_set(label, message);
138 elm_object_content_set(popup, label);
139 evas_object_show(label);
145 _confirm_ok_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
147 Eina_Bool *response = data;
148 *response = EINA_TRUE;
152 _confirm_cancel_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
154 Eina_Bool *response = data;
155 *response = EINA_FALSE;
159 _confirm_dismiss_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
161 evas_object_del(data);
165 _confirm_hook(void *data __UNUSED__, Evas_Object *obj, const char *message, Eina_Bool *response)
167 Evas_Object *popup, *box, *box2, *label, *btn_ok, *btn_cancel;
169 popup = elm_notify_add(obj);
170 elm_notify_orient_set(popup, ELM_NOTIFY_ORIENT_CENTER);
171 elm_notify_allow_events_set(popup, EINA_FALSE);
172 evas_object_show(popup);
174 box = elm_box_add(obj);
175 elm_object_content_set(popup, box);
176 evas_object_show(box);
178 label = elm_label_add(obj);
179 elm_object_text_set(label, message);
180 elm_box_pack_end(box, label);
181 evas_object_show(label);
183 box2 = elm_box_add(obj);
184 elm_box_horizontal_set(box2, EINA_TRUE);
185 elm_box_pack_end(box, box2);
186 evas_object_show(box2);
188 btn_ok = elm_button_add(obj);
189 elm_object_text_set(btn_ok, "Ok");
190 elm_box_pack_end(box2, btn_ok);
191 evas_object_show(btn_ok);
193 btn_cancel = elm_button_add(obj);
194 elm_object_text_set(btn_cancel, "Cancel");
195 elm_box_pack_end(box2, btn_cancel);
196 evas_object_show(btn_cancel);
198 evas_object_smart_callback_add(btn_ok, "clicked", _confirm_dismiss_cb,
200 evas_object_smart_callback_add(btn_cancel, "clicked", _confirm_dismiss_cb,
202 evas_object_smart_callback_add(btn_ok, "clicked", _confirm_ok_cb, response);
203 evas_object_smart_callback_add(btn_cancel, "clicked", _confirm_cancel_cb,
210 _prompt_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *message __UNUSED__, const char *default_value, char **value, Eina_Bool *response)
212 *response = EINA_TRUE;
213 *value = default_value ? strdup(default_value) : "No default!";
218 _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)
220 *selected_files = eina_list_append(NULL,
221 strdup("/path/to/non_existing_file"));
222 *response = EINA_TRUE;
227 _console_message_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *message, unsigned int line_number, const char *source_id)
229 printf("CONSOLE: %s:%d:%s\n", source_id, line_number, message);
233 _js_popup_hooks_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
237 wt->js_hooks = !wt->js_hooks;
240 elm_web_dialog_alert_hook_set(wt->web, _alert_hook, NULL);
241 elm_web_dialog_confirm_hook_set(wt->web, _confirm_hook, NULL);
242 elm_web_dialog_prompt_hook_set(wt->web, _prompt_hook, NULL);
243 elm_web_dialog_file_selector_hook_set(wt->web, _file_selector_hook,
245 elm_web_console_message_hook_set(wt->web, _console_message_hook, NULL);
249 elm_web_dialog_alert_hook_set(wt->web, NULL, NULL);
250 elm_web_dialog_confirm_hook_set(wt->web, NULL, NULL);
251 elm_web_dialog_prompt_hook_set(wt->web, NULL, NULL);
252 elm_web_dialog_file_selector_hook_set(wt->web, NULL, NULL);
253 elm_web_console_message_hook_set(wt->web, NULL, NULL);
258 _zoom_out_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
263 zoom = elm_web_zoom_get(wt->web);
270 elm_web_zoom_set(wt->web, zoom);
274 _zoom_in_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
279 zoom = elm_web_zoom_get(wt->web);
287 elm_web_zoom_set(wt->web, zoom);
291 _zoom_mode_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
294 Elm_Object_Item *hoversel_it = event_info;
295 const char *lbl = elm_object_item_text_get(hoversel_it);
297 if (!strcmp(lbl, "Manual"))
298 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_MANUAL);
299 else if (!strcmp(lbl, "Fit"))
300 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_AUTO_FIT);
302 elm_web_zoom_mode_set(wt->web, ELM_WEB_ZOOM_MODE_AUTO_FILL);
306 _show_region_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
309 elm_web_region_show(wt->web, 300, 300, 1, 1);
313 _bring_in_region_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
316 elm_web_region_bring_in(wt->web, 50, 0, 1, 1);
320 _main_web_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
323 Evas_Object *sub_win;
325 EINA_LIST_FREE(wt->sub_wins, sub_win)
326 evas_object_del(sub_win);
332 test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__, Eina_Bool mobile)
334 const char user_agent_firefox[] = "Mozilla/5.0 (X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1";
335 const char user_agent_mobile[] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3";
336 Evas_Object *win, *bx, *bx2, *bt, *web, *url;
341 wt = calloc(1, sizeof(*wt));
343 if (mobile == EINA_TRUE)
345 win = elm_win_util_standard_add("web-mobile", "Web Mobile");
346 wt->user_agent = user_agent_mobile;
350 win = elm_win_util_standard_add("web", "Web");
351 wt->user_agent = user_agent_firefox;
354 elm_win_autodel_set(win, EINA_TRUE);
356 bx = elm_box_add(win);
357 elm_win_resize_object_add(win, bx);
358 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
359 evas_object_show(bx);
361 bx2 = elm_box_add(win);
362 elm_box_horizontal_set(bx2, EINA_TRUE);
363 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
364 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0.0);
365 elm_box_pack_end(bx, bx2);
366 evas_object_show(bx2);
368 web = elm_web_add(win);
369 elm_web_useragent_set(web, wt->user_agent);
370 printf("elm_web useragent: %s\n", elm_web_useragent_get(web));
371 evas_object_size_hint_weight_set(web, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
372 evas_object_size_hint_align_set(web, EVAS_HINT_FILL, EVAS_HINT_FILL);
373 elm_box_pack_end(bx, web);
374 evas_object_show(web);
376 bt = elm_button_add(win);
377 elm_object_text_set(bt, "<");
378 elm_box_pack_end(bx2, bt);
379 evas_object_show(bt);
381 evas_object_smart_callback_add(bt, "clicked", _btn_back_cb, web);
384 bt = elm_button_add(win);
385 elm_object_text_set(bt, "R");
386 elm_box_pack_end(bx2, bt);
387 evas_object_show(bt);
389 evas_object_smart_callback_add(bt, "clicked", _btn_reload_cb, web);
391 bt = elm_button_add(win);
392 elm_object_text_set(bt, ">");
393 elm_box_pack_end(bx2, bt);
394 evas_object_show(bt);
396 evas_object_smart_callback_add(bt, "clicked", _btn_fwd_cb, web);
399 url = elm_entry_add(win);
400 elm_entry_single_line_set(url, EINA_TRUE);
401 elm_entry_scrollable_set(url, EINA_TRUE);
402 evas_object_size_hint_weight_set(url, EVAS_HINT_EXPAND, 0);
403 evas_object_size_hint_align_set(url, EVAS_HINT_FILL, EVAS_HINT_FILL);
404 elm_box_pack_end(bx2, url);
405 evas_object_show(url);
407 evas_object_smart_callback_add(url, "activated", _url_change_cb, web);
410 bx2 = elm_box_add(win);
411 elm_box_horizontal_set(bx2, EINA_TRUE);
412 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
413 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0);
414 elm_box_pack_end(bx, bx2);
415 evas_object_show(bx2);
417 bt = elm_button_add(win);
418 elm_object_text_set(bt, "Inwin Mode");
419 elm_box_pack_end(bx2, bt);
420 evas_object_show(bt);
422 evas_object_smart_callback_add(bt, "clicked", _toggle_inwin_mode_cb, web);
424 bt = elm_button_add(win);
425 elm_object_text_set(bt, "Custom Hooks");
426 elm_box_pack_end(bx2, bt);
427 evas_object_show(bt);
429 evas_object_smart_callback_add(bt, "clicked", _js_popup_hooks_set, wt);
431 bt = elm_button_add(win);
432 elm_object_text_set(bt, "-");
433 elm_box_pack_end(bx2, bt);
434 evas_object_show(bt);
436 evas_object_smart_callback_add(bt, "clicked", _zoom_out_cb, wt);
438 bt = elm_button_add(win);
439 elm_object_text_set(bt, "+");
440 elm_box_pack_end(bx2, bt);
441 evas_object_show(bt);
443 evas_object_smart_callback_add(bt, "clicked", _zoom_in_cb, wt);
445 bt = elm_hoversel_add(win);
446 elm_object_text_set(bt, "Zoom Mode");
447 elm_box_pack_end(bx2, bt);
448 evas_object_show(bt);
450 elm_hoversel_item_add(bt, "Manual", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
451 elm_hoversel_item_add(bt, "Fit", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
452 elm_hoversel_item_add(bt, "Fill", NULL, ELM_ICON_NONE, _zoom_mode_cb, wt);
454 bx2 = elm_box_add(win);
455 elm_box_horizontal_set(bx2, EINA_TRUE);
456 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
457 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0);
458 elm_box_pack_end(bx, bx2);
459 evas_object_show(bx2);
461 bt = elm_button_add(win);
462 elm_object_text_set(bt, "Show 300, 300");
463 elm_box_pack_end(bx2, bt);
464 evas_object_show(bt);
466 evas_object_smart_callback_add(bt, "clicked", _show_region_cb, wt);
468 bt = elm_button_add(win);
469 elm_object_text_set(bt, "Bring in 50, 0");
470 elm_box_pack_end(bx2, bt);
471 evas_object_show(bt);
473 evas_object_smart_callback_add(bt, "clicked", _bring_in_region_cb, wt);
475 evas_object_smart_callback_add(web, "title,changed", _title_changed_cb, win);
476 evas_object_smart_callback_add(web, "uri,changed", _uri_changed_cb, wt);
478 evas_object_event_callback_add(web, EVAS_CALLBACK_DEL, _main_web_del_cb, wt);
482 elm_web_uri_set(web, "http://www.enlightenment.org");
484 elm_web_window_create_hook_set(web, _new_window_hook, wt);
486 evas_object_resize(win, 320, 480);
487 evas_object_show(win);
491 test_web_normal(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
493 test_web(data, obj, event_info, EINA_FALSE);
497 test_web_mobile(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
499 test_web(data, obj, event_info, EINA_TRUE);