summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJeffrey Lee <me@phlamethrower.co.uk>2006-09-10 13:27:08 +0000
committerJeffrey Lee <me@phlamethrower.co.uk>2006-09-10 13:27:08 +0000
commit271c28a5df7f9e1634f7f35b9a61e7ce3e02cf34 (patch)
tree9330ac664e3870a470d43d7ed75bc22c6f948286 /render
parentd7834f1a34d63a068bd6bd76bec7a9574ec31624 (diff)
downloadnetsurf-271c28a5df7f9e1634f7f35b9a61e7ce3e02cf34.tar.gz
netsurf-271c28a5df7f9e1634f7f35b9a61e7ce3e02cf34.tar.bz2
textarea html tag fix; horizontal scrollbars; auto-scroll improvements
svn path=/trunk/netsurf/; revision=2940
Diffstat (limited to 'render')
-rw-r--r--render/box_construct.c28
-rw-r--r--render/layout.c49
2 files changed, 52 insertions, 25 deletions
diff --git a/render/box_construct.c b/render/box_construct.c
index d37d357c3..3aef253fe 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -2391,7 +2391,9 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
* Consecutive BR may not be present. These constraints are satisfied
* by using a 0-length TEXT for blank lines. */
- xmlChar *text, *current;
+ xmlChar *current;
+ xmlNode *n2;
+ xmlBufferPtr buf;
struct box *inline_container, *inline_box, *br_box;
char *s;
size_t len;
@@ -2415,20 +2417,32 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
inline_container->type = BOX_INLINE_CONTAINER;
box_add_child(box, inline_container);
- current = text = xmlNodeGetContent(n);
+ n2 = n->children;
+ buf = xmlBufferCreate();
+ while(n2) {
+ int ret = xmlNodeDump(buf,n2->doc,n2,0,0);
+ if (ret == -1) {
+ xmlBufferFree(buf);
+ return false;
+ }
+ n2 = n2->next;
+ }
+ current = buf->content;
while (1) {
/* BOX_TEXT */
len = strcspn(current, "\r\n");
s = talloc_strndup(content, current, len);
if (!s) {
- xmlFree(content);
+ xmlBufferFree(buf);
return false;
}
inline_box = box_create(box->style, 0, 0, box->title, 0,
content);
- if (!inline_box)
+ if (!inline_box) {
+ xmlBufferFree(buf);
return false;
+ }
inline_box->type = BOX_TEXT;
inline_box->text = s;
inline_box->length = len;
@@ -2441,8 +2455,10 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
/* BOX_BR */
br_box = box_create(box->style, 0, 0, box->title, 0, content);
- if (!br_box)
+ if (!br_box) {
+ xmlBufferFree(buf);
return false;
+ }
br_box->type = BOX_BR;
box_add_child(inline_container, br_box);
@@ -2451,7 +2467,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
else
current++;
}
- xmlFree(text);
+ xmlBufferFree(buf);
if (content->data.html.forms)
form_add_control(content->data.html.forms, box->gadget);
diff --git a/render/layout.c b/render/layout.c
index 715b126ec..38af06208 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -60,7 +60,7 @@ static void find_sides(struct box *fl, int y0, int y1,
int *x0, int *x1, struct box **left, struct box **right);
static void layout_minmax_inline_container(struct box *inline_container);
static int line_height(struct css_style *style);
-static bool layout_line(struct box *first, int width, int *y,
+static bool layout_line(struct box *first, int *width, int *y,
int cx, int cy, struct box *cont, bool indent,
bool has_text_children,
struct content *content, struct box **next_box);
@@ -523,9 +523,14 @@ void layout_block_find_dimensions(int available_width, struct box *box)
if (style->overflow == CSS_OVERFLOW_SCROLL ||
style->overflow == CSS_OVERFLOW_AUTO) {
/* make space for scrollbars */
- box->width -= SCROLLBAR_WIDTH;
- box->padding[RIGHT] += SCROLLBAR_WIDTH;
- box->padding[BOTTOM] += SCROLLBAR_WIDTH;
+ if ((style->overflow == CSS_OVERFLOW_SCROLL) || box_hscrollbar_present(box)) {
+ box->height -= SCROLLBAR_WIDTH;
+ box->padding[BOTTOM] += SCROLLBAR_WIDTH;
+ }
+ if ((style->overflow == CSS_OVERFLOW_SCROLL) || box_vscrollbar_present(box)) {
+ box->width -= SCROLLBAR_WIDTH;
+ box->padding[RIGHT] += SCROLLBAR_WIDTH;
+ }
}
if (margin[TOP] == AUTO)
@@ -809,6 +814,7 @@ bool layout_inline_container(struct box *inline_container, int width,
bool has_text_children;
struct box *c, *next;
int y = 0;
+ int curwidth,maxwidth = width;
assert(inline_container->type == BOX_INLINE_CONTAINER);
@@ -819,17 +825,20 @@ bool layout_inline_container(struct box *inline_container, int width,
for (c = inline_container->children; c; c = c->next)
if ((!c->object && c->text && c->length) || c->type == BOX_BR)
has_text_children = true;
-
+
+ /** \todo fix wrapping so that a box with horizontal scrollbar will shrink back to 'width' if no word is wider than 'width' (Or just set curwidth = width and have the multiword lines wrap to the min width) */
for (c = inline_container->children; c; ) {
LOG(("c %p", c));
- if (!layout_line(c, width, &y, cx, cy + y, cont, first_line,
+ curwidth = inline_container->width;
+ if (!layout_line(c, &curwidth, &y, cx, cy + y, cont, first_line,
has_text_children, content, &next))
return false;
+ maxwidth = max(maxwidth,curwidth);
c = next;
first_line = false;
}
- inline_container->width = width;
+ inline_container->width = maxwidth;
inline_container->height = y;
return true;
@@ -911,7 +920,8 @@ int line_height(struct css_style *style)
* Position a line of boxes in inline formatting context.
*
* \param first box at start of line
- * \param width available width
+ * \param width available width on input, updated with actual width on output
+ * (may be incorrect if the line gets split?)
* \param y coordinate of top of line, updated on exit to bottom
* \param cx coordinate of left of line relative to cont
* \param cy coordinate of top of line relative to cont
@@ -923,14 +933,14 @@ int line_height(struct css_style *style)
* \return true on success, false on memory exhaustion
*/
-bool layout_line(struct box *first, int width, int *y,
+bool layout_line(struct box *first, int *width, int *y,
int cx, int cy, struct box *cont, bool indent,
bool has_text_children,
struct content *content, struct box **next_box)
{
int height, used_height;
int x0 = 0;
- int x1 = width;
+ int x1 = *width;
int x, h, x_previous;
struct box *left;
struct box *right;
@@ -944,7 +954,7 @@ bool layout_line(struct box *first, int width, int *y,
unsigned int i;
LOG(("first %p, first->text '%.*s', width %i, y %i, cx %i, cy %i",
- first, (int) first->length, first->text, width,
+ first, (int) first->length, first->text, *width,
*y, cx, cy));
/* find sides at top of line */
@@ -955,7 +965,7 @@ bool layout_line(struct box *first, int width, int *y,
x1 -= cx;
if (indent)
- x0 += layout_text_indent(first->parent->parent->style, width);
+ x0 += layout_text_indent(first->parent->parent->style, *width);
if (x1 < x0)
x1 = x0;
@@ -990,7 +1000,7 @@ bool layout_line(struct box *first, int width, int *y,
if (b->type == BOX_INLINE_BLOCK) {
if (b->width == UNKNOWN_WIDTH)
- if (!layout_float(b, width, content))
+ if (!layout_float(b, *width, content))
return false;
/** \todo should margin be included? spec unclear */
h = b->border[TOP] + b->padding[TOP] + b->height +
@@ -1007,7 +1017,7 @@ bool layout_line(struct box *first, int width, int *y,
if (b->type == BOX_INLINE) {
/* calculate borders, margins, and padding */
- layout_find_dimensions(width, b->style,
+ layout_find_dimensions(*width, b->style,
0, 0, b->margin, b->padding, b->border);
for (i = 0; i != 4; i++)
if (b->margin[i] == AUTO)
@@ -1076,7 +1086,7 @@ bool layout_line(struct box *first, int width, int *y,
length, b->style);
break;
case CSS_WIDTH_PERCENT:
- b->width = width *
+ b->width = *width *
b->style->width.value.percent /
100;
break;
@@ -1141,14 +1151,14 @@ bool layout_line(struct box *first, int width, int *y,
/* find new sides using this height */
x0 = cx;
- x1 = cx + width;
+ x1 = cx + *width;
find_sides(cont->float_children, cy, cy + height, &x0, &x1,
&left, &right);
x0 -= cx;
x1 -= cx;
if (indent)
- x0 += layout_text_indent(first->parent->parent->style, width);
+ x0 += layout_text_indent(first->parent->parent->style, *width);
if (x1 < x0)
x1 = x0;
@@ -1214,7 +1224,7 @@ bool layout_line(struct box *first, int width, int *y,
d = b->children;
d->float_children = 0;
- if (!layout_float(d, width, content))
+ if (!layout_float(d, *width, content))
return false;
d->x = d->margin[LEFT] + d->border[LEFT];
d->y = d->margin[TOP] + d->border[TOP];
@@ -1242,7 +1252,7 @@ bool layout_line(struct box *first, int width, int *y,
b->y = cy;
} else {
/* doesn't fit: place below */
- place_float_below(b, width,
+ place_float_below(b, *width,
cx, cy + height + 1, cont);
}
if (cont->float_children == b) {
@@ -1427,6 +1437,7 @@ bool layout_line(struct box *first, int width, int *y,
if (move_y)
*y += used_height;
*next_box = b;
+ *width = x; /* return actual width */
return true;
}