2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2003-06-05 17:17:55 +04:00
|
|
|
* $Id: html.c,v 1.18 2003/06/05 13:17:55 philpem Exp $
|
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>
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/content/fetch.h"
|
|
|
|
#include "netsurf/content/fetchcache.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/desktop/gui.h"
|
|
|
|
#include "netsurf/render/html.h"
|
|
|
|
#include "netsurf/render/layout.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
struct fetch_data {
|
|
|
|
struct content *c;
|
|
|
|
unsigned int i;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void html_convert_css_callback(fetchcache_msg msg, struct content *css,
|
2003-04-04 19:19:32 +04:00
|
|
|
void *p, const char *error);
|
2003-04-11 01:44:45 +04:00
|
|
|
static void html_title(struct content *c, xmlNode *head);
|
|
|
|
static void html_find_stylesheets(struct content *c, xmlNode *head);
|
2003-04-15 21:53:00 +04:00
|
|
|
static void html_image_callback(fetchcache_msg msg, struct content *image,
|
|
|
|
void *p, const char *error);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
void html_create(struct content *c)
|
|
|
|
{
|
|
|
|
c->data.html.parser = htmlCreatePushParserCtxt(0, 0, "", 0, 0, XML_CHAR_ENCODING_8859_1);
|
|
|
|
c->data.html.layout = NULL;
|
|
|
|
c->data.html.style = NULL;
|
|
|
|
c->data.html.fonts = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CHUNK 4096
|
|
|
|
|
|
|
|
void html_process_data(struct content *c, char *data, unsigned long size)
|
|
|
|
{
|
|
|
|
unsigned long x;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int html_convert(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
2003-04-06 01:38:06 +04:00
|
|
|
unsigned int i;
|
2003-04-11 01:44:45 +04:00
|
|
|
xmlDoc *document;
|
|
|
|
xmlNode *html, *head;
|
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);
|
2003-04-11 01:44:45 +04: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);
|
|
|
|
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)
|
|
|
|
html_title(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"));
|
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
|
|
|
|
|
|
|
/* XML tree and stylesheets not required past this point */
|
2003-04-11 01:44:45 +04:00
|
|
|
xmlFreeDoc(document);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-12 01:06:51 +04:00
|
|
|
cache_free(c->data.html.stylesheet_content[0]);
|
2003-04-13 16:50:10 +04:00
|
|
|
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++)
|
2003-04-12 01:06:51 +04:00
|
|
|
if (c->data.html.stylesheet_content[i] != 0)
|
|
|
|
cache_free(c->data.html.stylesheet_content[i]);
|
|
|
|
xfree(c->data.html.stylesheet_content);
|
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* layout the box tree */
|
2003-04-11 01:44:45 +04:00
|
|
|
c->status_callback(c->status_p, "Formatting document");
|
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
|
|
|
|
|
|
|
if (c->active != 0)
|
|
|
|
c->status = CONTENT_PENDING;
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
void html_convert_css_callback(fetchcache_msg msg, struct content *css,
|
2003-04-04 19:19:32 +04:00
|
|
|
void *p, const char *error)
|
|
|
|
{
|
2003-04-06 01:38:06 +04:00
|
|
|
struct fetch_data *data = p;
|
|
|
|
struct content *c = data->c;
|
|
|
|
unsigned int i = data->i;
|
2003-04-04 19:19:32 +04:00
|
|
|
switch (msg) {
|
|
|
|
case FETCHCACHE_OK:
|
2003-04-06 01:38:06 +04:00
|
|
|
free(data);
|
2003-04-13 16:50:10 +04:00
|
|
|
LOG(("got stylesheet '%s'", css->url));
|
2003-04-06 01:38:06 +04:00
|
|
|
c->data.html.stylesheet_content[i] = css;
|
|
|
|
/*css_dump_stylesheet(css->data.css);*/
|
2003-04-04 19:19:32 +04:00
|
|
|
c->active--;
|
|
|
|
break;
|
|
|
|
case FETCHCACHE_BADTYPE:
|
|
|
|
case FETCHCACHE_ERROR:
|
2003-04-06 01:38:06 +04:00
|
|
|
free(data);
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
2003-04-04 19:19:32 +04:00
|
|
|
c->active--;
|
|
|
|
c->error = 1;
|
|
|
|
break;
|
|
|
|
case FETCHCACHE_STATUS:
|
|
|
|
/* TODO: need to add a way of sending status to the
|
|
|
|
* owning window */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
void html_title(struct content *c, xmlNode *head)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2003-04-06 01:38:06 +04:00
|
|
|
xmlNode *node;
|
2003-04-12 01:06:51 +04:00
|
|
|
xmlChar *title;
|
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) {
|
|
|
|
if (strcmp(node->name, "title") == 0) {
|
2003-04-12 01:06:51 +04:00
|
|
|
title = xmlNodeGetContent(node);
|
|
|
|
c->title = squash_tolat1(title);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(title);
|
2003-04-06 01:38:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2003-04-15 21:53:00 +04:00
|
|
|
char status[80];
|
2003-04-13 16:50:10 +04:00
|
|
|
unsigned int i = 2;
|
|
|
|
struct fetch_data *fetch_data;
|
|
|
|
|
|
|
|
/* 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-04-13 16:50:10 +04:00
|
|
|
fetch_data = xcalloc(1, sizeof(*fetch_data));
|
|
|
|
fetch_data->c = c;
|
|
|
|
fetch_data->i = 0;
|
|
|
|
c->active++;
|
|
|
|
fetchcache("file:///%3CNetSurf$Dir%3E/Resources/CSS", c->url,
|
|
|
|
html_convert_css_callback,
|
|
|
|
fetch_data, c->width, c->height, 1 << CONTENT_CSS);
|
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) {
|
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-04-13 16:50:10 +04:00
|
|
|
url = url_join(href, c->url);
|
|
|
|
LOG(("linked stylesheet %i '%s'", i, url));
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(href);
|
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));
|
|
|
|
fetch_data = xcalloc(1, sizeof(*fetch_data));
|
|
|
|
fetch_data->c = c;
|
|
|
|
fetch_data->i = i;
|
|
|
|
c->active++;
|
|
|
|
fetchcache(url, c->url, html_convert_css_callback,
|
|
|
|
fetch_data, c->width, c->height, 1 << CONTENT_CSS);
|
|
|
|
free(url);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
} else if (strcmp(node->name, "style") == 0) {
|
|
|
|
/* type='text/css' */
|
|
|
|
if (!(type = (char *) xmlGetProp(node, (const xmlChar *) "type")))
|
|
|
|
continue;
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2003-04-13 16:50:10 +04:00
|
|
|
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"));
|
|
|
|
if (c->data.html.stylesheet_content[1] == 0)
|
2003-04-15 21:53:00 +04:00
|
|
|
c->data.html.stylesheet_content[1] = content_create(CONTENT_CSS, c->url);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (c->data.html.stylesheet_content[1] != 0)
|
|
|
|
content_convert(c->data.html.stylesheet_content[1], c->width, c->height);
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* complete the fetches */
|
|
|
|
while (c->active != 0) {
|
|
|
|
if (c->status_callback != 0) {
|
|
|
|
sprintf(status, "Loading %u stylesheets", c->active);
|
|
|
|
c->status_callback(c->status_p, status);
|
|
|
|
}
|
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->error) {
|
|
|
|
c->status_callback(c->status_p, "Warning: some stylesheets failed to load");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void html_fetch_image(struct content *c, char *url, struct box *box)
|
|
|
|
{
|
|
|
|
struct fetch_data *fetch_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,
|
|
|
|
(c->data.html.object_count + 1) *
|
|
|
|
sizeof(*c->data.html.object));
|
|
|
|
c->data.html.object[c->data.html.object_count].url = url;
|
|
|
|
c->data.html.object[c->data.html.object_count].content = 0;
|
|
|
|
c->data.html.object[c->data.html.object_count].box = box;
|
|
|
|
|
|
|
|
/* start fetch */
|
|
|
|
fetch_data = xcalloc(1, sizeof(*fetch_data));
|
|
|
|
fetch_data->c = c;
|
|
|
|
fetch_data->i = c->data.html.object_count;
|
|
|
|
c->data.html.object_count++;
|
|
|
|
c->active++;
|
|
|
|
fetchcache(url, c->url,
|
|
|
|
html_image_callback,
|
2003-05-10 15:15:49 +04:00
|
|
|
fetch_data, 0, 0,
|
2003-06-05 17:17:55 +04:00
|
|
|
(1 << CONTENT_JPEG) | (1 << CONTENT_PNG) |
|
|
|
|
(1 << CONTENT_GIF));
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void html_image_callback(fetchcache_msg msg, struct content *image,
|
|
|
|
void *p, const char *error)
|
|
|
|
{
|
|
|
|
struct fetch_data *data = p;
|
|
|
|
struct content *c = data->c;
|
|
|
|
unsigned int i = data->i;
|
|
|
|
struct box *box = c->data.html.object[i].box;
|
|
|
|
switch (msg) {
|
|
|
|
case FETCHCACHE_OK:
|
|
|
|
LOG(("got image '%s'", image->url));
|
|
|
|
box->object = image;
|
|
|
|
c->data.html.object[i].content = image;
|
|
|
|
/* 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;
|
|
|
|
box->style->width.value.length.value = image->width;
|
2003-05-10 15:15:49 +04:00
|
|
|
box->min_width = box->max_width = box->width = image->width;
|
2003-04-15 21:53:00 +04:00
|
|
|
/* invalidate parent min, max widths */
|
|
|
|
if (box->parent->max_width != UNKNOWN_MAX_WIDTH) {
|
|
|
|
struct box *b = box->parent;
|
|
|
|
if (b->min_width < image->width)
|
|
|
|
b->min_width = image->width;
|
|
|
|
if (b->max_width < image->width)
|
|
|
|
b->max_width = image->width;
|
|
|
|
for (b = b->parent;
|
|
|
|
b != 0 && b->max_width != UNKNOWN_MAX_WIDTH;
|
|
|
|
b = b->parent)
|
|
|
|
b->max_width = UNKNOWN_MAX_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (box->style->height.height == CSS_HEIGHT_AUTO) {
|
|
|
|
box->style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
box->style->height.length.unit = CSS_UNIT_PX;
|
|
|
|
box->style->height.length.value = image->height;
|
|
|
|
}
|
|
|
|
/* remove alt text */
|
|
|
|
if (box->text != 0) {
|
|
|
|
free(box->text);
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
}
|
|
|
|
/*if (box->children != 0) {
|
|
|
|
box_free(box->children);
|
|
|
|
box->children = 0;
|
|
|
|
}*/
|
|
|
|
/* TODO: recalculate min, max width */
|
|
|
|
/* drop through */
|
|
|
|
case FETCHCACHE_BADTYPE:
|
|
|
|
case FETCHCACHE_ERROR:
|
|
|
|
if (c->active == 1 && c->status == CONTENT_PENDING) {
|
|
|
|
/* all images have arrived */
|
|
|
|
content_reformat(c, c->available_width, 0);
|
2003-05-10 15:15:49 +04:00
|
|
|
/*box_dump(c->data.html.layout->children, 0);*/
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
c->active--;
|
|
|
|
if (c->active == 0)
|
|
|
|
sprintf(c->status_message, "Document done");
|
|
|
|
else
|
|
|
|
sprintf(c->status_message, "Loading %i images", c->active);
|
|
|
|
free(data);
|
|
|
|
break;
|
|
|
|
case FETCHCACHE_STATUS:
|
|
|
|
/* TODO: need to add a way of sending status to the
|
|
|
|
* owning window */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
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;
|
|
|
|
struct fetch_data *fetch_data;
|
|
|
|
|
|
|
|
/* reload images and fix pointers */
|
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
if (c->data.html.object[i].content != 0) {
|
|
|
|
fetch_data = xcalloc(1, sizeof(*fetch_data));
|
|
|
|
fetch_data->c = c;
|
|
|
|
fetch_data->i = i;
|
|
|
|
c->active++;
|
|
|
|
fetchcache(c->data.html.object[i].url, c->url,
|
|
|
|
html_image_callback,
|
2003-05-10 15:15:49 +04:00
|
|
|
fetch_data, 0, 0,
|
2003-06-05 17:17:55 +04:00
|
|
|
(1 << CONTENT_JPEG) |
|
|
|
|
(1 << CONTENT_PNG) |
|
|
|
|
(1 << CONTENT_GIF));
|
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)
|
|
|
|
c->status = CONTENT_PENDING;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2003-04-25 12:03:15 +04:00
|
|
|
LOG(("layout %p", c->data.html.layout));
|
2003-02-09 15:58:15 +03:00
|
|
|
if (c->data.html.layout != 0)
|
|
|
|
box_free(c->data.html.layout);
|
2003-04-25 12:03:15 +04:00
|
|
|
LOG(("fonts %p", c->data.html.fonts));
|
2003-02-09 15:58:15 +03:00
|
|
|
if (c->data.html.fonts != 0)
|
|
|
|
font_free_set(c->data.html.fonts);
|
2003-04-25 12:03:15 +04:00
|
|
|
LOG(("title %p", c->title));
|
2003-03-04 01:40:39 +03:00
|
|
|
if (c->title != 0)
|
|
|
|
xfree(c->title);
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
2003-04-25 12:03:15 +04:00
|
|
|
LOG(("object %i %p", i, c->data.html.object[i].content));
|
2003-04-15 21:53:00 +04:00
|
|
|
if (c->data.html.object[i].content != 0)
|
|
|
|
cache_free(c->data.html.object[i].content);
|
|
|
|
free(c->data.html.object[i].url);
|
|
|
|
}
|
|
|
|
free(c->data.html.object);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
|