From 10258bb8f2049828553f674b728c184055936fa4 Mon Sep 17 00:00:00 2001 From: jcid Date: Fri, 30 May 2008 23:47:31 +0200 Subject: - html.cc cleanups --- src/html.cc | 347 ++++++++++++++++++++++++++++++++---------------------------- src/msg.h | 6 -- 2 files changed, 187 insertions(+), 166 deletions(-) diff --git a/src/html.cc b/src/html.cc index acacc5fc..61287015 100644 --- a/src/html.cc +++ b/src/html.cc @@ -74,6 +74,12 @@ // Top of the parsing stack #define S_TOP(html) (html->stack->getRef(html->stack->size()-1)) +// Add a bug-meter message. +#define BUG_MSG(...) \ + D_STMT_START { \ + html->bugMessage(__VA_ARGS__); \ + } D_STMT_END + /*----------------------------------------------------------------------------- * Name spaces *---------------------------------------------------------------------------*/ @@ -243,9 +249,9 @@ public: ~DilloHtmlForm (); inline DilloHtmlInput *getCurrentInput (); DilloHtmlInput *getInput (void *v_resource); + DilloHtmlInput *getRadioInput (const char *name); void reset (); void addInput(DilloHtmlInputType type, - Widget *widget, Embed *embed, const char *name, const char *init_str, @@ -266,10 +272,13 @@ struct _DilloHtmlSelect { }; class DilloHtmlInput { + + // DilloHtmlForm::addInput() calls connectTo() + friend class DilloHtmlForm; + public: //BUG: for now everything is public DilloHtmlInputType type; - void *widget; /* May be a FLTKWidget or a Dw Widget. */ - void *embed; /* May be NULL */ + Embed *embed; /* May be NULL (think: hidden input) */ char *name; char *init_str; /* note: some overloading - for buttons, init_str is simply the value of the button; for text @@ -279,9 +288,11 @@ public: //BUG: for now everything is public Dstr *file_data; /* only meaningful for file inputs. todo: may become a list... */ +private: + void connectTo(form::Form *form_receiver); + public: DilloHtmlInput (DilloHtmlInputType type, - Widget *widget, Embed *embed, const char *name, const char *init_str, @@ -374,6 +385,7 @@ private: public: DilloHtml(BrowserWindow *bw, const DilloUrl *url, const char *content_type); ~DilloHtml(); + void bugMessage(const char *format, ... ); void connectSignals(dw::core::Widget *dw); void write(char *Buf, int BufSize, int Eof); int getCurTagLineNumber(); @@ -448,17 +460,17 @@ extern const TagInfo Tags[]; /* * Collect HTML error strings. */ -static void Html_msg(DilloHtml *html, const char *format, ... ) +void DilloHtml::bugMessage(const char *format, ... ) { va_list argp; - dStr_sprintfa(html->bw->page_bugs, + dStr_sprintfa(bw->page_bugs, "HTML warning: line %d, ", - html->getCurTagLineNumber()); + getCurTagLineNumber()); va_start(argp, format); - dStr_vsprintfa(html->bw->page_bugs, format, argp); + dStr_vsprintfa(bw->page_bugs, format, argp); va_end(argp); - a_UIcmd_set_bug_prog(html->bw, ++html->bw->num_page_bugs); + a_UIcmd_set_bug_prog(bw, ++bw->num_page_bugs); } /* @@ -481,16 +493,16 @@ static DilloUrl *Html_url_new(DilloHtml *html, const char *suffix = (n_ic) > 1 ? "s" : ""; n_ic_spc = URL_ILLEGAL_CHARS_SPC(url); if (n_ic == n_ic_spc) { - MSG_HTML("URL has %d illegal character%s (%d space%s)\n", - n_ic, suffix, n_ic_spc, suffix); + BUG_MSG("URL has %d illegal character%s (%d space%s)\n", + n_ic, suffix, n_ic_spc, suffix); } else if (n_ic_spc == 0) { - MSG_HTML("URL has %d illegal character%s (%d in {00-1F, 7F} range)\n", - n_ic, suffix, n_ic); + BUG_MSG("URL has %d illegal character%s (%d in {00-1F, 7F} range)\n", + n_ic, suffix, n_ic); } else { - MSG_HTML("URL has %d illegal character%s: " - "%d space%s, and %d in {00-1F, 7F} range\n", - n_ic, suffix, - n_ic_spc, n_ic_spc > 1 ? "s" : "", n_ic-n_ic_spc); + BUG_MSG("URL has %d illegal character%s: " + "%d space%s, and %d in {00-1F, 7F} range\n", + n_ic, suffix, + n_ic_spc, n_ic_spc > 1 ? "s" : "", n_ic-n_ic_spc); } } return url; @@ -1224,7 +1236,6 @@ void DilloHtmlForm::reset () * Add a new input, setting the initial values. */ void DilloHtmlForm::addInput(DilloHtmlInputType type, - Widget *widget, Embed *embed, const char *name, const char *init_str, @@ -1234,7 +1245,8 @@ void DilloHtmlForm::addInput(DilloHtmlInputType type, _MSG("name=[%s] init_str=[%s] init_val=[%d]\n", name, init_str, init_val); DilloHtmlInput *input = - new DilloHtmlInput (type,widget,embed,name,init_str,select,init_val); + new DilloHtmlInput (type,embed,name,init_str,select,init_val); + input->connectTo (form_receiver); int ni = inputs->size (); inputs->increase (); inputs->set (ni,input); @@ -1254,7 +1266,6 @@ void DilloHtmlForm::addInput(DilloHtmlInputType type, * Create and initialize a new DilloHtmlInput class */ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, - Widget *widget2, Embed *embed2, const char *name2, const char *init_str2, @@ -1262,7 +1273,6 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, bool_t init_val2) { type = type2; - widget = widget2; embed = embed2; name = (name2) ? dStrdup(name2) : NULL; init_str = (init_str2) ? dStrdup(init_str2) : NULL; @@ -1297,6 +1307,43 @@ DilloHtmlInput::~DilloHtmlInput () } } +/* + * Connect to a receiver. + */ +void DilloHtmlInput::connectTo(form::Form *form_receiver) +{ + Resource *resource = NULL; + if (embed) + resource = embed->getResource (); + switch (type) { + case DILLO_HTML_INPUT_UNKNOWN: + case DILLO_HTML_INPUT_HIDDEN: + case DILLO_HTML_INPUT_CHECKBOX: + case DILLO_HTML_INPUT_RADIO: + case DILLO_HTML_INPUT_BUTTON: + case DILLO_HTML_INPUT_TEXTAREA: + case DILLO_HTML_INPUT_SELECT: + case DILLO_HTML_INPUT_SEL_LIST: + // do nothing + break; + case DILLO_HTML_INPUT_TEXT: + case DILLO_HTML_INPUT_PASSWORD: + case DILLO_HTML_INPUT_INDEX: + if (resource) + resource->connectActivate (form_receiver); + break; + case DILLO_HTML_INPUT_SUBMIT: + case DILLO_HTML_INPUT_RESET: + case DILLO_HTML_INPUT_BUTTON_SUBMIT: + case DILLO_HTML_INPUT_BUTTON_RESET: + case DILLO_HTML_INPUT_IMAGE: + case DILLO_HTML_INPUT_FILE: + if (resource) + ((ButtonResource *)resource)->connectClicked (form_receiver); + break; + } +} + /* * Reset to the initial value. */ @@ -1306,13 +1353,13 @@ void DilloHtmlInput::reset () case DILLO_HTML_INPUT_TEXT: case DILLO_HTML_INPUT_PASSWORD: EntryResource *entryres; - entryres = (EntryResource*)((Embed*)widget)->getResource(); + entryres = (EntryResource*)embed->getResource(); entryres->setText(init_str ? init_str : ""); break; case DILLO_HTML_INPUT_CHECKBOX: case DILLO_HTML_INPUT_RADIO: ToggleButtonResource *tb_r; - tb_r = (ToggleButtonResource*)((Embed*)widget)->getResource(); + tb_r = (ToggleButtonResource*)embed->getResource(); tb_r->setActivated(init_val); break; case DILLO_HTML_INPUT_SELECT: @@ -1350,13 +1397,13 @@ void DilloHtmlInput::reset () MultiLineTextResource *textres; textres = (MultiLineTextResource*) - ((Embed*)widget)->getResource(); + embed->getResource(); textres->setText(init_str ? init_str : ""); } break; case DILLO_HTML_INPUT_FILE: { LabelButtonResource *lbr = - (LabelButtonResource *)((Embed*)widget)->getResource(); + (LabelButtonResource *)embed->getResource(); lbr->setLabel(init_str); break; } @@ -1532,7 +1579,7 @@ static int Html_parse_entity(DilloHtml *html, const char *token, if (!isocode || errno || isocode > 0xffff) { /* this catches null bytes, errors and codes >= 0xFFFF */ - MSG_HTML("numeric character reference out of range\n"); + BUG_MSG("numeric character reference out of range\n"); isocode = -2; } @@ -1540,7 +1587,7 @@ static int Html_parse_entity(DilloHtml *html, const char *token, if (*s == ';') s++; else if (prefs.show_extra_warnings) - MSG_HTML("numeric character reference without trailing ';'\n"); + BUG_MSG("numeric character reference without trailing ';'\n"); } } else if (isalpha(*s)) { @@ -1552,7 +1599,7 @@ static int Html_parse_entity(DilloHtml *html, const char *token, if ((i = Html_entity_search(tok)) == -1) { if ((html->DocType == DT_HTML && html->DocTypeVersion == 4.01f) || html->DocType == DT_XHTML) - MSG_HTML("undefined character entity '%s'\n", tok); + BUG_MSG("undefined character entity '%s'\n", tok); isocode = -3; } else isocode = Entities[i].isocode; @@ -1560,7 +1607,7 @@ static int Html_parse_entity(DilloHtml *html, const char *token, if (c == ';') s++; else if (prefs.show_extra_warnings) - MSG_HTML("character entity reference without trailing ';'\n"); + BUG_MSG("character entity reference without trailing ';'\n"); } *entsize = s-tok+1; @@ -1570,7 +1617,7 @@ static int Html_parse_entity(DilloHtml *html, const char *token, /* TODO: remove this hack. */ isocode = Html_ms_stupid_quotes_2ucs(isocode); } else if (isocode == -1 && prefs.show_extra_warnings) - MSG_HTML("literal '&'\n"); + BUG_MSG("literal '&'\n"); return isocode; } @@ -1655,7 +1702,7 @@ static void Html_process_space(DilloHtml *html, const char *space, break; case '\t': if (prefs.show_extra_warnings) - MSG_HTML("TAB character inside
\n");
+               BUG_MSG("TAB character inside 
\n");
             offset = TAB_SIZE - html->pre_column % TAB_SIZE;
             spaceCnt += offset;
             html->pre_column += offset;
@@ -1881,8 +1928,8 @@ static void Html_tag_cleanup_at_close(DilloHtml *html, int TagIdx)
          /* Warn when we decide to close an open tag (for !w3c_mode) */
          if (html->stack->size() > stack_idx + 1 &&
              Tags[toptag_idx].EndTag != 'O')
-            MSG_HTML("  - forcing close of open tag: <%s>\n",
-                     Tags[toptag_idx].name);
+            BUG_MSG("  - forcing close of open tag: <%s>\n",
+                    Tags[toptag_idx].name);
 
          /* Close this and only this tag */
          html->CloseOneTag = TRUE;
@@ -1891,11 +1938,11 @@ static void Html_tag_cleanup_at_close(DilloHtml *html, int TagIdx)
 
    } else {
       if (stack_idx == 0) {
-         MSG_HTML("unexpected closing tag: .\n", Tags[new_idx].name);
+         BUG_MSG("unexpected closing tag: .\n", Tags[new_idx].name);
       } else {
-         MSG_HTML("unexpected closing tag: . -- expected \n",
-                  Tags[new_idx].name,
-                  Tags[html->stack->getRef(stack_idx)->tag_idx].name);
+         BUG_MSG("unexpected closing tag: . -- expected \n",
+                 Tags[new_idx].name,
+                 Tags[html->stack->getRef(stack_idx)->tag_idx].name);
       }
    }
 }
