summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-04-15 17:53:00 +0000
committerJames Bursa <james@netsurf-browser.org>2003-04-15 17:53:00 +0000
commit09b1ede5a3fe5c37e34fe1c13780536f30297806 (patch)
tree5bf9a19301354c45deb6fab2e0386b5ca822714f /render
parent63b6455f7365507ce502369b738ecc09e54e25ed (diff)
downloadnetsurf-09b1ede5a3fe5c37e34fe1c13780536f30297806.tar.gz
netsurf-09b1ede5a3fe5c37e34fe1c13780536f30297806.tar.bz2
[project @ 2003-04-15 17:53:00 by bursa]
Inline images and related. svn path=/import/netsurf/; revision=125
Diffstat (limited to 'render')
-rw-r--r--render/box.c192
-rw-r--r--render/box.h18
-rw-r--r--render/html.c207
-rw-r--r--render/html.h3
-rw-r--r--render/layout.c36
5 files changed, 285 insertions, 171 deletions
diff --git a/render/box.c b/render/box.c
index f99715659..04550a6ec 100644
--- a/render/box.c
+++ b/render/box.c
@@ -1,5 +1,5 @@
/**
- * $Id: box.c,v 1.41 2003/04/13 12:50:10 bursa Exp $
+ * $Id: box.c,v 1.42 2003/04/15 17:53:00 bursa Exp $
*/
#include <assert.h>
@@ -9,6 +9,7 @@
#include <string.h>
#include "libxml/HTMLparser.h"
#include "libutf-8/utf-8.h"
+#include "netsurf/content/fetchcache.h"
#include "netsurf/css/css.h"
#include "netsurf/riscos/font.h"
#include "netsurf/render/box.h"
@@ -21,14 +22,19 @@
* internal functions
*/
+struct fetch_data {
+ struct content *c;
+ unsigned int i;
+};
+
static void box_add_child(struct box * parent, struct box * child);
static struct box * box_create(box_type type, struct css_style * style,
char *href);
-static struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
- struct content ** stylesheet, unsigned int stylesheet_count,
+static struct box * convert_xml_to_box(xmlNode * n, struct content *c,
+ struct css_style * parent_style,
struct css_selector ** selector, unsigned int depth,
struct box * parent, struct box * inline_container,
- char *href, struct font_set *fonts,
+ char *href,
struct gui_gadget* current_select, struct formoption* current_option,
struct gui_gadget* current_textarea, struct form* current_form,
struct page_elements* elements);
@@ -42,7 +48,8 @@ static void box_normalise_table_row(struct box *row);
static void box_normalise_inline_container(struct box *cont);
static void gadget_free(struct gui_gadget* g);
static void box_free_box(struct box *box);
-static struct box* box_image(xmlNode * n, struct css_style* style, char* href);
+static struct box* box_image(xmlNode *n, struct content *content,
+ struct css_style *style, char *href);
static struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* current_form);
static struct box* box_select(xmlNode * n, struct css_style* style, struct form* current_form);
static struct formoption* box_option(xmlNode* n, struct css_style* style, struct gui_gadget* current_select);
@@ -99,49 +106,64 @@ struct box * box_create(box_type type, struct css_style * style,
box->col = 0;
box->font = 0;
box->gadget = 0;
- box->img = 0;
+ box->object = 0;
return box;
}
/**
* make a box tree with style data from an xml tree
+ */
+
+void xml_to_box(xmlNode *n, struct content *c)
+{
+ struct css_selector* selector = xcalloc(1, sizeof(struct css_selector));
+
+ LOG(("node %p", n));
+ assert(c->type == CONTENT_HTML);
+
+ c->data.html.layout = xcalloc(1, sizeof(struct box));
+ c->data.html.layout->type = BOX_BLOCK;
+
+ c->data.html.style = xcalloc(1, sizeof(struct css_style));
+ memcpy(c->data.html.style, &css_base_style, sizeof(struct css_style));
+ c->data.html.fonts = font_new_set();
+
+ c->data.html.object_count = 0;
+ c->data.html.object = xcalloc(0, sizeof(*c->data.html.object));
+
+ convert_xml_to_box(n, c, c->data.html.style,
+ &selector, 0, c->data.html.layout, 0, 0, 0, 0,
+ 0, 0, &c->data.html.elements);
+ LOG(("normalising"));
+ box_normalise_block(c->data.html.layout->children);
+}
+
+
+/**
+ * make a box tree with style data from an xml tree
*
* arguments:
* n xml tree
+ * content content structure
* parent_style style at this point in xml tree
- * stylesheet stylesheet to use
* selector element selector hierachy to this point
* depth depth in xml tree
* parent parent in box tree
* inline_container current inline container box, or 0
+ * href current link, or 0
+ * current_* forms state
+ * elements forms structure
*
* returns:
* updated current inline container
*/
-void xml_to_box(xmlNode * n, struct css_style * parent_style,
- struct content ** stylesheet, unsigned int stylesheet_count,
- struct css_selector ** selector, unsigned int depth,
- struct box * parent, struct box * inline_container,
- char *href, struct font_set *fonts,
- struct gui_gadget* current_select, struct formoption* current_option,
- struct gui_gadget* current_textarea, struct form* current_form,
- struct page_elements* elements)
-{
- LOG(("node %p", n));
- convert_xml_to_box(n, parent_style, stylesheet, stylesheet_count,
- selector, depth, parent, inline_container, href, fonts, current_select, current_option,
- current_textarea, current_form, elements);
- LOG(("normalising"));
- box_normalise_block(parent->children);
-}
-
-struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
- struct content ** stylesheet, unsigned int stylesheet_count,
+struct box * convert_xml_to_box(xmlNode * n, struct content *content,
+ struct css_style * parent_style,
struct css_selector ** selector, unsigned int depth,
struct box * parent, struct box * inline_container,
- char *href, struct font_set *fonts,
+ char *href,
struct gui_gadget* current_select, struct formoption* current_option,
struct gui_gadget* current_textarea, struct form* current_form,
struct page_elements* elements)
@@ -152,10 +174,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
xmlNode * c;
char * s;
char * text = 0;
- xmlChar *s2;
- assert(n != 0 && parent_style != 0 && stylesheet != 0 && selector != 0 &&
- parent != 0 && fonts != 0);
+ assert(n != 0 && content != 0 && parent_style != 0 && selector != 0 &&
+ parent != 0);
LOG(("depth %i, node %p, node type %i", depth, n, n->type));
gui_multitask();
@@ -168,13 +189,18 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
(*selector)[depth].class = s; /* TODO: free this later */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "id")))
(*selector)[depth].id = s;
- style = box_get_style(stylesheet, stylesheet_count, parent_style, n,
+ style = box_get_style(content->data.html.stylesheet_content,
+ content->data.html.stylesheet_count, parent_style, n,
*selector, depth + 1);
LOG(("display: %s", css_display_name[style->display]));
if (style->display == CSS_DISPLAY_NONE) {
free(style);
return inline_container;
}
+ /* floats are treated as blocks */
+ if (style->float_ == CSS_FLOAT_LEFT || style->float_ == CSS_FLOAT_RIGHT)
+ if (style->display == CSS_DISPLAY_INLINE)
+ style->display = CSS_DISPLAY_BLOCK;
/* special elements */
if (strcmp((const char *) n->name, "a") == 0) {
@@ -187,21 +213,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
add_form_element(elements, form);
} else if (strcmp((const char *) n->name, "img") == 0) {
- LOG(("image"));
- /*box = box_image(n, style, href);
- add_img_element(elements, box->img);*/
- /*if (style->display == CSS_DISPLAY_INLINE) {
- if ((s = (char *) xmlGetProp(n, (const xmlChar *) "alt"))) {
- text = squash_tolat1(s);
- xfree(s);
- }
- }*/
- /* TODO: block images, start fetch */
- if ((s2 = xmlGetProp(n, (const xmlChar *) "alt"))) {
- xmlNode *alt = xmlNewText(s2);
- free(s2);
- xmlAddChild(n, alt);
- }
+ box = box_image(n, content, style, href);
} else if (strcmp((const char *) n->name, "textarea") == 0) {
char * content = xmlNodeGetContent(n);
@@ -243,6 +255,8 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
text = squash_tolat1(n->content);
}
+ content->size += sizeof(struct box) + sizeof(struct css_style);
+
if (text != 0) {
if (text[0] == ' ' && text[1] == 0) {
if (inline_container != 0) {
@@ -286,7 +300,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
box->space = 0;
}
box->text = text;
- box->font = font_open(fonts, box->style);
+ box->font = font_open(content->data.html.fonts, box->style);
} else if (style->float_ == CSS_FLOAT_LEFT || style->float_ == CSS_FLOAT_RIGHT) {
LOG(("float"));
@@ -313,10 +327,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
box_add_child(parent, box);
inline_container_c = 0;
for (c = n->children; c != 0; c = c->next)
- inline_container_c = convert_xml_to_box(c, style,
- stylesheet, stylesheet_count,
+ inline_container_c = convert_xml_to_box(c, content, style,
selector, depth + 1, box, inline_container_c,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
if (style->float_ == CSS_FLOAT_NONE)
/* continue in this inline container if this is a float */
@@ -326,19 +339,18 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
assert(box == 0); /* special inline elements have already been
added to the inline container above */
for (c = n->children; c != 0; c = c->next)
- inline_container = convert_xml_to_box(c, style,
- stylesheet, stylesheet_count,
+ inline_container = convert_xml_to_box(c, content, style,
selector, depth + 1, parent, inline_container,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
break;
case CSS_DISPLAY_TABLE:
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,
+ convert_xml_to_box(c, content, style,
selector, depth + 1, box, 0,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
inline_container = 0;
break;
@@ -349,10 +361,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
box_add_child(parent, box);
inline_container_c = 0;
for (c = n->children; c != 0; c = c->next)
- inline_container_c = convert_xml_to_box(c, style,
- stylesheet, stylesheet_count,
+ inline_container_c = convert_xml_to_box(c, content, style,
selector, depth + 1, box, inline_container_c,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
inline_container = 0;
break;
@@ -360,9 +371,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
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,
+ convert_xml_to_box(c, content, style,
selector, depth + 1, box, 0,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
inline_container = 0;
break;
@@ -376,10 +387,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
box_add_child(parent, box);
inline_container_c = 0;
for (c = n->children; c != 0; c = c->next)
- inline_container_c = convert_xml_to_box(c, style,
- stylesheet, stylesheet_count,
+ inline_container_c = convert_xml_to_box(c, content, style,
selector, depth + 1, box, inline_container_c,
- href, fonts, current_select, current_option,
+ href, current_select, current_option,
current_textarea, current_form, elements);
inline_container = 0;
break;
@@ -972,11 +982,6 @@ void box_free_box(struct box *box)
free(box->gadget);
}
- if (box->img != 0)
- {
- free(box->img);
- }
-
if (box->text != 0)
free(box->text);
/* only free href if we're the top most user */
@@ -989,40 +994,45 @@ void box_free_box(struct box *box)
}
}
-struct box* box_image(xmlNode * n, struct css_style* style, char* href)
+
+/**
+ * add an image to the box tree
+ */
+
+struct box* box_image(xmlNode *n, struct content *content,
+ struct css_style *style, char *href)
{
- struct box* box = 0;
- char* s;
+ struct box *box;
+ char *s, *url;
+ xmlChar *s2;
+ struct fetch_data *fetch_data;
+ /* box type is decided by caller, BOX_INLINE is just a default */
box = box_create(BOX_INLINE, style, href);
- box->img = xcalloc(1, sizeof(struct img));
- box->text = 0;
- box->length = 0;
- box->font = 0;
+ /* handle alt text */
+ /*if ((s2 = xmlGetProp(n, (const xmlChar *) "alt"))) {
+ box->text = squash_tolat1(s2);
+ box->length = strlen(box->text);
+ box->font = font_open(content->data.html.fonts, style);
+ free(s2);
+ }*/
- if (style->width.width == CSS_WIDTH_AUTO) {
- /* should find the real image width */
- style->width.width = CSS_WIDTH_LENGTH;
- style->width.value.length.unit = CSS_UNIT_PX;
- style->width.value.length.value = 24;
- }
+ /* img without src is an error */
+ if (!(s = (char *) xmlGetProp(n, (const xmlChar *) "src")))
+ return box;
- if (style->height.height == CSS_HEIGHT_AUTO) {
- /* should find the real image height */
- style->height.height = CSS_HEIGHT_LENGTH;
- style->height.length.unit = CSS_UNIT_PX;
- style->height.length.value = 24;
- }
+ url = url_join(s, content->url);
+ LOG(("image '%s'", url));
+ free(s);
- if ((s = (char *) xmlGetProp(n, (const xmlChar *) "alt")))
- {
- box->img->alt = s;
- }
+ /* start fetch */
+ html_fetch_image(content, url, box);
return box;
}
+
struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* current_form)
{
struct box* box = 0;
diff --git a/render/box.h b/render/box.h
index b4972b6d0..5adb69554 100644
--- a/render/box.h
+++ b/render/box.h
@@ -1,5 +1,5 @@
/**
- * $Id: box.h,v 1.23 2003/04/10 21:44:45 bursa Exp $
+ * $Id: box.h,v 1.24 2003/04/15 17:53:00 bursa Exp $
*/
#ifndef _NETSURF_RENDER_BOX_H_
@@ -74,11 +74,6 @@ struct gui_gadget {
} data;
};
-struct img {
- char* alt;
- char* src;
-};
-
struct box {
box_type type;
struct css_style * style;
@@ -99,7 +94,7 @@ struct box {
struct column *col;
struct font_data *font;
struct gui_gadget* gadget;
- struct img* img;
+ struct content* object; /* usually an image */
};
struct form
@@ -132,14 +127,7 @@ struct page_elements
* interface
*/
-void xml_to_box(xmlNode * n, struct css_style * parent_style,
- struct content ** stylesheet, unsigned int stylesheet_count,
- struct css_selector ** selector, unsigned int depth,
- struct box * parent, struct box * inline_container,
- char *href, struct font_set *fonts,
- struct gui_gadget* current_select, struct formoption* current_option,
- struct gui_gadget* current_textarea, struct form* current_form,
- struct page_elements* elements);
+void xml_to_box(xmlNode *n, struct content *c);
void box_dump(struct box * box, unsigned int depth);
void box_free(struct box *box);
diff --git a/render/html.c b/render/html.c
index 9b38b7378..0c60acdb5 100644
--- a/render/html.c
+++ b/render/html.c
@@ -1,5 +1,5 @@
/**
- * $Id: html.c,v 1.14 2003/04/13 12:50:10 bursa Exp $
+ * $Id: html.c,v 1.15 2003/04/15 17:53:00 bursa Exp $
*/
#include <assert.h>
@@ -25,6 +25,8 @@ static void html_convert_css_callback(fetchcache_msg msg, struct content *css,
void *p, 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);
void html_create(struct content *c)
@@ -51,10 +53,7 @@ void html_process_data(struct content *c, char *data, unsigned long size)
int html_convert(struct content *c, unsigned int width, unsigned int height)
{
- struct css_selector* selector = xcalloc(1, sizeof(struct css_selector));
- struct fetch_data *fetch_data;
unsigned int i;
- char status[80];
xmlDoc *document;
xmlNode *html, *head;
@@ -91,39 +90,11 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
html_title(c, head);
/* get stylesheets */
- c->error = 0;
- c->active = 0;
-
html_find_stylesheets(c, head);
- 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");
- }
-
- LOG(("Copying base style"));
- c->data.html.style = xcalloc(1, sizeof(struct css_style));
- memcpy(c->data.html.style, &css_base_style, sizeof(struct css_style));
-
- LOG(("Creating box"));
- c->data.html.layout = xcalloc(1, sizeof(struct box));
- c->data.html.layout->type = BOX_BLOCK;
-
- c->data.html.fonts = font_new_set();
-
+ /* convert xml tree to box tree */
LOG(("XML to box"));
- 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);
+ xml_to_box(html, c);
/*box_dump(c->data.html.layout->children, 0);*/
/* XML tree and stylesheets not required past this point */
@@ -137,6 +108,7 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
cache_free(c->data.html.stylesheet_content[i]);
xfree(c->data.html.stylesheet_content);
+ /* layout the box tree */
c->status_callback(c->status_p, "Formatting document");
LOG(("Layout document"));
layout_document(c->data.html.layout->children, width);
@@ -144,6 +116,9 @@ 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;
return 0;
}
@@ -200,8 +175,9 @@ void html_title(struct content *c, xmlNode *head)
void html_find_stylesheets(struct content *c, xmlNode *head)
{
- xmlNode *node;
+ xmlNode *node, *node2;
char *rel, *type, *media, *href, *data, *url;
+ char status[80];
unsigned int i = 2;
struct fetch_data *fetch_data;
@@ -210,6 +186,9 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
c->data.html.stylesheet_content[1] = 0;
c->data.html.stylesheet_count = 2;
+ c->error = 0;
+ c->active = 0;
+
fetch_data = xcalloc(1, sizeof(*fetch_data));
fetch_data->c = c;
fetch_data->i = 0;
@@ -218,10 +197,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
html_convert_css_callback,
fetch_data, c->width, c->height, 1 << CONTENT_CSS);
- if (head == 0)
- return;
-
- for (node = head->children; node != 0; node = node->next) {
+ for (node = head == 0 ? 0 : head->children; node != 0; node = node->next) {
if (strcmp(node->name, "link") == 0) {
/* rel='stylesheet' */
if (!(rel = (char *) xmlGetProp(node, (const xmlChar *) "rel")))
@@ -294,11 +270,16 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
/* create stylesheet */
LOG(("style element"));
if (c->data.html.stylesheet_content[1] == 0)
- c->data.html.stylesheet_content[1] = content_create(CONTENT_CSS, "");
-
- data = xmlNodeGetContent(node);
- content_process_data(c->data.html.stylesheet_content[1], data, strlen(data));
- free(data);
+ 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));
+ free(data);
+ }
}
}
@@ -306,15 +287,142 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
if (c->data.html.stylesheet_content[1] != 0)
content_convert(c->data.html.stylesheet_content[1], c->width, c->height);
+
+ /* 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;
+
+ /* 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,
+ fetch_data, 0, 0, 1 << CONTENT_JPEG);
+}
+
+
+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;
+ box->min_width = box->max_width = image->width;
+ /* 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);
+ }
+ 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);
+ }
}
void html_revive(struct content *c, unsigned int width, unsigned int height)
{
- /* TODO: reload images and fix any pointers to them */
+ 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,
+ fetch_data, 0, 0, 1 << CONTENT_JPEG);
+ }
+ }
+
layout_document(c->data.html.layout->children, width);
c->width = c->data.html.layout->children->width;
c->height = c->data.html.layout->children->height;
+
+ if (c->active != 0)
+ c->status = CONTENT_PENDING;
}
@@ -328,6 +436,7 @@ void html_reformat(struct content *c, unsigned int width, unsigned int height)
void html_destroy(struct content *c)
{
+ unsigned int i;
LOG(("content %p", c));
if (c->data.html.layout != 0)
@@ -336,4 +445,12 @@ void html_destroy(struct content *c)
font_free_set(c->data.html.fonts);
if (c->title != 0)
xfree(c->title);
+
+ for (i = 0; i != c->data.html.object_count; i++) {
+ 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);
}
+
diff --git a/render/html.h b/render/html.h
index 1dd9e3a51..a22d04112 100644
--- a/render/html.h
+++ b/render/html.h
@@ -1,5 +1,5 @@
/**
- * $Id: html.h,v 1.1 2003/02/09 12:58:15 bursa Exp $
+ * $Id: html.h,v 1.2 2003/04/15 17:53:00 bursa Exp $
*/
#ifndef _NETSURF_RENDER_HTML_H_
@@ -13,5 +13,6 @@ int html_convert(struct content *c, unsigned int width, unsigned int height);
void html_revive(struct content *c, unsigned int width, unsigned int height);
void html_reformat(struct content *c, unsigned int width, unsigned int height);
void html_destroy(struct content *c);
+void html_fetch_image(struct content *c, char *url, struct box *box);
#endif
diff --git a/render/layout.c b/render/layout.c
index 7b1e40ba4..f2b950840 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -1,5 +1,5 @@
/**
- * $Id: layout.c,v 1.39 2003/04/13 12:50:10 bursa Exp $
+ * $Id: layout.c,v 1.40 2003/04/15 17:53:00 bursa Exp $
*/
#include <assert.h>
@@ -77,8 +77,12 @@ signed long len(struct css_length * length, struct css_style * style)
void layout_document(struct box * doc, unsigned long width)
{
+ struct box *box;
doc->float_children = 0;
layout_node(doc, width, doc, 0, 0);
+ for (box = doc->float_children; box != 0; box = box->next)
+ if (doc->height < box->y + box->height)
+ doc->height = box->y + box->height;
}
@@ -159,6 +163,7 @@ int gadget_height(struct gui_gadget* gadget)
}
return 0;
}
+
/**
* layout_block -- position block and recursively layout children
*
@@ -353,11 +358,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
h = line_height(b->style ? b->style : b->parent->parent->style);
else if (b->gadget != 0)
h = gadget_height(b->gadget);
- else {
- assert(b->style != 0);
- assert(b->style->height.height == CSS_HEIGHT_LENGTH);
+ else if (b->style != 0 && b->style->height.height == CSS_HEIGHT_LENGTH)
h = len(&b->style->height.length, b->style);
- }
+ else
+ h = 0;
b->height = h;
if (h > height) height = h;
@@ -367,17 +371,12 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
b->width = font_width(b->font, b->text, b->length);
else if (b->gadget != 0)
b->width = gadget_width(b->gadget);
- else {
- assert(b->style != 0);
- assert(b->style->width.width == CSS_WIDTH_LENGTH ||
- b->style->width.width == CSS_WIDTH_PERCENT);
- if (b->style->width.width == CSS_WIDTH_LENGTH)
- b->width = len(&b->style->width.value.length,
- b->style);
- else
- b->width = width * b->style->width.value.percent
- / 100;
- }
+ else if (b->style != 0 && b->style->width.width == CSS_WIDTH_LENGTH)
+ b->width = len(&b->style->width.value.length, b->style);
+ else if (b->style != 0 && b->style->width.width == CSS_WIDTH_PERCENT)
+ b->width = width * b->style->width.value.percent / 100;
+ else
+ b->width = 0;
}
if (b->text != 0)
@@ -417,10 +416,9 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
/* either a float with no width specified (contravenes standard)
* or we don't know the width for some reason, eg. image not loaded */
calculate_widths(b);
- w = width / 2;
- if (d->max_width < w)
+ if (d->max_width < width)
w = d->max_width;
- else if (w < d->min_width)
+ else
w = d->min_width;
}
layout_node(d, w, d, 0, 0);