From 311c488f5a29e056fbdc5951bf47c9237ba7dcd1 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 26 Sep 2003 23:22:00 +0000 Subject: [project @ 2003-09-26 23:22:00 by bursa] Implement button element and more work on input element. svn path=/import/netsurf/; revision=322 --- render/box.c | 77 +++++++++++++++++++++++++++++++++++++++++---------------- render/box.h | 13 ++++------ render/layout.c | 26 +++++++++++++------ 3 files changed, 79 insertions(+), 37 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index 749815f15..0c67fa8df 100644 --- a/render/box.c +++ b/render/box.c @@ -25,6 +25,7 @@ #endif #define NDEBUG #include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" @@ -64,7 +65,9 @@ static struct result box_textarea(xmlNode *n, struct status *status, struct css_style *style); static struct result box_select(xmlNode *n, struct status *status, struct css_style *style); -struct result box_input(xmlNode *n, struct status *status, +static struct result box_input(xmlNode *n, struct status *status, + struct css_style *style); +static struct result box_button(xmlNode *n, struct status *status, struct css_style *style); static void add_option(xmlNode* n, struct gui_gadget* current_select, char *text); static void box_normalise_block(struct box *block); @@ -100,7 +103,8 @@ static const struct element_entry element_table[] = { {"a", box_a}, {"applet", box_applet}, {"body", box_body}, - {"embed", box_embed}, + {"button", box_button}, + {"embed", box_embed}, {"form", box_form}, {"iframe", box_iframe}, {"img", box_image}, @@ -703,6 +707,7 @@ struct result box_textarea(xmlNode *n, struct status *status, box->gadget = xcalloc(1, sizeof(struct gui_gadget)); box->gadget->type = GADGET_TEXTAREA; box->gadget->form = status->current_form; + style->display = CSS_DISPLAY_INLINE_BLOCK; /* split the content at newlines and make an inline container with an * inline box for each line */ @@ -918,20 +923,24 @@ struct result box_input(xmlNode *n, struct status *status, } else if (stricmp(type, "submit") == 0 || stricmp(type, "reset") == 0) { - box = box_create(style, NULL, 0); - box->gadget = gadget = xcalloc(1, sizeof(struct gui_gadget)); - gadget->type = GADGET_ACTIONBUTTON; - - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { - gadget->data.actionbutt.label = s; - } + struct result result = box_button(n, status, style); + struct box *inline_container, *inline_box; + box = result.box; + inline_container = box_create(0, 0, 0); + inline_container->type = BOX_INLINE_CONTAINER; + inline_box = box_create(style, 0, 0); + inline_box->type = BOX_INLINE; + inline_box->style_clone = 1; + if (box->gadget->value) + inline_box->text = tolat1(box->gadget->value); + else if (box->gadget->type == GADGET_SUBMIT) + inline_box->text = xstrdup(messages_get("Form_Submit")); else - { - gadget->data.actionbutt.label = xstrdup(type); - gadget->data.actionbutt.label[0] = toupper(type[0]); - } - - box->gadget->data.actionbutt.butttype = strdup(type); + inline_box->text = xstrdup(messages_get("Form_Reset")); + inline_box->length = strlen(inline_box->text); + inline_box->font = font_open(status->content->data.html.fonts, style); + box_add_child(inline_container, inline_box); + box_add_child(box, inline_container); } else if (stricmp(type, "image") == 0) { @@ -962,14 +971,42 @@ struct result box_input(xmlNode *n, struct status *status, if (gadget != 0) { gadget->form = status->current_form; - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name"))) - gadget->name = s; + gadget->name = (char *) xmlGetProp(n, (const xmlChar *) "name"); add_gadget_element(status->elements, gadget); } return (struct result) {box, 0}; } +struct result box_button(xmlNode *n, struct status *status, + struct css_style *style) +{ + char *type = (char *) xmlGetProp(n, (const xmlChar *) "type"); + struct box *box = box_create(style, 0, 0); + style->display = CSS_DISPLAY_INLINE_BLOCK; + + if (!type || strcasecmp(type, "submit") == 0) { + box->gadget = xcalloc(1, sizeof(struct gui_gadget)); + box->gadget->type = GADGET_SUBMIT; + } else if (strcasecmp(type, "reset") == 0) { + box->gadget = xcalloc(1, sizeof(struct gui_gadget)); + box->gadget->type = GADGET_RESET; + } else { + /* type="button" or unknown: just render the contents */ + xmlFree(type); + return (struct result) {box, 1}; + } + + if (type) + xmlFree(type); + + box->gadget->form = status->current_form; + box->gadget->name = (char *) xmlGetProp(n, (const xmlChar *) "name"); + box->gadget->value = (char *) xmlGetProp(n, (const xmlChar *) "value"); + + return (struct result) {box, 1}; +} + /** * print a box tree to standard output @@ -1425,6 +1462,8 @@ void gadget_free(struct gui_gadget* g) if (g->name != 0) xmlFree(g->name); + free(g->value); + free(g->initial_value); switch (g->type) { @@ -1452,10 +1491,6 @@ void gadget_free(struct gui_gadget* g) if (g->data.password.text != 0) xmlFree(g->data.password.text); break; - case GADGET_ACTIONBUTTON: - if (g->data.actionbutt.label != 0) - xmlFree(g->data.actionbutt.label); - break; case GADGET_IMAGE: if (g->data.image.n != 0) xmlFree(g->data.image.n); diff --git a/render/box.h b/render/box.h index 9e8ce0599..0dad5400d 100644 --- a/render/box.h +++ b/render/box.h @@ -43,9 +43,11 @@ struct box; struct gui_gadget { enum { GADGET_HIDDEN = 0, GADGET_TEXTBOX, GADGET_RADIO, GADGET_CHECKBOX, - GADGET_SELECT, GADGET_TEXTAREA, GADGET_ACTIONBUTTON, - GADGET_IMAGE, GADGET_PASSWORD } type; - char* name; + GADGET_SELECT, GADGET_TEXTAREA, + GADGET_IMAGE, GADGET_PASSWORD, GADGET_SUBMIT, GADGET_RESET } type; + char *name; + char *value; + char *initial_value; struct form* form; union { struct { @@ -61,11 +63,6 @@ struct gui_gadget { char* text; int size; } password; - struct { - char* butttype; - char* label; - int pressed; - } actionbutt; struct { char* name; char* value; diff --git a/render/layout.c b/render/layout.c index 3ea45c789..4c9f2a832 100644 --- a/render/layout.c +++ b/render/layout.c @@ -314,12 +314,6 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long x += b->width + b->space ? b->font->space_width : 0; else x += b->width; - - } else if (b->type == BOX_INLINE_BLOCK) { - layout_block(b, width, b, 0, 0); - if (height < b->height) - height = b->height; - x += b->width; } } @@ -331,6 +325,21 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long /* pass 2: place boxes in line */ for (x = x_previous = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) { if (b->type == BOX_INLINE || b->type == BOX_INLINE_BLOCK) { + if (b->type == BOX_INLINE_BLOCK) { + unsigned long w = width; + if (b->style->width.width == CSS_WIDTH_AUTO) { + calculate_widths(b); + if (b->max_width < width) + w = b->max_width; + else + w = b->min_width; + } + layout_node(b, w, b, 0, 0); + /* increase height to contain any floats inside */ + for (fl = b->float_children; fl != 0; fl = fl->next_float) + if (b->height < fl->y + fl->height) + b->height = fl->y + fl->height; + } x_previous = x; x += space_after; b->x = x; @@ -400,7 +409,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long x = x_previous; - if (!c->object && c->text) + if (!c->object && !c->gadget && c->text) space = strchr(c->text, ' '); if (space != 0 && c->length <= (unsigned int) (space - c->text)) /* space after end of string */ @@ -849,7 +858,8 @@ void calculate_inline_container_widths(struct box *box) child->width = font_width(child->font, child->text, child->length); max += child->width; - /* TODO: add spaces */ + if (child->next && child->space) + max += child->font->space_width; /* min = widest word */ i = 0; -- cgit v1.2.3