@@ -1966,7 +2013,7 @@ static Length Html_parse_length (DilloHtml *html, const char *attr)
    else {
       /* allow only whitespaces */
       if (*end && !isspace (*end)) {
-         MSG_HTML("Garbage after length: %s\n", attr);
+         BUG_MSG("Garbage after length: %s\n", attr);
          return LENGTH_AUTO;
       }
    }
@@ -1986,7 +2033,7 @@ static int32_t
    int32_t color = a_Color_parse(subtag, default_color, &err);
 
    if (err) {
-      MSG_HTML("color is not in \"#RRGGBB\" format\n");
+      BUG_MSG("color is not in \"#RRGGBB\" format\n");
    }
    return color;
 }
@@ -2006,8 +2053,8 @@ static int
          break;
 
    if (val[i] || !isalpha(val[0]))
-      MSG_HTML("'%s' value is not of the form "
-               "[A-Za-z][A-Za-z0-9:_.-]*\n", attrname);
+      BUG_MSG("'%s' value is not of the form "
+              "[A-Za-z][A-Za-z0-9:_.-]*\n", attrname);
 
    return !(val[i]);
 }
@@ -2108,7 +2155,7 @@ static void Html_tag_open_html(DilloHtml *html, const char *tag, int tagsize)
    ++html->Num_HTML;
 
    if (html->Num_HTML > 1) {
-      MSG_HTML("HTML element was already open\n");
+      BUG_MSG("HTML element was already open\n");
    }
 }
 
