mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 20:46:50 +03:00
[project @ 2005-04-09 09:47:36 by bursa]
Move HTML contents almost fully over to talloc(), simplifying code. Improvements to title attributes, broken forms, cellpadding. Reorder functions in box_construct.c. svn path=/import/netsurf/; revision=1608
This commit is contained in:
parent
8728712699
commit
2920bca14a
34
css/css.c
34
css/css.c
@ -110,7 +110,6 @@ static void css_dump_selector(const struct css_selector *r);
|
|||||||
/** Default style for a document. These are the 'Initial values' from the
|
/** Default style for a document. These are the 'Initial values' from the
|
||||||
* spec. */
|
* spec. */
|
||||||
const struct css_style css_base_style = {
|
const struct css_style css_base_style = {
|
||||||
{ {CSS_CELLPADDING_VALUE, 1} },
|
|
||||||
CSS_BACKGROUND_ATTACHMENT_SCROLL,
|
CSS_BACKGROUND_ATTACHMENT_SCROLL,
|
||||||
0xffffff,
|
0xffffff,
|
||||||
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
|
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
|
||||||
@ -167,10 +166,10 @@ const struct css_style css_base_style = {
|
|||||||
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
|
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
|
||||||
CSS_BORDER_STYLE_NONE },
|
CSS_BORDER_STYLE_NONE },
|
||||||
CSS_OVERFLOW_VISIBLE,
|
CSS_OVERFLOW_VISIBLE,
|
||||||
{ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false }, },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } } },
|
||||||
CSS_PAGE_BREAK_AFTER_AUTO,
|
CSS_PAGE_BREAK_AFTER_AUTO,
|
||||||
CSS_PAGE_BREAK_BEFORE_AUTO,
|
CSS_PAGE_BREAK_BEFORE_AUTO,
|
||||||
CSS_PAGE_BREAK_INSIDE_AUTO,
|
CSS_PAGE_BREAK_INSIDE_AUTO,
|
||||||
@ -196,7 +195,6 @@ const struct css_style css_base_style = {
|
|||||||
|
|
||||||
/** Style with no values set. */
|
/** Style with no values set. */
|
||||||
const struct css_style css_empty_style = {
|
const struct css_style css_empty_style = {
|
||||||
{ { CSS_CELLPADDING_NOT_SET, 0 } },
|
|
||||||
CSS_BACKGROUND_ATTACHMENT_NOT_SET,
|
CSS_BACKGROUND_ATTACHMENT_NOT_SET,
|
||||||
CSS_COLOR_NOT_SET,
|
CSS_COLOR_NOT_SET,
|
||||||
{ CSS_BACKGROUND_IMAGE_NOT_SET, 0 },
|
{ CSS_BACKGROUND_IMAGE_NOT_SET, 0 },
|
||||||
@ -253,10 +251,10 @@ const struct css_style css_empty_style = {
|
|||||||
{ CSS_BORDER_WIDTH_NOT_SET, { 0, CSS_UNIT_PX } },
|
{ CSS_BORDER_WIDTH_NOT_SET, { 0, CSS_UNIT_PX } },
|
||||||
CSS_BORDER_STYLE_NOT_SET },
|
CSS_BORDER_STYLE_NOT_SET },
|
||||||
CSS_OVERFLOW_NOT_SET,
|
CSS_OVERFLOW_NOT_SET,
|
||||||
{ { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
|
{ { CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } }, false }, },
|
{ CSS_PADDING_NOT_SET, { { 0, CSS_UNIT_PX } } } },
|
||||||
CSS_PAGE_BREAK_AFTER_NOT_SET,
|
CSS_PAGE_BREAK_AFTER_NOT_SET,
|
||||||
CSS_PAGE_BREAK_BEFORE_NOT_SET,
|
CSS_PAGE_BREAK_BEFORE_NOT_SET,
|
||||||
CSS_PAGE_BREAK_INSIDE_NOT_SET,
|
CSS_PAGE_BREAK_INSIDE_NOT_SET,
|
||||||
@ -283,7 +281,6 @@ const struct css_style css_empty_style = {
|
|||||||
/** Default style for an element. These should be INHERIT if 'Inherited' is yes,
|
/** Default style for an element. These should be INHERIT if 'Inherited' is yes,
|
||||||
* and the 'Initial value' otherwise. */
|
* and the 'Initial value' otherwise. */
|
||||||
const struct css_style css_blank_style = {
|
const struct css_style css_blank_style = {
|
||||||
{ { CSS_CELLPADDING_INHERIT, 0 } },
|
|
||||||
CSS_BACKGROUND_ATTACHMENT_SCROLL,
|
CSS_BACKGROUND_ATTACHMENT_SCROLL,
|
||||||
TRANSPARENT,
|
TRANSPARENT,
|
||||||
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
|
{ CSS_BACKGROUND_IMAGE_NONE, 0 },
|
||||||
@ -340,10 +337,10 @@ const struct css_style css_blank_style = {
|
|||||||
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
|
{ CSS_BORDER_WIDTH_LENGTH, { 2, CSS_UNIT_PX } },
|
||||||
CSS_BORDER_STYLE_NONE },
|
CSS_BORDER_STYLE_NONE },
|
||||||
CSS_OVERFLOW_VISIBLE,
|
CSS_OVERFLOW_VISIBLE,
|
||||||
{ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ { CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } },
|
||||||
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } }, false }, },
|
{ CSS_PADDING_LENGTH, { { 0, CSS_UNIT_PX } } } },
|
||||||
CSS_PAGE_BREAK_AFTER_AUTO,
|
CSS_PAGE_BREAK_AFTER_AUTO,
|
||||||
CSS_PAGE_BREAK_BEFORE_AUTO,
|
CSS_PAGE_BREAK_BEFORE_AUTO,
|
||||||
CSS_PAGE_BREAK_INSIDE_INHERIT,
|
CSS_PAGE_BREAK_INSIDE_INHERIT,
|
||||||
@ -2383,11 +2380,6 @@ void css_cascade(struct css_style * const style,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
if (apply->html_style.cellpadding.type !=
|
|
||||||
CSS_CELLPADDING_INHERIT &&
|
|
||||||
apply->html_style.cellpadding.type !=
|
|
||||||
CSS_CELLPADDING_NOT_SET)
|
|
||||||
style->html_style.cellpadding = apply->html_style.cellpadding;
|
|
||||||
if (apply->background_attachment !=
|
if (apply->background_attachment !=
|
||||||
CSS_BACKGROUND_ATTACHMENT_INHERIT &&
|
CSS_BACKGROUND_ATTACHMENT_INHERIT &&
|
||||||
apply->background_attachment !=
|
apply->background_attachment !=
|
||||||
@ -2678,8 +2670,6 @@ void css_merge(struct css_style * const style,
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (apply->html_style.cellpadding.type != CSS_CELLPADDING_NOT_SET)
|
|
||||||
style->html_style.cellpadding = apply->html_style.cellpadding;
|
|
||||||
if (apply->background_attachment != CSS_BACKGROUND_ATTACHMENT_NOT_SET)
|
if (apply->background_attachment != CSS_BACKGROUND_ATTACHMENT_NOT_SET)
|
||||||
style->background_attachment = apply->background_attachment;
|
style->background_attachment = apply->background_attachment;
|
||||||
if (apply->background_color != CSS_COLOR_NOT_SET)
|
if (apply->background_color != CSS_COLOR_NOT_SET)
|
||||||
|
11
css/css.h
11
css/css.h
@ -149,16 +149,6 @@ struct css_content {
|
|||||||
|
|
||||||
/** Representation of a complete CSS 2 style. */
|
/** Representation of a complete CSS 2 style. */
|
||||||
struct css_style {
|
struct css_style {
|
||||||
/* html styles that don't translate directly to CSS */
|
|
||||||
struct {
|
|
||||||
struct {
|
|
||||||
enum { CSS_CELLPADDING_INHERIT,
|
|
||||||
CSS_CELLPADDING_VALUE,
|
|
||||||
CSS_CELLPADDING_NOT_SET } type;
|
|
||||||
int value;
|
|
||||||
} cellpadding;
|
|
||||||
} html_style;
|
|
||||||
|
|
||||||
/* background properties */
|
/* background properties */
|
||||||
css_background_attachment background_attachment;
|
css_background_attachment background_attachment;
|
||||||
colour background_color;
|
colour background_color;
|
||||||
@ -378,7 +368,6 @@ struct css_style {
|
|||||||
struct css_length length;
|
struct css_length length;
|
||||||
float percent;
|
float percent;
|
||||||
} value;
|
} value;
|
||||||
bool override_cellpadding; /* override HTML setting */
|
|
||||||
} padding[4]; /**< top, right, bottom, left */
|
} padding[4]; /**< top, right, bottom, left */
|
||||||
|
|
||||||
css_page_break_after page_break_after;
|
css_page_break_after page_break_after;
|
||||||
|
@ -2683,15 +2683,12 @@ void parse_padding_side(struct css_style * const s, const struct css_node * cons
|
|||||||
if (v->type == CSS_NODE_IDENT && v->data_length == 7 &&
|
if (v->type == CSS_NODE_IDENT && v->data_length == 7 &&
|
||||||
strncasecmp(v->data, "inherit", 7) == 0) {
|
strncasecmp(v->data, "inherit", 7) == 0) {
|
||||||
s->padding[i].padding = CSS_PADDING_INHERIT;
|
s->padding[i].padding = CSS_PADDING_INHERIT;
|
||||||
s->padding[i].override_cellpadding = true;
|
|
||||||
} else if (v->type == CSS_NODE_PERCENTAGE) {
|
} else if (v->type == CSS_NODE_PERCENTAGE) {
|
||||||
s->padding[i].padding = CSS_PADDING_PERCENT;
|
s->padding[i].padding = CSS_PADDING_PERCENT;
|
||||||
s->padding[i].value.percent = atof(v->data);
|
s->padding[i].value.percent = atof(v->data);
|
||||||
s->padding[i].override_cellpadding = true;
|
|
||||||
} else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
|
} else if ((v->type == CSS_NODE_DIMENSION || v->type == CSS_NODE_NUMBER) &&
|
||||||
parse_length(&s->padding[i].value.length, v, true) == 0) {
|
parse_length(&s->padding[i].value.length, v, true) == 0) {
|
||||||
s->padding[i].padding = CSS_PADDING_LENGTH;
|
s->padding[i].padding = CSS_PADDING_LENGTH;
|
||||||
s->padding[i].override_cellpadding = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "netsurf/render/layout.h"
|
#include "netsurf/render/layout.h"
|
||||||
#include "netsurf/utils/log.h"
|
#include "netsurf/utils/log.h"
|
||||||
#include "netsurf/utils/messages.h"
|
#include "netsurf/utils/messages.h"
|
||||||
|
#include "netsurf/utils/talloc.h"
|
||||||
#include "netsurf/utils/url.h"
|
#include "netsurf/utils/url.h"
|
||||||
#include "netsurf/utils/utils.h"
|
#include "netsurf/utils/utils.h"
|
||||||
|
|
||||||
@ -1279,7 +1280,8 @@ void browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
utf8[0] = key;
|
utf8[0] = key;
|
||||||
utf8_len = 1;
|
utf8_len = 1;
|
||||||
|
|
||||||
text = realloc(text_box->text, text_box->length + 8);
|
text = talloc_realloc(bw->current_content, text_box->text,
|
||||||
|
char, text_box->length + 8);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
return;
|
return;
|
||||||
@ -1299,16 +1301,16 @@ void browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
|
|
||||||
} else if (key == 10 || key == 13) {
|
} else if (key == 10 || key == 13) {
|
||||||
/* paragraph break */
|
/* paragraph break */
|
||||||
text = malloc(text_box->length + 1);
|
text = talloc_array(bw->current_content, char,
|
||||||
|
text_box->length + 1);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_br = box_create(text_box->style, 0, 0, 0,
|
new_br = box_create(text_box->style, 0, text_box->title, 0,
|
||||||
bw->current_content->data.html.box_pool);
|
bw->current_content);
|
||||||
new_text = pool_alloc(bw->current_content->data.html.box_pool,
|
new_text = talloc(bw->current_content, struct box);
|
||||||
sizeof (struct box));
|
|
||||||
if (!new_text) {
|
if (!new_text) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
return;
|
return;
|
||||||
@ -1353,7 +1355,8 @@ void browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
/* delete space by merging with previous text box */
|
/* delete space by merging with previous text box */
|
||||||
prev = text_box->prev;
|
prev = text_box->prev;
|
||||||
assert(prev->text);
|
assert(prev->text);
|
||||||
text = realloc(prev->text,
|
text = talloc_realloc(bw->current_content, prev->text,
|
||||||
|
char,
|
||||||
prev->length + text_box->length + 1);
|
prev->length + text_box->length + 1);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
@ -1469,7 +1472,7 @@ void browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
height = textarea->height;
|
height = textarea->height;
|
||||||
if (!layout_inline_container(inline_container, width,
|
if (!layout_inline_container(inline_container, width,
|
||||||
textarea, 0, 0,
|
textarea, 0, 0,
|
||||||
bw->current_content->data.html.box_pool))
|
bw->current_content))
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
textarea->width = width;
|
textarea->width = width;
|
||||||
textarea->height = height;
|
textarea->height = height;
|
||||||
@ -1627,7 +1630,8 @@ void browser_window_input_callback(struct browser_window *bw,
|
|||||||
return;
|
return;
|
||||||
utf8keySize = strlen(utf8key);
|
utf8keySize = strlen(utf8key);
|
||||||
|
|
||||||
value = realloc(input->gadget->value, input->gadget->length + utf8keySize + 1);
|
value = realloc(input->gadget->value,
|
||||||
|
input->gadget->length + utf8keySize + 1);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
free(utf8key);
|
free(utf8key);
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
@ -1651,7 +1655,8 @@ void browser_window_input_callback(struct browser_window *bw,
|
|||||||
return;
|
return;
|
||||||
utf8keySize = strlen(utf8key);
|
utf8keySize = strlen(utf8key);
|
||||||
|
|
||||||
value = realloc(text_box->text, text_box->length + utf8keySize + 1);
|
value = talloc_realloc(bw->current_content, text_box->text,
|
||||||
|
char, text_box->length + utf8keySize + 1);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
free(utf8key);
|
free(utf8key);
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
@ -1910,14 +1915,17 @@ void browser_window_form_select(struct browser_window *bw,
|
|||||||
control->data.select.current = o;
|
control->data.select.current = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(inline_box->text);
|
talloc_free(inline_box->text);
|
||||||
inline_box->text = 0;
|
inline_box->text = 0;
|
||||||
if (control->data.select.num_selected == 0)
|
if (control->data.select.num_selected == 0)
|
||||||
inline_box->text = strdup(messages_get("Form_None"));
|
inline_box->text = talloc_strdup(bw->current_content,
|
||||||
|
messages_get("Form_None"));
|
||||||
else if (control->data.select.num_selected == 1)
|
else if (control->data.select.num_selected == 1)
|
||||||
inline_box->text = strdup(control->data.select.current->text);
|
inline_box->text = talloc_strdup(bw->current_content,
|
||||||
|
control->data.select.current->text);
|
||||||
else
|
else
|
||||||
inline_box->text = strdup(messages_get("Form_Many"));
|
inline_box->text = talloc_strdup(bw->current_content,
|
||||||
|
messages_get("Form_Many"));
|
||||||
if (!inline_box->text) {
|
if (!inline_box->text) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
inline_box->length = 0;
|
inline_box->length = 0;
|
||||||
|
59
render/box.c
59
render/box.c
@ -18,7 +18,7 @@
|
|||||||
#include "netsurf/css/css.h"
|
#include "netsurf/css/css.h"
|
||||||
#include "netsurf/render/box.h"
|
#include "netsurf/render/box.h"
|
||||||
#include "netsurf/render/form.h"
|
#include "netsurf/render/form.h"
|
||||||
#include "netsurf/utils/pool.h"
|
#include "netsurf/utils/talloc.h"
|
||||||
|
|
||||||
|
|
||||||
static bool box_contains_point(struct box *box, int x, int y);
|
static bool box_contains_point(struct box *box, int x, int y);
|
||||||
@ -31,43 +31,23 @@ static bool box_contains_point(struct box *box, int x, int y);
|
|||||||
* Create a box tree node.
|
* Create a box tree node.
|
||||||
*
|
*
|
||||||
* \param style style for the box (not copied)
|
* \param style style for the box (not copied)
|
||||||
* \param href href for the box (copied), or 0
|
* \param href href for the box (not copied), or 0
|
||||||
* \param title title for the box (copied), or 0
|
* \param title title for the box (not copied), or 0
|
||||||
* \param id id for the box (copied), or 0
|
* \param id id for the box (not copied), or 0
|
||||||
* \param box_pool pool to allocate box from
|
* \param context context for allocations
|
||||||
* \return allocated and initialised box, or 0 on memory exhaustion
|
* \return allocated and initialised box, or 0 on memory exhaustion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct box * box_create(struct css_style *style,
|
struct box * box_create(struct css_style *style,
|
||||||
const char *href, const char *title, const char *id,
|
char *href, char *title, char *id,
|
||||||
pool box_pool)
|
void *context)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct box *box;
|
struct box *box;
|
||||||
char *href1 = 0;
|
|
||||||
char *title1 = 0;
|
|
||||||
char *id1 = 0;
|
|
||||||
|
|
||||||
if (href)
|
box = talloc(context, struct box);
|
||||||
href1 = strdup(href);
|
if (!box)
|
||||||
if (title)
|
|
||||||
title1 = strdup(title);
|
|
||||||
if (id)
|
|
||||||
id1 = strdup(id);
|
|
||||||
if ((href && !href1) || (title && !title1) || (id && !id1)) {
|
|
||||||
free(href1);
|
|
||||||
free(title1);
|
|
||||||
free(id1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
box = pool_alloc(box_pool, sizeof (struct box));
|
|
||||||
if (!box) {
|
|
||||||
free(href1);
|
|
||||||
free(title1);
|
|
||||||
free(id1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
box->type = BOX_INLINE;
|
box->type = BOX_INLINE;
|
||||||
box->style = style;
|
box->style = style;
|
||||||
@ -86,8 +66,8 @@ struct box * box_create(struct css_style *style,
|
|||||||
box->space = 0;
|
box->space = 0;
|
||||||
box->clone = 0;
|
box->clone = 0;
|
||||||
box->style_clone = 0;
|
box->style_clone = 0;
|
||||||
box->href = href1;
|
box->href = href;
|
||||||
box->title = title1;
|
box->title = title;
|
||||||
box->columns = 1;
|
box->columns = 1;
|
||||||
box->rows = 1;
|
box->rows = 1;
|
||||||
box->start_column = 0;
|
box->start_column = 0;
|
||||||
@ -101,7 +81,7 @@ struct box * box_create(struct css_style *style,
|
|||||||
box->col = NULL;
|
box->col = NULL;
|
||||||
box->gadget = NULL;
|
box->gadget = NULL;
|
||||||
box->usemap = NULL;
|
box->usemap = NULL;
|
||||||
box->id = id1;
|
box->id = id;
|
||||||
box->background = NULL;
|
box->background = NULL;
|
||||||
box->object = NULL;
|
box->object = NULL;
|
||||||
box->object_params = NULL;
|
box->object_params = NULL;
|
||||||
@ -153,12 +133,11 @@ void box_insert_sibling(struct box *box, struct box *new_box)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the data in a box tree recursively.
|
* Free the a box tree recursively.
|
||||||
*
|
*
|
||||||
* \param box box to free recursively
|
* \param box box to free recursively
|
||||||
*
|
*
|
||||||
* The data in box and all its children is freed. The actual box structures are
|
* The box and all its children is freed.
|
||||||
* not freed, only the data (since they will be in a pool).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void box_free(struct box *box)
|
void box_free(struct box *box)
|
||||||
@ -187,17 +166,11 @@ void box_free_box(struct box *box)
|
|||||||
if (!box->clone) {
|
if (!box->clone) {
|
||||||
if (box->gadget)
|
if (box->gadget)
|
||||||
form_free_control(box->gadget);
|
form_free_control(box->gadget);
|
||||||
free(box->href);
|
|
||||||
free(box->title);
|
|
||||||
free(box->col);
|
|
||||||
if (!box->style_clone && box->style)
|
|
||||||
css_free_style(box->style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(box->usemap);
|
|
||||||
free(box->text);
|
|
||||||
free(box->id);
|
|
||||||
box_free_object_params(box->object_params);
|
box_free_object_params(box->object_params);
|
||||||
|
|
||||||
|
talloc_free(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,6 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "libxml/HTMLparser.h"
|
#include "libxml/HTMLparser.h"
|
||||||
#include "netsurf/utils/pool.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct box;
|
struct box;
|
||||||
@ -90,7 +89,7 @@ typedef enum {
|
|||||||
BOX_TABLE, BOX_TABLE_ROW, BOX_TABLE_CELL,
|
BOX_TABLE, BOX_TABLE_ROW, BOX_TABLE_CELL,
|
||||||
BOX_TABLE_ROW_GROUP,
|
BOX_TABLE_ROW_GROUP,
|
||||||
BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT,
|
BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT,
|
||||||
BOX_INLINE_BLOCK, BOX_BR
|
BOX_INLINE_BLOCK, BOX_BR, BOX_TEXT
|
||||||
} box_type;
|
} box_type;
|
||||||
|
|
||||||
/* parameters for <object> and related elements */
|
/* parameters for <object> and related elements */
|
||||||
@ -232,8 +231,8 @@ struct column {
|
|||||||
|
|
||||||
|
|
||||||
struct box * box_create(struct css_style *style,
|
struct box * box_create(struct css_style *style,
|
||||||
const char *href, const char *title,
|
char *href, char *title,
|
||||||
const char *id, pool box_pool);
|
char *id, void *context);
|
||||||
void box_add_child(struct box *parent, struct box *child);
|
void box_add_child(struct box *parent, struct box *child);
|
||||||
void box_insert_sibling(struct box *box, struct box *new_box);
|
void box_insert_sibling(struct box *box, struct box *new_box);
|
||||||
void box_free(struct box *box);
|
void box_free(struct box *box);
|
||||||
@ -259,6 +258,6 @@ void box_scrollbar_dimensions(const struct box *box,
|
|||||||
|
|
||||||
bool xml_to_box(xmlNode *n, struct content *c);
|
bool xml_to_box(xmlNode *n, struct content *c);
|
||||||
|
|
||||||
bool box_normalise_block(struct box *block, pool box_pool);
|
bool box_normalise_block(struct box *block, struct content *c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include "netsurf/utils/log.h"
|
#include "netsurf/utils/log.h"
|
||||||
#include "netsurf/utils/pool.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct span_info {
|
struct span_info {
|
||||||
@ -45,18 +44,18 @@ struct columns {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static bool box_normalise_table(struct box *table, pool box_pool);
|
static bool box_normalise_table(struct box *table, struct content *c);
|
||||||
static void box_normalise_table_spans(struct box *table);
|
static void box_normalise_table_spans(struct box *table);
|
||||||
static bool box_normalise_table_row_group(struct box *row_group,
|
static bool box_normalise_table_row_group(struct box *row_group,
|
||||||
struct columns *col_info,
|
struct columns *col_info,
|
||||||
pool box_pool);
|
struct content *c);
|
||||||
static bool box_normalise_table_row(struct box *row,
|
static bool box_normalise_table_row(struct box *row,
|
||||||
struct columns *col_info,
|
struct columns *col_info,
|
||||||
pool box_pool);
|
struct content *c);
|
||||||
static bool calculate_table_row(struct columns *col_info,
|
static bool calculate_table_row(struct columns *col_info,
|
||||||
unsigned int col_span, unsigned int row_span,
|
unsigned int col_span, unsigned int row_span,
|
||||||
unsigned int *start_column);
|
unsigned int *start_column);
|
||||||
static bool box_normalise_inline_container(struct box *cont, pool box_pool);
|
static bool box_normalise_inline_container(struct box *cont, struct content *c);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +78,7 @@ static bool box_normalise_inline_container(struct box *cont, pool box_pool);
|
|||||||
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE \endcode
|
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE \endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool box_normalise_block(struct box *block, pool box_pool)
|
bool box_normalise_block(struct box *block, struct content *c)
|
||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *next_child;
|
struct box *next_child;
|
||||||
@ -98,16 +97,16 @@ bool box_normalise_block(struct box *block, pool box_pool)
|
|||||||
switch (child->type) {
|
switch (child->type) {
|
||||||
case BOX_BLOCK:
|
case BOX_BLOCK:
|
||||||
/* ok */
|
/* ok */
|
||||||
if (!box_normalise_block(child, box_pool))
|
if (!box_normalise_block(child, c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_INLINE_CONTAINER:
|
case BOX_INLINE_CONTAINER:
|
||||||
if (!box_normalise_inline_container(child,
|
if (!box_normalise_inline_container(child,
|
||||||
box_pool))
|
c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_TABLE:
|
case BOX_TABLE:
|
||||||
if (!box_normalise_table(child, box_pool))
|
if (!box_normalise_table(child, c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_INLINE:
|
case BOX_INLINE:
|
||||||
@ -127,7 +126,7 @@ bool box_normalise_block(struct box *block, pool box_pool)
|
|||||||
if (!style)
|
if (!style)
|
||||||
return false;
|
return false;
|
||||||
css_cascade(style, &css_blank_style);
|
css_cascade(style, &css_blank_style);
|
||||||
table = box_create(style, block->href, 0, 0, box_pool);
|
table = box_create(style, block->href, 0, 0, c);
|
||||||
if (!table) {
|
if (!table) {
|
||||||
css_free_style(style);
|
css_free_style(style);
|
||||||
return false;
|
return false;
|
||||||
@ -152,7 +151,7 @@ bool box_normalise_block(struct box *block, pool box_pool)
|
|||||||
if (table->next)
|
if (table->next)
|
||||||
table->next->prev = table;
|
table->next->prev = table;
|
||||||
table->parent = block;
|
table->parent = block;
|
||||||
if (!box_normalise_table(table, box_pool))
|
if (!box_normalise_table(table, c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -164,7 +163,7 @@ bool box_normalise_block(struct box *block, pool box_pool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool box_normalise_table(struct box *table, pool box_pool)
|
bool box_normalise_table(struct box *table, struct content * c)
|
||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *next_child;
|
struct box *next_child;
|
||||||
@ -192,7 +191,7 @@ bool box_normalise_table(struct box *table, pool box_pool)
|
|||||||
case BOX_TABLE_ROW_GROUP:
|
case BOX_TABLE_ROW_GROUP:
|
||||||
/* ok */
|
/* ok */
|
||||||
if (!box_normalise_table_row_group(child,
|
if (!box_normalise_table_row_group(child,
|
||||||
&col_info, box_pool)) {
|
&col_info, c)) {
|
||||||
free(col_info.spans);
|
free(col_info.spans);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -211,7 +210,7 @@ bool box_normalise_table(struct box *table, pool box_pool)
|
|||||||
}
|
}
|
||||||
css_cascade(style, &css_blank_style);
|
css_cascade(style, &css_blank_style);
|
||||||
row_group = box_create(style, table->href, 0,
|
row_group = box_create(style, table->href, 0,
|
||||||
0, box_pool);
|
0, c);
|
||||||
if (!row_group) {
|
if (!row_group) {
|
||||||
free(col_info.spans);
|
free(col_info.spans);
|
||||||
css_free_style(style);
|
css_free_style(style);
|
||||||
@ -240,7 +239,7 @@ bool box_normalise_table(struct box *table, pool box_pool)
|
|||||||
row_group->next->prev = row_group;
|
row_group->next->prev = row_group;
|
||||||
row_group->parent = table;
|
row_group->parent = table;
|
||||||
if (!box_normalise_table_row_group(row_group,
|
if (!box_normalise_table_row_group(row_group,
|
||||||
&col_info, box_pool)) {
|
&col_info, c)) {
|
||||||
free(col_info.spans);
|
free(col_info.spans);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -344,7 +343,7 @@ void box_normalise_table_spans(struct box *table)
|
|||||||
|
|
||||||
bool box_normalise_table_row_group(struct box *row_group,
|
bool box_normalise_table_row_group(struct box *row_group,
|
||||||
struct columns *col_info,
|
struct columns *col_info,
|
||||||
pool box_pool)
|
struct content * c)
|
||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *next_child;
|
struct box *next_child;
|
||||||
@ -361,7 +360,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
|||||||
case BOX_TABLE_ROW:
|
case BOX_TABLE_ROW:
|
||||||
/* ok */
|
/* ok */
|
||||||
if (!box_normalise_table_row(child, col_info,
|
if (!box_normalise_table_row(child, col_info,
|
||||||
box_pool))
|
c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_BLOCK:
|
case BOX_BLOCK:
|
||||||
@ -376,7 +375,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
|||||||
return false;
|
return false;
|
||||||
css_cascade(style, &css_blank_style);
|
css_cascade(style, &css_blank_style);
|
||||||
row = box_create(style, row_group->href, 0,
|
row = box_create(style, row_group->href, 0,
|
||||||
0, box_pool);
|
0, c);
|
||||||
if (!row) {
|
if (!row) {
|
||||||
css_free_style(style);
|
css_free_style(style);
|
||||||
return false;
|
return false;
|
||||||
@ -404,7 +403,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
|||||||
row->next->prev = row;
|
row->next->prev = row;
|
||||||
row->parent = row_group;
|
row->parent = row_group;
|
||||||
if (!box_normalise_table_row(row, col_info,
|
if (!box_normalise_table_row(row, col_info,
|
||||||
box_pool))
|
c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_INLINE:
|
case BOX_INLINE:
|
||||||
@ -440,7 +439,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
|||||||
|
|
||||||
bool box_normalise_table_row(struct box *row,
|
bool box_normalise_table_row(struct box *row,
|
||||||
struct columns *col_info,
|
struct columns *col_info,
|
||||||
pool box_pool)
|
struct content * c)
|
||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *next_child;
|
struct box *next_child;
|
||||||
@ -457,7 +456,7 @@ bool box_normalise_table_row(struct box *row,
|
|||||||
switch (child->type) {
|
switch (child->type) {
|
||||||
case BOX_TABLE_CELL:
|
case BOX_TABLE_CELL:
|
||||||
/* ok */
|
/* ok */
|
||||||
if (!box_normalise_block(child, box_pool))
|
if (!box_normalise_block(child, c))
|
||||||
return false;
|
return false;
|
||||||
cell = child;
|
cell = child;
|
||||||
break;
|
break;
|
||||||
@ -473,7 +472,7 @@ bool box_normalise_table_row(struct box *row,
|
|||||||
return false;
|
return false;
|
||||||
css_cascade(style, &css_blank_style);
|
css_cascade(style, &css_blank_style);
|
||||||
cell = box_create(style, row->href, 0, 0,
|
cell = box_create(style, row->href, 0, 0,
|
||||||
box_pool);
|
c);
|
||||||
if (!cell) {
|
if (!cell) {
|
||||||
css_free_style(style);
|
css_free_style(style);
|
||||||
return false;
|
return false;
|
||||||
@ -500,7 +499,7 @@ bool box_normalise_table_row(struct box *row,
|
|||||||
if (cell->next)
|
if (cell->next)
|
||||||
cell->next->prev = cell;
|
cell->next->prev = cell;
|
||||||
cell->parent = row;
|
cell->parent = row;
|
||||||
if (!box_normalise_block(cell, box_pool))
|
if (!box_normalise_block(cell, c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_INLINE:
|
case BOX_INLINE:
|
||||||
@ -627,7 +626,7 @@ bool calculate_table_row(struct columns *col_info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool box_normalise_inline_container(struct box *cont, pool box_pool)
|
bool box_normalise_inline_container(struct box *cont, struct content * c)
|
||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *next_child;
|
struct box *next_child;
|
||||||
@ -645,7 +644,7 @@ bool box_normalise_inline_container(struct box *cont, pool box_pool)
|
|||||||
break;
|
break;
|
||||||
case BOX_INLINE_BLOCK:
|
case BOX_INLINE_BLOCK:
|
||||||
/* ok */
|
/* ok */
|
||||||
if (!box_normalise_block(child, box_pool))
|
if (!box_normalise_block(child, c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_FLOAT_LEFT:
|
case BOX_FLOAT_LEFT:
|
||||||
@ -656,13 +655,13 @@ bool box_normalise_inline_container(struct box *cont, pool box_pool)
|
|||||||
case BOX_BLOCK:
|
case BOX_BLOCK:
|
||||||
if (!box_normalise_block(
|
if (!box_normalise_block(
|
||||||
child->children,
|
child->children,
|
||||||
box_pool))
|
c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case BOX_TABLE:
|
case BOX_TABLE:
|
||||||
if (!box_normalise_table(
|
if (!box_normalise_table(
|
||||||
child->children,
|
child->children,
|
||||||
box_pool))
|
c))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -42,6 +42,7 @@ struct form *form_new(char *action, form_method method)
|
|||||||
form->method = method;
|
form->method = method;
|
||||||
form->controls = 0;
|
form->controls = 0;
|
||||||
form->last_control = 0;
|
form->last_control = 0;
|
||||||
|
form->prev = 0;
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ struct form {
|
|||||||
form_method method; /**< Method and enctype. */
|
form_method method; /**< Method and enctype. */
|
||||||
struct form_control *controls; /**< Linked list of controls. */
|
struct form_control *controls; /**< Linked list of controls. */
|
||||||
struct form_control *last_control; /**< Last control in list. */
|
struct form_control *last_control; /**< Last control in list. */
|
||||||
|
struct form *prev; /**< Previous form in doc. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Type of a struct form_control. */
|
/** Type of a struct form_control. */
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "netsurf/render/layout.h"
|
#include "netsurf/render/layout.h"
|
||||||
#include "netsurf/utils/log.h"
|
#include "netsurf/utils/log.h"
|
||||||
#include "netsurf/utils/messages.h"
|
#include "netsurf/utils/messages.h"
|
||||||
|
#include "netsurf/utils/talloc.h"
|
||||||
#include "netsurf/utils/url.h"
|
#include "netsurf/utils/url.h"
|
||||||
#include "netsurf/utils/utils.h"
|
#include "netsurf/utils/utils.h"
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ bool html_create(struct content *c, const char *params[])
|
|||||||
html->encoding_handler = 0;
|
html->encoding_handler = 0;
|
||||||
html->encoding = 0;
|
html->encoding = 0;
|
||||||
html->getenc = true;
|
html->getenc = true;
|
||||||
html->base_url = strdup(c->url);
|
html->base_url = c->url;
|
||||||
html->layout = 0;
|
html->layout = 0;
|
||||||
html->background_colour = TRANSPARENT;
|
html->background_colour = TRANSPARENT;
|
||||||
html->stylesheet_count = 0;
|
html->stylesheet_count = 0;
|
||||||
@ -73,17 +74,13 @@ bool html_create(struct content *c, const char *params[])
|
|||||||
html->style = 0;
|
html->style = 0;
|
||||||
html->object_count = 0;
|
html->object_count = 0;
|
||||||
html->object = 0;
|
html->object = 0;
|
||||||
|
html->forms = 0;
|
||||||
html->imagemaps = 0;
|
html->imagemaps = 0;
|
||||||
html->box_pool = pool_create(sizeof (struct box) * 100);
|
|
||||||
html->string_pool = pool_create(8000);
|
|
||||||
html->bw = 0;
|
html->bw = 0;
|
||||||
|
|
||||||
if (!html->base_url || !html->string_pool || !html->box_pool)
|
|
||||||
goto no_memory;
|
|
||||||
|
|
||||||
for (i = 0; params[i]; i += 2) {
|
for (i = 0; params[i]; i += 2) {
|
||||||
if (strcasecmp(params[i], "charset") == 0) {
|
if (strcasecmp(params[i], "charset") == 0) {
|
||||||
html->encoding = strdup(params[i + 1]);
|
html->encoding = talloc_strdup(c, params[i + 1]);
|
||||||
if (!html->encoding)
|
if (!html->encoding)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
html->encoding_source = ENCODING_SOURCE_HEADER;
|
html->encoding_source = ENCODING_SOURCE_HEADER;
|
||||||
@ -135,7 +132,7 @@ bool html_process_data(struct content *c, char *data, unsigned int size)
|
|||||||
if (encoding) {
|
if (encoding) {
|
||||||
if (!html_set_parser_encoding(c, encoding))
|
if (!html_set_parser_encoding(c, encoding))
|
||||||
return false;
|
return false;
|
||||||
c->data.html.encoding = strdup(encoding);
|
c->data.html.encoding = talloc_strdup(c, encoding);
|
||||||
if (!c->data.html.encoding)
|
if (!c->data.html.encoding)
|
||||||
return false;
|
return false;
|
||||||
c->data.html.encoding_source =
|
c->data.html.encoding_source =
|
||||||
@ -266,7 +263,7 @@ bool html_convert(struct content *c, int width, int height)
|
|||||||
/* The encoding was not in headers or detected, and the parser
|
/* The encoding was not in headers or detected, and the parser
|
||||||
* found a <meta http-equiv="content-type"
|
* found a <meta http-equiv="content-type"
|
||||||
* content="text/html; charset=...">. */
|
* content="text/html; charset=...">. */
|
||||||
c->data.html.encoding = strdup(document->encoding);
|
c->data.html.encoding = talloc_strdup(c, document->encoding);
|
||||||
if (!c->data.html.encoding) {
|
if (!c->data.html.encoding) {
|
||||||
msg_data.error = messages_get("NoMemory");
|
msg_data.error = messages_get("NoMemory");
|
||||||
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
||||||
@ -338,12 +335,13 @@ bool html_convert(struct content *c, int width, int height)
|
|||||||
content_set_status(c, messages_get("Formatting"));
|
content_set_status(c, messages_get("Formatting"));
|
||||||
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
||||||
LOG(("Layout document"));
|
LOG(("Layout document"));
|
||||||
layout_document(c->data.html.layout, width,
|
layout_document(c, width);
|
||||||
c->data.html.box_pool);
|
|
||||||
/*box_dump(c->data.html.layout->children, 0);*/
|
/*box_dump(c->data.html.layout->children, 0);*/
|
||||||
c->width = c->data.html.layout->descendant_x1;
|
c->width = c->data.html.layout->descendant_x1;
|
||||||
c->height = c->data.html.layout->descendant_y1;
|
c->height = c->data.html.layout->descendant_y1;
|
||||||
|
|
||||||
|
c->size = talloc_total_size(c);
|
||||||
|
|
||||||
if (c->active == 0) {
|
if (c->active == 0) {
|
||||||
c->status = CONTENT_STATUS_DONE;
|
c->status = CONTENT_STATUS_DONE;
|
||||||
content_set_status(c, messages_get("Done"));
|
content_set_status(c, messages_get("Done"));
|
||||||
@ -380,20 +378,26 @@ bool html_head(struct content *c, xmlNode *head)
|
|||||||
xmlChar *title = xmlNodeGetContent(node);
|
xmlChar *title = xmlNodeGetContent(node);
|
||||||
if (!title)
|
if (!title)
|
||||||
return false;
|
return false;
|
||||||
c->title = squash_whitespace(title);
|
char *title2 = squash_whitespace(title);
|
||||||
|
xmlFree(title);
|
||||||
|
if (!title2)
|
||||||
|
return false;
|
||||||
|
c->title = talloc_strdup(c, title2);
|
||||||
|
free(title2);
|
||||||
if (!c->title)
|
if (!c->title)
|
||||||
return false;
|
return false;
|
||||||
xmlFree(title);
|
|
||||||
|
|
||||||
} else if (strcmp(node->name, "base") == 0) {
|
} else if (strcmp(node->name, "base") == 0) {
|
||||||
char *href = (char *) xmlGetProp(node, (const xmlChar *) "href");
|
char *href = (char *) xmlGetProp(node,
|
||||||
|
(const xmlChar *) "href");
|
||||||
if (href) {
|
if (href) {
|
||||||
char *url;
|
char *url;
|
||||||
url_func_result res;
|
url_func_result res;
|
||||||
res = url_normalize(href, &url);
|
res = url_normalize(href, &url);
|
||||||
if (res == URL_FUNC_OK) {
|
if (res == URL_FUNC_OK) {
|
||||||
free(c->data.html.base_url);
|
c->data.html.base_url =
|
||||||
c->data.html.base_url = url;
|
talloc_strdup(c, url);
|
||||||
|
free(url);
|
||||||
}
|
}
|
||||||
xmlFree(href);
|
xmlFree(href);
|
||||||
}
|
}
|
||||||
@ -424,8 +428,8 @@ bool html_find_stylesheets(struct content *c, xmlNode *head)
|
|||||||
/* stylesheet 0 is the base style sheet,
|
/* stylesheet 0 is the base style sheet,
|
||||||
* stylesheet 1 is the adblocking stylesheet,
|
* stylesheet 1 is the adblocking stylesheet,
|
||||||
* stylesheet 2 is any <style> elements */
|
* stylesheet 2 is any <style> elements */
|
||||||
c->data.html.stylesheet_content = malloc(STYLESHEET_START *
|
c->data.html.stylesheet_content = talloc_array(c, struct content *,
|
||||||
sizeof *c->data.html.stylesheet_content);
|
STYLESHEET_START);
|
||||||
if (!c->data.html.stylesheet_content)
|
if (!c->data.html.stylesheet_content)
|
||||||
return false;
|
return false;
|
||||||
c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = 0;
|
c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = 0;
|
||||||
@ -511,10 +515,9 @@ bool html_find_stylesheets(struct content *c, xmlNode *head)
|
|||||||
LOG(("linked stylesheet %i '%s'", i, url));
|
LOG(("linked stylesheet %i '%s'", i, url));
|
||||||
|
|
||||||
/* start fetch */
|
/* start fetch */
|
||||||
stylesheet_content = realloc(
|
stylesheet_content = talloc_realloc(c,
|
||||||
c->data.html.stylesheet_content,
|
c->data.html.stylesheet_content,
|
||||||
(i + 1) * sizeof
|
struct content *, i + 1);
|
||||||
*c->data.html.stylesheet_content);
|
|
||||||
if (!stylesheet_content)
|
if (!stylesheet_content)
|
||||||
return false;
|
return false;
|
||||||
c->data.html.stylesheet_content = stylesheet_content;
|
c->data.html.stylesheet_content = stylesheet_content;
|
||||||
@ -709,7 +712,7 @@ void html_convert_css_callback(content_msg msg, struct content *css,
|
|||||||
* Start a fetch for an object required by a page.
|
* Start a fetch for an object required by a page.
|
||||||
*
|
*
|
||||||
* \param c content structure
|
* \param c content structure
|
||||||
* \param url URL of object to fetch (not copied, must be on heap)
|
* \param url URL of object to fetch (copied)
|
||||||
* \param box box that will contain the object
|
* \param box box that will contain the object
|
||||||
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
||||||
* or 0 if all types except OTHER and UNKNOWN acceptable
|
* or 0 if all types except OTHER and UNKNOWN acceptable
|
||||||
@ -736,14 +739,18 @@ bool html_fetch_object(struct content *c, char *url, struct box *box,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* add to object list */
|
/* add to object list */
|
||||||
object = realloc(c->data.html.object,
|
object = talloc_realloc(c, c->data.html.object,
|
||||||
(i + 1) * sizeof *c->data.html.object);
|
struct content_html_object, i + 1);
|
||||||
if (!object) {
|
if (!object) {
|
||||||
content_remove_user(c_fetch, html_object_callback, c, (void*)i);
|
content_remove_user(c_fetch, html_object_callback, c, (void*)i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
c->data.html.object = object;
|
c->data.html.object = object;
|
||||||
c->data.html.object[i].url = url;
|
c->data.html.object[i].url = talloc_strdup(c, url);
|
||||||
|
if (!c->data.html.object[i].url) {
|
||||||
|
content_remove_user(c_fetch, html_object_callback, c, (void*)i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
c->data.html.object[i].box = box;
|
c->data.html.object[i].box = box;
|
||||||
c->data.html.object[i].permitted_types = permitted_types;
|
c->data.html.object[i].permitted_types = permitted_types;
|
||||||
c->data.html.object[i].background = background;
|
c->data.html.object[i].background = background;
|
||||||
@ -829,8 +836,9 @@ void html_object_callback(content_msg msg, struct content *object,
|
|||||||
|
|
||||||
case CONTENT_MSG_REDIRECT:
|
case CONTENT_MSG_REDIRECT:
|
||||||
c->active--;
|
c->active--;
|
||||||
free(c->data.html.object[i].url);
|
talloc_free(c->data.html.object[i].url);
|
||||||
c->data.html.object[i].url = strdup(data.redirect);
|
c->data.html.object[i].url = talloc_strdup(c,
|
||||||
|
data.redirect);
|
||||||
if (!c->data.html.object[i].url) {
|
if (!c->data.html.object[i].url) {
|
||||||
/** \todo report oom */
|
/** \todo report oom */
|
||||||
} else {
|
} else {
|
||||||
@ -1003,8 +1011,7 @@ void html_stop(struct content *c)
|
|||||||
|
|
||||||
void html_reformat(struct content *c, int width, int height)
|
void html_reformat(struct content *c, int width, int height)
|
||||||
{
|
{
|
||||||
layout_document(c->data.html.layout, width,
|
layout_document(c, width);
|
||||||
c->data.html.box_pool);
|
|
||||||
c->width = c->data.html.layout->descendant_x1;
|
c->width = c->data.html.layout->descendant_x1;
|
||||||
c->height = c->data.html.layout->descendant_y1;
|
c->height = c->data.html.layout->descendant_y1;
|
||||||
}
|
}
|
||||||
@ -1019,20 +1026,11 @@ void html_destroy(struct content *c)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
LOG(("content %p", c));
|
LOG(("content %p", c));
|
||||||
|
|
||||||
free(c->title);
|
|
||||||
|
|
||||||
imagemap_destroy(c);
|
imagemap_destroy(c);
|
||||||
|
|
||||||
if (c->data.html.parser)
|
if (c->data.html.parser)
|
||||||
htmlFreeParserCtxt(c->data.html.parser);
|
htmlFreeParserCtxt(c->data.html.parser);
|
||||||
|
|
||||||
free(c->data.html.encoding);
|
|
||||||
|
|
||||||
free(c->data.html.base_url);
|
|
||||||
|
|
||||||
if (c->data.html.layout)
|
|
||||||
box_free(c->data.html.layout);
|
|
||||||
|
|
||||||
/* Free stylesheets */
|
/* Free stylesheets */
|
||||||
if (c->data.html.stylesheet_count) {
|
if (c->data.html.stylesheet_count) {
|
||||||
for (i = 0; i != c->data.html.stylesheet_count; i++) {
|
for (i = 0; i != c->data.html.stylesheet_count; i++) {
|
||||||
@ -1043,10 +1041,9 @@ void html_destroy(struct content *c)
|
|||||||
c, (void *) i);
|
c, (void *) i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(c->data.html.stylesheet_content);
|
|
||||||
|
|
||||||
if (c->data.html.style)
|
/*if (c->data.html.style)
|
||||||
css_free_style(c->data.html.style);
|
css_free_style(c->data.html.style);*/
|
||||||
|
|
||||||
/* Free objects */
|
/* Free objects */
|
||||||
for (i = 0; i != c->data.html.object_count; i++) {
|
for (i = 0; i != c->data.html.object_count; i++) {
|
||||||
@ -1054,12 +1051,7 @@ void html_destroy(struct content *c)
|
|||||||
if (c->data.html.object[i].content)
|
if (c->data.html.object[i].content)
|
||||||
content_remove_user(c->data.html.object[i].content,
|
content_remove_user(c->data.html.object[i].content,
|
||||||
html_object_callback, c, (void*)i);
|
html_object_callback, c, (void*)i);
|
||||||
free(c->data.html.object[i].url);
|
|
||||||
}
|
}
|
||||||
free(c->data.html.object);
|
|
||||||
|
|
||||||
pool_destroy(c->data.html.string_pool);
|
|
||||||
pool_destroy(c->data.html.box_pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "libxml/HTMLparser.h"
|
#include "libxml/HTMLparser.h"
|
||||||
#include "netsurf/content/content_type.h"
|
#include "netsurf/content/content_type.h"
|
||||||
#include "netsurf/css/css.h"
|
#include "netsurf/css/css.h"
|
||||||
#include "netsurf/utils/pool.h"
|
|
||||||
|
|
||||||
struct box;
|
struct box;
|
||||||
struct browser_window;
|
struct browser_window;
|
||||||
@ -75,11 +74,10 @@ struct content_html_data {
|
|||||||
unsigned int object_count;
|
unsigned int object_count;
|
||||||
/** Objects. Each may be 0. */
|
/** Objects. Each may be 0. */
|
||||||
struct content_html_object *object;
|
struct content_html_object *object;
|
||||||
|
/** Forms, in reverse order to document. */
|
||||||
struct imagemap **imagemaps; /**< Hashtable of imagemaps */
|
struct form *forms;
|
||||||
|
/** Hash table of imagemaps */
|
||||||
pool box_pool; /**< Memory pool for box tree. */
|
struct imagemap **imagemaps;
|
||||||
pool string_pool; /**< Memory pool for strings. */
|
|
||||||
|
|
||||||
/**< Browser window containing this document, or 0 if not open. */
|
/**< Browser window containing this document, or 0 if not open. */
|
||||||
struct browser_window *bw;
|
struct browser_window *bw;
|
||||||
|
109
render/layout.c
109
render/layout.c
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE /* for strndup */
|
#define _GNU_SOURCE /* for strndup */
|
||||||
#include <alloca.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -34,7 +33,7 @@
|
|||||||
#include "netsurf/render/layout.h"
|
#include "netsurf/render/layout.h"
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include "netsurf/utils/log.h"
|
#include "netsurf/utils/log.h"
|
||||||
#include "netsurf/utils/pool.h"
|
#include "netsurf/utils/talloc.h"
|
||||||
#include "netsurf/utils/utils.h"
|
#include "netsurf/utils/utils.h"
|
||||||
|
|
||||||
|
|
||||||
@ -55,12 +54,13 @@ static void find_sides(struct box *fl, int y0, int y1,
|
|||||||
static int line_height(struct css_style *style);
|
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,
|
int cx, int cy, struct box *cont, bool indent,
|
||||||
pool box_pool, struct box **next_box);
|
struct content *content, struct box **next_box);
|
||||||
static int layout_text_indent(struct css_style *style, int width);
|
static int layout_text_indent(struct css_style *style, int width);
|
||||||
static bool layout_float(struct box *b, int width, pool box_pool);
|
static bool layout_float(struct box *b, int width, struct content *content);
|
||||||
static void place_float_below(struct box *c, int width, int cx, int y,
|
static void place_float_below(struct box *c, int width, int cx, int y,
|
||||||
struct box *cont);
|
struct box *cont);
|
||||||
static bool layout_table(struct box *box, int available_width, pool box_pool);
|
static bool layout_table(struct box *box, int available_width,
|
||||||
|
struct content *content);
|
||||||
static void layout_move_children(struct box *box, int x, int y);
|
static void layout_move_children(struct box *box, int x, int y);
|
||||||
static bool calculate_widths(struct box *box);
|
static bool calculate_widths(struct box *box);
|
||||||
static bool calculate_block_widths(struct box *box, int *min, int *max,
|
static bool calculate_block_widths(struct box *box, int *min, int *max,
|
||||||
@ -75,15 +75,17 @@ static bool calculate_table_widths(struct box *table);
|
|||||||
/**
|
/**
|
||||||
* Calculate positions of boxes in a document.
|
* Calculate positions of boxes in a document.
|
||||||
*
|
*
|
||||||
* \param doc root of document box tree
|
* \param doc content of type CONTENT_HTML
|
||||||
* \param width available page width
|
* \param width available page width
|
||||||
* \param box_pool memory pool for any new boxes
|
|
||||||
* \return true on success, false on memory exhaustion
|
* \return true on success, false on memory exhaustion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool layout_document(struct box *doc, int width, pool box_pool)
|
bool layout_document(struct content *content, int width)
|
||||||
{
|
{
|
||||||
bool ret;
|
bool ret;
|
||||||
|
struct box *doc = content->data.html.layout;
|
||||||
|
|
||||||
|
assert(content->type == CONTENT_HTML);
|
||||||
|
|
||||||
doc->float_children = 0;
|
doc->float_children = 0;
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ bool layout_document(struct box *doc, int width, pool box_pool)
|
|||||||
doc->border[RIGHT] + doc->margin[RIGHT];
|
doc->border[RIGHT] + doc->margin[RIGHT];
|
||||||
doc->width = width;
|
doc->width = width;
|
||||||
|
|
||||||
ret = layout_block_context(doc, box_pool);
|
ret = layout_block_context(doc, content);
|
||||||
|
|
||||||
layout_calculate_descendant_bboxes(doc);
|
layout_calculate_descendant_bboxes(doc);
|
||||||
|
|
||||||
@ -109,14 +111,14 @@ bool layout_document(struct box *doc, int width, pool box_pool)
|
|||||||
* Layout a block formatting context.
|
* Layout a block formatting context.
|
||||||
*
|
*
|
||||||
* \param block BLOCK, INLINE_BLOCK, or TABLE_CELL to layout.
|
* \param block BLOCK, INLINE_BLOCK, or TABLE_CELL to layout.
|
||||||
* \param box_pool memory pool for any new boxes
|
* \param content memory pool for any new boxes
|
||||||
* \return true on success, false on memory exhaustion
|
* \return true on success, false on memory exhaustion
|
||||||
*
|
*
|
||||||
* This function carries out layout of a block and its children, as described
|
* This function carries out layout of a block and its children, as described
|
||||||
* in CSS 2.1 9.4.1.
|
* in CSS 2.1 9.4.1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool layout_block_context(struct box *block, pool box_pool)
|
bool layout_block_context(struct box *block, struct content *content)
|
||||||
{
|
{
|
||||||
struct box *box;
|
struct box *box;
|
||||||
int cx;
|
int cx;
|
||||||
@ -154,7 +156,7 @@ bool layout_block_context(struct box *block, pool box_pool)
|
|||||||
if (box->type == BOX_BLOCK)
|
if (box->type == BOX_BLOCK)
|
||||||
layout_block_find_dimensions(box->parent->width, box);
|
layout_block_find_dimensions(box->parent->width, box);
|
||||||
else if (box->type == BOX_TABLE) {
|
else if (box->type == BOX_TABLE) {
|
||||||
if (!layout_table(box, box->parent->width, box_pool))
|
if (!layout_table(box, box->parent->width, content))
|
||||||
return false;
|
return false;
|
||||||
layout_solve_width(box->parent->width, box->width,
|
layout_solve_width(box->parent->width, box->width,
|
||||||
box->margin, box->padding, box->border);
|
box->margin, box->padding, box->border);
|
||||||
@ -195,7 +197,7 @@ bool layout_block_context(struct box *block, pool box_pool)
|
|||||||
if (box->type == BOX_INLINE_CONTAINER) {
|
if (box->type == BOX_INLINE_CONTAINER) {
|
||||||
box->width = box->parent->width;
|
box->width = box->parent->width;
|
||||||
if (!layout_inline_container(box, box->width, block,
|
if (!layout_inline_container(box, box->width, block,
|
||||||
cx, cy, box_pool))
|
cx, cy, content))
|
||||||
return false;
|
return false;
|
||||||
} else if (box->type == BOX_TABLE) {
|
} else if (box->type == BOX_TABLE) {
|
||||||
/* Move down to avoid floats if necessary. */
|
/* Move down to avoid floats if necessary. */
|
||||||
@ -634,12 +636,12 @@ void find_sides(struct box *fl, int y0, int y1,
|
|||||||
* \param cont ancestor box which defines horizontal space, for floats
|
* \param cont ancestor box which defines horizontal space, for floats
|
||||||
* \param cx box position relative to cont
|
* \param cx box position relative to cont
|
||||||
* \param cy box position relative to cont
|
* \param cy box position relative to cont
|
||||||
* \param box_pool memory pool for any new boxes
|
* \param content memory pool for any new boxes
|
||||||
* \return true on success, false on memory exhaustion
|
* \return true on success, false on memory exhaustion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool layout_inline_container(struct box *box, int width,
|
bool layout_inline_container(struct box *box, int width,
|
||||||
struct box *cont, int cx, int cy, pool box_pool)
|
struct box *cont, int cx, int cy, struct content *content)
|
||||||
{
|
{
|
||||||
bool first_line = true;
|
bool first_line = true;
|
||||||
struct box *c, *next;
|
struct box *c, *next;
|
||||||
@ -653,7 +655,7 @@ bool layout_inline_container(struct box *box, int width,
|
|||||||
for (c = box->children; c; ) {
|
for (c = box->children; c; ) {
|
||||||
LOG(("c %p", c));
|
LOG(("c %p", c));
|
||||||
if (!layout_line(c, width, &y, cx, cy + y, cont, first_line,
|
if (!layout_line(c, width, &y, cx, cy + y, cont, first_line,
|
||||||
box_pool, &next))
|
content, &next))
|
||||||
return false;
|
return false;
|
||||||
c = next;
|
c = next;
|
||||||
first_line = false;
|
first_line = false;
|
||||||
@ -710,13 +712,13 @@ int line_height(struct css_style *style)
|
|||||||
* \param cont ancestor box which defines horizontal space, for floats
|
* \param cont ancestor box which defines horizontal space, for floats
|
||||||
* \param indent apply any first-line indent
|
* \param indent apply any first-line indent
|
||||||
* \param next_box updated to first box for next line, or 0 at end
|
* \param next_box updated to first box for next line, or 0 at end
|
||||||
* \param box_pool memory pool for any new boxes
|
* \param content memory pool for any new boxes
|
||||||
* \return true on success, false on memory exhaustion
|
* \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,
|
int cx, int cy, struct box *cont, bool indent,
|
||||||
pool box_pool, struct box **next_box)
|
struct content *content, struct box **next_box)
|
||||||
{
|
{
|
||||||
int height, used_height;
|
int height, used_height;
|
||||||
int x0 = 0;
|
int x0 = 0;
|
||||||
@ -759,7 +761,7 @@ bool layout_line(struct box *first, int width, int *y,
|
|||||||
|
|
||||||
if (b->type == BOX_INLINE_BLOCK) {
|
if (b->type == BOX_INLINE_BLOCK) {
|
||||||
if (b->width == UNKNOWN_WIDTH)
|
if (b->width == UNKNOWN_WIDTH)
|
||||||
if (!layout_float(b, width, box_pool))
|
if (!layout_float(b, width, content))
|
||||||
return false;
|
return false;
|
||||||
/** \todo should margin be included? spec unclear */
|
/** \todo should margin be included? spec unclear */
|
||||||
h = b->border[TOP] + b->padding[TOP] + b->height +
|
h = b->border[TOP] + b->padding[TOP] + b->height +
|
||||||
@ -943,7 +945,7 @@ bool layout_line(struct box *first, int width, int *y,
|
|||||||
d->float_children = 0;
|
d->float_children = 0;
|
||||||
/* css_dump_style(b->style); */
|
/* css_dump_style(b->style); */
|
||||||
|
|
||||||
if (!layout_float(d, width, box_pool))
|
if (!layout_float(d, width, content))
|
||||||
return false;
|
return false;
|
||||||
d->x = d->margin[LEFT] + d->border[LEFT];
|
d->x = d->margin[LEFT] + d->border[LEFT];
|
||||||
d->y = d->margin[TOP] + d->border[TOP];
|
d->y = d->margin[TOP] + d->border[TOP];
|
||||||
@ -1022,12 +1024,13 @@ bool layout_line(struct box *first, int width, int *y,
|
|||||||
b = split_box->next;
|
b = split_box->next;
|
||||||
} else {
|
} else {
|
||||||
/* cut off first word for this line */
|
/* cut off first word for this line */
|
||||||
/* \todo allocate from box_pool */
|
/* \todo allocate from content */
|
||||||
c2 = pool_alloc(box_pool, sizeof *c2);
|
c2 = talloc_memdup(content, split_box,
|
||||||
|
sizeof *c2);
|
||||||
if (!c2)
|
if (!c2)
|
||||||
return false;
|
return false;
|
||||||
memcpy(c2, split_box, sizeof *c2);
|
c2->text = talloc_strndup(content,
|
||||||
c2->text = strndup(split_box->text + space + 1,
|
split_box->text + space + 1,
|
||||||
split_box->length -(space + 1));
|
split_box->length -(space + 1));
|
||||||
if (!c2->text)
|
if (!c2->text)
|
||||||
return false;
|
return false;
|
||||||
@ -1066,11 +1069,12 @@ bool layout_line(struct box *first, int width, int *y,
|
|||||||
if (space == 0)
|
if (space == 0)
|
||||||
space = 1;
|
space = 1;
|
||||||
if (space != split_box->length) {
|
if (space != split_box->length) {
|
||||||
c2 = pool_alloc(box_pool, sizeof *c2);
|
c2 = talloc_memdup(content, split_box,
|
||||||
|
sizeof *c2);
|
||||||
if (!c2)
|
if (!c2)
|
||||||
return false;
|
return false;
|
||||||
memcpy(c2, split_box, sizeof *c2);
|
c2->text = talloc_strndup(content,
|
||||||
c2->text = strndup(split_box->text + space + 1,
|
split_box->text + space + 1,
|
||||||
split_box->length -(space + 1));
|
split_box->length -(space + 1));
|
||||||
if (!c2->text)
|
if (!c2->text)
|
||||||
return false;
|
return false;
|
||||||
@ -1147,22 +1151,22 @@ int layout_text_indent(struct css_style *style, int width)
|
|||||||
*
|
*
|
||||||
* \param b float or inline block box
|
* \param b float or inline block box
|
||||||
* \param width available width
|
* \param width available width
|
||||||
* \param box_pool memory pool for any new boxes
|
* \param content memory pool for any new boxes
|
||||||
* \return true on success, false on memory exhaustion
|
* \return true on success, false on memory exhaustion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool layout_float(struct box *b, int width, pool box_pool)
|
bool layout_float(struct box *b, int width, struct content *content)
|
||||||
{
|
{
|
||||||
layout_float_find_dimensions(width, b->style, b);
|
layout_float_find_dimensions(width, b->style, b);
|
||||||
if (b->type == BOX_TABLE) {
|
if (b->type == BOX_TABLE) {
|
||||||
if (!layout_table(b, width, box_pool))
|
if (!layout_table(b, width, content))
|
||||||
return false;
|
return false;
|
||||||
if (b->margin[LEFT] == AUTO)
|
if (b->margin[LEFT] == AUTO)
|
||||||
b->margin[LEFT] = 0;
|
b->margin[LEFT] = 0;
|
||||||
if (b->margin[RIGHT] == AUTO)
|
if (b->margin[RIGHT] == AUTO)
|
||||||
b->margin[RIGHT] = 0;
|
b->margin[RIGHT] = 0;
|
||||||
} else
|
} else
|
||||||
return layout_block_context(b, box_pool);
|
return layout_block_context(b, content);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1212,12 +1216,12 @@ void place_float_below(struct box *c, int width, int cx, int y,
|
|||||||
*
|
*
|
||||||
* \param table table to layout
|
* \param table table to layout
|
||||||
* \param available_width width of containing block
|
* \param available_width width of containing block
|
||||||
* \param box_pool memory pool for any new boxes
|
* \param content memory pool for any new boxes
|
||||||
* \return true on success, false on memory exhaustion
|
* \return true on success, false on memory exhaustion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool layout_table(struct box *table, int available_width,
|
bool layout_table(struct box *table, int available_width,
|
||||||
pool box_pool)
|
struct content *content)
|
||||||
{
|
{
|
||||||
unsigned int columns = table->columns; /* total columns */
|
unsigned int columns = table->columns; /* total columns */
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -1225,7 +1229,7 @@ bool layout_table(struct box *table, int available_width,
|
|||||||
int *excess_y;
|
int *excess_y;
|
||||||
int table_width, min_width = 0, max_width = 0;
|
int table_width, min_width = 0, max_width = 0;
|
||||||
int required_width = 0;
|
int required_width = 0;
|
||||||
int x, cp, remainder = 0, count = 0;
|
int x, remainder = 0, count = 0;
|
||||||
int table_height = 0;
|
int table_height = 0;
|
||||||
int *xs; /* array of column x positions */
|
int *xs; /* array of column x positions */
|
||||||
int auto_width;
|
int auto_width;
|
||||||
@ -1273,11 +1277,6 @@ bool layout_table(struct box *table, int available_width,
|
|||||||
layout_find_dimensions(available_width,
|
layout_find_dimensions(available_width,
|
||||||
c->style, 0,
|
c->style, 0,
|
||||||
c->padding, c->border);
|
c->padding, c->border);
|
||||||
if (c->style->html_style.cellpadding.type == CSS_CELLPADDING_VALUE)
|
|
||||||
for (cp = 0; cp < 4; cp++)
|
|
||||||
if (!c->style->padding[cp].override_cellpadding)
|
|
||||||
c->padding[cp] =
|
|
||||||
c->style->html_style.cellpadding.value;
|
|
||||||
if (c->style->overflow ==
|
if (c->style->overflow ==
|
||||||
CSS_OVERFLOW_SCROLL ||
|
CSS_OVERFLOW_SCROLL ||
|
||||||
c->style->overflow ==
|
c->style->overflow ==
|
||||||
@ -1489,7 +1488,7 @@ bool layout_table(struct box *table, int available_width,
|
|||||||
c->float_children = 0;
|
c->float_children = 0;
|
||||||
|
|
||||||
c->height = AUTO;
|
c->height = AUTO;
|
||||||
if (!layout_block_context(c, box_pool)) {
|
if (!layout_block_context(c, content)) {
|
||||||
free(col);
|
free(col);
|
||||||
free(excess_y);
|
free(excess_y);
|
||||||
free(row_span);
|
free(row_span);
|
||||||
@ -1692,25 +1691,25 @@ bool calculate_widths(struct box *box)
|
|||||||
/* add margins, border, padding to min, max widths */
|
/* add margins, border, padding to min, max widths */
|
||||||
if (style) {
|
if (style) {
|
||||||
for (side = 1; side != 5; side += 2) { /* RIGHT, LEFT */
|
for (side = 1; side != 5; side += 2) { /* RIGHT, LEFT */
|
||||||
if ((box->type == BOX_TABLE_CELL) &&
|
if (style->padding[side].padding == CSS_PADDING_LENGTH)
|
||||||
(style->html_style.cellpadding.type == CSS_CELLPADDING_VALUE) &&
|
extra_fixed += css_len2px(&style->padding[side].
|
||||||
(!style->padding[side].override_cellpadding))
|
value.length, style);
|
||||||
extra_fixed += style->html_style.cellpadding.value;
|
else if (style->padding[side].padding ==
|
||||||
else if (style->padding[side].padding == CSS_PADDING_LENGTH)
|
CSS_PADDING_PERCENT)
|
||||||
extra_fixed += (int)css_len2px(&style->padding[side].value.length,
|
extra_frac += style->padding[side].value.
|
||||||
style);
|
percent * 0.01;
|
||||||
else if (style->padding[side].padding == CSS_PADDING_PERCENT)
|
|
||||||
extra_frac += style->padding[side].value.percent * 0.01;
|
|
||||||
|
|
||||||
if (style->border[side].style != CSS_BORDER_STYLE_NONE)
|
if (style->border[side].style != CSS_BORDER_STYLE_NONE)
|
||||||
extra_fixed += (int)css_len2px(&style->border[side].width.value,
|
extra_fixed += css_len2px(&style->border[side].
|
||||||
style);
|
width.value, style);
|
||||||
|
|
||||||
if (style->margin[side].margin == CSS_MARGIN_LENGTH)
|
if (style->margin[side].margin == CSS_MARGIN_LENGTH)
|
||||||
extra_fixed += (int)css_len2px(&style->margin[side].value.length,
|
extra_fixed += css_len2px(&style->margin[side].
|
||||||
style);
|
value.length, style);
|
||||||
else if (style->margin[side].margin == CSS_MARGIN_PERCENT)
|
else if (style->margin[side].margin ==
|
||||||
extra_frac += style->margin[side].value.percent * 0.01;
|
CSS_MARGIN_PERCENT)
|
||||||
|
extra_frac += style->margin[side].value.
|
||||||
|
percent * 0.01;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,16 +16,14 @@
|
|||||||
#ifndef _NETSURF_RENDER_LAYOUT_H_
|
#ifndef _NETSURF_RENDER_LAYOUT_H_
|
||||||
#define _NETSURF_RENDER_LAYOUT_H_
|
#define _NETSURF_RENDER_LAYOUT_H_
|
||||||
|
|
||||||
#include "netsurf/utils/pool.h"
|
|
||||||
|
|
||||||
#define SCROLLBAR_WIDTH 16
|
#define SCROLLBAR_WIDTH 16
|
||||||
|
|
||||||
struct box;
|
struct box;
|
||||||
|
|
||||||
bool layout_document(struct box *box, int width, pool box_pool);
|
bool layout_document(struct content *content, int width);
|
||||||
bool layout_block_context(struct box *block, pool box_pool);
|
bool layout_block_context(struct box *block, struct content *content);
|
||||||
bool layout_inline_container(struct box *box, int width,
|
bool layout_inline_container(struct box *box, int width,
|
||||||
struct box *cont, int cx, int cy, pool box_pool);
|
struct box *cont, int cx, int cy, struct content *content);
|
||||||
void layout_calculate_descendant_bboxes(struct box *box);
|
void layout_calculate_descendant_bboxes(struct box *box);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -471,7 +471,6 @@ bool print_document(struct gui_window *g, const char *filename)
|
|||||||
int left, right, top, bottom, width, height;
|
int left, right, top, bottom, width, height;
|
||||||
int saved_width;
|
int saved_width;
|
||||||
int yscroll = 0, sheets = print_max_sheets;
|
int yscroll = 0, sheets = print_max_sheets;
|
||||||
struct box *box = 0;
|
|
||||||
struct content *c = g->bw->current_content;
|
struct content *c = g->bw->current_content;
|
||||||
const char *error_message;
|
const char *error_message;
|
||||||
pdriver_features features;
|
pdriver_features features;
|
||||||
@ -484,9 +483,6 @@ bool print_document(struct gui_window *g, const char *filename)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->type == CONTENT_HTML)
|
|
||||||
box = c->data.html.layout;
|
|
||||||
|
|
||||||
/* read printer driver features */
|
/* read printer driver features */
|
||||||
error = xpdriver_info(0, 0, 0, &features, 0, 0, 0, 0);
|
error = xpdriver_info(0, 0, 0, &features, 0, 0, 0, 0);
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -511,7 +507,7 @@ bool print_document(struct gui_window *g, const char *filename)
|
|||||||
/* layout the document to the correct width */
|
/* layout the document to the correct width */
|
||||||
saved_width = c->width;
|
saved_width = c->width;
|
||||||
if (c->type == CONTENT_HTML)
|
if (c->type == CONTENT_HTML)
|
||||||
layout_document(box, width, c->data.html.box_pool);
|
layout_document(c, width);
|
||||||
|
|
||||||
/* open printer file */
|
/* open printer file */
|
||||||
error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR |
|
error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR |
|
||||||
@ -648,7 +644,7 @@ bool print_document(struct gui_window *g, const char *filename)
|
|||||||
|
|
||||||
/* restore document layout */
|
/* restore document layout */
|
||||||
if (c->type == CONTENT_HTML)
|
if (c->type == CONTENT_HTML)
|
||||||
layout_document(box, saved_width, c->data.html.box_pool);
|
layout_document(c, saved_width);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -666,7 +662,7 @@ error:
|
|||||||
|
|
||||||
/* restore document layout */
|
/* restore document layout */
|
||||||
if (c->type == CONTENT_HTML)
|
if (c->type == CONTENT_HTML)
|
||||||
layout_document(box, saved_width, c->data.html.box_pool);
|
layout_document(c, saved_width);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ bool save_as_draw(struct content *c, const char *path)
|
|||||||
memcpy(diagram->source, "NetSurf ", 12);
|
memcpy(diagram->source, "NetSurf ", 12);
|
||||||
|
|
||||||
/* recalculate box widths for an A4 page */
|
/* recalculate box widths for an A4 page */
|
||||||
if (!layout_document(box, A4PAGEWIDTH, c->data.html.box_pool)) {
|
if (!layout_document(c, A4PAGEWIDTH)) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
goto draw_save_error;
|
goto draw_save_error;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ bool save_as_draw(struct content *c, const char *path)
|
|||||||
drawbuf_free();
|
drawbuf_free();
|
||||||
|
|
||||||
/* reset layout to current window width */
|
/* reset layout to current window width */
|
||||||
if (!layout_document(box, current_width, c->data.html.box_pool)) {
|
if (!layout_document(c, current_width)) {
|
||||||
warn_user("NoMemory", 0);
|
warn_user("NoMemory", 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ bool save_as_draw(struct content *c, const char *path)
|
|||||||
draw_save_error:
|
draw_save_error:
|
||||||
drawbuf_free();
|
drawbuf_free();
|
||||||
/* attempt to reflow back on failure */
|
/* attempt to reflow back on failure */
|
||||||
(void)layout_document(box, current_width, c->data.html.box_pool);
|
(void)layout_document(c, current_width);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user