From 0380dbb75d60d7543236989407e2e8fda5142383 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 11 Sep 2002 21:18:18 +0000 Subject: [project @ 2002-09-11 21:18:18 by bursa] Column widths changes, bug fix. svn path=/import/netsurf/; revision=34 --- render/layout.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'render/layout.c') diff --git a/render/layout.c b/render/layout.c index 53f4eedea..f1c47a623 100644 --- a/render/layout.c +++ b/render/layout.c @@ -1,5 +1,5 @@ /** - * $Id: layout.c,v 1.15 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: layout.c,v 1.16 2002/09/11 21:18:18 bursa Exp $ */ #include @@ -373,7 +373,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long } else { c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box)); c2->text = xstrdup(space + 1); - c2->length = c->length - (c2->text - c->text); + c2->length = c->length - ((space + 1) - c->text); c->length = space - c->text; c2->next = c->next; c->next = c2; @@ -397,7 +397,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long } c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box)); c2->text = xstrdup(space + 1); - c2->length = c->length - (c2->text - c->text); + c2->length = c->length - ((space + 1) - c->text); c->length = space - c->text; c2->next = c->next; c->next = c2; @@ -470,6 +470,7 @@ void layout_table(struct box * table, unsigned long width, struct box * cont, { unsigned int columns = 0; /* total columns */ unsigned int auto_columns = 0; /* number of columns with auto width */ + unsigned int percent_columns = 0; /* no of columns with percent width */ unsigned long table_width; unsigned long percent_width; /* width available for percent columns */ unsigned long used_width = 0; /* width used by fixed or percent columns */ @@ -521,6 +522,8 @@ void layout_table(struct box * table, unsigned long width, struct box * cont, auto_columns += c->colspan; break; case CSS_WIDTH_PERCENT: + percent_columns += c->colspan; + break; default: break; } @@ -529,11 +532,20 @@ void layout_table(struct box * table, unsigned long width, struct box * cont, } assert(columns != 0); - /* percentages are relative to remaining width */ - percent_width = used_width < table_width ? table_width - used_width : 0; - for (c = table->children->children->children; c != 0; c = c->next) - if (c->style->width.width == CSS_WIDTH_PERCENT) - used_width += percent_width * c->style->width.value.percent / 100; + if (percent_columns != 0) { + /* percentages are relative to remaining width */ + if (used_width < table_width) + /* fast heuristic */ + percent_width = (table_width - used_width) * + percent_columns / (percent_columns + auto_columns); + else + /* unless there is none */ + percent_width = table_width; + + for (c = table->children->children->children; c != 0; c = c->next) + if (c->style->width.width == CSS_WIDTH_PERCENT) + used_width += percent_width * c->style->width.value.percent / 100; + } /* fprintf(stderr, "columns %u, auto_columns %u\n", columns, auto_columns); */ -- cgit v1.2.3