From 51ee42fc080293aba2bcde9c85e06282530b8ab6 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 31 May 2003 18:47:00 +0000 Subject: [project @ 2003-05-31 18:47:00 by jmb] Begin support for , and tags. NB: this doesn't work yet svn path=/import/netsurf/; revision=137 --- render/box.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- riscos/plugin.c | 87 +++++++++++++++++++++++++ riscos/plugin.h | 26 ++++++++ 3 files changed, 300 insertions(+), 10 deletions(-) create mode 100644 riscos/plugin.c create mode 100644 riscos/plugin.h diff --git a/render/box.c b/render/box.c index cafc7dda5..3816f3455 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.45 2003/05/23 11:08:17 bursa Exp $ + * $Id: box.c,v 1.46 2003/05/31 18:47:00 jmb Exp $ */ #include @@ -10,12 +10,13 @@ #include "libxml/HTMLparser.h" #include "netsurf/content/fetchcache.h" #include "netsurf/css/css.h" -#include "netsurf/riscos/font.h" +#include "netsurf/desktop/gui.h" #include "netsurf/render/box.h" +#include "netsurf/riscos/font.h" +#include "netsurf/riscos/plugin.h" +#include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" #define NDEBUG -#include "netsurf/utils/log.h" -#include "netsurf/desktop/gui.h" /** * internal functions @@ -52,6 +53,12 @@ static struct box* box_image(xmlNode *n, struct content *content, 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); +static struct box* box_object(xmlNode *n, struct content *content, + struct css_style *style, char *href); +static struct box* box_embed(xmlNode *n, struct content *content, + struct css_style *style, char *href); +static struct box* box_applet(xmlNode *n, struct content *content, + struct css_style *style, char *href); static void textarea_addtext(struct gui_gadget* textarea, char* text); static void option_addtext(struct formoption* option, char* text); static struct box* box_input(xmlNode * n, struct css_style* style, struct form* current_form, struct page_elements* elements); @@ -244,6 +251,15 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content, LOG(("input")); box = box_input(n, style, current_form, elements); + } else if (strcmp((const char*) n->name, "object") == 0) { LOG(("object")); + box = box_object(n, content, style, href); + + } else if (strcmp((const char*) n->name, "embed") == 0) { LOG(("embed")); + box = box_embed(n, content, style, href); + + } else if (strcmp((const char*) n->name, "applet") == 0) { LOG(("applet")); + box = box_applet(n, content, style, href); + } /* special elements must be inline or block */ @@ -255,7 +271,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content, } content->size += sizeof(struct box) + sizeof(struct css_style); - + if (text != 0) { if (text[0] == ' ' && text[1] == 0) { if (inline_container != 0) { @@ -1271,17 +1287,17 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current } box->gadget->data.actionbutt.butttype = strdup(type); - + add_gadget_element(elements, box->gadget); } if (!(stricmp(type, "text") == 0 || stricmp(type, "password") == 0)) { - + xmlFree (type); return box; } - + } //style->display = CSS_DISPLAY_BLOCK; fprintf(stderr, "CREATING TEXT BOX!\n"); @@ -1297,7 +1313,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current #ifdef ARSEMONKEYS // box->gadget->data.textbox.maxlength = 255; -// if ((s = (char *) xmlGetProp(n, (xmlChar *) "maxlength"))) +// if ((s = (char *) xmlGetProp(n, (xmlChar *) "maxlength"))) // #endif box->gadget->data.textbox.maxlength = 32; @@ -1310,7 +1326,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current #ifdef ARSEMONKEYS //<<<<<<< box.c // box->gadget->data.textbox.size = 20;/*box->gadget->data.textbox.maxlength;*/ -// if ((s = (char *) xmlGetProp(n, (xmlChar *) "size"))) +// if ((s = (char *) xmlGetProp(n, (xmlChar *) "size"))) //======= #endif box->gadget->data.textbox.size = box->gadget->data.textbox.maxlength; @@ -1379,4 +1395,165 @@ void add_img_element(struct page_elements* pe, struct img* i) pe->numImages++; } +/** + * add an object to the box tree + */ + +struct box* box_object(xmlNode *n, struct content *content, + struct css_style *style, char *href) +{ + struct box *box; + struct plugin_object *po; + 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); + + po = xcalloc(1,sizeof(*po)); + + /* object data */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "data"))) { + + po->data = s; + url = url_join(s, content->url); + LOG(("object '%s'", url)); + xmlFree(s); + } + + /* object type */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "type"))) { + + po->type = s; + LOG(("type: %s", po->type)); + xmlFree(s); + } + + /* object codetype */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codetype"))) { + + po->codetype = s; + LOG(("codetype: %s", po->codetype)); + xmlFree(s); + } + + /* object codebase */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codebase"))) { + + po->codebase = s; + LOG(("codebase: %s", po->codebase)); + xmlFree(s); + } + + /* object classid */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "classid"))) { + + po->classid = s; + LOG(("classid: %s", po->classid)); + xmlFree(s); + } + + /* object param */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "param"))) { + + /* TODO - create data structure to hold param elements */ + LOG(("param: %s", s)); + xmlFree(s); + } + + /* object width */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "width"))) { + + po->width = (unsigned int)atoi(s); + LOG(("width: %u", po->width)); + xmlFree(s); + } + + /* object height */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height"))) { + + po->height = (unsigned int)atoi(s); + LOG(("height: %u", po->height)); + xmlFree(s); + } + + /* start fetch */ + plugin_fetch(content, url, box, po); + + return box; +} + +/** + * add an embed to the box tree + */ + +struct box* box_embed(xmlNode *n, struct content *content, + struct css_style *style, char *href) +{ + struct box *box; + struct plugin_object *po; + 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); + + po = xcalloc(1, sizeof(*po)); + + /* embed src */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src"))) { + + po->src = s; + url = url_join(s, content->url); + LOG(("embed '%s'", url)); + xmlFree(s); + } + + /* embed param */ + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "param"))) { + + /* TODO - create data structure for param elements */ + LOG(("param '%s'", s)); + xmlFree(s); + } + + /* start fetch */ + plugin_fetch(content, url, box, po); + + return box; +} + +/** + * TODO - finish this ;-) + * add an applet to the box tree + */ + +struct box* box_applet(xmlNode *n, struct content *content, + struct css_style *style, char *href) +{ + struct box *box; + struct plugin_object *po; + 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); + + po = xcalloc(1,sizeof(struct plugin_object)); + + /* object without data is an error */ + if (!(s = (char *) xmlGetProp(n, (const xmlChar *) "data"))) + return box; + + url = url_join(s, content->url); + LOG(("object '%s'", url)); + xmlFree(s); + + /* start fetch */ + //plugin_fetch(content, url, box, po); + + return box; +} diff --git a/riscos/plugin.c b/riscos/plugin.c new file mode 100644 index 000000000..e6b3aabb8 --- /dev/null +++ b/riscos/plugin.c @@ -0,0 +1,87 @@ +/** + * $Id: plugin.c,v 1.1 2003/05/31 18:47:00 jmb Exp $ + */ + +#include +#include +#include +#include +#include + +#include "netsurf/content/content.h" +#include "netsurf/render/html.h" +#include "netsurf/riscos/plugin.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" + +char* create_mime_from_ext(char* data); + +void plugin_fetch(struct content* content, char* url, struct box* box, + struct plugin_object* po) { + + + content_type mime_type; + + if (po->data != NULL) { + + if (po->type != NULL) { + + mime_type = content_lookup((const char*)po->type); + } + else { + + po->type = create_mime_from_ext(po->data); + + if (po->type != NULL) + mime_type = content_lookup((const char*)po->type); + + } + + /* OK, we have an image. Let's make the image handler + deal with it */ + if (mime_type == CONTENT_JPEG || mime_type == CONTENT_PNG) { + + xfree(po); + LOG(("sending data to image handler")); + /* TODO - stop segfault when redrawing window */ + /*html_fetch_image(content, url, box);*/ + } + } + else { + + + } + /* TODO - this function.*/ + +} + +/** + * create_mime_from_ext + * attempts to create a mime type from the filename extension. + * returns NULL if it fails. + */ + +char* create_mime_from_ext(char* data){ + + char* ret; + + ret = strrchr(data, '.'); + LOG(("ret = %s", ++ret)); + + if ((stricmp(ret,"jpg")) == 0 || (stricmp(ret,"jpeg")) == 0) { + strcpy(ret,"image/jpeg"); + LOG(("jpeg image")); + + } else if ((stricmp(ret,"png")) == 0) { + strcpy(ret,"image/png"); + LOG(("png image")); + + } /*else if ((stricmp(ret, "gif")) == 0) { + ret = "image/gif"; + }*/ else { + + ret = NULL; + } + + return ret; +} diff --git a/riscos/plugin.h b/riscos/plugin.h new file mode 100644 index 000000000..98b94c4da --- /dev/null +++ b/riscos/plugin.h @@ -0,0 +1,26 @@ +/** + * $Id: plugin.h,v 1.1 2003/05/31 18:47:00 jmb Exp $ + */ + +#ifndef _NETSURF_RISCOS_PLUGIN_H_ +#define _NETSURF_RISCOS_PLUGIN_H_ + +struct plugin_object { + + char* data; + char* src; + char* type; + char* codetype; + char* codebase; + char* classid; + char* paramds; /* very likely to change */ + unsigned int* width; + unsigned int* height; + +}; + + +void plugin_fetch(struct content* content, char* url, struct box* box, + struct plugin_object* po); + +#endif -- cgit v1.2.3