From 0d7f1cfc93008add9a082c2c54de8427ac0f1786 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:04:35 +0000 Subject: Add infrastructure for calling front ends to set file gadget filenames via clicking in addition to drag-and-drop --- render/html.c | 70 ++++++++++++++++++++++++++++++---------------------- render/html.h | 2 ++ render/html_object.c | 1 + 3 files changed, 44 insertions(+), 29 deletions(-) (limited to 'render') diff --git a/render/html.c b/render/html.c index c1e831571..103dec14f 100644 --- a/render/html.c +++ b/render/html.c @@ -1729,6 +1729,46 @@ static void html__dom_user_data_handler(dom_node_operation operation, } } +static void html__set_file_gadget_filename(struct content *c, + struct form_control *gadget, const char *fn) +{ + utf8_convert_ret ret; + char *utf8_fn, *oldfile = NULL; + html_content *html = (html_content *)c; + struct box *file_box = gadget->box; + + ret = utf8_from_local_encoding(fn,0, &utf8_fn); + if (ret != UTF8_CONVERT_OK) { + assert(ret != UTF8_CONVERT_BADENC); + LOG(("utf8_from_local_encoding failed")); + /* Load was for us - just no memory */ + return; + } + + form_gadget_update_value(html, gadget, utf8_fn); + + /* corestring_dom___ns_key_file_name_node_data */ + LOG(("XYZZY: Setting userdata to %s", fn)); + if (dom_node_set_user_data((dom_node *)file_box->gadget->node, + corestring_dom___ns_key_file_name_node_data, + strdup(fn), html__dom_user_data_handler, + &oldfile) == DOM_NO_ERR) { + LOG(("XYZZY: Userdata used to be %s", oldfile)); + if (oldfile != NULL) + free(oldfile); + } + + /* Redraw box. */ + html__redraw_a_box(html, file_box); +} + +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn) +{ + return html__set_file_gadget_filename(hlcache_handle_get_content(hl), + gadget, fn); +} + /** * Drop a file onto a content at a particular point, or determine if a file * may be dropped onto the content at given point. @@ -1794,35 +1834,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) /* Handle the drop */ if (file_box) { /* File dropped on file input */ - utf8_convert_ret ret; - char *utf8_fn, *oldfile = NULL; - - ret = utf8_from_local_encoding(file, 0, - &utf8_fn); - if (ret != UTF8_CONVERT_OK) { - /* A bad encoding should never happen */ - assert(ret != UTF8_CONVERT_BADENC); - LOG(("utf8_from_local_encoding failed")); - /* Load was for us - just no memory */ - return true; - } - - /* Found: update form input */ - form_gadget_update_value(html, file_box->gadget, utf8_fn); - - /* corestring_dom___ns_key_file_name_node_data */ - LOG(("XYZZY: Setting userdata to %s", file)); - if (dom_node_set_user_data((dom_node *)file_box->gadget->node, - corestring_dom___ns_key_file_name_node_data, - strdup(file), html__dom_user_data_handler, - &oldfile) == DOM_NO_ERR) { - LOG(("XYZZY: Userdata used to be %s", oldfile)); - if (oldfile != NULL) - free(oldfile); - } - - /* Redraw box. */ - html__redraw_a_box(html, file_box); + html__set_file_gadget_filename(c, box->gadget, file); } else { /* File dropped on text input */ diff --git a/render/html.h b/render/html.h index 162541d72..7ca75e713 100644 --- a/render/html.h +++ b/render/html.h @@ -178,6 +178,8 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h); struct content_html_iframe *html_get_iframe(struct hlcache_handle *h); nsurl *html_get_base_url(struct hlcache_handle *h); const char *html_get_base_target(struct hlcache_handle *h); +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn); /** * Retrieve stylesheets used by HTML document diff --git a/render/html_object.c b/render/html_object.c index 7b34c4a7e..15ca7ed3b 100644 --- a/render/html_object.c +++ b/render/html_object.c @@ -368,6 +368,7 @@ html_object_callback(hlcache_handle *object, case CONTENT_MSG_SAVELINK: case CONTENT_MSG_POINTER: + case CONTENT_MSG_GADGETCLICK: /* These messages are for browser window layer. * we're not interested, so pass them on. */ content_broadcast(&c->base, event->type, event->data); -- cgit v1.2.3