Add infrastructure for calling front ends to set file gadget filenames via clicking in addition to drag-and-drop

This commit is contained in:
Rob Kendrick 2014-01-05 16:04:35 +00:00
parent d8ad3b8e78
commit 0d7f1cfc93
6 changed files with 69 additions and 31 deletions

View File

@ -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 */

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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);