diff options
Diffstat (limited to 'content/handlers/html/box_normalise.c')
-rw-r--r-- | content/handlers/html/box_normalise.c | 224 |
1 files changed, 216 insertions, 8 deletions
diff --git a/content/handlers/html/box_normalise.c b/content/handlers/html/box_normalise.c index b7032da55..8f25b031f 100644 --- a/content/handlers/html/box_normalise.c +++ b/content/handlers/html/box_normalise.c @@ -177,6 +177,7 @@ box_normalise_table_row(struct box *row, return false; cell = child; break; + case BOX_FLEX: case BOX_BLOCK: case BOX_INLINE_CONTAINER: case BOX_TABLE: @@ -190,7 +191,8 @@ box_normalise_table_row(struct box *row, ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, row->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + row->style); if (style == NULL) return false; @@ -210,6 +212,7 @@ box_normalise_table_row(struct box *row, cell->prev = child->prev; while (child != NULL && ( + child->type == BOX_FLEX || child->type == BOX_BLOCK || child->type == BOX_INLINE_CONTAINER || child->type == BOX_TABLE || @@ -237,6 +240,7 @@ box_normalise_table_row(struct box *row, break; case BOX_INLINE: case BOX_INLINE_END: + case BOX_INLINE_FLEX: case BOX_INLINE_BLOCK: case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: @@ -313,6 +317,7 @@ box_normalise_table_row_group(struct box *row_group, c) == false) return false; break; + case BOX_FLEX: case BOX_BLOCK: case BOX_INLINE_CONTAINER: case BOX_TABLE: @@ -326,7 +331,8 @@ box_normalise_table_row_group(struct box *row_group, ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, row_group->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + row_group->style); if (style == NULL) return false; @@ -346,6 +352,7 @@ box_normalise_table_row_group(struct box *row_group, row->prev = child->prev; while (child != NULL && ( + child->type == BOX_FLEX || child->type == BOX_BLOCK || child->type == BOX_INLINE_CONTAINER || child->type == BOX_TABLE || @@ -375,6 +382,7 @@ box_normalise_table_row_group(struct box *row_group, break; case BOX_INLINE: case BOX_INLINE_END: + case BOX_INLINE_FLEX: case BOX_INLINE_BLOCK: case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: @@ -402,7 +410,8 @@ box_normalise_table_row_group(struct box *row_group, ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, row_group->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + row_group->style); if (style == NULL) { return false; } @@ -533,6 +542,7 @@ box_normalise_table_spans(struct box *table, ctx.universal = c->universal; style = nscss_get_blank_style(&ctx, + &c->unit_len_ctx, table_row->style); if (style == NULL) return false; @@ -644,6 +654,7 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) return false; } break; + case BOX_FLEX: case BOX_BLOCK: case BOX_INLINE_CONTAINER: case BOX_TABLE: @@ -657,7 +668,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, table->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + table->style); if (style == NULL) { free(col_info.spans); return false; @@ -681,6 +693,7 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) row_group->prev = child->prev; while (child != NULL && ( + child->type == BOX_FLEX || child->type == BOX_BLOCK || child->type == BOX_INLINE_CONTAINER || child->type == BOX_TABLE || @@ -711,6 +724,7 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) break; case BOX_INLINE: case BOX_INLINE_END: + case BOX_INLINE_FLEX: case BOX_INLINE_BLOCK: case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: @@ -744,7 +758,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, table->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + table->style); if (style == NULL) { free(col_info.spans); return false; @@ -759,7 +774,8 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) } row_group->type = BOX_TABLE_ROW_GROUP; - style = nscss_get_blank_style(&ctx, row_group->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + row_group->style); if (style == NULL) { box_free(row_group); free(col_info.spans); @@ -799,6 +815,181 @@ box_normalise_table(struct box *table, const struct box *root, html_content * c) return true; } +static bool box_normalise_flex( + struct box *flex_container, + const struct box *root, + html_content *c) +{ + struct box *child; + struct box *next_child; + struct box *implied_flex_item; + css_computed_style *style; + nscss_select_ctx ctx; + + assert(flex_container != NULL); + assert(root != NULL); + + ctx.root_style = root->style; + +#ifdef BOX_NORMALISE_DEBUG + NSLOG(netsurf, INFO, "flex_container %p, flex_container->type %u", + flex_container, flex_container->type); +#endif + + assert(flex_container->type == BOX_FLEX || + flex_container->type == BOX_INLINE_FLEX); + + for (child = flex_container->children; child != NULL; child = next_child) { +#ifdef BOX_NORMALISE_DEBUG + NSLOG(netsurf, INFO, "child %p, child->type = %d", + child, child->type); +#endif + + next_child = child->next; /* child may be destroyed */ + + switch (child->type) { + case BOX_FLEX: + /* ok */ + if (box_normalise_flex(child, root, c) == false) + return false; + break; + case BOX_BLOCK: + /* ok */ + if (box_normalise_block(child, root, c) == false) + return false; + break; + case BOX_INLINE_CONTAINER: + /* insert implied flex item */ + assert(flex_container->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, &c->unit_len_ctx, + flex_container->style); + if (style == NULL) + return false; + + implied_flex_item = box_create(NULL, style, true, + flex_container->href, + flex_container->target, + NULL, NULL, c->bctx); + if (implied_flex_item == NULL) { + css_computed_style_destroy(style); + return false; + } + implied_flex_item->type = BOX_BLOCK; + + if (child->prev == NULL) + flex_container->children = implied_flex_item; + else + child->prev->next = implied_flex_item; + + implied_flex_item->prev = child->prev; + + while (child != NULL && + child->type == BOX_INLINE_CONTAINER) { + box_add_child(implied_flex_item, child); + + next_child = child->next; + child->next = NULL; + child = next_child; + } + + implied_flex_item->last->next = NULL; + implied_flex_item->next = next_child = child; + if (implied_flex_item->next != NULL) + implied_flex_item->next->prev = implied_flex_item; + else + flex_container->last = implied_flex_item; + implied_flex_item->parent = flex_container; + + if (box_normalise_block(implied_flex_item, + root, c) == false) + return false; + break; + + case BOX_TABLE: + if (box_normalise_table(child, root, c) == false) + return false; + break; + case BOX_INLINE: + case BOX_INLINE_END: + case BOX_INLINE_FLEX: + case BOX_INLINE_BLOCK: + case BOX_FLOAT_LEFT: + case BOX_FLOAT_RIGHT: + case BOX_BR: + case BOX_TEXT: + /* 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: + /* insert implied table */ + assert(flex_container->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, &c->unit_len_ctx, + flex_container->style); + if (style == NULL) + return false; + + implied_flex_item = box_create(NULL, style, true, + flex_container->href, + flex_container->target, + NULL, NULL, c->bctx); + if (implied_flex_item == NULL) { + css_computed_style_destroy(style); + return false; + } + implied_flex_item->type = BOX_TABLE; + + if (child->prev == NULL) + flex_container->children = implied_flex_item; + else + child->prev->next = implied_flex_item; + + implied_flex_item->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(implied_flex_item, child); + + next_child = child->next; + child->next = NULL; + child = next_child; + } + + implied_flex_item->last->next = NULL; + implied_flex_item->next = next_child = child; + if (implied_flex_item->next != NULL) + implied_flex_item->next->prev = implied_flex_item; + else + flex_container->last = implied_flex_item; + implied_flex_item->parent = flex_container; + + if (box_normalise_table(implied_flex_item, + root, c) == false) + return false; + break; + default: + assert(0); + } + } + + return true; +} static bool box_normalise_inline_container(struct box *cont, @@ -829,6 +1020,11 @@ box_normalise_inline_container(struct box *cont, if (box_normalise_block(child, root, c) == false) return false; break; + case BOX_INLINE_FLEX: + /* ok */ + if (box_normalise_flex(child, root, c) == false) + return false; + break; case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: /* ok */ @@ -845,6 +1041,11 @@ box_normalise_inline_container(struct box *cont, c) == false) return false; break; + case BOX_FLEX: + if (box_normalise_flex(child->children, root, + c) == false) + return false; + break; default: assert(0); } @@ -863,6 +1064,7 @@ box_normalise_inline_container(struct box *cont, box_free(child); } break; + case BOX_FLEX: case BOX_BLOCK: case BOX_INLINE_CONTAINER: case BOX_TABLE: @@ -881,7 +1083,6 @@ box_normalise_inline_container(struct box *cont, return true; } - /* Exported function documented in html/box_normalise.h */ bool box_normalise_block(struct box *block, const struct box *root, html_content *c) @@ -913,6 +1114,11 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c) next_child = child->next; /* child may be destroyed */ switch (child->type) { + case BOX_FLEX: + /* ok */ + if (box_normalise_flex(child, root, c) == false) + return false; + break; case BOX_BLOCK: /* ok */ if (box_normalise_block(child, root, c) == false) @@ -928,6 +1134,7 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c) break; case BOX_INLINE: case BOX_INLINE_END: + case BOX_INLINE_FLEX: case BOX_INLINE_BLOCK: case BOX_FLOAT_LEFT: case BOX_FLOAT_RIGHT: @@ -948,7 +1155,8 @@ box_normalise_block(struct box *block, const struct box *root, html_content *c) ctx.base_url = c->base_url; ctx.universal = c->universal; - style = nscss_get_blank_style(&ctx, block->style); + style = nscss_get_blank_style(&ctx, &c->unit_len_ctx, + block->style); if (style == NULL) return false; |