[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
This commit is contained in:
James Bursa 2005-06-04 12:12:38 +00:00
parent b2918fc57b
commit 99a483dd7b
5 changed files with 26 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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 */

View File

@ -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,