2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-02-20 03:43:17 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Content for text/html (implementation).
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2003-04-06 01:38:06 +04:00
|
|
|
#include <strings.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <stdlib.h>
|
2004-03-08 21:21:21 +03:00
|
|
|
#include "libxml/parserInternals.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/content/fetch.h"
|
|
|
|
#include "netsurf/content/fetchcache.h"
|
2004-03-27 01:16:31 +03:00
|
|
|
#include "netsurf/desktop/imagemap.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#ifdef riscos
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/desktop/gui.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/render/html.h"
|
|
|
|
#include "netsurf/render/layout.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2004-03-02 21:02:41 +03:00
|
|
|
#include "netsurf/utils/messages.h"
|
|
|
|
#include "netsurf/utils/url.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
#define CHUNK 4096
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
static void html_convert_css_callback(content_msg msg, struct content *css,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data);
|
2003-12-26 03:17:55 +03:00
|
|
|
static void html_head(struct content *c, xmlNode *head);
|
2003-04-11 01:44:45 +04:00
|
|
|
static void html_find_stylesheets(struct content *c, xmlNode *head);
|
2003-06-17 23:24:21 +04:00
|
|
|
static void html_object_callback(content_msg msg, struct content *object,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data);
|
2004-01-24 20:08:16 +03:00
|
|
|
static bool html_object_type_permitted(const content_type type,
|
|
|
|
const content_type *permitted_types);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Create a CONTENT_HTML.
|
|
|
|
*
|
|
|
|
* The content_html_data structure is initialized and the HTML parser is
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
|
2003-12-27 23:15:23 +03:00
|
|
|
void html_create(struct content *c, const char *params[])
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2003-12-27 23:15:23 +03:00
|
|
|
unsigned int i;
|
2004-02-20 03:43:17 +03:00
|
|
|
struct content_html_data *html = &c->data.html;
|
|
|
|
|
2004-04-17 20:00:16 +04:00
|
|
|
html->encoding = XML_CHAR_ENCODING_NONE;
|
2004-03-08 21:21:21 +03:00
|
|
|
html->getenc = true;
|
2003-12-27 23:15:23 +03:00
|
|
|
|
|
|
|
for (i = 0; params[i]; i += 2) {
|
|
|
|
if (strcasecmp(params[i], "charset") == 0) {
|
2004-02-20 03:43:17 +03:00
|
|
|
html->encoding = xmlParseCharEncoding(params[i + 1]);
|
2004-03-08 21:21:21 +03:00
|
|
|
html->getenc = false; /* encoding specified - trust the server... */
|
|
|
|
if (html->encoding == XML_CHAR_ENCODING_ERROR) {
|
2004-04-17 20:00:16 +04:00
|
|
|
html->encoding = XML_CHAR_ENCODING_NONE;
|
2004-03-08 21:21:21 +03:00
|
|
|
html->getenc = true;
|
|
|
|
}
|
2003-12-27 23:15:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
html->parser = htmlCreatePushParserCtxt(0, 0, "", 0, 0, html->encoding);
|
|
|
|
html->base_url = xstrdup(c->url);
|
|
|
|
html->layout = 0;
|
|
|
|
html->background_colour = TRANSPARENT;
|
|
|
|
html->stylesheet_count = 0;
|
|
|
|
html->stylesheet_content = 0;
|
|
|
|
html->style = 0;
|
|
|
|
html->fonts = 0;
|
|
|
|
html->object_count = 0;
|
|
|
|
html->object = 0;
|
|
|
|
html->string_pool = pool_create(8000);
|
|
|
|
assert(html->string_pool);
|
|
|
|
html->box_pool = pool_create(sizeof (struct box) * 100);
|
|
|
|
assert(html->box_pool);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Process data for CONTENT_HTML.
|
|
|
|
*
|
|
|
|
* The data is parsed in chunks of size CHUNK, multitasking in between.
|
|
|
|
*/
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
void html_process_data(struct content *c, char *data, unsigned long size)
|
|
|
|
{
|
|
|
|
unsigned long x;
|
2004-04-17 20:00:16 +04:00
|
|
|
|
|
|
|
/* First time through, check if we need to detect the encoding
|
|
|
|
* if so, detect it and reset the parser instance with it.
|
2004-03-08 21:21:21 +03:00
|
|
|
*/
|
|
|
|
if (c->data.html.getenc) {
|
2004-04-17 20:00:16 +04:00
|
|
|
xmlCharEncoding encoding = xmlDetectCharEncoding(data, size);
|
|
|
|
if (encoding != XML_CHAR_ENCODING_ERROR &&
|
|
|
|
encoding != XML_CHAR_ENCODING_NONE) {
|
|
|
|
xmlSwitchEncoding(c->data.html.parser, encoding);
|
|
|
|
c->data.html.encoding = encoding;
|
|
|
|
}
|
2004-03-08 21:21:21 +03:00
|
|
|
c->data.html.getenc = false;
|
|
|
|
}
|
2004-04-17 20:00:16 +04:00
|
|
|
|
2003-02-26 21:22:24 +03:00
|
|
|
for (x = 0; x + CHUNK <= size; x += CHUNK) {
|
2003-02-09 15:58:15 +03:00
|
|
|
htmlParseChunk(c->data.html.parser, data + x, CHUNK, 0);
|
|
|
|
gui_multitask();
|
|
|
|
}
|
2003-03-04 14:59:36 +03:00
|
|
|
htmlParseChunk(c->data.html.parser, data + x, (int) (size - x), 0);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Convert a CONTENT_HTML for display.
|
|
|
|
*
|
|
|
|
* The following steps are carried out in order:
|
|
|
|
*
|
|
|
|
* - parsing to an XML tree is completed
|
|
|
|
* - stylesheets are fetched
|
|
|
|
* - the XML tree is converted to a box tree and object fetches are started
|
|
|
|
* - the box tree is laid out
|
|
|
|
*
|
|
|
|
* On exit, the content status will be either CONTENT_STATUS_DONE if the
|
|
|
|
* document is completely loaded or CONTENT_STATUS_READY if objects are still
|
|
|
|
* being fetched.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
int html_convert(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
2003-04-11 01:44:45 +04:00
|
|
|
xmlDoc *document;
|
|
|
|
xmlNode *html, *head;
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* finish parsing */
|
2003-02-09 15:58:15 +03:00
|
|
|
htmlParseChunk(c->data.html.parser, "", 0, 1);
|
2004-03-24 23:10:03 +03:00
|
|
|
document = c->data.html.parser->myDoc;
|
2003-02-09 15:58:15 +03:00
|
|
|
/*xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);*/
|
2003-04-11 01:44:45 +04:00
|
|
|
htmlFreeParserCtxt(c->data.html.parser);
|
2004-02-20 03:43:17 +03:00
|
|
|
c->data.html.parser = 0;
|
2003-04-11 01:44:45 +04:00
|
|
|
if (document == NULL) {
|
|
|
|
LOG(("Parsing failed"));
|
2003-02-09 15:58:15 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* 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);
|
2003-02-09 15:58:15 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2003-04-11 01:44:45 +04:00
|
|
|
for (head = html->children;
|
|
|
|
head != 0 && head->type != XML_ELEMENT_NODE;
|
|
|
|
head = head->next)
|
|
|
|
;
|
2003-04-12 01:06:51 +04:00
|
|
|
if (strcmp((const char *) head->name, "head") != 0) {
|
|
|
|
head = 0;
|
2003-04-11 01:44:45 +04:00
|
|
|
LOG(("head element not found"));
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-11 01:44:45 +04:00
|
|
|
|
2003-04-12 01:06:51 +04:00
|
|
|
if (head != 0)
|
2003-12-26 03:17:55 +03:00
|
|
|
html_head(c, head);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
/* get stylesheets */
|
2003-04-13 16:50:10 +04:00
|
|
|
html_find_stylesheets(c, head);
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* convert xml tree to box tree */
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("XML to box"));
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("Processing"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2003-04-15 21:53:00 +04:00
|
|
|
xml_to_box(html, c);
|
2003-03-26 00:51:29 +03:00
|
|
|
/*box_dump(c->data.html.layout->children, 0);*/
|
2003-04-12 01:06:51 +04:00
|
|
|
|
2004-03-27 01:16:31 +03:00
|
|
|
/* extract image maps - can't do this sensibly in xml_to_box */
|
|
|
|
imagemap_extract(html, c);
|
|
|
|
/*imagemap_dump(c);*/
|
|
|
|
|
2004-02-17 15:41:38 +03:00
|
|
|
/* XML tree not required past this point */
|
2004-03-24 23:10:03 +03:00
|
|
|
xmlFreeDoc(document);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* layout the box tree */
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("Formatting"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("Layout document"));
|
|
|
|
layout_document(c->data.html.layout->children, width);
|
2003-03-26 00:51:29 +03:00
|
|
|
/*box_dump(c->data.html.layout->children, 0);*/
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-02-26 00:00:27 +03:00
|
|
|
c->width = c->data.html.layout->children->width;
|
|
|
|
c->height = c->data.html.layout->children->height;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2003-09-17 16:57:43 +04:00
|
|
|
if (c->active == 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("Done"));
|
2003-09-17 16:57:43 +04:00
|
|
|
} else {
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_READY;
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("FetchObjs"),
|
|
|
|
c->active);
|
2003-09-17 16:57:43 +04:00
|
|
|
}
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
/**
|
|
|
|
* Process elements in <head>.
|
2004-02-20 03:43:17 +03:00
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param head xml node of head element
|
|
|
|
*
|
|
|
|
* The title and base href are extracted if present.
|
2003-12-26 03:17:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void html_head(struct content *c, xmlNode *head)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2003-04-06 01:38:06 +04:00
|
|
|
xmlNode *node;
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
c->title = 0;
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
for (node = head->children; node != 0; node = node->next) {
|
2004-02-20 03:43:17 +03:00
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
if (!c->title && strcmp(node->name, "title") == 0) {
|
|
|
|
xmlChar *title = xmlNodeGetContent(node);
|
2003-04-12 01:06:51 +04:00
|
|
|
c->title = squash_tolat1(title);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(title);
|
2003-12-26 03:17:55 +03:00
|
|
|
|
|
|
|
} else if (strcmp(node->name, "base") == 0) {
|
|
|
|
char *href = (char *) xmlGetProp(node, (const xmlChar *) "href");
|
|
|
|
if (href) {
|
2004-03-02 21:02:41 +03:00
|
|
|
char *url = url_normalize(href);
|
2004-02-20 03:43:17 +03:00
|
|
|
if (url) {
|
|
|
|
free(c->data.html.base_url);
|
2003-12-26 03:17:55 +03:00
|
|
|
c->data.html.base_url = url;
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
2003-12-26 03:17:55 +03:00
|
|
|
xmlFree(href);
|
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Process inline stylesheets and fetch linked stylesheets.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param head xml node of head element, or 0 if none
|
|
|
|
*/
|
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
void html_find_stylesheets(struct content *c, xmlNode *head)
|
2003-04-06 01:38:06 +04:00
|
|
|
{
|
2003-04-15 21:53:00 +04:00
|
|
|
xmlNode *node, *node2;
|
2003-04-13 16:50:10 +04:00
|
|
|
char *rel, *type, *media, *href, *data, *url;
|
|
|
|
unsigned int i = 2;
|
2003-06-17 23:24:21 +04:00
|
|
|
unsigned int last_active = 0;
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data msg_data;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
|
|
|
/* stylesheet 0 is the base style sheet, stylesheet 1 is any <style> elements */
|
|
|
|
c->data.html.stylesheet_content = xcalloc(2, sizeof(*c->data.html.stylesheet_content));
|
|
|
|
c->data.html.stylesheet_content[1] = 0;
|
|
|
|
c->data.html.stylesheet_count = 2;
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
c->error = 0;
|
|
|
|
c->active = 0;
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.html.stylesheet_content[0] = fetchcache(
|
|
|
|
#ifdef riscos
|
|
|
|
"file:///%3CNetSurf$Dir%3E/Resources/CSS",
|
|
|
|
#else
|
|
|
|
"file:///home/james/Projects/netsurf/CSS",
|
|
|
|
#endif
|
|
|
|
c->url,
|
2003-04-13 16:50:10 +04:00
|
|
|
html_convert_css_callback,
|
2004-01-20 22:08:34 +03:00
|
|
|
c, 0, c->width, c->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
assert(c->data.html.stylesheet_content[0] != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE)
|
|
|
|
c->active++;
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
for (node = head == 0 ? 0 : head->children; node != 0; node = node->next) {
|
2004-02-20 03:43:17 +03:00
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
if (strcmp(node->name, "link") == 0) {
|
|
|
|
/* rel='stylesheet' */
|
|
|
|
if (!(rel = (char *) xmlGetProp(node, (const xmlChar *) "rel")))
|
|
|
|
continue;
|
|
|
|
if (strcasecmp(rel, "stylesheet") != 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(rel);
|
2003-02-09 15:58:15 +03:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(rel);
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-12 01:06:51 +04:00
|
|
|
/* type='text/css' or not present */
|
|
|
|
if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) {
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2003-04-12 01:06:51 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-12 01:06:51 +04:00
|
|
|
/* media contains 'screen' or 'all' or not present */
|
2003-04-06 01:38:06 +04:00
|
|
|
if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) {
|
2003-04-12 01:06:51 +04:00
|
|
|
if (strstr(media, "screen") == 0 &&
|
|
|
|
strstr(media, "all") == 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2003-04-06 01:38:06 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
/* href='...' */
|
|
|
|
if (!(href = (char *) xmlGetProp(node, (const xmlChar *) "href")))
|
|
|
|
continue;
|
|
|
|
|
2003-06-30 16:44:03 +04:00
|
|
|
/* TODO: only the first preferred stylesheets (ie. those with a
|
|
|
|
* title attribute) should be loaded (see HTML4 14.3) */
|
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
url = url_join(href, c->data.html.base_url);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(href);
|
2003-12-26 03:17:55 +03:00
|
|
|
if (!url)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LOG(("linked stylesheet %i '%s'", i, url));
|
2003-04-13 16:50:10 +04:00
|
|
|
|
|
|
|
/* start fetch */
|
|
|
|
c->data.html.stylesheet_content = xrealloc(c->data.html.stylesheet_content,
|
|
|
|
(i + 1) * sizeof(*c->data.html.stylesheet_content));
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.html.stylesheet_content[i] = fetchcache(url, c->url,
|
2003-12-27 05:03:48 +03:00
|
|
|
html_convert_css_callback, c, (void*)i,
|
2004-01-20 22:08:34 +03:00
|
|
|
c->width, c->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.html.stylesheet_content[i] &&
|
|
|
|
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
2003-06-17 23:24:21 +04:00
|
|
|
c->active++;
|
2003-04-13 16:50:10 +04:00
|
|
|
free(url);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
} else if (strcmp(node->name, "style") == 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
/* type='text/css', or not present (invalid but common) */
|
|
|
|
if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) {
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
|
|
|
xmlFree(type);
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2003-04-13 16:50:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* media contains 'screen' or 'all' or not present */
|
|
|
|
if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) {
|
|
|
|
if (strstr(media, "screen") == 0 &&
|
|
|
|
strstr(media, "all") == 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2003-04-13 16:50:10 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2003-04-13 16:50:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create stylesheet */
|
|
|
|
LOG(("style element"));
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->data.html.stylesheet_content[1] == 0) {
|
2003-12-27 23:15:23 +03:00
|
|
|
const char *params[] = { 0 };
|
2003-12-26 03:17:55 +03:00
|
|
|
c->data.html.stylesheet_content[1] =
|
|
|
|
content_create(c->data.html.base_url);
|
2004-02-20 03:43:17 +03:00
|
|
|
content_set_type(c->data.html.stylesheet_content[1],
|
|
|
|
CONTENT_CSS, "text/css", params);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* can't just use xmlNodeGetContent(node), because that won't give
|
|
|
|
* the content of comments which may be used to 'hide' the content */
|
|
|
|
for (node2 = node->children; node2 != 0; node2 = node2->next) {
|
|
|
|
data = xmlNodeGetContent(node2);
|
|
|
|
content_process_data(c->data.html.stylesheet_content[1],
|
|
|
|
data, strlen(data));
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(data);
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-13 16:50:10 +04:00
|
|
|
c->data.html.stylesheet_count = i;
|
|
|
|
|
2003-10-17 21:39:29 +04:00
|
|
|
if (c->data.html.stylesheet_content[1] != 0) {
|
|
|
|
if (css_convert(c->data.html.stylesheet_content[1], c->width,
|
|
|
|
c->height)) {
|
|
|
|
/* conversion failed */
|
|
|
|
content_destroy(c->data.html.stylesheet_content[1]);
|
|
|
|
c->data.html.stylesheet_content[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* complete the fetches */
|
|
|
|
while (c->active != 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->active != last_active) {
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("FetchStyle"),
|
|
|
|
c->active);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
2003-06-17 23:24:21 +04:00
|
|
|
last_active = c->active;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->error) {
|
2003-06-17 23:24:21 +04:00
|
|
|
sprintf(c->status_message, "Warning: some stylesheets failed to load");
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for linked stylesheets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_convert_css_callback(content_msg msg, struct content *css,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data)
|
2004-02-20 03:43:17 +03:00
|
|
|
{
|
|
|
|
struct content *c = p1;
|
|
|
|
unsigned int i = (unsigned int) p2;
|
2004-04-25 03:42:32 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
switch (msg) {
|
|
|
|
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;
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("NotCSS"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2004-02-20 03:43:17 +03:00
|
|
|
content_remove_user(css, html_convert_css_callback, c, (void*)i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
LOG(("got stylesheet '%s'", css->url));
|
|
|
|
c->active--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2004-02-27 20:45:19 +03:00
|
|
|
snprintf(c->status_message, 80, messages_get("FetchStyle2"),
|
2004-02-20 03:43:17 +03:00
|
|
|
c->active, css->status_message);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2004-02-20 03:43:17 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_REDIRECT:
|
|
|
|
c->active--;
|
|
|
|
c->data.html.stylesheet_content[i] = fetchcache(
|
2004-04-25 03:42:32 +04:00
|
|
|
data.redirect, c->url,
|
|
|
|
html_convert_css_callback,
|
2004-02-20 03:43:17 +03:00
|
|
|
c, (void*)i, css->width, css->height, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (c->data.html.stylesheet_content[i] != 0 &&
|
|
|
|
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
|
|
|
c->active++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef WITH_AUTH
|
|
|
|
case CONTENT_MSG_AUTH:
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start a fetch for an object required by a page.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param url URL of object to fetch
|
|
|
|
* \param box box that will contain the object
|
|
|
|
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
|
|
|
* or 0 if all types except OTHER and UNKNOWN acceptable
|
|
|
|
*/
|
|
|
|
|
2004-01-24 20:08:16 +03:00
|
|
|
void html_fetch_object(struct content *c, char *url, struct box *box,
|
|
|
|
const content_type *permitted_types)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
unsigned int i = c->data.html.object_count;
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* add to object list */
|
|
|
|
c->data.html.object = xrealloc(c->data.html.object,
|
2003-06-17 23:24:21 +04:00
|
|
|
(i + 1) * sizeof(*c->data.html.object));
|
|
|
|
c->data.html.object[i].url = url;
|
|
|
|
c->data.html.object[i].box = box;
|
2004-01-24 20:08:16 +03:00
|
|
|
c->data.html.object[i].permitted_types = permitted_types;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* start fetch */
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.html.object[i].content = fetchcache(url, c->url,
|
|
|
|
html_object_callback,
|
2003-12-27 05:03:48 +03:00
|
|
|
c, (void*)i, c->width, c->height,
|
2004-01-20 22:08:34 +03:00
|
|
|
true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
); /* we don't know the object's
|
|
|
|
dimensions yet; use
|
|
|
|
parent's as an estimate */
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.html.object[i].content) {
|
|
|
|
c->active++;
|
|
|
|
if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE)
|
|
|
|
html_object_callback(CONTENT_MSG_DONE,
|
2004-04-25 03:42:32 +04:00
|
|
|
c->data.html.object[i].content, c, (void*)i, data);
|
2003-07-16 21:38:46 +04:00
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
c->data.html.object_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for objects.
|
|
|
|
*/
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
void html_object_callback(content_msg msg, struct content *object,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content *c = p1;
|
|
|
|
unsigned int i = (unsigned int) p2;
|
2004-04-25 03:42:32 +04:00
|
|
|
int x, y;
|
2003-04-15 21:53:00 +04:00
|
|
|
struct box *box = c->data.html.object[i].box;
|
2004-02-20 03:43:17 +03:00
|
|
|
struct box *b;
|
2004-01-24 20:08:16 +03:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
switch (msg) {
|
2003-06-17 23:24:21 +04:00
|
|
|
case CONTENT_MSG_LOADING:
|
2004-01-24 20:08:16 +03:00
|
|
|
/* check if the type is acceptable for this object */
|
|
|
|
if (html_object_type_permitted(object->type,
|
|
|
|
c->data.html.object[i].permitted_types))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* not acceptable */
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("BadObject"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2004-01-24 20:08:16 +03:00
|
|
|
content_remove_user(object, html_object_callback, c, (void*)i);
|
2003-06-17 23:24:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
LOG(("got object '%s'", object->url));
|
|
|
|
box->object = object;
|
2004-04-11 04:35:24 +04:00
|
|
|
/* retain aspect ratio of box content */
|
|
|
|
if ((box->style->width.width == CSS_WIDTH_LENGTH /*||
|
|
|
|
box->style->width.width == CSS_WIDTH_PERCENT*/) &&
|
|
|
|
box->style->height.height == CSS_HEIGHT_AUTO) {
|
|
|
|
box->style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
box->style->height.length.unit = CSS_UNIT_PX;
|
|
|
|
if (box->style->width.width == CSS_WIDTH_LENGTH) {
|
|
|
|
box->style->height.length.value = object->height * (box->style->width.value.length.value / object->width);
|
|
|
|
}
|
|
|
|
/*else {
|
|
|
|
box->style->height.length.value = object->height * (box->style->width.value.percent / 100);
|
|
|
|
}*/
|
|
|
|
box->height = box->style->height.length.value;
|
|
|
|
}
|
|
|
|
if (box->style->height.height == CSS_HEIGHT_LENGTH &&
|
|
|
|
box->style->width.width == CSS_WIDTH_AUTO) {
|
|
|
|
box->style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
box->style->width.value.length.unit = CSS_UNIT_PX;
|
|
|
|
box->style->width.value.length.value = object->width * (box->style->height.length.value / object->height);
|
|
|
|
box->min_width = box->max_width = box->width = box->style->width.value.length.value;
|
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
/* set dimensions to object dimensions if auto */
|
|
|
|
if (box->style->width.width == CSS_WIDTH_AUTO) {
|
|
|
|
box->style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
box->style->width.value.length.unit = CSS_UNIT_PX;
|
2003-06-17 23:24:21 +04:00
|
|
|
box->style->width.value.length.value = object->width;
|
|
|
|
box->min_width = box->max_width = box->width = object->width;
|
2003-09-10 01:43:44 +04:00
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
if (box->style->height.height == CSS_HEIGHT_AUTO) {
|
|
|
|
box->style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
box->style->height.length.unit = CSS_UNIT_PX;
|
2003-06-17 23:24:21 +04:00
|
|
|
box->style->height.length.value = object->height;
|
2003-09-10 01:43:44 +04:00
|
|
|
box->height = object->height;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
/* invalidate parent min, max widths */
|
|
|
|
for (b = box->parent; b; b = b->parent)
|
|
|
|
b->max_width = UNKNOWN_MAX_WIDTH;
|
2003-09-10 01:43:44 +04:00
|
|
|
/* delete any clones of this box */
|
|
|
|
while (box->next && box->next->clone) {
|
|
|
|
/* box_free_box(box->next); */
|
|
|
|
box->next = box->next->next;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
c->active--;
|
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
2004-02-27 20:45:19 +03:00
|
|
|
snprintf(c->status_message, 80,
|
2004-04-25 03:42:32 +04:00
|
|
|
messages_get("ObjError"), data.error);
|
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2003-06-17 23:24:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2004-02-27 20:45:19 +03:00
|
|
|
snprintf(c->status_message, 80, messages_get("FetchObjs2"),
|
2003-06-17 23:24:21 +04:00
|
|
|
c->active, object->status_message);
|
2003-10-01 20:12:04 +04:00
|
|
|
/* content_broadcast(c, CONTENT_MSG_STATUS, 0); */
|
2003-04-15 21:53:00 +04:00
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2003-06-26 15:41:26 +04:00
|
|
|
case CONTENT_MSG_REDIRECT:
|
|
|
|
c->active--;
|
|
|
|
free(c->data.html.object[i].url);
|
2004-04-25 03:42:32 +04:00
|
|
|
c->data.html.object[i].url = xstrdup(data.redirect);
|
2003-06-26 15:41:26 +04:00
|
|
|
c->data.html.object[i].content = fetchcache(
|
2004-04-25 03:42:32 +04:00
|
|
|
data.redirect, c->url,
|
|
|
|
html_object_callback,
|
2004-01-20 22:08:34 +03:00
|
|
|
c, (void*)i, 0, 0, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-09-28 21:37:19 +04:00
|
|
|
if (c->data.html.object[i].content) {
|
2003-06-26 15:41:26 +04:00
|
|
|
c->active++;
|
2003-09-28 21:37:19 +04:00
|
|
|
if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE)
|
|
|
|
html_object_callback(CONTENT_MSG_DONE,
|
2004-04-25 03:42:32 +04:00
|
|
|
c->data.html.object[i].content, c, (void*)i, data);
|
2003-09-28 21:37:19 +04:00
|
|
|
}
|
2003-07-08 02:10:51 +04:00
|
|
|
break;
|
2003-06-26 15:41:26 +04:00
|
|
|
|
2003-09-11 01:44:11 +04:00
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
break;
|
|
|
|
|
2004-03-21 15:50:10 +03:00
|
|
|
case CONTENT_MSG_REDRAW:
|
2004-04-25 03:42:32 +04:00
|
|
|
box_coords(box, &x, &y);
|
2004-04-26 17:47:51 +04:00
|
|
|
if (box->object == data.redraw.object) {
|
|
|
|
data.redraw.x = data.redraw.x *
|
|
|
|
box->width / box->object->width;
|
|
|
|
data.redraw.y = data.redraw.y *
|
|
|
|
box->height / box->object->height;
|
|
|
|
data.redraw.width = data.redraw.width *
|
|
|
|
box->width / box->object->width;
|
|
|
|
data.redraw.height = data.redraw.height *
|
|
|
|
box->height / box->object->height;
|
|
|
|
data.redraw.object_width = box->width;
|
|
|
|
data.redraw.object_height = box->height;
|
|
|
|
}
|
|
|
|
data.redraw.x += x + box->padding[LEFT];
|
|
|
|
data.redraw.y += y + box->padding[TOP];
|
|
|
|
data.redraw.object_x += x + box->padding[LEFT];
|
|
|
|
data.redraw.object_y += y + box->padding[TOP];
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REDRAW, data);
|
2004-03-21 15:50:10 +03:00
|
|
|
break;
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2003-10-25 23:20:13 +04:00
|
|
|
case CONTENT_MSG_AUTH:
|
2003-10-26 02:51:45 +04:00
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
2003-10-25 23:20:13 +04:00
|
|
|
break;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2003-06-30 19:56:35 +04:00
|
|
|
if (c->status == CONTENT_STATUS_READY && c->active == 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
/* all objects have arrived */
|
|
|
|
content_reformat(c, c->available_width, 0);
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("Done"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_DONE, data);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2003-06-30 19:56:35 +04:00
|
|
|
if (c->status == CONTENT_STATUS_READY)
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(c->status_message, messages_get("FetchObjs"),
|
|
|
|
c->active);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-24 20:08:16 +03:00
|
|
|
/**
|
|
|
|
* Check if a type is in a list.
|
|
|
|
*
|
|
|
|
* \param type the content_type to search for
|
|
|
|
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
|
|
|
* or 0 if all types except OTHER and UNKNOWN acceptable
|
|
|
|
* \return the type is in the list or acceptable
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_object_type_permitted(const content_type type,
|
|
|
|
const content_type *permitted_types)
|
|
|
|
{
|
|
|
|
if (permitted_types) {
|
|
|
|
for (; *permitted_types != CONTENT_UNKNOWN; permitted_types++)
|
|
|
|
if (*permitted_types == type)
|
|
|
|
return true;
|
|
|
|
} else if (type < CONTENT_OTHER) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
void html_revive(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
2003-04-15 21:53:00 +04:00
|
|
|
unsigned int i;
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
assert(0); /* dead code, do not use as is */
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
/* reload objects and fix pointers */
|
2003-04-15 21:53:00 +04:00
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
if (c->data.html.object[i].content != 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.html.object[i].content = fetchcache(
|
|
|
|
c->data.html.object[i].url, c->url,
|
|
|
|
html_object_callback,
|
2004-01-20 22:08:34 +03:00
|
|
|
c, (void*)i, 0, 0, true
|
|
|
|
#ifdef WITH_POST
|
|
|
|
, 0, 0
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
, false
|
|
|
|
#endif
|
|
|
|
);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->data.html.object[i].content &&
|
|
|
|
c->data.html.object[i].content->status != CONTENT_STATUS_DONE)
|
2003-06-17 23:24:21 +04:00
|
|
|
c->active++;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
layout_document(c->data.html.layout->children, width);
|
2003-02-26 00:00:27 +03:00
|
|
|
c->width = c->data.html.layout->children->width;
|
|
|
|
c->height = c->data.html.layout->children->height;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
if (c->active != 0)
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_READY;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Reformat a CONTENT_HTML to a new width.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
void html_reformat(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
layout_document(c->data.html.layout->children, width);
|
2003-02-26 00:00:27 +03:00
|
|
|
c->width = c->data.html.layout->children->width;
|
|
|
|
c->height = c->data.html.layout->children->height;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_HTML and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
void html_destroy(struct content *c)
|
|
|
|
{
|
2003-04-15 21:53:00 +04:00
|
|
|
unsigned int i;
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("content %p", c));
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
free(c->title);
|
|
|
|
|
2004-03-27 01:16:31 +03:00
|
|
|
imagemap_destroy(c);
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
if (c->data.html.parser)
|
|
|
|
htmlFreeParserCtxt(c->data.html.parser);
|
|
|
|
|
|
|
|
free(c->data.html.base_url);
|
|
|
|
|
|
|
|
if (c->data.html.layout)
|
|
|
|
box_free(c->data.html.layout);
|
|
|
|
|
|
|
|
/* Free stylesheets */
|
|
|
|
if (c->data.html.stylesheet_count) {
|
|
|
|
content_remove_user(c->data.html.stylesheet_content[0],
|
|
|
|
html_convert_css_callback, c, 0);
|
|
|
|
if (c->data.html.stylesheet_content[1])
|
|
|
|
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])
|
|
|
|
content_remove_user(c->data.html.stylesheet_content[i],
|
|
|
|
html_convert_css_callback, c, (void*)i);
|
|
|
|
}
|
|
|
|
free(c->data.html.stylesheet_content);
|
|
|
|
free(c->data.html.style);
|
|
|
|
|
|
|
|
if (c->data.html.fonts)
|
|
|
|
font_free_set(c->data.html.fonts);
|
|
|
|
|
|
|
|
/* Free objects */
|
2003-07-10 01:33:01 +04:00
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
LOG(("object %i %p", i, c->data.html.object[i].content));
|
2004-02-20 03:43:17 +03:00
|
|
|
if (c->data.html.object[i].content)
|
2003-07-10 01:33:01 +04:00
|
|
|
content_remove_user(c->data.html.object[i].content,
|
2003-12-27 05:03:48 +03:00
|
|
|
html_object_callback, c, (void*)i);
|
2003-07-10 01:33:01 +04:00
|
|
|
free(c->data.html.object[i].url);
|
|
|
|
}
|
|
|
|
free(c->data.html.object);
|
|
|
|
|
2004-01-02 15:04:04 +03:00
|
|
|
pool_destroy(c->data.html.string_pool);
|
|
|
|
pool_destroy(c->data.html.box_pool);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|