diff options
Diffstat (limited to 'render/layout.c')
-rw-r--r-- | render/layout.c | 261 |
1 files changed, 148 insertions, 113 deletions
diff --git a/render/layout.c b/render/layout.c index 6782fdfc6..7ca688fab 100644 --- a/render/layout.c +++ b/render/layout.c @@ -47,6 +47,7 @@ #include "utils/talloc.h" #include "utils/utils.h" #include "utils/nsoption.h" +#include "netsurf/inttypes.h" #include "netsurf/content.h" #include "netsurf/browser_window.h" #include "netsurf/layout.h" @@ -62,10 +63,6 @@ #include "render/layout.h" #include "render/table.h" - -/* Define to enable layout debugging */ -#undef LAYOUT_DEBUG - #define AUTO INT_MIN /* Fixed point percentage (a) of an integer (b), to an integer */ @@ -342,9 +339,7 @@ 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 + NSLOG(layout, DEBUG, "%p: min %i, max %i", b, min, max); if (b->type == BOX_BR) { b = b->next; @@ -624,9 +619,7 @@ 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 + NSLOG(layout, DEBUG, "line_min %i, line_max %i", min, max); assert(b != first); assert(0 <= *line_min); @@ -1117,7 +1110,7 @@ layout_find_dimensions(int available_width, css_fixed value = 0; css_unit unit = CSS_UNIT_PX; - type = css_computed_min_width(style, &value, &unit); + type = ns_computed_min_width(style, &value, &unit); if (type == CSS_MIN_WIDTH_SET) { if (unit == CSS_UNIT_PCT) { @@ -1164,7 +1157,7 @@ layout_find_dimensions(int available_width, css_fixed value = 0; css_unit unit = CSS_UNIT_PX; - type = css_computed_min_height(style, &value, &unit); + type = ns_computed_min_height(style, &value, &unit); if (type == CSS_MIN_HEIGHT_SET) { if (unit == CSS_UNIT_PCT) { @@ -1469,9 +1462,7 @@ find_sides(struct box *fl, { int fy0, fy1, fx0, fx1; -#ifdef LAYOUT_DEBUG - LOG("y0 %i, y1 %i, x0 %i, x1 %i", y0, y1, *x0, *x1); -#endif + NSLOG(layout, DEBUG, "y0 %i, y1 %i, x0 %i, x1 %i", y0, y1, *x0, *x1); *left = *right = 0; for (; fl; fl = fl->next_float) { @@ -1500,9 +1491,8 @@ find_sides(struct box *fl, } } -#ifdef LAYOUT_DEBUG - LOG("x0 %i, x1 %i, left %p, right %p", *x0, *x1, *left, *right); -#endif + NSLOG(layout, DEBUG, "x0 %i, x1 %i, left %p, right %p", *x0, *x1, + *left, *right); } @@ -1964,15 +1954,22 @@ static 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 + + NSLOG(layout, DEBUG, + "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); + if (col[i].positioned) { positioned_columns++; @@ -1990,16 +1987,14 @@ static bool layout_table(struct box *table, int available_width, } else required_width += col[i].min; -#ifdef LAYOUT_DEBUG - LOG("required_width %i", required_width); -#endif + NSLOG(layout, DEBUG, "required_width %i", required_width); } 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 + NSLOG(layout, DEBUG, + "width %i, min %i, max %i, auto %i, required %i", table_width, + table->min_width, table->max_width, auto_width, required_width); if (auto_width < required_width) { /* table narrower than required width for columns: @@ -2400,7 +2395,7 @@ static bool layout_apply_minmax_height(struct box *box, struct box *container) } /* min-height */ - if (css_computed_min_height(box->style, &value, &unit) == + if (ns_computed_min_height(box->style, &value, &unit) == CSS_MIN_HEIGHT_SET) { if (unit == CSS_UNIT_PCT) { if (containing_block && @@ -2448,9 +2443,8 @@ static 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, hlcache_handle_get_url(block->object), block->width); -#endif + NSLOG(layout, DEBUG, "block %p, object %p, width %i", block, + hlcache_handle_get_url(block->object), block->width); if (content_get_type(block->object) == CONTENT_HTML) { content_reformat(block->object, false, block->width, 1); @@ -2746,9 +2740,7 @@ layout_block_context(struct box *block, goto advance_to_next_box; } -#ifdef LAYOUT_DEBUG - LOG("box %p, cx %i, cy %i", box, cx, cy); -#endif + NSLOG(layout, DEBUG, "box %p, cx %i, cy %i", box, cx, cy); /* Layout (except tables). */ if (box->object) { @@ -3187,9 +3179,12 @@ layout_absolute(struct box *box, 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 + NSLOG(layout, DEBUG, + "%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); + if (left == AUTO && width == AUTO && right == AUTO) { if (margin[LEFT] == AUTO) @@ -3352,9 +3347,11 @@ layout_absolute(struct box *box, } } -#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 + NSLOG(layout, DEBUG, + "%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); box->x = left + margin[LEFT] + border[LEFT].width - cx; if (containing_block->type == BOX_BLOCK || @@ -3386,9 +3383,11 @@ layout_absolute(struct box *box, } /* 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 + NSLOG(layout, DEBUG, + "%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); if (top == AUTO && height == AUTO && bottom == AUTO) { top = static_top; @@ -3474,9 +3473,11 @@ layout_absolute(struct box *box, } } -#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 + NSLOG(layout, DEBUG, + "%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); box->y = top + margin[TOP] + border[TOP].width - cy; if (containing_block->type == BOX_BLOCK || @@ -3624,9 +3625,8 @@ static void layout_compute_relative_offset(struct box *box, int *x, int *y) bottom = -top; } -#ifdef LAYOUT_DEBUG - LOG("left %i, right %i, top %i, bottom %i", left, right, top, bottom); -#endif + NSLOG(layout, DEBUG, "left %i, right %i, top %i, bottom %i", left, + right, top, bottom); *x = left; *y = top; @@ -3887,10 +3887,20 @@ layout_text_box_split(html_content *content, c2->next->prev = c2; else c2->parent->last = c2; -#ifdef LAYOUT_DEBUG - LOG("split_box %p len: %u \"%.*s\"", split_box, split_box->length, split_box->length, split_box->text); - LOG(" new_box %p len: %u \"%.*s\"", c2, c2->length, c2->length, c2->text); -#endif + + NSLOG(layout, DEBUG, + "split_box %p len: %" PRIsizet " \"%.*s\"", + split_box, + split_box->length, + (int)split_box->length, + split_box->text); + NSLOG(layout, DEBUG, + " new_box %p len: %" PRIsizet " \"%.*s\"", + c2, + c2->length, + (int)c2->length, + c2->text); + return true; } @@ -4079,9 +4089,9 @@ place_float_below(struct box *c, int width, int cx, int y, struct box *cont) yy = y > cont->cached_place_below_level ? y : cont->cached_place_below_level; -#ifdef LAYOUT_DEBUG - LOG("c %p, width %i, cx %i, y %i, cont %p", c, width, cx, y, cont); -#endif + NSLOG(layout, DEBUG, + "c %p, width %i, cx %i, y %i, cont %p", c, + width, cx, y, cont); do { y = yy; @@ -4158,9 +4168,15 @@ layout_line(struct box *first, const struct gui_layout_table *font_func = content->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 + NSLOG(layout, DEBUG, + "first %p, first->text '%.*s', width %i, y %i, cx %i, cy %i", + first, + (int)first->length, + first->text, + *width, + *y, + cx, + cy); /* find sides at top of line */ x0 += cx; @@ -4189,9 +4205,9 @@ layout_line(struct box *first, /* 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 + + NSLOG(layout, DEBUG, "x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0); + for (x = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) { int min_width, max_width, min_height, max_height; @@ -4202,9 +4218,9 @@ layout_line(struct box *first, 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 + + NSLOG(layout, DEBUG, "pass 1: b %p, x %i", b, x); + if (b->type == BOX_BR) break; @@ -4413,14 +4429,12 @@ layout_line(struct box *first, 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 + + NSLOG(layout, DEBUG, "x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0); 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 + + NSLOG(layout, DEBUG, "pass 2: b %p, x %i", b, x); if (b->type == BOX_INLINE_BLOCK && (css_computed_position(b->style) == @@ -4488,9 +4502,7 @@ layout_line(struct box *first, } else { /* float */ -#ifdef LAYOUT_DEBUG - LOG("float %p", b); -#endif + NSLOG(layout, DEBUG, "float %p", b); d = b->children; d->float_children = 0; @@ -4500,9 +4512,11 @@ layout_line(struct box *first, if (!layout_float(d, *width, content)) return false; -#ifdef LAYOUT_DEBUG - LOG("%p : %d %d", d, d->margin[TOP], d->border[TOP].width); -#endif + NSLOG(layout, DEBUG, + "%p : %d %d", + d, + d->margin[TOP], + d->border[TOP].width); d->x = d->margin[LEFT] + d->border[LEFT].width; d->y = d->margin[TOP] + d->border[TOP].width; @@ -4633,9 +4647,18 @@ layout_line(struct box *first, if (split == 0) w = split_box->width; -#ifdef LAYOUT_DEBUG - LOG("splitting: split_box %p \"%.*s\", spilt %zu, w %i, ""left %p, right %p, inline_count %u", split_box, (int)split_box->length, split_box->text, split, w, left, right, inline_count); -#endif + + NSLOG(layout, DEBUG, + "splitting: split_box %p \"%.*s\", spilt %zu, w %i, " + "left %p, right %p, inline_count %u", + split_box, + (int)split_box->length, + split_box->text, + split, + w, + left, + right, + inline_count); if ((split == 0 || x1 - x0 <= x + space_before + w) && !left && !right && inline_count == 1) { @@ -4653,9 +4676,9 @@ layout_line(struct box *first, b = split_box->next; } x += space_before + w; -#ifdef LAYOUT_DEBUG - LOG("forcing"); -#endif + + NSLOG(layout, DEBUG, "forcing"); + } else if ((split == 0 || x1 - x0 <= x + space_before + w) && inline_count == 1) { /* first word of first box doesn't fit, but a float is @@ -4663,13 +4686,18 @@ layout_line(struct box *first, 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 + + NSLOG(layout, DEBUG, + "cy %i, left->y %i, left->height %i", + cy, + left->y, + left->height); + used_height = left->y + left->height - cy + 1; -#ifdef LAYOUT_DEBUG - LOG("used_height %i", used_height); -#endif + + NSLOG(layout, DEBUG, "used_height %i", + used_height); + } if (right && used_height < right->y + right->height - cy + 1) @@ -4679,22 +4707,24 @@ layout_line(struct box *first, used_height = 0; b = split_box; -#ifdef LAYOUT_DEBUG - LOG("moving below float"); -#endif + + NSLOG(layout, DEBUG, "moving below float"); + } else if (split == 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 + + NSLOG(layout, DEBUG, "leaving for next line"); + } else { /* fit as many words as possible */ assert(split != 0); -#ifdef LAYOUT_DEBUG - LOG("'%.*s' %i %zu %i", (int)split_box->length, split_box->text, x1 - x0, split, w); -#endif + + NSLOG(layout, DEBUG, "'%.*s' %i %zu %i", + (int)split_box->length, split_box->text, + x1 - x0, split, w); + if (split != split_box->length) { if (!layout_text_box_split(content, &fstyle, split_box, split, w)) @@ -4702,9 +4732,9 @@ layout_line(struct box *first, b = split_box->next; } x += space_before + w; -#ifdef LAYOUT_DEBUG - LOG("fitting words"); -#endif + + NSLOG(layout, DEBUG, "fitting words"); + } move_y = true; } @@ -4842,9 +4872,14 @@ 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 + NSLOG(layout, DEBUG, + "inline_container %p, width %i, cont %p, cx %i, cy %i", + inline_container, + width, + cont, + cx, + cy); + has_text_children = false; for (c = inline_container->children; c; c = c->next) { @@ -4872,9 +4907,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 + + NSLOG(layout, DEBUG, "c %p", c); + curwidth = inline_container->width; if (!layout_line(c, &curwidth, &y, cx, cy + y, cont, first_line, has_text_children, content, &next)) |