remove user warning and fix up error handling in form select menus

This commit is contained in:
Vincent Sanders 2019-11-07 18:52:49 +00:00
parent 7de3100624
commit 570f2dc036
3 changed files with 36 additions and 28 deletions

View File

@ -1486,10 +1486,11 @@ form_encode_item(const char *item,
} }
/* exported interface documented in html/form_internal.h */ /* exported interface documented in html/form_internal.h */
bool form_open_select_menu(void *client_data, nserror
struct form_control *control, form_open_select_menu(void *client_data,
select_menu_redraw_callback callback, struct form_control *control,
struct content *c) select_menu_redraw_callback callback,
struct content *c)
{ {
int line_height_with_spacing; int line_height_with_spacing;
struct box *box; struct box *box;
@ -1497,15 +1498,14 @@ bool form_open_select_menu(void *client_data,
int total_height; int total_height;
struct form_select_menu *menu; struct form_select_menu *menu;
html_content *html = (html_content *)c; html_content *html = (html_content *)c;
nserror res;
/* if the menu is opened for the first time */ /* if the menu is opened for the first time */
if (control->data.select.menu == NULL) { if (control->data.select.menu == NULL) {
menu = calloc(1, sizeof (struct form_select_menu)); menu = calloc(1, sizeof (struct form_select_menu));
if (menu == NULL) { if (menu == NULL) {
guit->misc->warning("NoMemory", 0); return NSERROR_NOMEM;
return false;
} }
control->data.select.menu = menu; control->data.select.menu = menu;
@ -1513,9 +1513,8 @@ bool form_open_select_menu(void *client_data,
box = control->box; box = control->box;
menu->width = box->width + menu->width = box->width +
box->border[RIGHT].width + box->border[RIGHT].width + box->padding[RIGHT] +
box->border[LEFT].width + box->border[LEFT].width + box->padding[LEFT];
box->padding[RIGHT] + box->padding[LEFT];
font_plot_style_from_css(&html->len_ctx, control->box->style, font_plot_style_from_css(&html->len_ctx, control->box->style,
&fstyle); &fstyle);
@ -1535,28 +1534,31 @@ bool form_open_select_menu(void *client_data,
menu->height = total_height; menu->height = total_height;
if (menu->height > MAX_SELECT_HEIGHT) { if (menu->height > MAX_SELECT_HEIGHT) {
menu->height = MAX_SELECT_HEIGHT; menu->height = MAX_SELECT_HEIGHT;
} }
menu->client_data = client_data; menu->client_data = client_data;
menu->callback = callback; menu->callback = callback;
if (scrollbar_create(false, res = scrollbar_create(false,
menu->height, menu->height,
total_height, total_height,
menu->height, menu->height,
control, control,
form_select_menu_scroll_callback, form_select_menu_scroll_callback,
&(menu->scrollbar)) != NSERROR_OK) { &(menu->scrollbar));
if (res != NSERROR_OK) {
control->data.select.menu = NULL;
free(menu); free(menu);
return false; return res;
} }
menu->c = c; menu->c = c;
} else {
menu = control->data.select.menu;
} }
else menu = control->data.select.menu;
menu->callback(client_data, 0, 0, menu->width, menu->height); menu->callback(client_data, 0, 0, menu->width, menu->height);
return true; return NSERROR_OK;
} }

View File

@ -200,13 +200,13 @@ bool form_successful_controls(struct form *form,
/** /**
* Open a select menu for a select form control, creating it if necessary. * Open a select menu for a select form control, creating it if necessary.
* *
* \param client_data data passed to the redraw callback * \param client_data data passed to the redraw callback
* \param control The select form control for which the menu is being opened * \param control The select form control for which the menu is being opened
* \param redraw_callback The callback to redraw the select menu. * \param redraw_callback The callback to redraw the select menu.
* \param c The content the select menu is opening for. * \param c The content the select menu is opening for.
* \return false on memory exhaustion, true otherwise * \return NSERROR_OK on sucess else error code.
*/ */
bool form_open_select_menu(void *client_data, nserror form_open_select_menu(void *client_data,
struct form_control *control, struct form_control *control,
select_menu_redraw_callback redraw_callback, select_menu_redraw_callback redraw_callback,
struct content *c); struct content *c);

View File

@ -716,9 +716,15 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
if (mouse & BROWSER_MOUSE_CLICK_1 && if (mouse & BROWSER_MOUSE_CLICK_1 &&
nsoption_bool(core_select_menu)) { nsoption_bool(core_select_menu)) {
html->visible_select_menu = gadget; html->visible_select_menu = gadget;
form_open_select_menu(c, gadget, res = form_open_select_menu(c, gadget,
form_select_menu_callback, form_select_menu_callback,
c); c);
if (res != NSERROR_OK) {
NSLOG(netsurf, ERROR,
"%s",
messages_get_errorcode(res));
html->visible_select_menu = NULL;
}
pointer = BROWSER_POINTER_DEFAULT; pointer = BROWSER_POINTER_DEFAULT;
} else if (mouse & BROWSER_MOUSE_CLICK_1) { } else if (mouse & BROWSER_MOUSE_CLICK_1) {
msg_data.select_menu.gadget = gadget; msg_data.select_menu.gadget = gadget;