From 66fa843389023a8ec4dd37e60bccea97d64e9b10 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 13 Mar 2013 10:50:11 +0100 Subject: [PATCH] Added support for . Hidden form fields are aded to the page attribute buffer like text form fields so there's no need for special treatment in formsubmit(). However they are not added as widgets to the window so there's no user interaction. --- apps/webbrowser/html-strings | 3 +- apps/webbrowser/html-strings.c | 3 ++ apps/webbrowser/html-strings.h | 1 + apps/webbrowser/htmlparser.c | 25 +++++++------ apps/webbrowser/htmlparser.h | 15 ++++---- apps/webbrowser/www.c | 65 ++++++++++++++++++---------------- 6 files changed, 63 insertions(+), 49 deletions(-) diff --git a/apps/webbrowser/html-strings b/apps/webbrowser/html-strings index 0c9a7c99f..e56d8f600 100644 --- a/apps/webbrowser/html-strings +++ b/apps/webbrowser/html-strings @@ -32,4 +32,5 @@ html_action "action\0" html_name "name\0" html_text "text\0" html_size "size\0" -html_image "image\0" \ No newline at end of file +html_image "image\0" +html_hidden "hidden\0" diff --git a/apps/webbrowser/html-strings.c b/apps/webbrowser/html-strings.c index 567d9ce4a..51fc3f1cd 100644 --- a/apps/webbrowser/html-strings.c +++ b/apps/webbrowser/html-strings.c @@ -103,3 +103,6 @@ const char html_size[6] = const char html_image[7] = /* "image\0" */ {0x69, 0x6d, 0x61, 0x67, 0x65, 00, }; +const char html_hidden[8] = +/* "hidden\0" */ +{0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 00, }; diff --git a/apps/webbrowser/html-strings.h b/apps/webbrowser/html-strings.h index ec8587997..cf09c0107 100644 --- a/apps/webbrowser/html-strings.h +++ b/apps/webbrowser/html-strings.h @@ -33,3 +33,4 @@ extern const char html_name[6]; extern const char html_text[6]; extern const char html_size[6]; extern const char html_image[7]; +extern const char html_hidden[8]; diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index 2e2727993..725aae433 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -149,20 +149,20 @@ struct htmlparser_state { unsigned char tagptr; char tagattr[20]; unsigned char tagattrptr; - char tagattrparam[WWW_CONF_MAX_URLLEN]; + char tagattrparam[WWW_CONF_MAX_URLLEN + 1]; unsigned char tagattrparamptr; unsigned char lastchar, quotechar; unsigned char majorstate, lastmajorstate; - char linkurl[WWW_CONF_MAX_URLLEN]; + char linkurl[WWW_CONF_MAX_URLLEN + 1]; char word[WWW_CONF_WEBPAGE_WIDTH]; unsigned char wordlen; #if WWW_CONF_FORMS - char formaction[WWW_CONF_MAX_FORMACTIONLEN]; + char formaction[WWW_CONF_MAX_FORMACTIONLEN + 1]; unsigned char inputtype; - char inputname[WWW_CONF_MAX_INPUTNAMELEN]; - char inputvalue[WWW_CONF_MAX_INPUTVALUELEN]; + char inputname[WWW_CONF_MAX_INPUTNAMELEN + 1]; + char inputvalue[WWW_CONF_MAX_INPUTVALUELEN + 1]; unsigned char inputvaluesize; #endif /* WWW_CONF_FORMS */ }; @@ -241,7 +241,10 @@ static void init_input(void) { s.inputtype = HTMLPARSER_INPUTTYPE_NONE; - s.inputname[0] = s.inputvalue[0] = 0; + s.inputname[0] = s.inputvalue[0] = + s.formaction[WWW_CONF_MAX_FORMACTIONLEN] = + s.inputname[WWW_CONF_MAX_INPUTNAMELEN] = + s.inputvalue[WWW_CONF_MAX_INPUTVALUELEN] = 0; s.inputvaluesize = 20; /* De facto default size */ } #endif /* WWW_CONF_FORMS */ @@ -474,8 +477,8 @@ parse_tag(void) switch(s.inputtype) { case HTMLPARSER_INPUTTYPE_NONE: case HTMLPARSER_INPUTTYPE_TEXT: - s.inputvalue[s.inputvaluesize] = 0; - htmlparser_inputfield(s.inputvaluesize, s.inputvalue, s.inputname); + case HTMLPARSER_INPUTTYPE_HIDDEN: + htmlparser_inputfield(s.inputtype, s.inputvaluesize, s.inputvalue, s.inputname); break; case HTMLPARSER_INPUTTYPE_SUBMIT: case HTMLPARSER_INPUTTYPE_IMAGE: @@ -492,14 +495,16 @@ parse_tag(void) s.inputtype = HTMLPARSER_INPUTTYPE_IMAGE; } else if(strncmp(s.tagattrparam, html_text, sizeof(html_text)) == 0) { s.inputtype = HTMLPARSER_INPUTTYPE_TEXT; + } else if(strncmp(s.tagattrparam, html_hidden, sizeof(html_hidden)) == 0) { + s.inputtype = HTMLPARSER_INPUTTYPE_HIDDEN; } else { s.inputtype = HTMLPARSER_INPUTTYPE_OTHER; } } else if(strncmp(s.tagattr, html_name, sizeof(html_name)) == 0) { strncpy(s.inputname, s.tagattrparam, WWW_CONF_MAX_INPUTNAMELEN); } else if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 && - s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) { - strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN); + s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) { + strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN); } else if(strncmp(s.tagattr, html_value, sizeof(html_value)) == 0) { strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN); } else if(strncmp(s.tagattr, html_size, sizeof(html_size)) == 0) { diff --git a/apps/webbrowser/htmlparser.h b/apps/webbrowser/htmlparser.h index 245a02d5c..a42d43c18 100644 --- a/apps/webbrowser/htmlparser.h +++ b/apps/webbrowser/htmlparser.h @@ -41,19 +41,20 @@ void htmlparser_link(char *text, unsigned char textlen, char *url); void htmlparser_form(char *action); void htmlparser_submitbutton(char *value, char *name); -void htmlparser_inputfield(unsigned char size, +void htmlparser_inputfield(unsigned char type, + unsigned char size, char *value, char *name); void htmlparser_newline(void); void htmlparser_word(char *word, unsigned char wordlen); -#define HTMLPARSER_INPUTTYPE_NONE 0 -#define HTMLPARSER_INPUTTYPE_TEXT 1 -#define HTMLPARSER_INPUTTYPE_PASSWORD 2 -#define HTMLPARSER_INPUTTYPE_SUBMIT 3 -#define HTMLPARSER_INPUTTYPE_IMAGE 4 -#define HTMLPARSER_INPUTTYPE_OTHER 5 +#define HTMLPARSER_INPUTTYPE_NONE 0 +#define HTMLPARSER_INPUTTYPE_TEXT 1 +#define HTMLPARSER_INPUTTYPE_HIDDEN 2 +#define HTMLPARSER_INPUTTYPE_SUBMIT 3 +#define HTMLPARSER_INPUTTYPE_IMAGE 4 +#define HTMLPARSER_INPUTTYPE_OTHER 5 /* Functions. */ diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c index 53d8becf7..b53e2834a 100644 --- a/apps/webbrowser/www.c +++ b/apps/webbrowser/www.c @@ -684,7 +684,7 @@ webclient_datahandler(char *data, uint16_t len) } /*-----------------------------------------------------------------------------------*/ static void CC_FASTCALL -add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char type, +add_pagewidget(char *text, unsigned char size, char *attrib, unsigned char type, unsigned char border) { char *wptr; @@ -694,16 +694,13 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty return; } - if(textlen + border == 0) { - return; - } - - maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border); + maxwidth = size ? WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border) + : WWW_CONF_WEBPAGE_WIDTH; /* If the text of the link is too long so that it does not fit into the width of the current window, counting from the current x coordinate, we first try to jump to the next line. */ - if(textlen + x > maxwidth) { + if(size + x > maxwidth) { htmlparser_newline(); if(!loading) { return; @@ -714,9 +711,9 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty XXX: this is not really the right thing to do, we should probably either make a link into a multiline link, or add multiple buttons. But this will do for now. */ - if(textlen > maxwidth) { + if(size > maxwidth) { text[maxwidth] = 0; - textlen = maxwidth; + size = maxwidth; } if(firsty == pagey) { @@ -727,17 +724,16 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty drawing area and reference it from there. */ wptr[0] = 0; wptr += border; - memcpy(wptr, text, textlen); - wptr[textlen] = 0; - wptr[textlen + border] = ' '; + memcpy(wptr, text, size); + wptr[size] = 0; + wptr[size + border] = ' '; switch(type) { case CTK_WIDGET_HYPERLINK: { - struct linkattrib *linkptr; - - linkptr = (struct linkattrib *)add_pageattrib(sizeof(struct linkattrib) /* incl 1 attrib char */ + attriblen); + struct linkattrib *linkptr = + (struct linkattrib *)add_pageattrib(sizeof(struct linkattrib) /* incl 1 attrib char */ + attriblen); if(linkptr != NULL) { - CTK_HYPERLINK_NEW(&linkptr->hyperlink, x, y + 3, textlen, wptr, linkptr->url); + CTK_HYPERLINK_NEW(&linkptr->hyperlink, x, y + 3, size, wptr, linkptr->url); strcpy(linkptr->url, attrib); CTK_WIDGET_SET_FLAG(&linkptr->hyperlink, CTK_WIDGET_FLAG_MONOSPACE); CTK_WIDGET_ADD(&mainwindow, &linkptr->hyperlink); @@ -746,11 +742,10 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty } #if WWW_CONF_FORMS case CTK_WIDGET_BUTTON: { - struct submitattrib *submitptr; - - submitptr = (struct submitattrib *)add_pageattrib(sizeof(struct submitattrib) /* incl 1 attrib char */ + attriblen); + struct submitattrib *submitptr = + (struct submitattrib *)add_pageattrib(sizeof(struct submitattrib) /* incl 1 attrib char */ + attriblen); if(submitptr != NULL) { - CTK_BUTTON_NEW((struct ctk_button *)&submitptr->button, x, y + 3, textlen, wptr); + CTK_BUTTON_NEW((struct ctk_button *)&submitptr->button, x, y + 3, size, wptr); add_forminput((struct inputattrib *)submitptr); submitptr->formptr = formptr; strcpy(submitptr->name, attrib); @@ -760,18 +755,20 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty break; } case CTK_WIDGET_TEXTENTRY: { - struct textattrib *textptr; - - textptr = (struct textattrib *)add_pageattrib(sizeof(struct textattrib) /* incl 1 attrib char */ + attriblen + WWW_CONF_MAX_INPUTVALUELEN); + struct textattrib *textptr = + (struct textattrib *)add_pageattrib(sizeof(struct textattrib) /* incl 1 attrib char */ + attriblen + + (size ? WWW_CONF_MAX_INPUTVALUELEN : strlen(text)) + 1); if(textptr != NULL) { - CTK_TEXTENTRY_NEW((struct ctk_textentry *)&textptr->textentry, x, y + 3, textlen, 1, + CTK_TEXTENTRY_NEW((struct ctk_textentry *)&textptr->textentry, x, y + 3, size, 1, textptr->name + attriblen + 1, WWW_CONF_MAX_INPUTVALUELEN); add_forminput((struct inputattrib *)textptr); textptr->formptr = formptr; strcpy(textptr->textentry.text, text); strcpy(textptr->name, attrib); - CTK_WIDGET_SET_FLAG(&textptr->textentry, CTK_WIDGET_FLAG_MONOSPACE); - CTK_WIDGET_ADD(&mainwindow, &textptr->textentry); + if(size) { + CTK_WIDGET_SET_FLAG(&textptr->textentry, CTK_WIDGET_FLAG_MONOSPACE); + CTK_WIDGET_ADD(&mainwindow, &textptr->textentry); + } } break; } @@ -780,11 +777,13 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty } /* Increase the x coordinate with the length of the link text plus the extra space behind it and the CTK button markers. */ - textlen = textlen + 1 + 2 * border; - x += textlen; + if(size) { + size += 1 + 2 * border; + } + x += size; if(firsty == pagey) { - webpageptr += textlen; + webpageptr += size; } if(x == WWW_CONF_WEBPAGE_WIDTH) { @@ -868,9 +867,13 @@ htmlparser_submitbutton(char *text, char *name) } /*-----------------------------------------------------------------------------------*/ void -htmlparser_inputfield(unsigned char size, char *text, char *name) +htmlparser_inputfield(unsigned char type, unsigned char size, char *text, char *name) { - add_pagewidget(text, size, name, CTK_WIDGET_TEXTENTRY, 1); + if(type == HTMLPARSER_INPUTTYPE_HIDDEN) { + add_pagewidget(text, 0, name, CTK_WIDGET_TEXTENTRY, 0); + } else { + add_pagewidget(text, size, name, CTK_WIDGET_TEXTENTRY, 1); + } } /*-----------------------------------------------------------------------------------*/ static void CC_FASTCALL