@@ -2131,7 +2178,7 @@ static void Html_tag_close_html(DilloHtml *html, int TagIdx)
 static void Html_tag_open_head(DilloHtml *html, const char *tag, int tagsize)
 {
    if (html->InFlags & IN_BODY || html->Num_BODY > 0) {
-      MSG_HTML("HEAD element must go before the BODY section\n");
+      BUG_MSG("HEAD element must go before the BODY section\n");
       html->ReqTagClose = TRUE;
       return;
    }
@@ -2141,7 +2188,7 @@ static void Html_tag_open_head(DilloHtml *html, const char *tag, int tagsize)
    ++html->Num_HEAD;
 
    if (html->Num_HEAD > 1) {
-      MSG_HTML("HEAD element was already open\n");
+      BUG_MSG("HEAD element was already open\n");
    }
 }
 
@@ -2154,7 +2201,7 @@ static void Html_tag_close_head(DilloHtml *html, int TagIdx)
 {
    if (html->InFlags & IN_HEAD) {
       if (html->Num_TITLE == 0)
-         MSG_HTML("HEAD section lacks the TITLE element\n");
+         BUG_MSG("HEAD section lacks the TITLE element\n");
    
       html->InFlags &= ~IN_HEAD;
    }
@@ -2182,7 +2229,7 @@ static void Html_tag_close_title(DilloHtml *html, int TagIdx)
       a_UIcmd_set_page_title(html->bw, html->Stash->str);
       a_History_set_title(NAV_TOP_UIDX(html->bw),html->Stash->str);
    } else {
-      MSG_HTML("the TITLE element must be inside the HEAD section\n");
+      BUG_MSG("the TITLE element must be inside the HEAD section\n");
    }
    Html_pop_tag(html, TagIdx);
 }
