From 78594f3f60a2ce28f1d6ee95676bfa10492320fe Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 9 Jun 2004 19:55:06 +0000 Subject: [project @ 2004-06-09 19:55:06 by jmb] Implement background-image, background-repeat, background-position and background-attachment CSS properties. background-attachment and background-position need more work. Some redraw issues remain. svn path=/import/netsurf/; revision=938 --- render/box.c | 72 ++++++++++++++++++++++++++++++++++++++++------------------- render/box.h | 4 ++++ render/html.c | 21 ++++++++++++----- render/html.h | 2 ++ 4 files changed, 71 insertions(+), 28 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index fdda43c94..eb0befdfd 100644 --- a/render/box.c +++ b/render/box.c @@ -60,12 +60,30 @@ struct box_multi_length { float value; }; +static const content_type image_types[] = { +#ifdef WITH_JPEG + CONTENT_JPEG, +#endif +#ifdef WITH_GIF + CONTENT_GIF, +#endif +#ifdef WITH_PNG + CONTENT_PNG, +#endif +#ifdef WITH_SPRITE + CONTENT_SPRITE, +#endif +#ifdef WITH_DRAW + CONTENT_DRAW, +#endif + CONTENT_UNKNOWN }; static struct box * convert_xml_to_box(xmlNode * n, struct content *content, struct css_style * parent_style, struct box * parent, struct box *inline_container, struct box_status status); -static struct css_style * box_get_style(struct content ** stylesheet, +static struct css_style * box_get_style(struct content *c, + struct content ** stylesheet, unsigned int stylesheet_count, struct css_style * parent_style, xmlNode * n); static void box_text_transform(char *s, unsigned int len, @@ -195,6 +213,7 @@ struct box * box_create(struct css_style * style, box->font = 0; box->gadget = 0; box->usemap = 0; + box->background = 0; box->object = 0; box->object_params = 0; box->object_state = 0; @@ -312,7 +331,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content, gui_multitask(); - style = box_get_style(content->data.html.stylesheet_content, + style = box_get_style(content, content->data.html.stylesheet_content, content->data.html.stylesheet_count, parent_style, n); LOG(("display: %s", css_display_name[style->display])); if (style->display == CSS_DISPLAY_NONE) { @@ -551,6 +570,17 @@ end: if (!href_in) xmlFree(status.href); + /* Now fetch any background image for this box */ + if (box && box->style && + box->style->background_image.type == CSS_BACKGROUND_IMAGE_URI) { + /* start fetch */ + html_fetch_object(content, box->style->background_image.uri, + box, + image_types, + content->available_width, + 1000); + } + LOG(("node %p, node type %i END", n, n->type)); return inline_container; } @@ -565,7 +595,8 @@ end: * 3. the 'style' attribute */ -struct css_style * box_get_style(struct content ** stylesheet, +struct css_style * box_get_style(struct content *c, + struct content ** stylesheet, unsigned int stylesheet_count, struct css_style * parent_style, xmlNode * n) { @@ -584,6 +615,19 @@ struct css_style * box_get_style(struct content ** stylesheet, } css_cascade(style, &style_new); + /* This property only applies to the body element, if you believe + the spec. Many browsers seem to allow it on other elements too, + so let's be generic ;) + */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "background"))) { + style->background_image.type = CSS_BACKGROUND_IMAGE_URI; + /**\todo This will leak memory. */ + style->background_image.uri = url_join(s, c->data.html.base_url); + if (!style->background_image.uri) + style->background_image.type = CSS_BACKGROUND_IMAGE_NONE; + xmlFree(s); + } + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "bgcolor"))) { unsigned int r, g, b; if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3) @@ -747,7 +791,6 @@ void box_text_transform(char *s, unsigned int len, * have been processed in some way by the function). If box is 0, no box will * be created for that element, and convert_children must be 0. */ - struct box_result box_a(xmlNode *n, struct box_status *status, struct css_style *style) { @@ -765,8 +808,9 @@ struct box_result box_body(xmlNode *n, struct box_status *status, { struct box *box; status->content->data.html.background_colour = style->background_color; - box = box_create(style, status->href, status->title, + box = box_create(style, status->href, status->title, status->content->data.html.box_pool); + return (struct box_result) {box, true, false}; } @@ -780,24 +824,6 @@ struct box_result box_br(xmlNode *n, struct box_status *status, return (struct box_result) {box, false, false}; } -static const content_type image_types[] = { -#ifdef WITH_JPEG - CONTENT_JPEG, -#endif -#ifdef WITH_GIF - CONTENT_GIF, -#endif -#ifdef WITH_PNG - CONTENT_PNG, -#endif -#ifdef WITH_SPRITE - CONTENT_SPRITE, -#endif -#ifdef WITH_DRAW - CONTENT_DRAW, -#endif - CONTENT_UNKNOWN }; - struct box_result box_image(xmlNode *n, struct box_status *status, struct css_style *style) { diff --git a/render/box.h b/render/box.h index b4ecfa631..c1250469a 100644 --- a/render/box.h +++ b/render/box.h @@ -77,6 +77,7 @@ #include #include "libxml/HTMLparser.h" #include "netsurf/utils/config.h" +#include "netsurf/content/content_type.h" #include "netsurf/css/css.h" #include "netsurf/render/font.h" #include "netsurf/utils/pool.h" @@ -189,6 +190,9 @@ struct box { char *usemap; /** (Image)map to use with this object, or 0 if none */ + /** Background image for this box, or 0 if none */ + struct content *background; + /** Object in this box (usually an image), or 0 if none. */ struct content* object; /** Parameters for the object, or 0. */ diff --git a/render/html.c b/render/html.c index 722fcc5ba..12f286579 100644 --- a/render/html.c +++ b/render/html.c @@ -38,7 +38,8 @@ static void html_head(struct content *c, xmlNode *head); static void html_find_stylesheets(struct content *c, xmlNode *head); static void html_object_callback(content_msg msg, struct content *object, void *p1, void *p2, union content_msg_data data); -static void html_object_done(struct box *box, struct content *object); +static void html_object_done(struct box *box, struct content *object, + bool background); static bool html_object_type_permitted(const content_type type, const content_type *permitted_types); @@ -537,6 +538,10 @@ void html_fetch_object(struct content *c, char *url, struct box *box, c->data.html.object[i].url = url; c->data.html.object[i].box = box; c->data.html.object[i].permitted_types = permitted_types; + if (box->style->background_image.type == CSS_BACKGROUND_IMAGE_URI) + c->data.html.object[i].background = true; + else + c->data.html.object[i].background = false; /* start fetch */ c->data.html.object[i].content = fetchcache(url, c->url, @@ -591,13 +596,13 @@ void html_object_callback(content_msg msg, struct content *object, case CONTENT_MSG_READY: if (object->type == CONTENT_HTML) { - html_object_done(box, object); + html_object_done(box, object, c->data.html.object[i].background); content_reformat(c, c->available_width, 0); } break; case CONTENT_MSG_DONE: - html_object_done(box, object); + html_object_done(box, object, c->data.html.object[i].background); c->active--; break; @@ -696,11 +701,17 @@ void html_object_callback(content_msg msg, struct content *object, * Update a box whose content has completed rendering. */ -void html_object_done(struct box *box, struct content *object) +void html_object_done(struct box *box, struct content *object, + bool background) { struct box *b; - box->object = object; + if (background) { + box->background = object; + } + else { + box->object = object; + } if (box->width != UNKNOWN_WIDTH && object->available_width != box->width) diff --git a/render/html.h b/render/html.h index 8446b651e..860af9680 100644 --- a/render/html.h +++ b/render/html.h @@ -14,6 +14,7 @@ #ifndef _NETSURF_RENDER_HTML_H_ #define _NETSURF_RENDER_HTML_H_ +#include #include "libxml/HTMLparser.h" #include "netsurf/content/content_type.h" #include "netsurf/css/css.h" @@ -72,6 +73,7 @@ struct content_html_data { /** Pointer to array of permitted content_type, terminated by * CONTENT_UNKNOWN, or 0 if any type is acceptable. */ const content_type *permitted_types; + bool background; /** Is this object a background image? */ } *object; struct imagemap **imagemaps; /**< Hashtable of imagemaps */ -- cgit v1.2.3