From 99a483dd7b744ede170eeffde5ec30fd8ed1a0e5 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sat, 4 Jun 2005 12:12:38 +0000 Subject: [project @ 2005-06-04 12:12:38 by bursa] Fix text-decoration and borders on inline elements by replacing inline_parent in box structure with end_inline_children. svn path=/import/netsurf/; revision=1741 --- render/box.c | 7 ++++--- render/box.h | 8 +++++--- render/box_construct.c | 26 ++++++++++---------------- render/box_normalise.c | 4 ++++ render/html_redraw.c | 7 +++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/render/box.c b/render/box.c index 51db3c0cf..b53ae2b2b 100644 --- a/render/box.c +++ b/render/box.c @@ -76,7 +76,7 @@ struct box * box_create(struct css_style *style, box->last = NULL; box->parent = NULL; box->fallback = NULL; - box->inline_parent = NULL; + box->end_inline_children = NULL; box->float_children = NULL; box->next_float = NULL; box->col = NULL; @@ -476,8 +476,9 @@ void box_dump(struct box *box, unsigned int depth) fprintf(stderr, " [%s]", box->title); if (box->id != 0) fprintf(stderr, " <%s>", box->id); - if (box->inline_parent) - fprintf(stderr, " inline_parent %p", box->inline_parent); + if (box->type == BOX_INLINE) + fprintf(stderr, " end_inline_children %p", + box->end_inline_children); if (box->float_children) fprintf(stderr, " float_children %p", box->float_children); if (box->next_float) diff --git a/render/box.h b/render/box.h index 9bef5edd3..b377cd91a 100644 --- a/render/box.h +++ b/render/box.h @@ -166,9 +166,11 @@ struct box { struct box *last; /**< Last child box, or 0. */ struct box *parent; /**< Parent box, or 0. */ struct box *fallback; /**< Fallback children for object, or 0. */ - /** Box of type INLINE which contains this box in the document tree - * (only valid for TEXT boxes). */ - struct box *inline_parent; + /** Sibling box after the last sibling box which was a child of this box + * in the document tree (the box after is used so that splitting boxes + * for line wrapping doesn't change it), or 0 if continues to end of + * inline container (only valid for INLINE boxes). */ + struct box *end_inline_children; /** First float child box, or 0. Float boxes are in the tree twice, in * this list for the block box which defines the area for floats, and diff --git a/render/box_construct.c b/render/box_construct.c index a88fded95..c3dc1e7bc 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -72,17 +72,14 @@ static const content_type image_types[] = { static bool convert_xml_to_box(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title); bool box_construct_element(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title); bool box_construct_text(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title); static struct css_style * box_get_style(struct content *c, struct css_style *parent_style, @@ -177,7 +174,7 @@ bool xml_to_box(xmlNode *n, struct content *c) c->data.html.object = 0; if (!convert_xml_to_box(n, c, c->data.html.style, &root, - &inline_container, 0, 0, 0)) + &inline_container, 0, 0)) return false; if (!box_normalise_block(&root, c)) return false; @@ -227,16 +224,15 @@ static const box_type box_map[] = { bool convert_xml_to_box(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title) { switch (n->type) { case XML_ELEMENT_NODE: return box_construct_element(n, content, parent_style, parent, - inline_container, inline_parent, href, title); + inline_container, href, title); case XML_TEXT_NODE: return box_construct_text(n, content, parent_style, parent, - inline_container, inline_parent, href, title); + inline_container, href, title); default: /* not an element or text node: ignore it (eg. comment) */ return true; @@ -260,7 +256,6 @@ bool convert_xml_to_box(xmlNode *n, struct content *content, bool box_construct_element(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title) { bool convert_children = true; @@ -340,19 +335,21 @@ bool box_construct_element(xmlNode *n, struct content *content, if (box->type == BOX_INLINE || box->type == BOX_BR) { /* inline box: add to tree and recurse */ - box->inline_parent = inline_parent; box_add_child(*inline_container, box); for (c = n->children; convert_children && c; c = c->next) if (!convert_xml_to_box(c, content, style, parent, - inline_container, box, href, title)) + inline_container, href, title)) return false; + /* corrected to next box (which doesn't exist yet) in + * box_normalise_inline_container() */ + box->end_inline_children = (*inline_container)->last; } else if (box->type == BOX_INLINE_BLOCK) { /* inline block box: add to tree and recurse */ box_add_child(*inline_container, box); inline_container_c = 0; for (c = n->children; convert_children && c; c = c->next) if (!convert_xml_to_box(c, content, style, box, - &inline_container_c, 0, href, title)) + &inline_container_c, href, title)) return false; } else { if (style->float_ == CSS_FLOAT_LEFT || @@ -379,7 +376,7 @@ bool box_construct_element(xmlNode *n, struct content *content, inline_container_c = 0; for (c = n->children; convert_children && c; c = c->next) if (!convert_xml_to_box(c, content, style, box, - &inline_container_c, 0, href, title)) + &inline_container_c, href, title)) return false; if (style->float_ == CSS_FLOAT_NONE) /* new inline container unless this is a float */ @@ -492,7 +489,6 @@ bool box_construct_element(xmlNode *n, struct content *content, bool box_construct_text(xmlNode *n, struct content *content, struct css_style *parent_style, struct box *parent, struct box **inline_container, - struct box *inline_parent, char *href, char *title) { struct box *box = 0; @@ -537,7 +533,6 @@ bool box_construct_text(xmlNode *n, struct content *content, return false; } box->type = BOX_TEXT; - box->inline_parent = inline_parent; box->text = talloc_strdup(content, text); free(text); if (!box->text) @@ -614,7 +609,6 @@ bool box_construct_text(xmlNode *n, struct content *content, return false; } box->type = BOX_TEXT; - box->inline_parent = inline_parent; box->text = talloc_strdup(content, current); if (!box->text) { free(text); @@ -1291,7 +1285,7 @@ bool box_object(BOX_SPECIAL_PARAMS) /* convert children and place into fallback */ for (c = n->children; c; c = c->next) { if (!convert_xml_to_box(c, content, box->style, box, - &inline_container, 0, 0, 0)) + &inline_container, 0, 0)) return false; } box->fallback = box->children; diff --git a/render/box_normalise.c b/render/box_normalise.c index 05e2f2d76..c67fe285d 100644 --- a/render/box_normalise.c +++ b/render/box_normalise.c @@ -643,6 +643,10 @@ bool box_normalise_inline_container(struct box *cont, struct content * c) next_child = child->next; switch (child->type) { case BOX_INLINE: + /* correct end_inline_children to the box after the + * last inline child (see box_construct_element()) */ + child->end_inline_children = + child->end_inline_children->next; case BOX_BR: case BOX_TEXT: /* ok */ diff --git a/render/html_redraw.c b/render/html_redraw.c index 68a20bf88..d6b255de2 100644 --- a/render/html_redraw.c +++ b/render/html_redraw.c @@ -464,7 +464,7 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, * inline parent as this box (which must mean it was the next * sibling of this inline in the HTML tree) */ for (struct box *c = box->next; - c && c->inline_parent != box->inline_parent; + c && c != box->end_inline_children; c = c->next) { int x = (x_parent + c->x) * scale; int y = (y_parent + c->y - box->padding[TOP]) * scale; @@ -502,8 +502,7 @@ bool html_redraw_borders(struct box *box, int x_parent, int y_parent, style, box->border[BOTTOM] * scale); if (box->border[RIGHT] && (!c->next || - c->next->inline_parent == - box->inline_parent)) + c->next == box->end_inline_children)) html_redraw_border_plot(RIGHT, p, box->style->border[RIGHT].color, box->style->border[RIGHT].style, @@ -1038,7 +1037,7 @@ bool html_redraw_text_decoration_inline(struct box *box, int x, int y, * parent as this box (which must mean it was the next sibling of this * inline in the HTML tree) */ for (struct box *c = box->next; - c && c->inline_parent != box->inline_parent; + c && c != box->end_inline_children; c = c->next) { if (!plot.line((x + c->x) * scale, (y + c->y + c->height * ratio) * scale, -- cgit v1.2.3