From ff6000745886cb085ca80e42498020497bc7f95f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 3 Apr 2011 22:23:14 +0000 Subject: Fix build with NDEBUG defined svn path=/trunk/netsurf/; revision=12154 --- render/box_normalise.c | 31 +++++++++++++++-- render/layout.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-- render/table.c | 7 ++-- 3 files changed, 123 insertions(+), 6 deletions(-) (limited to 'render') diff --git a/render/box_normalise.c b/render/box_normalise.c index b4c005c8e..21ede6dd4 100644 --- a/render/box_normalise.c +++ b/render/box_normalise.c @@ -30,11 +30,11 @@ #include "render/box.h" #include "render/table.h" #include "desktop/gui.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" +/* Define to enable box normalise debug */ +#undef BOX_NORMALISE_DEBUG /** * Row spanning information for a cell @@ -105,7 +105,9 @@ bool box_normalise_block(struct box *block, struct content *c) assert(block != NULL); +#ifdef BOX_NORMALISE_DEBUG LOG(("block %p, block->type %u", block, block->type)); +#endif assert(block->type == BOX_BLOCK || block->type == BOX_INLINE_BLOCK || block->type == BOX_TABLE_CELL); @@ -113,7 +115,9 @@ bool box_normalise_block(struct box *block, struct content *c) gui_multitask(); for (child = block->children; child != NULL; child = next_child) { +#ifdef BOX_NORMALISE_DEBUG LOG(("child %p, child->type = %d", child, child->type)); +#endif next_child = child->next; /* child may be destroyed */ @@ -210,7 +214,9 @@ bool box_normalise_table(struct box *table, struct content * c) assert(table != NULL); assert(table->type == BOX_TABLE); +#ifdef BOX_NORMALISE_DEBUG LOG(("table %p", table)); +#endif col_info.num_columns = 1; col_info.current_column = 0; @@ -318,7 +324,9 @@ bool box_normalise_table(struct box *table, struct content * c) if (table->children == NULL) { struct box *row; +#ifdef BOX_NORMALISE_DEBUG LOG(("table->children == 0, creating implied row")); +#endif assert(table->style != NULL); @@ -375,7 +383,9 @@ bool box_normalise_table(struct box *table, struct content * c) if (table_calculate_column_types(table) == false) return false; +#ifdef BOX_NORMALISE_DEBUG LOG(("table %p done", table)); +#endif return true; } @@ -531,7 +541,9 @@ bool box_normalise_table_row_group(struct box *row_group, assert(row_group != 0); assert(row_group->type == BOX_TABLE_ROW_GROUP); +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group %p", row_group)); +#endif for (child = row_group->children; child != NULL; child = next_child) { next_child = child->next; @@ -615,7 +627,9 @@ bool box_normalise_table_row_group(struct box *row_group, } if (row_group->children == NULL) { +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group->children == 0, inserting implied row")); +#endif assert(row_group->style != NULL); @@ -640,7 +654,9 @@ bool box_normalise_table_row_group(struct box *row_group, col_info->num_rows++; } +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group %p done", row_group)); +#endif return true; } @@ -658,7 +674,10 @@ bool box_normalise_table_row(struct box *row, assert(row != NULL); assert(row->type == BOX_TABLE_ROW); + +#ifdef BOX_NORMALISE_DEBUG LOG(("row %p", row)); +#endif for (child = row->children; child != NULL; child = next_child) { next_child = child->next; @@ -761,7 +780,9 @@ bool box_normalise_table_row(struct box *row, /* Increment row counter */ col_info->num_rows++; +#ifdef BOX_NORMALISE_DEBUG LOG(("row %p done", row)); +#endif return true; } @@ -842,7 +863,10 @@ bool box_normalise_inline_container(struct box *cont, struct content * c) assert(cont != NULL); assert(cont->type == BOX_INLINE_CONTAINER); + +#ifdef BOX_NORMALISE_DEBUG LOG(("cont %p", cont)); +#endif for (child = cont->children; child != NULL; child = next_child) { next_child = child->next; @@ -902,7 +926,10 @@ bool box_normalise_inline_container(struct box *cont, struct content * c) assert(0); } } + +#ifdef BOX_NORMALISE_DEBUG LOG(("cont %p done", cont)); +#endif return true; } diff --git a/render/layout.c b/render/layout.c index 2270bdfd8..d99fa0056 100644 --- a/render/layout.c +++ b/render/layout.c @@ -51,13 +51,14 @@ #include "render/form.h" #include "render/layout.h" #include "render/table.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" #include "utils/utils.h" +/* Define to enable layout debugging */ +#undef LAYOUT_DEBUG + #define AUTO INT_MIN /* Fixed point value percentage of an integer, to an integer */ @@ -489,7 +490,9 @@ bool layout_block_context(struct box *block, int viewport_height, max_pos_margin = max_neg_margin = 0; } +#ifdef LAYOUT_DEBUG LOG(("box %p, cx %i, cy %i", box, cx, cy)); +#endif /* Layout (except tables). */ if (box->object) { @@ -836,8 +839,10 @@ bool layout_block_object(struct box *block) block->type == BOX_TABLE_CELL); assert(block->object); +#ifdef LAYOUT_DEBUG LOG(("block %p, object %s, width %i", block, content_get_url(block->object), block->width)); +#endif if (content_get_type(block->object) == CONTENT_HTML) { content_reformat(block->object, block->width, 1); @@ -1756,7 +1761,11 @@ void find_sides(struct box *fl, int y0, int y1, int *x0, int *x1, struct box **left, struct box **right) { int fy0, fy1, fx0, fx1; + +#ifdef LAYOUT_DEBUG LOG(("y0 %i, y1 %i, x0 %i, x1 %i", y0, y1, *x0, *x1)); +#endif + *left = *right = 0; for (; fl; fl = fl->next_float) { fy0 = fl->y; @@ -1777,7 +1786,10 @@ void find_sides(struct box *fl, int y0, int y1, } } } + +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, left %p, right %p", *x0, *x1, *left, *right)); +#endif } @@ -1804,8 +1816,10 @@ bool layout_inline_container(struct box *inline_container, int width, assert(inline_container->type == BOX_INLINE_CONTAINER); +#ifdef LAYOUT_DEBUG LOG(("inline_container %p, width %i, cont %p, cx %i, cy %i", inline_container, width, cont, cx, cy)); +#endif has_text_children = false; for (c = inline_container->children; c; c = c->next) { @@ -1831,7 +1845,9 @@ bool layout_inline_container(struct box *inline_container, int width, * curwidth = width and have the multiword lines wrap to the min width) */ for (c = inline_container->children; c; ) { +#ifdef LAYOUT_DEBUG LOG(("c %p", c)); +#endif curwidth = inline_container->width; if (!layout_line(c, &curwidth, &y, cx, cy + y, cont, first_line, has_text_children, content, &next)) @@ -2049,9 +2065,11 @@ bool layout_line(struct box *first, int *width, int *y, const struct font_functions *font_func = content->data.html.font_func; plot_font_style_t fstyle; +#ifdef LAYOUT_DEBUG LOG(("first %p, first->text '%.*s', width %i, y %i, cx %i, cy %i", first, (int) first->length, first->text, *width, *y, cx, cy)); +#endif /* find sides at top of line */ x0 += cx; @@ -2080,7 +2098,10 @@ bool layout_line(struct box *first, int *width, int *y, /* pass 1: find height of line assuming sides at top of line: loop * body executed at least once * keep in sync with the loop in layout_minmax_line() */ +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0)); +#endif + for (x = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) { enum css_width_e wtype; enum css_height_e htype; @@ -2092,7 +2113,10 @@ bool layout_line(struct box *first, int *width, int *y, b->type == BOX_FLOAT_RIGHT || b->type == BOX_BR || b->type == BOX_TEXT || b->type == BOX_INLINE_END); + +#ifdef LAYOUT_DEBUG LOG(("pass 1: b %p, x %i", b, x)); +#endif if (b->type == BOX_BR) break; @@ -2305,9 +2329,15 @@ bool layout_line(struct box *first, int *width, int *y, space_after = space_before = 0; /* pass 2: place boxes in line: loop body executed at least once */ +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0)); +#endif + for (x = x_previous = 0, b = first; x <= x1 - x0 && b; b = b->next) { +#ifdef LAYOUT_DEBUG LOG(("pass 2: b %p, x %i", b, x)); +#endif + if (b->type == BOX_INLINE_BLOCK && (css_computed_position(b->style) == CSS_POSITION_ABSOLUTE || @@ -2373,15 +2403,22 @@ bool layout_line(struct box *first, int *width, int *y, } else { /* float */ +#ifdef LAYOUT_DEBUG LOG(("float %p", b)); +#endif + d = b->children; d->float_children = 0; b->float_container = d->float_container = cont; if (!layout_float(d, *width, content)) return false; + +#ifdef LAYOUT_DEBUG LOG(("%p : %d %d", d, d->margin[TOP], d->border[TOP].width)); +#endif + d->x = d->margin[LEFT] + d->border[LEFT].width; d->y = d->margin[TOP] + d->border[TOP].width; b->width = d->margin[LEFT] + d->border[LEFT].width + @@ -2468,7 +2505,10 @@ bool layout_line(struct box *first, int *width, int *y, right = b; } if (cont->float_children == b) { +#ifdef LAYOUT_DEBUG LOG(("float %p already placed", b)); +#endif + box_dump(stderr, cont, 0); assert(0); } @@ -2514,11 +2554,13 @@ bool layout_line(struct box *first, int *width, int *y, space, &w); } +#ifdef LAYOUT_DEBUG LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, " "left %p, right %p, inline_count %u", split_box, (int) split_box->length, split_box->text, space, w, left, right, inline_count)); +#endif if ((space == 0 || x1 - x0 <= x + space_before + w) && !left && !right && inline_count == 1) { @@ -2535,7 +2577,9 @@ bool layout_line(struct box *first, int *width, int *y, b = split_box->next; } x += space_before + w; +#ifdef LAYOUT_DEBUG LOG(("forcing")); +#endif } else if ((space == 0 || x1 - x0 <= x + space_before + w) && inline_count == 1) { /* first word of first box doesn't fit, but a float is @@ -2543,22 +2587,30 @@ bool layout_line(struct box *first, int *width, int *y, assert(left || right); used_height = 0; if (left) { +#ifdef LAYOUT_DEBUG LOG(("cy %i, left->y %i, left->height %i", cy, left->y, left->height)); +#endif used_height = left->y + left->height - cy + 1; +#ifdef LAYOUT_DEBUG LOG(("used_height %i", used_height)); +#endif } if (right && used_height < right->y + right->height - cy + 1) used_height = right->y + right->height - cy + 1; assert(0 < used_height); b = split_box; +#ifdef LAYOUT_DEBUG LOG(("moving below float")); +#endif } else if (space == 0 || x1 - x0 <= x + space_before + w) { /* first word of box doesn't fit so leave box for next * line */ b = split_box; +#ifdef LAYOUT_DEBUG LOG(("leaving for next line")); +#endif } else { /* fit as many words as possible */ assert(space != 0); @@ -2567,8 +2619,10 @@ bool layout_line(struct box *first, int *width, int *y, font_func->font_split(&fstyle, split_box->text, split_box->length, x1 - x0 - x - space_before, &space, &w); +#ifdef LAYOUT_DEBUG LOG(("'%.*s' %i %zu %i", (int) split_box->length, split_box->text, x1 - x0, space, w)); +#endif if (space == 0) space = 1; if (space != split_box->length) { @@ -2578,7 +2632,9 @@ bool layout_line(struct box *first, int *width, int *y, b = split_box->next; } x += space_before + w; +#ifdef LAYOUT_DEBUG LOG(("fitting words")); +#endif } move_y = true; } @@ -2743,7 +2799,9 @@ struct box *layout_minmax_line(struct box *first, b->type == BOX_BR || b->type == BOX_TEXT || b->type == BOX_INLINE_END); +#ifdef LAYOUT_DEBUG LOG(("%p: min %i, max %i", b, min, max)); +#endif if (b->type == BOX_BR) { b = b->next; @@ -2937,7 +2995,10 @@ struct box *layout_minmax_line(struct box *first, *line_min = min; *line_max = max; + +#ifdef LAYOUT_DEBUG LOG(("line_min %i, line_max %i", min, max)); +#endif assert(b != first); assert(0 <= *line_min && *line_min <= *line_max); @@ -3015,7 +3076,11 @@ void place_float_below(struct box *c, int width, int cx, int y, int x0, x1, yy = y; struct box *left; struct box *right; + +#ifdef LAYOUT_DEBUG LOG(("c %p, width %i, cx %i, y %i, cont %p", c, width, cx, y, cont)); +#endif + do { y = yy; x0 = cx; @@ -3231,11 +3296,14 @@ bool layout_table(struct box *table, int available_width, /* calculate width required by cells */ for (i = 0; i != columns; i++) { +#ifdef LAYOUT_DEBUG LOG(("table %p, column %u: type %s, width %i, min %i, max %i", table, i, ((const char *[]) {"UNKNOWN", "FIXED", "AUTO", "PERCENT", "RELATIVE"})[col[i].type], col[i].width, col[i].min, col[i].max)); +#endif + if (col[i].positioned) { positioned_columns++; continue; @@ -3251,14 +3319,19 @@ bool layout_table(struct box *table, int available_width, col[i].min; } else required_width += col[i].min; + +#ifdef LAYOUT_DEBUG LOG(("required_width %i", required_width)); +#endif } required_width += (columns + 1 - positioned_columns) * border_spacing_h; +#ifdef LAYOUT_DEBUG LOG(("width %i, min %i, max %i, auto %i, required %i", table_width, table->min_width, table->max_width, auto_width, required_width)); +#endif if (auto_width < required_width) { /* table narrower than required width for columns: @@ -4072,7 +4145,9 @@ void layout_compute_relative_offset(struct box *box, int *x, int *y) else bottom = -top; +#ifdef LAYOUT_DEBUG LOG(("left %i, right %i, top %i, bottom %i", left, right, top, bottom)); +#endif *x = left; *y = top; @@ -4207,11 +4282,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, box->float_container = NULL; /* 10.3.7 */ +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", left, margin[LEFT], border[LEFT].width, padding[LEFT], width, padding[RIGHT], border[RIGHT].width, margin[RIGHT], right, containing_block->width)); +#endif + if (left == AUTO && width == AUTO && right == AUTO) { if (margin[LEFT] == AUTO) margin[LEFT] = 0; @@ -4372,11 +4450,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, border[RIGHT].width - margin[RIGHT]; } } + +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", left, margin[LEFT], border[LEFT].width, padding[LEFT], width, padding[RIGHT], border[RIGHT].width, margin[RIGHT], right, containing_block->width)); +#endif box->x = left + margin[LEFT] + border[LEFT].width - cx; if (containing_block->type == BOX_BLOCK || @@ -4404,11 +4485,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, } /* 10.6.4 */ +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", top, margin[TOP], border[TOP].width, padding[TOP], height, padding[BOTTOM], border[BOTTOM].width, margin[BOTTOM], bottom, containing_block->height)); +#endif + if (top == AUTO && height == AUTO && bottom == AUTO) { top = static_top; height = box->height; @@ -4492,11 +4576,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, margin[BOTTOM]; } } + +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", top, margin[TOP], border[TOP].width, padding[TOP], height, padding[BOTTOM], border[BOTTOM].width, margin[BOTTOM], bottom, containing_block->height)); +#endif box->y = top + margin[TOP] + border[TOP].width - cy; if (containing_block->type == BOX_BLOCK || diff --git a/render/table.c b/render/table.c index ad7e3bd3c..f9bac2ac8 100644 --- a/render/table.c +++ b/render/table.c @@ -26,11 +26,12 @@ #include "css/utils.h" #include "render/box.h" #include "render/table.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" +/* Define to enable verbose table debug */ +#undef TABLE_DEBUG + /** * Container for border values during table border calculations */ @@ -214,11 +215,13 @@ bool table_calculate_column_types(struct box *table) col[i].type = COLUMN_WIDTH_AUTO; } +#ifdef TABLE_DEBUG for (i = 0; i != table->columns; i++) LOG(("table %p, column %u: type %s, width %i", table, i, ((const char *[]) {"UNKNOWN", "FIXED", "AUTO", "PERCENT", "RELATIVE"})[col[i].type], col[i].width)); +#endif return true; } -- cgit v1.2.3