2005-03-26 04:12:27 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
* Copyright 2004 Kevin Bagust <kevin.bagust@ntlworld.com>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Box tree normalisation (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
2012-08-22 15:22:58 +04:00
|
|
|
#include <string.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "css/css.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "css/select.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/box.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "render/html_internal.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/table.h"
|
|
|
|
#include "utils/log.h"
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
/* Define to enable box normalise debug */
|
|
|
|
#undef BOX_NORMALISE_DEBUG
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Row spanning information for a cell
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
struct span_info {
|
2009-07-24 03:05:34 +04:00
|
|
|
/** Number of rows this cell spans */
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int row_span;
|
2014-04-12 19:09:17 +04:00
|
|
|
/** Row group of cell */
|
|
|
|
struct box *rg;
|
2009-07-24 03:05:34 +04:00
|
|
|
/** The cell in this column spans all rows until the end of the table */
|
2005-03-26 04:12:27 +03:00
|
|
|
bool auto_row;
|
|
|
|
};
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Column record for a table
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
struct columns {
|
2009-07-24 03:05:34 +04:00
|
|
|
/** Current column index */
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int current_column;
|
2009-07-24 03:05:34 +04:00
|
|
|
/** Number of columns in main part of table 1..max columns */
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int num_columns;
|
2009-07-24 03:05:34 +04:00
|
|
|
/** Information about columns in main table, array [0, num_columns) */
|
2005-03-26 04:12:27 +03:00
|
|
|
struct span_info *spans;
|
2009-07-24 03:05:34 +04:00
|
|
|
/** Number of rows in table */
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int num_rows;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool box_normalise_table(struct box *table, html_content *c);
|
2009-07-24 03:05:34 +04:00
|
|
|
static bool box_normalise_table_spans(struct box *table,
|
2011-05-07 00:40:09 +04:00
|
|
|
struct span_info *spans, html_content *c);
|
2005-03-26 04:12:27 +03:00
|
|
|
static bool box_normalise_table_row_group(struct box *row_group,
|
|
|
|
struct columns *col_info,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c);
|
2005-03-26 04:12:27 +03:00
|
|
|
static bool box_normalise_table_row(struct box *row,
|
|
|
|
struct columns *col_info,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c);
|
2005-03-26 04:12:27 +03:00
|
|
|
static bool calculate_table_row(struct columns *col_info,
|
|
|
|
unsigned int col_span, unsigned int row_span,
|
2014-04-12 19:09:17 +04:00
|
|
|
unsigned int *start_column, struct box *cell);
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool box_normalise_inline_container(struct box *cont, html_content *c);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure the box tree is correctly nested by adding and removing nodes.
|
|
|
|
*
|
2014-11-10 23:15:14 +03:00
|
|
|
* \param block box of type BLOCK, INLINE_BLOCK, or TABLE_CELL
|
|
|
|
* \param c content of boxes
|
|
|
|
* \return true on success, false on memory exhaustion
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
|
|
|
* The tree is modified to satisfy the following:
|
|
|
|
* \code
|
|
|
|
* parent permitted child nodes
|
2006-11-05 15:58:24 +03:00
|
|
|
* BLOCK, INLINE_BLOCK BLOCK, INLINE_CONTAINER, TABLE
|
2005-05-23 01:50:14 +04:00
|
|
|
* INLINE_CONTAINER INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, TEXT
|
|
|
|
* INLINE, TEXT none
|
2005-03-26 04:12:27 +03:00
|
|
|
* TABLE at least 1 TABLE_ROW_GROUP
|
|
|
|
* TABLE_ROW_GROUP at least 1 TABLE_ROW
|
|
|
|
* TABLE_ROW at least 1 TABLE_CELL
|
|
|
|
* TABLE_CELL BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
|
2006-11-04 22:53:22 +03:00
|
|
|
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE
|
|
|
|
* \endcode
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool box_normalise_block(struct box *block, html_content *c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
struct box *next_child;
|
2015-01-27 22:01:16 +03:00
|
|
|
struct box *table;
|
|
|
|
css_computed_style *style;
|
|
|
|
nscss_select_ctx ctx;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
assert(block != NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("block %p, block->type %u", block, block->type);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
assert(block->type == BOX_BLOCK || block->type == BOX_INLINE_BLOCK ||
|
2006-11-05 15:58:24 +03:00
|
|
|
block->type == BOX_TABLE_CELL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
for (child = block->children; child != NULL; child = next_child) {
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("child %p, child->type = %d", child, child->type);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next; /* child may be destroyed */
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_BLOCK:
|
|
|
|
/* ok */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_block(child, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_INLINE_CONTAINER:
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_inline_container(child, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table(child, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2005-06-06 00:54:37 +04:00
|
|
|
case BOX_INLINE_END:
|
2005-03-26 04:12:27 +03:00
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
case BOX_BR:
|
2005-05-23 01:50:14 +04:00
|
|
|
case BOX_TEXT:
|
2005-03-26 04:12:27 +03:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
2015-01-27 22:01:16 +03:00
|
|
|
/* insert implied table */
|
|
|
|
assert(block->style != NULL);
|
|
|
|
|
|
|
|
ctx.ctx = c->select_ctx;
|
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
|
|
|
ctx.base_url = c->base_url;
|
|
|
|
ctx.universal = c->universal;
|
|
|
|
|
|
|
|
style = nscss_get_blank_style(&ctx, block->style);
|
|
|
|
if (style == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
table = box_create(NULL, style, true, block->href,
|
|
|
|
block->target, NULL, NULL, c->bctx);
|
|
|
|
if (table == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
table->type = BOX_TABLE;
|
|
|
|
|
|
|
|
if (child->prev == NULL)
|
|
|
|
block->children = table;
|
|
|
|
else
|
|
|
|
child->prev->next = table;
|
|
|
|
|
|
|
|
table->prev = child->prev;
|
|
|
|
|
|
|
|
while (child != NULL && (
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(table, child);
|
|
|
|
|
|
|
|
next_child = child->next;
|
|
|
|
child->next = NULL;
|
|
|
|
child = next_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
table->last->next = NULL;
|
|
|
|
table->next = next_child = child;
|
|
|
|
if (table->next != NULL)
|
|
|
|
table->next->prev = table;
|
|
|
|
else
|
|
|
|
block->last = table;
|
|
|
|
table->parent = block;
|
|
|
|
|
|
|
|
if (box_normalise_table(table, c) == false)
|
|
|
|
return false;
|
|
|
|
break;
|
2005-03-26 04:12:27 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool box_normalise_table(struct box *table, html_content * c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
struct box *next_child;
|
|
|
|
struct box *row_group;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_style *style;
|
2005-03-26 04:12:27 +03:00
|
|
|
struct columns col_info;
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx ctx;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
assert(table != NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
assert(table->type == BOX_TABLE);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("table %p", table);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
col_info.num_columns = 1;
|
|
|
|
col_info.current_column = 0;
|
|
|
|
col_info.spans = malloc(2 * sizeof *col_info.spans);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (col_info.spans == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
col_info.spans[0].row_span = col_info.spans[1].row_span = 0;
|
2009-07-24 03:05:34 +04:00
|
|
|
col_info.spans[0].auto_row = false;
|
|
|
|
col_info.spans[1].auto_row = false;
|
|
|
|
col_info.num_rows = 0;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
for (child = table->children; child != NULL; child = next_child) {
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
/* ok */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table_row_group(child,
|
|
|
|
&col_info, c) == false) {
|
2005-03-26 04:12:27 +03:00
|
|
|
free(col_info.spans);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row group */
|
|
|
|
assert(table->style != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, table->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL) {
|
2005-03-26 04:12:27 +03:00
|
|
|
free(col_info.spans);
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
row_group = box_create(NULL, style, true, table->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
table->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row_group == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
2005-03-26 04:12:27 +03:00
|
|
|
free(col_info.spans);
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->type = BOX_TABLE_ROW_GROUP;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (child->prev == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
table->children = row_group;
|
|
|
|
else
|
|
|
|
child->prev->next = row_group;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->prev = child->prev;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
while (child != NULL && (
|
2005-03-26 04:12:27 +03:00
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
2006-11-05 15:58:24 +03:00
|
|
|
child->type == BOX_TABLE_CELL)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(row_group, child);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
child->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
child = next_child;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-04 22:53:22 +03:00
|
|
|
assert(row_group->last != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
row_group->last->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->next = next_child = child;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row_group->next != NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->next->prev = row_group;
|
2008-03-10 17:23:04 +03:00
|
|
|
else
|
|
|
|
table->last = row_group;
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->parent = table;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (box_normalise_table_row_group(row_group,
|
|
|
|
&col_info, c) == false) {
|
2005-03-26 04:12:27 +03:00
|
|
|
free(col_info.spans);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2005-06-06 00:54:37 +04:00
|
|
|
case BOX_INLINE_END:
|
2005-03-26 04:12:27 +03:00
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
case BOX_BR:
|
2005-05-23 01:50:14 +04:00
|
|
|
case BOX_TEXT:
|
2005-03-26 04:12:27 +03:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%i\n", child->type);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
table->columns = col_info.num_columns;
|
|
|
|
table->rows = col_info.num_rows;
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (table->children == NULL) {
|
2008-03-10 17:24:41 +03:00
|
|
|
struct box *row;
|
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("table->children == 0, creating implied row");
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2008-03-10 17:24:41 +03:00
|
|
|
|
|
|
|
assert(table->style != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, table->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL) {
|
|
|
|
free(col_info.spans);
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
row_group = box_create(NULL, style, true, table->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
table->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row_group == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
|
|
|
free(col_info.spans);
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
row_group->type = BOX_TABLE_ROW_GROUP;
|
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, row_group->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL) {
|
2008-03-10 17:24:41 +03:00
|
|
|
box_free(row_group);
|
2009-07-24 03:05:34 +04:00
|
|
|
free(col_info.spans);
|
2005-07-02 22:17:51 +04:00
|
|
|
return false;
|
2008-03-10 17:24:41 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
row = box_create(NULL, style, true, row_group->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
row_group->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
2008-03-10 17:24:41 +03:00
|
|
|
box_free(row_group);
|
2009-07-24 03:05:34 +04:00
|
|
|
free(col_info.spans);
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
row->type = BOX_TABLE_ROW;
|
|
|
|
|
|
|
|
row->parent = row_group;
|
|
|
|
row_group->children = row_group->last = row;
|
|
|
|
|
|
|
|
row_group->parent = table;
|
|
|
|
table->children = table->last = row_group;
|
|
|
|
|
|
|
|
table->rows = 1;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table_spans(table, col_info.spans, c) == false) {
|
|
|
|
free(col_info.spans);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(col_info.spans);
|
|
|
|
|
|
|
|
if (table_calculate_column_types(table) == false)
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("table %p done", table);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/**
|
|
|
|
* Normalise table cell column/row counts for colspan/rowspan = 0.
|
|
|
|
* Additionally, generate empty cells.
|
|
|
|
*
|
|
|
|
* \param table Table to process
|
|
|
|
* \param spans Array of length table->columns for use in empty cell detection
|
|
|
|
* \param c Content containing table
|
|
|
|
* \return True on success, false on memory exhaustion.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_normalise_table_spans(struct box *table, struct span_info *spans,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *table_row_group;
|
|
|
|
struct box *table_row;
|
|
|
|
struct box *table_cell;
|
|
|
|
unsigned int rows_left = table->rows;
|
2014-04-09 21:17:56 +04:00
|
|
|
unsigned int group_rows_left;
|
2009-07-24 03:05:34 +04:00
|
|
|
unsigned int col;
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx ctx;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Clear span data */
|
|
|
|
memset(spans, 0, table->columns * sizeof(struct span_info));
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Scan table, filling in width and height of table cells with
|
|
|
|
* colspan = 0 and rowspan = 0. Also generate empty cells */
|
2014-04-09 21:17:56 +04:00
|
|
|
for (table_row_group = table->children;
|
|
|
|
table_row_group != NULL;
|
|
|
|
table_row_group = table_row_group->next) {
|
|
|
|
|
|
|
|
group_rows_left = table_row_group->rows;
|
|
|
|
|
|
|
|
for (table_row = table_row_group->children;
|
|
|
|
table_row != NULL;
|
|
|
|
table_row = table_row->next) {
|
|
|
|
|
|
|
|
for (table_cell = table_row->children;
|
|
|
|
table_cell != NULL;
|
|
|
|
table_cell = table_cell->next) {
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* colspan = 0 -> colspan = 1 */
|
2014-04-09 21:17:56 +04:00
|
|
|
if (table_cell->columns == 0) {
|
2005-03-26 04:12:27 +03:00
|
|
|
table_cell->columns = 1;
|
2014-04-09 21:17:56 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-04-09 21:17:56 +04:00
|
|
|
/* if rowspan is 0 it is expanded to
|
|
|
|
* the number of rows left in the row
|
|
|
|
* group
|
|
|
|
*/
|
|
|
|
if (table_cell->rows == 0) {
|
|
|
|
table_cell->rows = group_rows_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* limit rowspans within group */
|
|
|
|
if (table_cell->rows > group_rows_left) {
|
|
|
|
table_cell->rows = group_rows_left;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Record span information */
|
|
|
|
for (col = table_cell->start_column;
|
|
|
|
col < table_cell->start_column +
|
|
|
|
table_cell->columns; col++) {
|
|
|
|
spans[col].row_span = table_cell->rows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reduce span count of each column */
|
|
|
|
for (col = 0; col < table->columns; col++) {
|
|
|
|
if (spans[col].row_span == 0) {
|
|
|
|
unsigned int start = col;
|
|
|
|
css_computed_style *style;
|
|
|
|
struct box *cell, *prev;
|
|
|
|
|
|
|
|
/* If it's already zero, then we need
|
|
|
|
* to generate an empty cell for the
|
|
|
|
* gap in the row that spans as many
|
|
|
|
* columns as remain blank.
|
|
|
|
*/
|
|
|
|
assert(table_row->style != NULL);
|
|
|
|
|
|
|
|
/* Find width of gap */
|
|
|
|
while (col < table->columns &&
|
|
|
|
spans[col].row_span ==
|
|
|
|
0) {
|
|
|
|
col++;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
|
|
|
ctx.quirks = (c->quirks ==
|
2012-07-14 19:13:21 +04:00
|
|
|
DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
style = nscss_get_blank_style(&ctx,
|
2013-12-14 00:25:08 +04:00
|
|
|
table_row->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL)
|
|
|
|
return false;
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
cell = box_create(NULL, style, true,
|
2009-07-24 03:05:34 +04:00
|
|
|
table_row->href,
|
|
|
|
table_row->target,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (cell == NULL) {
|
|
|
|
css_computed_style_destroy(
|
|
|
|
style);
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
cell->type = BOX_TABLE_CELL;
|
|
|
|
|
|
|
|
cell->rows = 1;
|
|
|
|
cell->columns = col - start;
|
|
|
|
cell->start_column = start;
|
|
|
|
|
|
|
|
/* Find place to insert cell */
|
|
|
|
for (prev = table_row->children;
|
|
|
|
prev != NULL;
|
|
|
|
prev = prev->next) {
|
|
|
|
if (prev->start_column +
|
|
|
|
prev->columns ==
|
|
|
|
start)
|
|
|
|
break;
|
|
|
|
if (prev->next == NULL)
|
|
|
|
break;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Insert it */
|
|
|
|
if (prev == NULL) {
|
|
|
|
if (table_row->children != NULL)
|
|
|
|
table_row->children->
|
|
|
|
prev = cell;
|
|
|
|
else
|
|
|
|
table_row->last = cell;
|
|
|
|
|
|
|
|
cell->next =
|
|
|
|
table_row->children;
|
|
|
|
table_row->children = cell;
|
|
|
|
} else {
|
|
|
|
if (prev->next != NULL)
|
|
|
|
prev->next->prev = cell;
|
|
|
|
else
|
|
|
|
table_row->last = cell;
|
|
|
|
|
|
|
|
cell->next = prev->next;
|
|
|
|
prev->next = cell;
|
|
|
|
cell->prev = prev;
|
|
|
|
}
|
|
|
|
cell->parent = table_row;
|
|
|
|
} else {
|
|
|
|
spans[col].row_span--;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
assert(rows_left > 0);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
rows_left--;
|
|
|
|
}
|
2014-04-09 21:17:56 +04:00
|
|
|
|
|
|
|
group_rows_left--;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool box_normalise_table_row_group(struct box *row_group,
|
|
|
|
struct columns *col_info,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content * c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
struct box *next_child;
|
|
|
|
struct box *row;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_style *style;
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx ctx;
|
2014-04-09 21:17:56 +04:00
|
|
|
unsigned int group_row_count = 0;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
assert(row_group != 0);
|
|
|
|
assert(row_group->type == BOX_TABLE_ROW_GROUP);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("row_group %p", row_group);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
for (child = row_group->children; child != NULL; child = next_child) {
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* ok */
|
2014-04-09 21:17:56 +04:00
|
|
|
group_row_count++;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table_row(child, col_info,
|
|
|
|
c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row */
|
|
|
|
assert(row_group->style != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, row_group->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
row = box_create(NULL, style, true, row_group->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
row_group->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
row->type = BOX_TABLE_ROW;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (child->prev == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
row_group->children = row;
|
|
|
|
else
|
|
|
|
child->prev->next = row;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
row->prev = child->prev;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
while (child != NULL && (
|
2005-03-26 04:12:27 +03:00
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
2006-11-05 15:58:24 +03:00
|
|
|
child->type == BOX_TABLE_CELL)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(row, child);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
child->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
child = next_child;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-04 22:53:22 +03:00
|
|
|
assert(row->last != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
row->last->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
row->next = next_child = child;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row->next != NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
row->next->prev = row;
|
2008-03-10 17:23:04 +03:00
|
|
|
else
|
|
|
|
row_group->last = row;
|
2005-03-26 04:12:27 +03:00
|
|
|
row->parent = row_group;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-04-09 23:58:12 +04:00
|
|
|
group_row_count++;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table_row(row, col_info,
|
|
|
|
c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2005-06-06 00:54:37 +04:00
|
|
|
case BOX_INLINE_END:
|
2005-03-26 04:12:27 +03:00
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
case BOX_BR:
|
2005-05-23 01:50:14 +04:00
|
|
|
case BOX_TEXT:
|
2005-03-26 04:12:27 +03:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row_group->children == NULL) {
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("row_group->children == 0, inserting implied row");
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2008-03-10 17:24:41 +03:00
|
|
|
assert(row_group->style != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, row_group->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL) {
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
row = box_create(NULL, style, true, row_group->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
row_group->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (row == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
2008-03-10 17:24:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
row->type = BOX_TABLE_ROW;
|
|
|
|
|
|
|
|
row->parent = row_group;
|
|
|
|
row_group->children = row_group->last = row;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-04-09 21:17:56 +04:00
|
|
|
group_row_count = 1;
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Keep table's row count in sync */
|
|
|
|
col_info->num_rows++;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2014-04-09 21:17:56 +04:00
|
|
|
row_group->rows = group_row_count;
|
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("row_group %p done", row_group);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool box_normalise_table_row(struct box *row,
|
|
|
|
struct columns *col_info,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content * c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
struct box *next_child;
|
2009-03-02 22:47:27 +03:00
|
|
|
struct box *cell = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_style *style;
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int i;
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx ctx;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
assert(row != NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
assert(row->type == BOX_TABLE_ROW);
|
2011-04-04 02:23:14 +04:00
|
|
|
|
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("row %p", row);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
for (child = row->children; child != NULL; child = next_child) {
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* ok */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_block(child, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
cell = child;
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* insert implied table cell */
|
|
|
|
assert(row->style != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-14 00:25:08 +04:00
|
|
|
style = nscss_get_blank_style(&ctx, row->style);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (style == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
cell = box_create(NULL, style, true, row->href,
|
2012-10-03 22:24:58 +04:00
|
|
|
row->target, NULL, NULL, c->bctx);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (cell == NULL) {
|
|
|
|
css_computed_style_destroy(style);
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cell->type = BOX_TABLE_CELL;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (child->prev == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
row->children = cell;
|
|
|
|
else
|
|
|
|
child->prev->next = cell;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
cell->prev = child->prev;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
while (child != NULL && (
|
2005-03-26 04:12:27 +03:00
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
2006-11-05 15:58:24 +03:00
|
|
|
child->type == BOX_TABLE_ROW)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(cell, child);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
child->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
child = next_child;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-04 22:53:22 +03:00
|
|
|
assert(cell->last != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
cell->last->next = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
cell->next = next_child = child;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (cell->next != NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
cell->next->prev = cell;
|
2009-07-24 03:05:34 +04:00
|
|
|
else
|
|
|
|
row->last = cell;
|
2005-03-26 04:12:27 +03:00
|
|
|
cell->parent = row;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (box_normalise_block(cell, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2005-06-06 00:54:37 +04:00
|
|
|
case BOX_INLINE_END:
|
2005-03-26 04:12:27 +03:00
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
case BOX_BR:
|
2005-05-23 01:50:14 +04:00
|
|
|
case BOX_TEXT:
|
2005-03-26 04:12:27 +03:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (calculate_table_row(col_info, cell->columns, cell->rows,
|
2014-04-12 19:09:17 +04:00
|
|
|
&cell->start_column, cell) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Update row spanning details for all columns */
|
2005-03-26 04:12:27 +03:00
|
|
|
for (i = 0; i < col_info->num_columns; i++) {
|
2009-07-24 03:05:34 +04:00
|
|
|
if (col_info->spans[i].row_span != 0 &&
|
|
|
|
col_info->spans[i].auto_row == false) {
|
|
|
|
/* This cell spans rows, and is not an auto row.
|
|
|
|
* Reduce number of rows left to span */
|
2005-03-26 04:12:27 +03:00
|
|
|
col_info->spans[i].row_span--;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Reset current column for next row */
|
2005-03-26 04:12:27 +03:00
|
|
|
col_info->current_column = 0;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Increment row counter */
|
|
|
|
col_info->num_rows++;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("row %p done", row);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Compute the column index at which the current cell begins.
|
|
|
|
* Additionally, update the column record to reflect row spanning.
|
|
|
|
*
|
|
|
|
* \param col_info Column record
|
|
|
|
* \param col_span Number of columns that current cell spans
|
|
|
|
* \param row_span Number of rows that current cell spans
|
|
|
|
* \param start_column Pointer to location to receive column index
|
2014-04-12 19:09:17 +04:00
|
|
|
* \param cell Box for current table cell
|
2005-03-26 04:12:27 +03:00
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool calculate_table_row(struct columns *col_info,
|
|
|
|
unsigned int col_span, unsigned int row_span,
|
2014-04-12 19:09:17 +04:00
|
|
|
unsigned int *start_column, struct box *cell)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
unsigned int cell_start_col = col_info->current_column;
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int cell_end_col;
|
|
|
|
unsigned int i;
|
|
|
|
struct span_info *spans;
|
2014-04-12 19:09:17 +04:00
|
|
|
struct box *rg = cell->parent->parent; /* Cell's row group */
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Skip columns with cells spanning from above */
|
2014-04-10 00:54:05 +04:00
|
|
|
/* TODO: Need to ignore cells spanning from above that belong to
|
|
|
|
* different row group. We don't have that info here. */
|
2014-04-12 19:09:17 +04:00
|
|
|
while (col_info->spans[cell_start_col].row_span != 0 &&
|
|
|
|
col_info->spans[cell_start_col].rg == rg) {
|
2009-07-24 03:05:34 +04:00
|
|
|
cell_start_col++;
|
2014-04-12 19:09:17 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/* Update current column with calculated start */
|
|
|
|
col_info->current_column = cell_start_col;
|
|
|
|
|
|
|
|
/* If this cell has a colspan of 0, then assume 1.
|
|
|
|
* No other browser supports colspan=0, anyway. */
|
|
|
|
if (col_span == 0)
|
|
|
|
col_span = 1;
|
|
|
|
|
|
|
|
cell_end_col = cell_start_col + col_span;
|
|
|
|
|
|
|
|
if (col_info->num_columns < cell_end_col) {
|
|
|
|
/* It appears that this row has more columns than
|
|
|
|
* the maximum recorded for the table so far.
|
|
|
|
* Allocate more span records. */
|
|
|
|
spans = realloc(col_info->spans,
|
|
|
|
sizeof *spans * (cell_end_col + 1));
|
|
|
|
if (spans == NULL)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
col_info->spans = spans;
|
|
|
|
col_info->num_columns = cell_end_col;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Mark new final column as sentinel */
|
|
|
|
col_info->spans[cell_end_col].row_span = 0;
|
|
|
|
col_info->spans[cell_end_col].auto_row = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This cell may span multiple columns. If it also wants to span
|
|
|
|
* multiple rows, temporarily assume it spans 1 row only. This will
|
|
|
|
* be fixed up in box_normalise_table_spans() */
|
|
|
|
for (i = cell_start_col; i < cell_end_col; i++) {
|
|
|
|
col_info->spans[i].row_span = (row_span == 0) ? 1 : row_span;
|
|
|
|
col_info->spans[i].auto_row = (row_span == 0);
|
2014-04-12 19:09:17 +04:00
|
|
|
col_info->spans[i].rg = rg;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Update current column with calculated end. */
|
|
|
|
col_info->current_column = cell_end_col;
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
*start_column = cell_start_col;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool box_normalise_inline_container(struct box *cont, html_content * c)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
struct box *next_child;
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
assert(cont != NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
assert(cont->type == BOX_INLINE_CONTAINER);
|
2011-04-04 02:23:14 +04:00
|
|
|
|
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("cont %p", cont);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
for (child = cont->children; child != NULL; child = next_child) {
|
2005-03-26 04:12:27 +03:00
|
|
|
next_child = child->next;
|
|
|
|
switch (child->type) {
|
|
|
|
case BOX_INLINE:
|
2005-06-06 00:54:37 +04:00
|
|
|
case BOX_INLINE_END:
|
2005-03-26 04:12:27 +03:00
|
|
|
case BOX_BR:
|
2005-05-23 01:50:14 +04:00
|
|
|
case BOX_TEXT:
|
2005-03-26 04:12:27 +03:00
|
|
|
/* ok */
|
|
|
|
break;
|
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
/* ok */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_block(child, c) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* ok */
|
2009-07-24 03:05:34 +04:00
|
|
|
assert(child->children != NULL);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
switch (child->children->type) {
|
2006-11-05 15:58:24 +03:00
|
|
|
case BOX_BLOCK:
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_block(child->children,
|
|
|
|
c) == false)
|
2006-11-05 15:58:24 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box_normalise_table(child->children,
|
|
|
|
c) == false)
|
2006-11-05 15:58:24 +03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (child->children == NULL) {
|
2005-03-26 04:12:27 +03:00
|
|
|
/* the child has destroyed itself: remove float */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (child->prev == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
child->parent->children = child->next;
|
|
|
|
else
|
|
|
|
child->prev->next = child->next;
|
2009-07-24 03:05:34 +04:00
|
|
|
if (child->next != NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
child->next->prev = child->prev;
|
2009-07-24 03:05:34 +04:00
|
|
|
else
|
|
|
|
child->parent->last = child->prev;
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_free(child);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2011-04-04 02:23:14 +04:00
|
|
|
|
|
|
|
#ifdef BOX_NORMALISE_DEBUG
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("cont %p done", cont);
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|