From 0c0ff3c59631d0968c888279195ea40d4a7fd824 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Tue, 17 Jun 2003 19:24:21 +0000 Subject: [project @ 2003-06-17 19:24:20 by bursa] Change fetchcache system to store loading contents in cache. svn path=/import/netsurf/; revision=180 --- render/box.c | 12 +-- render/box.h | 4 +- render/html.c | 271 ++++++++++++++++++++++++++++++++------------------------ render/html.h | 4 +- render/layout.c | 9 +- 5 files changed, 173 insertions(+), 127 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index af1c88c9e..5d44a305c 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.50 2003/06/07 22:24:22 jmb Exp $ + * $Id: box.c,v 1.51 2003/06/17 19:24:21 bursa Exp $ */ #include @@ -10,13 +10,15 @@ #include "libxml/HTMLparser.h" #include "netsurf/content/fetchcache.h" #include "netsurf/css/css.h" -#include "netsurf/desktop/gui.h" #include "netsurf/render/box.h" +#ifdef riscos +#include "netsurf/desktop/gui.h" #include "netsurf/riscos/font.h" +#endif #include "netsurf/riscos/plugin.h" +#define NDEBUG #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" -//#define NDEBUG /** * internal functions @@ -1052,7 +1054,7 @@ struct box* box_image(xmlNode *n, struct content *content, xmlFree(s); /* start fetch */ - html_fetch_image(content, url, box); + html_fetch_object(content, url, box); return box; } @@ -1368,7 +1370,7 @@ struct form* box_form(xmlNode* n) struct form* form; char* s; - form = xcalloc(1, sizeof(struct form*)); + form = xcalloc(1, sizeof(*form)); if ((s = (char *) xmlGetProp(n, (const xmlChar *) "action"))) { form->action = s; diff --git a/render/box.h b/render/box.h index fb5e4c5bd..dbff18cf2 100644 --- a/render/box.h +++ b/render/box.h @@ -1,5 +1,5 @@ /** - * $Id: box.h,v 1.25 2003/05/22 13:21:45 bursa Exp $ + * $Id: box.h,v 1.26 2003/06/17 19:24:21 bursa Exp $ */ #ifndef _NETSURF_RENDER_BOX_H_ @@ -8,7 +8,9 @@ #include #include "libxml/HTMLparser.h" #include "netsurf/css/css.h" +#ifdef riscos #include "netsurf/riscos/font.h" +#endif /** * structures diff --git a/render/html.c b/render/html.c index 304de133c..ab6b55560 100644 --- a/render/html.c +++ b/render/html.c @@ -1,32 +1,29 @@ /** - * $Id: html.c,v 1.18 2003/06/05 13:17:55 philpem Exp $ + * $Id: html.c,v 1.19 2003/06/17 19:24:21 bursa Exp $ */ #include #include #include #include +#include "netsurf/content/content.h" #include "netsurf/content/fetch.h" #include "netsurf/content/fetchcache.h" +#ifdef riscos #include "netsurf/desktop/gui.h" +#endif #include "netsurf/render/html.h" #include "netsurf/render/layout.h" #include "netsurf/utils/utils.h" #include "netsurf/utils/log.h" -struct fetch_data { - struct content *c; - unsigned int i; -}; - - -static void html_convert_css_callback(fetchcache_msg msg, struct content *css, - void *p, const char *error); +static void html_convert_css_callback(content_msg msg, struct content *css, + void *p1, void *p2, const char *error); static void html_title(struct content *c, xmlNode *head); static void html_find_stylesheets(struct content *c, xmlNode *head); -static void html_image_callback(fetchcache_msg msg, struct content *image, - void *p, const char *error); +static void html_object_callback(content_msg msg, struct content *object, + void *p1, void *p2, const char *error); void html_create(struct content *c) @@ -43,6 +40,8 @@ void html_create(struct content *c) void html_process_data(struct content *c, char *data, unsigned long size) { unsigned long x; + LOG(("content %s, size %lu", c->url, size)); + cache_dump(); for (x = 0; x + CHUNK <= size; x += CHUNK) { htmlParseChunk(c->data.html.parser, data + x, CHUNK, 0); gui_multitask(); @@ -100,16 +99,19 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) /* XML tree and stylesheets not required past this point */ xmlFreeDoc(document); - cache_free(c->data.html.stylesheet_content[0]); + content_remove_user(c->data.html.stylesheet_content[0], + html_convert_css_callback, c, 0); if (c->data.html.stylesheet_content[1] != 0) content_destroy(c->data.html.stylesheet_content[1]); for (i = 2; i != c->data.html.stylesheet_count; i++) if (c->data.html.stylesheet_content[i] != 0) - cache_free(c->data.html.stylesheet_content[i]); + content_remove_user(c->data.html.stylesheet_content[i], + html_convert_css_callback, c, i); xfree(c->data.html.stylesheet_content); /* layout the box tree */ - c->status_callback(c->status_p, "Formatting document"); + sprintf(c->status_message, "Formatting document"); + content_broadcast(c, CONTENT_MSG_STATUS, 0); LOG(("Layout document")); layout_document(c->data.html.layout->children, width); /*box_dump(c->data.html.layout->children, 0);*/ @@ -117,38 +119,53 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) c->width = c->data.html.layout->children->width; c->height = c->data.html.layout->children->height; - if (c->active != 0) - c->status = CONTENT_PENDING; + if (c->active == 0) + c->status = CONTENT_STATUS_DONE; + else + c->status = CONTENT_STATUS_READY; return 0; } -void html_convert_css_callback(fetchcache_msg msg, struct content *css, - void *p, const char *error) +void html_convert_css_callback(content_msg msg, struct content *css, + void *p1, void *p2, const char *error) { - struct fetch_data *data = p; - struct content *c = data->c; - unsigned int i = data->i; + struct content *c = p1; + unsigned int i = (unsigned int) p2; switch (msg) { - case FETCHCACHE_OK: - free(data); + case CONTENT_MSG_LOADING: + /* check that the stylesheet is really CSS */ + if (css->type != CONTENT_CSS) { + c->data.html.stylesheet_content[i] = 0; + c->active--; + c->error = 1; + sprintf(c->status_message, "Warning: stylesheet is not CSS"); + content_broadcast(c, CONTENT_MSG_STATUS, 0); + content_remove_user(css, html_convert_css_callback, c, i); + } + break; + + case CONTENT_MSG_READY: + break; + + case CONTENT_MSG_DONE: LOG(("got stylesheet '%s'", css->url)); - c->data.html.stylesheet_content[i] = css; - /*css_dump_stylesheet(css->data.css);*/ c->active--; break; - case FETCHCACHE_BADTYPE: - case FETCHCACHE_ERROR: - free(data); + + case CONTENT_MSG_ERROR: c->data.html.stylesheet_content[i] = 0; c->active--; c->error = 1; break; - case FETCHCACHE_STATUS: - /* TODO: need to add a way of sending status to the - * owning window */ + + case CONTENT_MSG_STATUS: + sprintf(c->status_message, "Loading %u stylesheets: %s", + c->active, css->status_message); + content_broadcast(c, CONTENT_MSG_STATUS, 0); break; + default: assert(0); } @@ -177,9 +194,8 @@ void html_find_stylesheets(struct content *c, xmlNode *head) { xmlNode *node, *node2; char *rel, *type, *media, *href, *data, *url; - char status[80]; unsigned int i = 2; - struct fetch_data *fetch_data; + unsigned int last_active = 0; /* stylesheet 0 is the base style sheet, stylesheet 1 is any