From 7c94cf8be972d6853cc15f3971bf36fe64b04d92 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 10 Apr 2003 21:44:45 +0000 Subject: [project @ 2003-04-10 21:44:45 by bursa] Memory usage cleaning. svn path=/import/netsurf/; revision=121 --- content/content.h | 4 +--- css/ruleset.c | 3 ++- render/box.c | 43 ++++++++++++++++----------------- render/box.h | 3 +-- render/html.c | 72 ++++++++++++++++++++++++++----------------------------- riscos/gui.c | 19 +-------------- 6 files changed, 59 insertions(+), 85 deletions(-) diff --git a/content/content.h b/content/content.h index e65f62fb1..381a36bf5 100644 --- a/content/content.h +++ b/content/content.h @@ -1,5 +1,5 @@ /** - * $Id: content.h,v 1.6 2003/04/09 21:57:09 bursa Exp $ + * $Id: content.h,v 1.7 2003/04/10 21:44:45 bursa Exp $ */ #ifndef _NETSURF_DESKTOP_CONTENT_H_ @@ -57,8 +57,6 @@ struct content struct { htmlParserCtxt* parser; - xmlDoc* document; - xmlNode* markup; struct box* layout; unsigned int stylesheet_count; char **stylesheet_url; diff --git a/css/ruleset.c b/css/ruleset.c index 79587611e..57f4f6946 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -1,5 +1,5 @@ /** - * $Id: ruleset.c,v 1.5 2003/04/06 18:09:34 bursa Exp $ + * $Id: ruleset.c,v 1.6 2003/04/10 21:44:45 bursa Exp $ */ #include @@ -125,6 +125,7 @@ void css_add_ruleset(struct content *c, sel->style = style; sel->next = stylesheet->rule[hash]; stylesheet->rule[hash] = sel; + c->size += sizeof(*style); } else { /* already exists: augument existing style */ LOG(("augumenting existing style")); diff --git a/render/box.c b/render/box.c index 46c20c073..ad139f7c2 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.38 2003/04/06 18:09:34 bursa Exp $ + * $Id: box.c,v 1.39 2003/04/10 21:44:45 bursa Exp $ */ #include @@ -22,7 +22,7 @@ */ static void box_add_child(struct box * parent, struct box * child); -static struct box * box_create(xmlNode * node, box_type type, struct css_style * style, +static struct box * box_create(box_type type, struct css_style * style, char *href); static char * tolat1(xmlChar * s); static struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, @@ -78,12 +78,11 @@ void box_add_child(struct box * parent, struct box * child) * create a box tree node */ -struct box * box_create(xmlNode * node, box_type type, struct css_style * style, +struct box * box_create(box_type type, struct css_style * style, char *href) { struct box * box = xcalloc(1, sizeof(struct box)); box->type = type; - box->node = node; box->style = style; box->width = UNKNOWN_WIDTH; box->max_width = UNKNOWN_MAX_WIDTH; @@ -284,7 +283,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, if (text != 0) { LOG(("text node")); - box = box_create(n, BOX_INLINE, parent_style, href); + box = box_create(BOX_INLINE, parent_style, href); box_add_child(inline_container, box); box->length = strlen(text); if (text[0] == ' ') { @@ -304,7 +303,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, } else if (style->float_ == CSS_FLOAT_LEFT || style->float_ == CSS_FLOAT_RIGHT) { LOG(("float")); - parent = box_create(0, BOX_FLOAT_LEFT, 0, href); + parent = box_create(BOX_FLOAT_LEFT, 0, href); if (style->float_ == CSS_FLOAT_RIGHT) parent->type = BOX_FLOAT_RIGHT; box_add_child(inline_container, parent); style->float_ = CSS_FLOAT_NONE; @@ -322,7 +321,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, switch (style->display) { case CSS_DISPLAY_BLOCK: /* blocks get a node in the box tree */ if (box == 0) - box = box_create(n, BOX_BLOCK, style, href); + box = box_create(BOX_BLOCK, style, href); else box->type = BOX_BLOCK; box_add_child(parent, box); @@ -346,7 +345,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, current_textarea, current_form, elements); break; case CSS_DISPLAY_TABLE: - box = box_create(n, BOX_TABLE, style, href); + box = box_create(BOX_TABLE, style, href); box_add_child(parent, box); for (c = n->children; c != 0; c = c->next) convert_xml_to_box(c, style, stylesheet, stylesheet_count, @@ -358,7 +357,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, case CSS_DISPLAY_TABLE_ROW_GROUP: case CSS_DISPLAY_TABLE_HEADER_GROUP: case CSS_DISPLAY_TABLE_FOOTER_GROUP: - box = box_create(n, BOX_TABLE_ROW_GROUP, style, href); + box = box_create(BOX_TABLE_ROW_GROUP, style, href); box_add_child(parent, box); inline_container_c = 0; for (c = n->children; c != 0; c = c->next) @@ -370,7 +369,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, inline_container = 0; break; case CSS_DISPLAY_TABLE_ROW: - box = box_create(n, BOX_TABLE_ROW, style, href); + box = box_create(BOX_TABLE_ROW, style, href); box_add_child(parent, box); for (c = n->children; c != 0; c = c->next) convert_xml_to_box(c, style, stylesheet, stylesheet_count, @@ -380,7 +379,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, inline_container = 0; break; case CSS_DISPLAY_TABLE_CELL: - box = box_create(n, BOX_TABLE_CELL, style, href); + box = box_create(BOX_TABLE_CELL, style, href); if ((s = (char *) xmlGetProp(n, (const xmlChar *) "colspan"))) { if ((box->columns = strtol(s, 0, 10)) == 0) box->columns = 1; @@ -539,8 +538,6 @@ void box_dump(struct box * box, unsigned int depth) case BOX_FLOAT_RIGHT: fprintf(stderr, "BOX_FLOAT_RIGHT "); break; default: fprintf(stderr, "Unknown box type "); } - if (box->node) - fprintf(stderr, "<%s> ", box->node->name); if (box->style) css_dump_style(box->style); if (box->href != 0) @@ -605,7 +602,7 @@ void box_normalise_block(struct box *block) style = xcalloc(1, sizeof(struct css_style)); memcpy(style, block->style, sizeof(struct css_style)); css_cascade(style, &css_blank_style); - table = box_create(0, BOX_TABLE, style, block->href); + table = box_create(BOX_TABLE, style, block->href); if (child->prev == 0) block->children = table; else @@ -659,7 +656,7 @@ void box_normalise_table(struct box *table) style = xcalloc(1, sizeof(struct css_style)); memcpy(style, table->style, sizeof(struct css_style)); css_cascade(style, &css_blank_style); - row_group = box_create(0, BOX_TABLE_ROW_GROUP, style, table->href); + row_group = box_create(BOX_TABLE_ROW_GROUP, style, table->href); if (child->prev == 0) table->children = row_group; else @@ -734,7 +731,7 @@ void box_normalise_table_row_group(struct box *row_group) style = xcalloc(1, sizeof(struct css_style)); memcpy(style, row_group->style, sizeof(struct css_style)); css_cascade(style, &css_blank_style); - row = box_create(0, BOX_TABLE_ROW, style, row_group->href); + row = box_create(BOX_TABLE_ROW, style, row_group->href); if (child->prev == 0) row_group->children = row; else @@ -810,7 +807,7 @@ void box_normalise_table_row(struct box *row) style = xcalloc(1, sizeof(struct css_style)); memcpy(style, row->style, sizeof(struct css_style)); css_cascade(style, &css_blank_style); - cell = box_create(0, BOX_TABLE_CELL, style, row->href); + cell = box_create(BOX_TABLE_CELL, style, row->href); if (child->prev == 0) row->children = cell; else @@ -1003,7 +1000,7 @@ struct box* box_image(xmlNode * n, struct css_style* style, char* href) struct box* box = 0; char* s; - box = box_create(n, BOX_INLINE, style, href); + box = box_create(BOX_INLINE, style, href); box->img = xcalloc(1, sizeof(struct img)); box->text = 0; @@ -1038,7 +1035,7 @@ struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* curre char* s; LOG(("creating box")); - box = box_create(n, BOX_INLINE, style, NULL); + box = box_create(BOX_INLINE, style, NULL); LOG(("creating gadget")); box->gadget = xcalloc(1, sizeof(struct gui_gadget)); box->gadget->type = GADGET_TEXTAREA; @@ -1080,7 +1077,7 @@ struct box* box_select(xmlNode * n, struct css_style* style, struct form* curren char* s; LOG(("creating box")); - box = box_create(n, BOX_INLINE, style, NULL); + box = box_create(BOX_INLINE, style, NULL); LOG(("creating gadget")); box->gadget = xcalloc(1, sizeof(struct gui_gadget)); box->gadget->type = GADGET_SELECT; @@ -1211,7 +1208,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current if (stricmp(type, "checkbox") == 0 || stricmp(type, "radio") == 0) { - box = box_create(n, BOX_INLINE, style, NULL); + box = box_create(BOX_INLINE, style, NULL); box->gadget = xcalloc(1, sizeof(struct gui_gadget)); if (type[0] == 'c') box->gadget->type = GADGET_CHECKBOX; @@ -1248,7 +1245,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current { //style->display = CSS_DISPLAY_BLOCK; - box = box_create(n, BOX_INLINE, style, NULL); + box = box_create(BOX_INLINE, style, NULL); box->gadget = xcalloc(1, sizeof(struct gui_gadget)); box->gadget->type = GADGET_ACTIONBUTTON; box->gadget->form = current_form; @@ -1283,7 +1280,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current //style->display = CSS_DISPLAY_BLOCK; fprintf(stderr, "CREATING TEXT BOX!\n"); - box = box_create(n, BOX_INLINE, style, NULL); + box = box_create(BOX_INLINE, style, NULL); box->gadget = xcalloc(1, sizeof(struct gui_gadget)); box->gadget->type = GADGET_TEXTBOX; box->gadget->form = current_form; diff --git a/render/box.h b/render/box.h index 21e80a096..b4972b6d0 100644 --- a/render/box.h +++ b/render/box.h @@ -1,5 +1,5 @@ /** - * $Id: box.h,v 1.22 2003/04/05 21:38:06 bursa Exp $ + * $Id: box.h,v 1.23 2003/04/10 21:44:45 bursa Exp $ */ #ifndef _NETSURF_RENDER_BOX_H_ @@ -81,7 +81,6 @@ struct img { struct box { box_type type; - xmlNode * node; struct css_style * style; unsigned long x, y, width, height; unsigned long min_width, max_width; diff --git a/render/html.c b/render/html.c index 5105089be..c6b96719a 100644 --- a/render/html.c +++ b/render/html.c @@ -1,5 +1,5 @@ /** - * $Id: html.c,v 1.11 2003/04/09 21:57:09 bursa Exp $ + * $Id: html.c,v 1.12 2003/04/10 21:44:45 bursa Exp $ */ #include @@ -23,15 +23,13 @@ struct fetch_data { static void html_convert_css_callback(fetchcache_msg msg, struct content *css, void *p, const char *error); -static void html_title(struct content *c); -static void html_find_stylesheets(struct content *c); +static void html_title(struct content *c, xmlNode *head); +static void html_find_stylesheets(struct content *c, xmlNode *head); void html_create(struct content *c) { c->data.html.parser = htmlCreatePushParserCtxt(0, 0, "", 0, 0, XML_CHAR_ENCODING_8859_1); - c->data.html.document = NULL; - c->data.html.markup = NULL; c->data.html.layout = NULL; c->data.html.style = NULL; c->data.html.fonts = NULL; @@ -57,34 +55,43 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) struct fetch_data *fetch_data; unsigned int i; char status[80]; + xmlDoc *document; + xmlNode *html, *head; + /* finish parsing */ htmlParseChunk(c->data.html.parser, "", 0, 1); - c->data.html.document = c->data.html.parser->myDoc; + document = c->data.html.parser->myDoc; /*xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);*/ - - LOG(("Skipping to html")); - if (c->data.html.document == NULL) { - LOG(("There is no document!")); + htmlFreeParserCtxt(c->data.html.parser); + if (document == NULL) { + LOG(("Parsing failed")); return 1; } - for (c->data.html.markup = c->data.html.document->children; - c->data.html.markup != 0 && c->data.html.markup->type != XML_ELEMENT_NODE; - c->data.html.markup = c->data.html.markup->next) - ; - if (c->data.html.markup == 0) { - LOG(("No markup")); + /* locate html and head elements */ + for (html = document->children; + html != 0 && html->type != XML_ELEMENT_NODE; + html = html->next) + ; + if (html == 0 || strcmp((const char *) html->name, "html") != 0) { + LOG(("html element not found")); + xmlFreeDoc(document); return 1; } - if (strcmp((const char *) c->data.html.markup->name, "html")) { - LOG(("Not html")); + for (head = html->children; + head != 0 && head->type != XML_ELEMENT_NODE; + head = head->next) + ; + if (head == 0 || strcmp((const char *) head->name, "head") != 0) { + LOG(("head element not found")); + xmlFreeDoc(document); return 1; } - - html_title(c); + + html_title(c, head); /* get stylesheets */ - html_find_stylesheets(c); + html_find_stylesheets(c, head); c->data.html.stylesheet_content = xcalloc(c->data.html.stylesheet_count, sizeof(*c->data.html.stylesheet_content)); @@ -111,8 +118,7 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) } if (c->error) { - /* TODO: clean up */ - return 1; + c->status_callback(c->status_p, "Warning: some stylesheets failed to load"); } LOG(("Copying base style")); @@ -122,18 +128,18 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) LOG(("Creating box")); c->data.html.layout = xcalloc(1, sizeof(struct box)); c->data.html.layout->type = BOX_BLOCK; - c->data.html.layout->node = c->data.html.markup; c->data.html.fonts = font_new_set(); - c->status_callback(c->status_p, "Formatting document"); LOG(("XML to box")); - xml_to_box(c->data.html.markup, c->data.html.style, + xml_to_box(html, c->data.html.style, c->data.html.stylesheet_content, c->data.html.stylesheet_count, &selector, 0, c->data.html.layout, 0, 0, c->data.html.fonts, 0, 0, 0, 0, &c->data.html.elements); /*box_dump(c->data.html.layout->children, 0);*/ + xmlFreeDoc(document); + c->status_callback(c->status_p, "Formatting document"); LOG(("Layout document")); layout_document(c->data.html.layout->children, width); /*box_dump(c->data.html.layout->children, 0);*/ @@ -176,15 +182,12 @@ void html_convert_css_callback(fetchcache_msg msg, struct content *css, } -void html_title(struct content *c) +void html_title(struct content *c, xmlNode *head) { - xmlNode *head = c->data.html.markup->children; xmlNode *node; c->title = 0; - if (strcmp(head->name, "head") != 0) - return; for (node = head->children; node != 0; node = node->next) { if (strcmp(node->name, "title") == 0) { c->title = xmlNodeGetContent(node); @@ -194,9 +197,8 @@ void html_title(struct content *c) } -void html_find_stylesheets(struct content *c) +void html_find_stylesheets(struct content *c, xmlNode *head) { - xmlNode *head = c->data.html.markup->children; xmlNode *node; char *rel, *type, *media, *href; unsigned int count = 1; @@ -205,8 +207,6 @@ void html_find_stylesheets(struct content *c) c->data.html.stylesheet_url[0] = "file:///%3CNetSurf$Dir%3E/Resources/CSS"; c->data.html.stylesheet_count = 1; - if (strcmp(head->name, "head") != 0) - return; for (node = head->children; node != 0; node = node->next) { if (strcmp(node->name, "link") == 0) { /* rel='stylesheet' */ @@ -274,10 +274,6 @@ void html_destroy(struct content *c) { LOG(("content %p", c)); - htmlFreeParserCtxt(c->data.html.parser); - - if (c->data.html.document != 0) - xmlFreeDoc(c->data.html.document); if (c->data.html.layout != 0) box_free(c->data.html.layout); if (c->data.html.fonts != 0) diff --git a/riscos/gui.c b/riscos/gui.c index 1e53d00ee..c8f293f51 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -1,5 +1,5 @@ /** - * $Id: gui.c,v 1.23 2003/03/25 21:51:29 bursa Exp $ + * $Id: gui.c,v 1.24 2003/04/10 21:44:45 bursa Exp $ */ #include "netsurf/riscos/font.h" @@ -550,26 +550,9 @@ void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, signed long y, os_box* clip, unsigned long current_background_color) { struct box * c; - const char * const noname = ""; - const char * name = noname; char* select_text; struct formoption* opt; - switch (box->type) - { - case BOX_TABLE: - case BOX_TABLE_ROW: - case BOX_TABLE_CELL: - case BOX_FLOAT_LEFT: - case BOX_FLOAT_RIGHT: - case BOX_BLOCK: if (box->node) name = (const char *) box->node->name; - break; - case BOX_INLINE: - case BOX_INLINE_CONTAINER: - default: - break; - } - if (x + (signed long) (box->x*2 + box->width*2) /* right edge */ >= clip->x0 && x + (signed long) (box->x*2) /* left edge */ <= clip->x1 && y - (signed long) (box->y*2 + box->height*2 + 8) /* bottom edge */ <= clip->y1 && -- cgit v1.2.3