diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c index 2918ce7d2..fd0f2fa3e 100644 --- a/content/handlers/html/form.c +++ b/content/handlers/html/form.c @@ -1486,10 +1486,11 @@ form_encode_item(const char *item, } /* exported interface documented in html/form_internal.h */ -bool form_open_select_menu(void *client_data, - struct form_control *control, - select_menu_redraw_callback callback, - struct content *c) +nserror +form_open_select_menu(void *client_data, + struct form_control *control, + select_menu_redraw_callback callback, + struct content *c) { int line_height_with_spacing; struct box *box; @@ -1497,15 +1498,14 @@ bool form_open_select_menu(void *client_data, int total_height; struct form_select_menu *menu; html_content *html = (html_content *)c; - + nserror res; /* if the menu is opened for the first time */ if (control->data.select.menu == NULL) { menu = calloc(1, sizeof (struct form_select_menu)); if (menu == NULL) { - guit->misc->warning("NoMemory", 0); - return false; + return NSERROR_NOMEM; } control->data.select.menu = menu; @@ -1513,9 +1513,8 @@ bool form_open_select_menu(void *client_data, box = control->box; menu->width = box->width + - box->border[RIGHT].width + - box->border[LEFT].width + - box->padding[RIGHT] + box->padding[LEFT]; + box->border[RIGHT].width + box->padding[RIGHT] + + box->border[LEFT].width + box->padding[LEFT]; font_plot_style_from_css(&html->len_ctx, control->box->style, &fstyle); @@ -1535,28 +1534,31 @@ bool form_open_select_menu(void *client_data, menu->height = total_height; if (menu->height > MAX_SELECT_HEIGHT) { - menu->height = MAX_SELECT_HEIGHT; } + menu->client_data = client_data; menu->callback = callback; - if (scrollbar_create(false, - menu->height, - total_height, - menu->height, - control, - form_select_menu_scroll_callback, - &(menu->scrollbar)) != NSERROR_OK) { + res = scrollbar_create(false, + menu->height, + total_height, + menu->height, + control, + form_select_menu_scroll_callback, + &(menu->scrollbar)); + if (res != NSERROR_OK) { + control->data.select.menu = NULL; free(menu); - return false; + return res; } 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); - return true; + return NSERROR_OK; } diff --git a/content/handlers/html/form_internal.h b/content/handlers/html/form_internal.h index 657522488..45f861f87 100644 --- a/content/handlers/html/form_internal.h +++ b/content/handlers/html/form_internal.h @@ -200,13 +200,13 @@ bool form_successful_controls(struct form *form, /** * Open a select menu for a select form control, creating it if necessary. * - * \param client_data data passed to the redraw callback - * \param control The select form control for which the menu is being opened - * \param redraw_callback The callback to redraw the select menu. - * \param c The content the select menu is opening for. - * \return false on memory exhaustion, true otherwise + * \param client_data data passed to the redraw callback + * \param control The select form control for which the menu is being opened + * \param redraw_callback The callback to redraw the select menu. + * \param c The content the select menu is opening for. + * \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, select_menu_redraw_callback redraw_callback, struct content *c); diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c index 330dd24d0..4de15f872 100644 --- a/content/handlers/html/html_interaction.c +++ b/content/handlers/html/html_interaction.c @@ -716,9 +716,15 @@ void html_mouse_action(struct content *c, struct browser_window *bw, if (mouse & BROWSER_MOUSE_CLICK_1 && nsoption_bool(core_select_menu)) { html->visible_select_menu = gadget; - form_open_select_menu(c, gadget, + res = form_open_select_menu(c, gadget, form_select_menu_callback, c); + if (res != NSERROR_OK) { + NSLOG(netsurf, ERROR, + "%s", + messages_get_errorcode(res)); + html->visible_select_menu = NULL; + } pointer = BROWSER_POINTER_DEFAULT; } else if (mouse & BROWSER_MOUSE_CLICK_1) { msg_data.select_menu.gadget = gadget;