From 4565574eaab2e73766190a72c951601b1da355f9 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 2 Jun 2004 21:16:48 +0000 Subject: [project @ 2004-06-02 21:14:40 by bursa] Revert accidental checkin. svn path=/import/netsurf/; revision=916 --- render/form.c | 40 ++++----- render/layout.c | 265 ++++++++++++++++++-------------------------------------- render/layout.h | 6 +- 3 files changed, 107 insertions(+), 204 deletions(-) (limited to 'render') diff --git a/render/form.c b/render/form.c index 933d15148..6b1b247df 100644 --- a/render/form.c +++ b/render/form.c @@ -135,10 +135,10 @@ struct form_successful_control *form_successful_controls(struct form *form, for (option = control->data.select.items; option; option = option->next) { if (option->selected) { - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = strdup(control->name); - success_new->value = strdup(option->value); + success_new->name = xstrdup(control->name); + success_new->value = xstrdup(option->value); success_new->next = 0; last_success->next = success_new; last_success = success_new; @@ -149,9 +149,9 @@ struct form_successful_control *form_successful_controls(struct form *form, /* textarea */ if (control->type == GADGET_TEXTAREA) { - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = strdup(control->name); + success_new->name = xstrdup(control->name); success_new->value = form_textarea_value(control); success_new->next = 0; last_success->next = success_new; @@ -163,21 +163,21 @@ struct form_successful_control *form_successful_controls(struct form *form, if (control->type == GADGET_IMAGE) { unsigned int len = strlen(control->name) + 3; /* x */ - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = calloc(1, len); + success_new->name = xcalloc(1, len); sprintf(success_new->name, "%s.x", control->name); - success_new->value = calloc(1, 20); + success_new->value = xcalloc(1, 20); sprintf(success_new->value, "%i", control->data.image.mx); success_new->next = 0; last_success->next = success_new; last_success = success_new; /* y */ - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = calloc(1, len); + success_new->name = xcalloc(1, len); sprintf(success_new->name, "%s.y", control->name); - success_new->value = calloc(1, 20); + success_new->value = xcalloc(1, 20); sprintf(success_new->value, "%i", control->data.image.my); success_new->next = 0; last_success->next = success_new; @@ -190,10 +190,10 @@ struct form_successful_control *form_successful_controls(struct form *form, /* file */ if (control->type == GADGET_FILE && control->value) { - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = true; - success_new->name = strdup(control->name); - success_new->value = strdup(control->value); + success_new->name = xstrdup(control->name); + success_new->value = xstrdup(control->value); success_new->next = 0; last_success->next = success_new; last_success = success_new; @@ -202,10 +202,10 @@ struct form_successful_control *form_successful_controls(struct form *form, /* all others added if they have a value */ if (control->value) { - success_new = calloc(1, sizeof(*success_new)); + success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = strdup(control->name); - success_new->value = strdup(control->value); + success_new->name = xstrdup(control->name); + success_new->value = xstrdup(control->value); success_new->next = 0; last_success->next = success_new; last_success = success_new; @@ -239,7 +239,7 @@ char *form_textarea_value(struct form_control *textarea) } /* construct value */ - s = value = calloc(1, len); + s = value = xcalloc(1, len); for (inline_container = textarea->box->children; inline_container; inline_container = inline_container->next) { @@ -265,14 +265,14 @@ char *form_textarea_value(struct form_control *textarea) char *form_url_encode(struct form_successful_control *control) { - char *s = calloc(1, 0); + char *s = xcalloc(1, 0); unsigned int len = 0, len1; for (; control; control = control->next) { char *name = curl_escape(control->name, 0); char *value = curl_escape(control->value, 0); len1 = len + strlen(name) + strlen(value) + 2; - s = realloc(s, len1 + 1); + s = xrealloc(s, len1 + 1); sprintf(s + len, "%s=%s&", name, value); len = len1; curl_free(name); diff --git a/render/layout.c b/render/layout.c index 0c9877757..35e9560ed 100644 --- a/render/layout.c +++ b/render/layout.c @@ -32,12 +32,10 @@ #include "netsurf/render/layout.h" #define NDEBUG #include "netsurf/utils/log.h" -#include "netsurf/utils/pool.h" #include "netsurf/utils/utils.h" #define AUTO INT_MIN -#define ERROR_OUT_OF_MEMORY 1 static void layout_block_find_dimensions(int available_width, struct box *box); @@ -51,42 +49,38 @@ static void layout_find_dimensions(int available_width, static int layout_clear(struct box *fl, css_clear clear); static void find_sides(struct box *fl, int y0, int y1, int *x0, int *x1, struct box **left, struct box **right); -static bool layout_inline_container(struct box *box, int width, - struct box *cont, int cx, int cy, pool box_pool); +static void layout_inline_container(struct box *box, int width, + struct box *cont, int cx, int cy); static int line_height(struct css_style *style); -static bool layout_line(struct box *first, int width, int *y, - int cx, int cy, struct box *cont, bool indent, - pool box_pool, struct box **next_box); +static struct box * layout_line(struct box *first, int width, int *y, + int cx, int cy, struct box *cont, bool indent); static int layout_text_indent(struct css_style *style, int width); -static bool layout_float(struct box *b, int width, pool box_pool); +static void layout_float(struct box *b, int width); static void place_float_below(struct box *c, int width, int cx, int y, struct box *cont); -static bool layout_table(struct box *box, int available_width, pool box_pool); -static bool calculate_widths(struct box *box); -static bool calculate_block_widths(struct box *box, int *min, int *max, +static void layout_table(struct box *box, int available_width); +static void calculate_widths(struct box *box); +static void calculate_block_widths(struct box *box, int *min, int *max, int *max_sum); -static bool calculate_inline_container_widths(struct box *box); +static void calculate_inline_container_widths(struct box *box); static void calculate_inline_replaced_widths(struct box *box, int *min, int *max, int *line_max); static void calculate_inline_widths(struct box *box, int *min, int *line_max); -static bool calculate_table_widths(struct box *table); +static void calculate_table_widths(struct box *table); /** * Calculate positions of boxes in a document. * - * \param doc root of document box tree - * \param width available page width - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion + * \param doc root of document box tree + * \param width available page width */ -bool layout_document(struct box *doc, int width, pool box_pool) +void layout_document(struct box *doc, int width) { doc->float_children = 0; - if (!calculate_widths(doc)) - return false; + calculate_widths(doc); layout_block_find_dimensions(width, doc); doc->x = doc->margin[LEFT] + doc->border[LEFT]; @@ -94,7 +88,7 @@ bool layout_document(struct box *doc, int width, pool box_pool) width -= doc->margin[LEFT] + doc->border[LEFT] + doc->border[RIGHT] + doc->margin[RIGHT]; doc->width = width; - return layout_block_context(doc, box_pool); + layout_block_context(doc); } @@ -102,14 +96,12 @@ bool layout_document(struct box *doc, int width, pool box_pool) * Layout a block formatting context. * * \param block BLOCK, INLINE_BLOCK, or TABLE_CELL to layout. - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion * * This function carries out layout of a block and its children, as described * in CSS 2.1 9.4.1. */ -bool layout_block_context(struct box *block, pool box_pool) +void layout_block_context(struct box *block) { struct box *box; int cx; @@ -147,8 +139,7 @@ bool layout_block_context(struct box *block, pool box_pool) if (box->type == BOX_BLOCK) layout_block_find_dimensions(box->parent->width, box); else if (box->type == BOX_TABLE) { - if (!layout_table(box, box->parent->width, box_pool)) - return false; + layout_table(box, box->parent->width); layout_solve_width(box->parent->width, box->width, box->margin, box->padding, box->border); } @@ -187,9 +178,7 @@ bool layout_block_context(struct box *block, pool box_pool) /* Layout (except tables). */ if (box->type == BOX_INLINE_CONTAINER) { box->width = box->parent->width; - if (!layout_inline_container(box, box->width, block, - cx, cy, box_pool)) - return false; + layout_inline_container(box, box->width, block, cx, cy); } else if (box->type == BOX_TABLE) { /* Move down to avoid floats if necessary. */ int x0, x1; @@ -278,8 +267,6 @@ bool layout_block_context(struct box *block, pool box_pool) if (block->height == AUTO) block->height = cy - block->padding[TOP]; - - return true; } @@ -592,15 +579,13 @@ void find_sides(struct box *fl, int y0, int y1, * \param cont ancestor box which defines horizontal space, for floats * \param cx box position relative to cont * \param cy box position relative to cont - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion */ -bool layout_inline_container(struct box *box, int width, - struct box *cont, int cx, int cy, pool box_pool) +void layout_inline_container(struct box *box, int width, + struct box *cont, int cx, int cy) { bool first_line = true; - struct box *c, *next; + struct box *c; int y = 0; assert(box->type == BOX_INLINE_CONTAINER); @@ -610,17 +595,12 @@ bool layout_inline_container(struct box *box, int width, for (c = box->children; c; ) { LOG(("c %p", c)); - if (!layout_line(c, width, &y, cx, cy + y, cont, first_line, - box_pool, &next)) - return false; - c = next; + c = layout_line(c, width, &y, cx, cy + y, cont, first_line); first_line = false; } box->width = width; box->height = y; - - return true; } @@ -667,14 +647,10 @@ int line_height(struct css_style *style) * \param cy coordinate of top of line relative to cont * \param cont ancestor box which defines horizontal space, for floats * \param indent apply any first-line indent - * \param next_box updated to first box for next line, or 0 at end - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion */ -bool layout_line(struct box *first, int width, int *y, - int cx, int cy, struct box *cont, bool indent, - pool box_pool, struct box **next_box) +struct box * layout_line(struct box *first, int width, int *y, + int cx, int cy, struct box *cont, bool indent) { int height, used_height; int x0 = 0; @@ -711,8 +687,7 @@ bool layout_line(struct box *first, int width, int *y, if (b->type == BOX_INLINE_BLOCK) { if (b->width == UNKNOWN_WIDTH) - if (!layout_float(b, width, box_pool)) - return false; + layout_float(b, width); /** \todo should margin be included? spec unclear */ h = b->border[TOP] + b->padding[TOP] + b->height + b->padding[BOTTOM] + b->border[BOTTOM]; @@ -781,32 +756,23 @@ bool layout_line(struct box *first, int width, int *y, break; } - if (b->object) { - if (b->width == AUTO && b->height == AUTO) { + if (b->width == AUTO && b->height == AUTO) { + b->width = b->object->width; + b->height = b->object->height; + } else if (b->width == AUTO) { + if (b->object->height) + b->width = b->object->width * + (float) b->height / + b->object->height; + else b->width = b->object->width; + } else if (b->height == AUTO) { + if (b->object->width) + b->height = b->object->height * + (float) b->width / + b->object->width; + else b->height = b->object->height; - } else if (b->width == AUTO) { - if (b->object->height) - b->width = b->object->width * - (float) b->height / - b->object->height; - else - b->width = b->object->width; - } else if (b->height == AUTO) { - if (b->object->width) - b->height = b->object->height * - (float) b->width / - b->object->width; - else - b->height = b->object->height; - } - } else { - /* form control with no object */ - if (b->width == AUTO) - b->width = 0; - if (b->height == AUTO) - b->height = line_height(b->style ? b->style : - b->parent->parent->style); } if (b->object && b->object->type == CONTENT_HTML && @@ -877,8 +843,7 @@ bool layout_line(struct box *first, int width, int *y, d->float_children = 0; /* css_dump_style(b->style); */ - if (!layout_float(d, width, box_pool)) - return false; + layout_float(d, width); d->x = d->margin[LEFT] + d->border[LEFT]; d->y = d->margin[TOP] + d->border[TOP]; b->width = d->margin[LEFT] + d->border[LEFT] + @@ -955,13 +920,9 @@ bool layout_line(struct box *first, int width, int *y, } else { /* cut off first word for this line */ /* \todo allocate from box_pool */ - c2 = pool_alloc(box_pool, sizeof *c2); - if (!c2) - return false; - memcpy(c2, split_box, sizeof *c2); - c2->text = strdup(split_box->text + space + 1); - if (!c2->text) - return false; + c2 = memcpy(xcalloc(1, sizeof (struct box)), + split_box, sizeof (struct box)); + c2->text = xstrdup(split_box->text + space + 1); c2->length = split_box->length - (space + 1); c2->width = UNKNOWN_WIDTH; c2->clone = 1; @@ -997,13 +958,9 @@ bool layout_line(struct box *first, int width, int *y, if (space == 0) space = 1; /* \todo use box pool */ - c2 = pool_alloc(box_pool, sizeof *c2); - if (!c2) - return false; - memcpy(c2, split_box, sizeof *c2); - c2->text = strdup(split_box->text + space + 1); - if (!c2->text) - return false; + c2 = memcpy(xcalloc(1, sizeof (struct box)), split_box, + sizeof (struct box)); + c2->text = xstrdup(split_box->text + space + 1); c2->length = split_box->length - (space + 1); c2->width = UNKNOWN_WIDTH; c2->clone = 1; @@ -1045,8 +1002,7 @@ bool layout_line(struct box *first, int width, int *y, assert(b != first || (move_y && 0 < used_height && (left || right))); if (move_y) *y += used_height; - *next_box = b; - return true; + return b; } @@ -1076,23 +1032,19 @@ int layout_text_indent(struct css_style *style, int width) * * \param b float or inline block box * \param width available width - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion */ -bool layout_float(struct box *b, int width, pool box_pool) +void layout_float(struct box *b, int width) { layout_float_find_dimensions(width, b->style, b); if (b->type == BOX_TABLE) { - if (!layout_table(b, width, box_pool)) - return false; + layout_table(b, width); if (b->margin[LEFT] == AUTO) b->margin[LEFT] = 0; if (b->margin[RIGHT] == AUTO) b->margin[RIGHT] = 0; } else - return layout_block_context(b, box_pool); - return true; + layout_block_context(b); } @@ -1138,13 +1090,9 @@ void place_float_below(struct box *c, int width, int cx, int y, /** * Layout a table. - * - * \param box_pool memory pool for any new boxes - * \return true on success, false on memory exhaustion */ -bool layout_table(struct box *table, int available_width, - pool box_pool) +void layout_table(struct box *table, int available_width) { unsigned int columns = table->columns; /* total columns */ unsigned int i; @@ -1162,7 +1110,7 @@ bool layout_table(struct box *table, int available_width, struct box *row; struct box *row_group; struct box **row_span_cell; - struct column *col; + struct column *col = alloca(columns * sizeof(struct column)); struct css_style *style = table->style; assert(table->type == BOX_TABLE); @@ -1170,20 +1118,6 @@ bool layout_table(struct box *table, int available_width, assert(table->children && table->children->children); assert(columns); - col = malloc(columns * sizeof col[0]); - excess_y = malloc(columns * sizeof excess_y[0]); - row_span = malloc(columns * sizeof row_span[0]); - row_span_cell = malloc(columns * sizeof row_span_cell[0]); - xs = malloc((columns + 1) * sizeof xs[0]); - if (!col || !xs || !row_span || !excess_y || !row_span_cell) { - free(col); - free(excess_y); - free(row_span); - free(row_span_cell); - free(xs); - return false; - } - memcpy(col, table->col, sizeof(col[0]) * columns); layout_find_dimensions(available_width, style, table->margin, @@ -1327,6 +1261,10 @@ bool layout_table(struct box *table, int available_width, table_width = auto_width; } + xs = xcalloc(columns + 1, sizeof(*xs)); + row_span = xcalloc(columns, sizeof(row_span[0])); + excess_y = xcalloc(columns, sizeof(excess_y[0])); + row_span_cell = xcalloc(columns, sizeof(row_span_cell[0])); xs[0] = x = 0; for (i = 0; i != columns; i++) { x += col[i].width; @@ -1347,14 +1285,7 @@ bool layout_table(struct box *table, int available_width, c->float_children = 0; c->height = AUTO; - if (!layout_block_context(c, box_pool)) { - free(col); - free(excess_y); - free(row_span); - free(row_span_cell); - free(xs); - return false; - } + layout_block_context(c); if (c->style->height.height == CSS_HEIGHT_LENGTH) { /* some sites use height="1" or similar to attempt * to make cells as small as possible, so treat @@ -1411,16 +1342,13 @@ bool layout_table(struct box *table, int available_width, table_height += row_group_height; } - free(col); - free(excess_y); - free(row_span); - free(row_span_cell); - free(xs); + xfree(row_span_cell); + xfree(excess_y); + xfree(row_span); + xfree(xs); table->width = table_width; table->height = table_height; - - return true; } @@ -1428,12 +1356,11 @@ bool layout_table(struct box *table, int available_width, * Find min, max widths required by boxes. * * \param box top of tree of boxes - * \return true on success, false on memory exhaustion * * The min_width and max_width fields of each box in the tree are computed. */ -bool calculate_widths(struct box *box) +void calculate_widths(struct box *box) { struct box *child; int min = 0, max = 0, extra_fixed = 0; @@ -1447,20 +1374,17 @@ bool calculate_widths(struct box *box) /* check if the widths have already been calculated */ if (box->max_width != UNKNOWN_MAX_WIDTH) - return true; + return; for (child = box->children; child != 0; child = child->next) { switch (child->type) { case BOX_BLOCK: case BOX_TABLE: - if (!calculate_block_widths(child, &min, &max, - 0)) - return false; + calculate_block_widths(child, &min, &max, 0); break; case BOX_INLINE_CONTAINER: - if (!calculate_inline_container_widths(child)) - return false; + calculate_inline_container_widths(child); if (min < child->min_width) min = child->min_width; if (max < child->max_width) @@ -1498,8 +1422,6 @@ bool calculate_widths(struct box *box) box->min_width = (min + extra_fixed) / (1.0 - extra_frac); box->max_width = (max + extra_fixed) / (1.0 - extra_frac); - - return true; } @@ -1511,21 +1433,17 @@ bool calculate_widths(struct box *box) * \param min current min, updated to new min * \param max current max, updated to new max * \param max_sum sum of maximum widths, updated, or 0 if not required - * \return true on success, false on memory exhaustion */ -bool calculate_block_widths(struct box *box, int *min, int *max, +void calculate_block_widths(struct box *box, int *min, int *max, int *max_sum) { int width; - if (box->type == BOX_TABLE) { - if (!calculate_table_widths(box)) - return false; - } else { - if (!calculate_widths(box)) - return false; - } + if (box->type == BOX_TABLE) + calculate_table_widths(box); + else + calculate_widths(box); if (box->style->width.width == CSS_WIDTH_LENGTH) { width = len(&box->style->width.value.length, box->style); @@ -1548,8 +1466,6 @@ bool calculate_block_widths(struct box *box, int *min, int *max, if (*max < box->max_width) *max = box->max_width; if (max_sum) *max_sum += box->max_width; } - - return true; } @@ -1557,7 +1473,7 @@ bool calculate_block_widths(struct box *box, int *min, int *max, * Find min, max width for an inline container. */ -bool calculate_inline_container_widths(struct box *box) +void calculate_inline_container_widths(struct box *box) { struct box *child; int min = 0, max = 0, line_max = 0; @@ -1565,7 +1481,7 @@ bool calculate_inline_container_widths(struct box *box) for (child = box->children; child != 0; child = child->next) { switch (child->type) { case BOX_INLINE: - if (child->object) + if (child->object || child->gadget) calculate_inline_replaced_widths(child, &min, &max, &line_max); else if (child->text) @@ -1574,16 +1490,14 @@ bool calculate_inline_container_widths(struct box *box) break; case BOX_INLINE_BLOCK: - if (!calculate_block_widths(child, &min, &max, - &line_max)) - return false; + calculate_block_widths(child, &min, &max, + &line_max); break; case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: - if (!calculate_block_widths(child->children, - &min, &max, 0)) - return false; + calculate_block_widths(child->children, + &min, &max, 0); break; case BOX_BR: @@ -1608,8 +1522,6 @@ bool calculate_inline_container_widths(struct box *box) assert(min <= max); box->min_width = min; box->max_width = max; - - return true; } @@ -1671,20 +1583,18 @@ void calculate_inline_widths(struct box *box, int *min, int *line_max) * Find min, max widths for a table and determine column width types. * * \param table table box to calculate widths - * \return true on success, false on memory exhaustion * - * If table->max_width is not UNKNOWN_MAX_WIDTH, returns with no change to - * table. + * If table->max_width is not UNKNOWN_MAX_WIDTH, returns with no change to table. * * If table->col is 0, it is created and filled in completely. * - * If table->col exists, the type and width fields are left unchanged, and the - * min and max fields are updated. + * If table->col exists, the type and width fields are left unchanged, and the min + * and max fields are updated. * * table->min_width and table->max_width are set. */ -bool calculate_table_widths(struct box *table) +void calculate_table_widths(struct box *table) { unsigned int i, j; struct box *row_group, *row, *cell; @@ -1695,12 +1605,11 @@ bool calculate_table_widths(struct box *table) /* check if the widths have already been calculated */ if (table->max_width != UNKNOWN_MAX_WIDTH) - return true; + return; if (!table->col) { col = table->col = malloc(table->columns * sizeof *col); - if (!col) - return false; + assert(col); for (i = 0; i != table->columns; i++) col[i].type = COLUMN_WIDTH_UNKNOWN; } @@ -1723,8 +1632,7 @@ bool calculate_table_widths(struct box *table) if (cell->columns != 1) continue; - if (!calculate_widths(cell)) - return false; + calculate_widths(cell); i = cell->start_column; /* update column min, max widths @@ -1774,8 +1682,7 @@ bool calculate_table_widths(struct box *table) if (cell->columns == 1) continue; - if (!calculate_widths(cell)) - return false; + calculate_widths(cell); i = cell->start_column; cell_min = cell->min_width; @@ -1843,6 +1750,4 @@ bool calculate_table_widths(struct box *table) table->max_width = max_width; LOG(("min_width %i, max_width %i", min_width, max_width)); - - return true; } diff --git a/render/layout.h b/render/layout.h index b1495f2d9..fc2e2744a 100644 --- a/render/layout.h +++ b/render/layout.h @@ -16,9 +16,7 @@ #ifndef _NETSURF_RENDER_LAYOUT_H_ #define _NETSURF_RENDER_LAYOUT_H_ -#include "netsurf/utils/pool.h" - -bool layout_document(struct box *box, int width, pool box_pool); -bool layout_block_context(struct box *block, pool box_pool); +void layout_document(struct box *box, int width); +void layout_block_context(struct box *block); #endif -- cgit v1.2.3