@@ -2243,12 +2290,12 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize)
    ++html->Num_BODY;
 
    if (html->Num_BODY > 1) {
-      MSG_HTML("BODY element was already open\n");
+      BUG_MSG("BODY element was already open\n");
       return;
    }
    if (html->InFlags & IN_HEAD) {
       /* if we're here, it's bad XHTML, no need to recover */
-      MSG_HTML("unclosed HEAD element\n");
+      BUG_MSG("unclosed HEAD element\n");
    }
 
    textblock = DW2TB(html->dw);
@@ -2434,11 +2481,11 @@ static void Html_tag_open_table_cell(DilloHtml *html,
 
    switch (S_TOP(html)->table_mode) {
    case DILLO_HTML_TABLE_MODE_NONE:
-      MSG_HTML(" or  outside \n");
+      BUG_MSG("
or outside \n"); return; case DILLO_HTML_TABLE_MODE_TOP: - MSG_HTML("\n"); + BUG_MSG("\n"); /* a_Dw_table_add_cell takes care that dillo does not crash. */ /* continues */ case DILLO_HTML_TABLE_MODE_TR: @@ -2761,11 +2808,11 @@ static void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize) char *type; if (!(html->InFlags & IN_FORM)) { - MSG_HTML("
or outside
or outside