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 --- content/content.h | 7 +++++- desktop/browser.c | 17 ++++++++++++- desktop/browser.h | 3 +++ render/html.c | 70 ++++++++++++++++++++++++++++++---------------------- render/html.h | 2 ++ render/html_object.c | 1 + 6 files changed, 69 insertions(+), 31 deletions(-) diff --git a/content/content.h b/content/content.h index 467fa6055..91a6ae9df 100644 --- a/content/content.h +++ b/content/content.h @@ -83,7 +83,8 @@ typedef enum { CONTENT_MSG_POINTER, /**< Wants a specific mouse pointer set */ CONTENT_MSG_SELECTION, /**< A selection made or cleared */ CONTENT_MSG_CARET, /**< Caret movement / hiding */ - CONTENT_MSG_DRAG /**< A drag started or ended */ + CONTENT_MSG_DRAG, /**< A drag started or ended */ + CONTENT_MSG_GADGETCLICK/**< A gadget has been clicked on (mainly for file) */ } content_msg; /** RFC5988 metadata link */ @@ -190,6 +191,10 @@ union content_msg_data { } type; const struct rect *rect; } drag; + /** CONTENT_MSG_GADGETCLICK - User clicked on a form gadget */ + struct { + struct form_control *gadget; + } gadget_click; }; /** parameters to content redraw */ diff --git a/desktop/browser.c b/desktop/browser.c index 83b06bac5..3d279f727 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -661,6 +661,13 @@ bool browser_window_drop_file_at_point(struct browser_window *bw, return false; } +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn) +{ + html_set_file_gadget_filename(bw->current_content, + gadget, fn); +} + /* exported interface, documented in browser.h */ void browser_window_debug_dump(struct browser_window *bw, FILE *f) { @@ -1162,7 +1169,7 @@ static void browser_window_convert_to_download(struct browser_window *bw, /** - * Callback for fetchcache() for browser window fetches. + * Callback handler for content event messages. */ static nserror browser_window_callback(hlcache_handle *c, @@ -1555,6 +1562,14 @@ static nserror browser_window_callback(hlcache_handle *c, event->data.selection.read_only); break; + case CONTENT_MSG_GADGETCLICK: + if (event->data.gadget_click.gadget->type == GADGET_FILE) { + gui_file_gadget_open(bw, c, + event->data.gadget_click.gadget); + } + + break; + default: break; } diff --git a/desktop/browser.h b/desktop/browser.h index ee55e72c4..0ca2e009b 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -173,6 +173,9 @@ bool browser_window_scroll_at_point(struct browser_window *bw, bool browser_window_drop_file_at_point(struct browser_window *bw, int x, int y, char *file); +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn); + void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, lwc_string *frag); 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