remove unecessary user warning calls and improve error propogation in html box

This commit is contained in:
Vincent Sanders 2019-11-05 23:05:42 +00:00
parent 78aa34e5d7
commit cbb0c05258
4 changed files with 63 additions and 50 deletions

View File

@ -1114,22 +1114,18 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style)
}
}
/**
* Applies the given scroll setup to a box. This includes scroll
* creation/deletion as well as scroll dimension updates.
*
* \param c content in which the box is located
* \param box the box to handle the scrolls for
* \param bottom whether the horizontal scrollbar should be present
* \param right whether the vertical scrollbar should be present
* \return true on success false otherwise
*/
bool box_handle_scrollbars(struct content *c, struct box *box,
bool bottom, bool right)
/* exported interface documented in html/box.h */
nserror
box_handle_scrollbars(struct content *c,
struct box *box,
bool bottom,
bool right)
{
struct html_scrollbar_data *data;
int visible_width, visible_height;
int full_width, full_height;
nserror res;
if (!bottom && box->scroll_x != NULL) {
data = scrollbar_get_data(box->scroll_x);
@ -1145,8 +1141,9 @@ bool box_handle_scrollbars(struct content *c, struct box *box,
box->scroll_y = NULL;
}
if (!bottom && !right)
return true;
if (!bottom && !right) {
return NSERROR_OK;
}
visible_width = box->width + box->padding[RIGHT] + box->padding[LEFT];
visible_height = box->height + box->padding[TOP] + box->padding[BOTTOM];
@ -1164,40 +1161,44 @@ bool box_handle_scrollbars(struct content *c, struct box *box,
if (box->scroll_y == NULL) {
data = malloc(sizeof(struct html_scrollbar_data));
if (data == NULL) {
NSLOG(netsurf, INFO, "malloc failed");
guit->misc->warning("NoMemory", 0);
return false;
return NSERROR_NOMEM;
}
data->c = c;
data->box = box;
if (scrollbar_create(false, visible_height,
full_height, visible_height,
data, html_overflow_scroll_callback,
&(box->scroll_y)) != NSERROR_OK) {
return false;
res = scrollbar_create(false,
visible_height,
full_height,
visible_height,
data,
html_overflow_scroll_callback,
&(box->scroll_y));
if (res != NSERROR_OK) {
return res;
}
} else {
scrollbar_set_extents(box->scroll_y, visible_height,
visible_height, full_height);
scrollbar_set_extents(box->scroll_y,
visible_height,
visible_height,
full_height);
}
}
if (bottom) {
if (box->scroll_x == NULL) {
data = malloc(sizeof(struct html_scrollbar_data));
if (data == NULL) {
NSLOG(netsurf, INFO, "malloc failed");
guit->misc->warning("NoMemory", 0);
return false;
return NSERROR_OK;
}
data->c = c;
data->box = box;
if (scrollbar_create(true,
visible_width -
(right ? SCROLLBAR_WIDTH : 0),
full_width, visible_width,
data, html_overflow_scroll_callback,
&box->scroll_x) != NSERROR_OK) {
return false;
res = scrollbar_create(true,
visible_width - (right ? SCROLLBAR_WIDTH : 0),
full_width,
visible_width,
data,
html_overflow_scroll_callback,
&box->scroll_x);
if (res != NSERROR_OK) {
return res;
}
} else {
scrollbar_set_extents(box->scroll_x,
@ -1207,10 +1208,11 @@ bool box_handle_scrollbars(struct content *c, struct box *box,
}
}
if (right && bottom)
if (right && bottom) {
scrollbar_make_pair(box->scroll_x, box->scroll_y);
}
return true;
return NSERROR_OK;
}
/**

View File

@ -353,8 +353,19 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style);
*/
bool box_extract_link(const struct html_content *content, const struct dom_string *dsrel, struct nsurl *base, struct nsurl **result);
bool box_handle_scrollbars(struct content *c, struct box *box,
/**
* Applies the given scroll setup to a box. This includes scroll
* creation/deletion as well as scroll dimension updates.
*
* \param c content in which the box is located
* \param box the box to handle the scrolls for
* \param bottom whether the horizontal scrollbar should be present
* \param right whether the vertical scrollbar should be present
* \return true on success false otherwise
*/
nserror box_handle_scrollbars(struct content *c, struct box *box,
bool bottom, bool right);
bool box_vscrollbar_present(const struct box *box);
bool box_hscrollbar_present(const struct box *box);

View File

@ -1841,20 +1841,24 @@ bool html_redraw_box(const html_content *html, struct box *box,
/* scrollbars */
if (((box->style && box->type != BOX_BR &&
box->type != BOX_TABLE && box->type != BOX_INLINE &&
(overflow_x == CSS_OVERFLOW_SCROLL ||
overflow_x == CSS_OVERFLOW_AUTO ||
overflow_y == CSS_OVERFLOW_SCROLL ||
overflow_y == CSS_OVERFLOW_AUTO)) ||
(box->object && content_get_type(box->object) ==
CONTENT_HTML)) && box->parent != NULL) {
box->type != BOX_TABLE && box->type != BOX_INLINE &&
(overflow_x == CSS_OVERFLOW_SCROLL ||
overflow_x == CSS_OVERFLOW_AUTO ||
overflow_y == CSS_OVERFLOW_SCROLL ||
overflow_y == CSS_OVERFLOW_AUTO)) ||
(box->object && content_get_type(box->object) ==
CONTENT_HTML)) && box->parent != NULL) {
nserror res;
has_x_scroll = box_hscrollbar_present(box);
has_y_scroll = box_vscrollbar_present(box);
if (!box_handle_scrollbars((struct content *)html,
box, has_x_scroll, has_y_scroll))
res = box_handle_scrollbars((struct content *)html,
box, has_x_scroll, has_y_scroll);
if (res != NSERROR_OK) {
NSLOG(netsurf, INFO, "%s", messages_get_errorcode(res));
return false;
}
if (box->scroll_x != NULL)
scrollbar_redraw(box->scroll_x,

View File

@ -3486,8 +3486,6 @@ navigate_internal_real(struct browser_window *bw,
default: /* report error to user */
browser_window_set_status(bw, messages_get_errorcode(res));
/** @todo should the caller report the error? */
guit->misc->warning(messages_get_errorcode(res), NULL);
break;
}
@ -4445,8 +4443,6 @@ browser_window_find_target(struct browser_window *bw,
* that begin with an underscore. */
if (target[0] != '_') {
bw_target->name = strdup(target);
if (!bw_target->name)
guit->misc->warning("NoMemory", NULL);
}
return bw_target;
}