From 6f63fbd639ccc4a3bc90b53a0393a090f15cd0ee Mon Sep 17 00:00:00 2001 From: Ryuan Choi Date: Fri, 27 Dec 2013 22:23:21 +0900 Subject: [PATCH] web: Added elm_web_html_string_load() to load html string as the content It is usefull to load html string instead of url, especially for testing. --- legacy/elementary/src/bin/test.c | 2 ++ legacy/elementary/src/bin/test_web.c | 35 ++++++++++++++++++++ legacy/elementary/src/lib/elm_web.c | 53 ++++++++++++++++++++++++++++++ legacy/elementary/src/lib/elm_web2.c | 27 +++++++++++++++ legacy/elementary/src/lib/elm_web_eo.h | 18 ++++++++++ legacy/elementary/src/lib/elm_web_legacy.h | 22 +++++++++++++ 6 files changed, 157 insertions(+) diff --git a/legacy/elementary/src/bin/test.c b/legacy/elementary/src/bin/test.c index 75172d6..21d2959 100644 --- a/legacy/elementary/src/bin/test.c +++ b/legacy/elementary/src/bin/test.c @@ -228,6 +228,7 @@ void test_eio(void *data, Evas_Object *obj, void *event_info); #endif #ifdef HAVE_ELEMENTARY_WEB void test_web(void *data, Evas_Object *obj, void *event_info); +void test_web_ui(void *data, Evas_Object *obj, void *event_info); #endif void test_dnd_genlist_default_anim(void *data, Evas_Object *obj, void *event_info); void test_dnd_genlist_user_anim(void *data, Evas_Object *obj, void *event_info); @@ -669,6 +670,7 @@ add_tests: //------------------------------// #ifdef HAVE_ELEMENTARY_WEB ADD_TEST(NULL, "Web", "Web", test_web); + ADD_TEST(NULL, "Web", "Web UI", test_web_ui); #endif //------------------------------// diff --git a/legacy/elementary/src/bin/test_web.c b/legacy/elementary/src/bin/test_web.c index c03de30..ee20420 100644 --- a/legacy/elementary/src/bin/test_web.c +++ b/legacy/elementary/src/bin/test_web.c @@ -509,3 +509,38 @@ test_web(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info evas_object_resize(win, 320, 480); evas_object_show(win); } + +void +test_web_ui(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *win, *bx, *web; + Web_Test *wt; + + elm_need_web(); + + wt = calloc(1, sizeof(*wt)); + win = elm_win_util_standard_add("web", "Web"); + + elm_win_autodel_set(win, EINA_TRUE); + + bx = elm_box_add(win); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bx); + evas_object_show(bx); + + web = elm_web_add(win); + evas_object_size_hint_weight_set(web, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(web, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, web); + evas_object_show(web); + + evas_object_event_callback_add(web, EVAS_CALLBACK_DEL, _main_web_del_cb, wt); + wt->web = web; + + elm_web_html_string_load(wt->web, + "Hello, WebKit/Efl", + NULL, NULL); + + evas_object_resize(win, 320, 480); + evas_object_show(win); +} diff --git a/legacy/elementary/src/lib/elm_web.c b/legacy/elementary/src/lib/elm_web.c index 4e2cf3f..fea18dc 100644 --- a/legacy/elementary/src/lib/elm_web.c +++ b/legacy/elementary/src/lib/elm_web.c @@ -1583,6 +1583,57 @@ _url_get(Eo *obj, void *_pd EINA_UNUSED, va_list *list) #endif } +EAPI Eina_Bool +elm_web_html_string_load(Evas_Object *obj, const char *html, const char *base_url, const char *unreachable_url) +{ +#ifdef HAVE_ELEMENTARY_WEB + ELM_WEB_CHECK(obj) EINA_FALSE; + Eina_Bool ret = EINA_FALSE; + eo_do(obj, elm_obj_web_html_string_load(html, base_url, unreachable_url, &ret)); + return ret; +#else + (void)obj; + (void)html; + (void)base_url; + (void)unreachable_url; + return EINA_FALSE; +#endif +} + +static void +_html_string_load(Eo *obj, void *_pd EINA_UNUSED, va_list *list) +{ + const char *html = va_arg(*list, const char *); + const char *base_url = va_arg(*list, const char *); + const char *unreachable_url = va_arg(*list, const char *); + Eina_Bool *ret = va_arg(*list, Eina_Bool *); + if (ret) *ret = EINA_FALSE; + +#ifdef HAVE_ELEMENTARY_WEB + Eina_Bool int_ret; + + ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); + + if (!unreachable_url) + int_ret = ewk_frame_contents_set( + ewk_view_frame_main_get(wd->resize_obj), + html, 0, NULL, NULL, + base_url); + else + int_ret = ewk_frame_contents_alternate_set( + ewk_view_frame_main_get(wd->resize_obj), + html, 0, NULL, NULL, + base_url, unreachable_url); + + if (ret) *ret = int_ret; +#else + (void)obj; + (void)html; + (void)base_url; + (void)unreachable_url; +#endif +} + EAPI const char * elm_web_title_get(const Evas_Object *obj) { @@ -2671,6 +2722,7 @@ _class_constructor(Eo_Class *klass) EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_TAB_PROPAGATE_SET), _tab_propagate_set), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_URL_SET), _url_set), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_URL_GET), _url_get), + EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD), _html_string_load), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_TITLE_GET), _title_get), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_BG_COLOR_SET), _bg_color_set), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_BG_COLOR_GET), _bg_color_get), @@ -2722,6 +2774,7 @@ static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_TAB_PROPAGATE_SET, "Sets whether to use tab propagation."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_URL_SET, "Sets the URL for the web object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_URL_GET, "Get the current URL for the object."), + EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD, "Loads the specified html string as the content of the object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_TITLE_GET, "Get the current title."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_BG_COLOR_SET, "Sets the background color to be used by the web object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_BG_COLOR_GET, "Get the background color to be used by the web object."), diff --git a/legacy/elementary/src/lib/elm_web2.c b/legacy/elementary/src/lib/elm_web2.c index fb2cbd9..8538790 100644 --- a/legacy/elementary/src/lib/elm_web2.c +++ b/legacy/elementary/src/lib/elm_web2.c @@ -455,6 +455,31 @@ _url_get(Eo *obj, void *_pd EINA_UNUSED, va_list *list) *ret = ewk_view_url_get(wd->resize_obj); } +EAPI Eina_Bool +elm_web_html_string_load(Evas_Object *obj, const char *html, const char *base_url, const char *unreachable_url) +{ + ELM_WEB_CHECK(obj) EINA_FALSE; + Eina_Bool ret = EINA_FALSE; + eo_do(obj, elm_obj_web_html_string_load(html, base_url, unreachable_url, &ret)); + return ret; +} + +static void +_html_string_load(Eo *obj, void *_pd EINA_UNUSED, va_list *list) +{ + const char *html = va_arg(*list, const char *); + const char *base_url = va_arg(*list, const char *); + const char *unreachable_url = va_arg(*list, const char *); + Eina_Bool *ret = va_arg(*list, Eina_Bool *); + + if (ret) *ret = EINA_FALSE; + + ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); + + if (ret) *ret = ewk_view_html_string_load(wd->resize_obj, + html, base_url, unreachable_url); +} + EAPI const char * elm_web_title_get(const Evas_Object *obj) { @@ -1323,6 +1348,7 @@ _class_constructor(Eo_Class *klass) EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_URL_SET), _url_set), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_URL_GET), _url_get), + EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD), _html_string_load), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_TITLE_GET), _title_get), EO_OP_FUNC(ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_BG_COLOR_SET), _bg_color_set), @@ -1375,6 +1401,7 @@ static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_TAB_PROPAGATE_SET, "Sets whether to use tab propagation."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_URL_SET, "Sets the URL for the web object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_URL_GET, "Get the current URL for the object."), + EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD, "Loads the specified html string as the content of the object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_TITLE_GET, "Get the current title."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_BG_COLOR_SET, "Sets the background color to be used by the web object."), EO_OP_DESCRIPTION(ELM_OBJ_WEB_SUB_ID_BG_COLOR_GET, "Get the background color to be used by the web object."), diff --git a/legacy/elementary/src/lib/elm_web_eo.h b/legacy/elementary/src/lib/elm_web_eo.h index 62e2fa2..798ee95 100644 --- a/legacy/elementary/src/lib/elm_web_eo.h +++ b/legacy/elementary/src/lib/elm_web_eo.h @@ -19,6 +19,7 @@ enum ELM_OBJ_WEB_SUB_ID_TAB_PROPAGATE_SET, ELM_OBJ_WEB_SUB_ID_URL_SET, ELM_OBJ_WEB_SUB_ID_URL_GET, + ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD, ELM_OBJ_WEB_SUB_ID_TITLE_GET, ELM_OBJ_WEB_SUB_ID_BG_COLOR_SET, ELM_OBJ_WEB_SUB_ID_BG_COLOR_GET, @@ -246,6 +247,23 @@ enum #define elm_obj_web_url_get(ret) ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_URL_GET), EO_TYPECHECK(const char **, ret) /** + * @def elm_obj_web_html_string_load + * @since 1.9 + * + * Loads the specified @a html string as the content of the web object + * + * @param[in] html + * @param[in] base_url + * @param[in] unreachable_url + * @param[out] ret + * + * @see elm_web_html_string_load + * + * @ingroup Web + */ +#define elm_obj_web_html_string_load(html, base_url, unreachable_url, ret) ELM_OBJ_WEB_ID(ELM_OBJ_WEB_SUB_ID_HTML_STRING_LOAD), EO_TYPECHECK(const char *, html), EO_TYPECHECK(const char *, base_url), EO_TYPECHECK(const char *, unreachable_url), EO_TYPECHECK(Eina_Bool *, ret) + +/** * @def elm_obj_web_title_get * @since 1.8 * diff --git a/legacy/elementary/src/lib/elm_web_legacy.h b/legacy/elementary/src/lib/elm_web_legacy.h index 74f8e81..533c06b 100644 --- a/legacy/elementary/src/lib/elm_web_legacy.h +++ b/legacy/elementary/src/lib/elm_web_legacy.h @@ -180,6 +180,28 @@ EAPI void elm_web_tab_propagate_set(Evas_Object *obj, Eina_Bool pro EAPI Eina_Bool elm_web_url_set(Evas_Object *obj, const char *url); /** + * Loads the specified @a html string as the content of the web object + * + * @param obj The web object + * @param html HTML data to load + * @param base_url Base URL used for relative paths to external objects (optional) + * @param unreachable_url URL that could not be reached (optional) + * + * @return @c EINA_TRUE if it the HTML was successfully loaded, @c EINA_FALSE otherwise + * + * External objects such as stylesheets or images referenced in the HTML + * document are located relative to @a base_url. + * + * If an @a unreachable_url is passed it is used as the url for the loaded + * content. This is typically used to display error pages for a failed + * load. + * + * @since 1.9 + * @ingroup Web + */ +EAPI Eina_Bool elm_web_html_string_load(Evas_Object *obj, const char *html, const char *base_url, const char *unreachable_url); + +/** * Get the current URL for the object * * The returned string must not be freed and is guaranteed to be -- 2.7.4