diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/form.cc | 13 | ||||
-rw-r--r-- | src/form.hh | 25 | ||||
-rw-r--r-- | src/html.cc | 205 | ||||
-rw-r--r-- | src/html_common.hh | 226 |
5 files changed, 267 insertions, 204 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index fd2549a2..303b86c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,6 +69,8 @@ dillo_fltk_SOURCES = \ plain.cc \ html.cc \ html.hh \ + form.cc \ + form.hh \ bookmark.c \ bookmark.h \ dns.c \ diff --git a/src/form.cc b/src/form.cc new file mode 100644 index 00000000..08062a7a --- /dev/null +++ b/src/form.cc @@ -0,0 +1,13 @@ +/* + * File: form.cc + * + * Copyright 2008 Jorge Arellano Cid <jcid@dillo.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + +#include "form.hh" +#include "html_common.hh" diff --git a/src/form.hh b/src/form.hh new file mode 100644 index 00000000..291bfd75 --- /dev/null +++ b/src/form.hh @@ -0,0 +1,25 @@ +#ifndef __FORM_HH__ +#define __FORM_HH__ + +/* + * Typedefs + */ + +typedef enum { + DILLO_HTML_METHOD_UNKNOWN, + DILLO_HTML_METHOD_GET, + DILLO_HTML_METHOD_POST +} DilloHtmlMethod; + +typedef enum { + DILLO_HTML_ENC_URLENCODING, + DILLO_HTML_ENC_MULTIPART +} DilloHtmlEnc; + +/* + * Classes + */ + +class DilloHtmlForm; + +#endif /* __FORM_HH__ */ diff --git a/src/html.cc b/src/html.cc index 8baa1d55..05371926 100644 --- a/src/html.cc +++ b/src/html.cc @@ -43,6 +43,7 @@ #include "prefs.h" #include "capi.h" #include "html.hh" +#include "html_common.hh" #include "dw/textblock.hh" #include "dw/bullet.hh" @@ -65,21 +66,6 @@ #define TAB_SIZE 8 #define dillo_dbg_rendering 0 -// Dw to Textblock -#define DW2TB(dw) ((Textblock*)dw) -// "html struct" to "Layout" -#define HT2LT(html) ((Layout*)html->bw->render_layout) -// "Image" to "Dw Widget" -#define IM2DW(Image) ((Widget*)Image->dw) -// 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 *---------------------------------------------------------------------------*/ @@ -94,31 +80,13 @@ using namespace dw::core::style; class DilloHtml; typedef void (*TagOpenFunct) (DilloHtml *Html, const char *Tag, int Tagsize); typedef void (*TagCloseFunct) (DilloHtml *Html, int TagIdx); -typedef struct _DilloLinkImage DilloLinkImage; typedef struct _DilloHtmlClass DilloHtmlClass; -typedef struct _DilloHtmlState DilloHtmlState; -class DilloHtmlForm; class DilloHtmlReceiver; class DilloHtmlInput; typedef struct _DilloHtmlSelect DilloHtmlSelect; typedef struct _DilloHtmlOption DilloHtmlOption; typedef enum { - DT_NONE, - DT_HTML, - DT_XHTML -} DilloHtmlDocumentType; - -typedef enum { - DILLO_HTML_PARSE_MODE_INIT = 0, - DILLO_HTML_PARSE_MODE_STASH, - DILLO_HTML_PARSE_MODE_STASH_AND_BODY, - DILLO_HTML_PARSE_MODE_VERBATIM, - DILLO_HTML_PARSE_MODE_BODY, - DILLO_HTML_PARSE_MODE_PRE -} DilloHtmlParseMode; - -typedef enum { SEEK_ATTR_START, MATCH_ATTR_NAME, SEEK_TOKEN_START, @@ -135,30 +103,6 @@ typedef enum { } DilloHtmlTagParsingFlags; typedef enum { - DILLO_HTML_TABLE_MODE_NONE, /* no table at all */ - DILLO_HTML_TABLE_MODE_TOP, /* outside of <tr> */ - DILLO_HTML_TABLE_MODE_TR, /* inside of <tr>, outside of <td> */ - DILLO_HTML_TABLE_MODE_TD /* inside of <td> */ -} DilloHtmlTableMode; - -typedef enum { - HTML_LIST_NONE, - HTML_LIST_UNORDERED, - HTML_LIST_ORDERED -} DilloHtmlListMode; - -typedef enum { - DILLO_HTML_METHOD_UNKNOWN, - DILLO_HTML_METHOD_GET, - DILLO_HTML_METHOD_POST -} DilloHtmlMethod; - -typedef enum { - DILLO_HTML_ENC_URLENCODING, - DILLO_HTML_ENC_MULTIPART -} DilloHtmlEnc; - -typedef enum { DILLO_HTML_INPUT_UNKNOWN, DILLO_HTML_INPUT_TEXT, DILLO_HTML_INPUT_PASSWORD, @@ -178,50 +122,9 @@ typedef enum { DILLO_HTML_INPUT_INDEX } DilloHtmlInputType; -typedef enum { - IN_NONE = 0, - IN_HTML = 1 << 0, - IN_HEAD = 1 << 1, - IN_BODY = 1 << 2, - IN_FORM = 1 << 3, - IN_SELECT = 1 << 4, - IN_OPTION = 1 << 5, - IN_TEXTAREA = 1 << 6, - IN_MAP = 1 << 7, - IN_PRE = 1 << 8, - IN_BUTTON = 1 << 9, - IN_LI = 1 << 10, -} DilloHtmlProcessingState; - /*----------------------------------------------------------------------------- * Data Structures *---------------------------------------------------------------------------*/ -struct _DilloLinkImage { - DilloUrl *url; - DilloImage *image; -}; - -struct _DilloHtmlState { - dw::core::style::Style *style, *table_cell_style; - DilloHtmlParseMode parse_mode; - DilloHtmlTableMode table_mode; - bool_t cell_text_align_set; - DilloHtmlListMode list_type; - int list_number; - - /* TagInfo index for the tag that's being processed */ - int tag_idx; - - dw::core::Widget *textblock, *table; - - /* This is used to align list items (especially in enumerated lists) */ - dw::core::Widget *ref_list_item; - - /* This is used for list items etc; if it is set to TRUE, breaks - have to be "handed over" (see Html_add_indented and - Html_eventually_pop_dw). */ - bool_t hand_over_break; -}; class DilloHtmlForm { friend class DilloHtmlReceiver; @@ -317,95 +220,6 @@ public: /*----------------------------------------------------------------------------- * Classes *---------------------------------------------------------------------------*/ -class DilloHtml { -private: - class HtmlLinkReceiver: public dw::core::Widget::LinkReceiver { - public: - DilloHtml *html; - - bool enter (dw::core::Widget *widget, int link, int img, int x, int y); - bool press (dw::core::Widget *widget, int link, int img, int x, int y, - dw::core::EventButton *event); - bool click (dw::core::Widget *widget, int link, int img, int x, int y, - dw::core::EventButton *event); - }; - HtmlLinkReceiver linkReceiver; - -public: //BUG: for now everything is public - - BrowserWindow *bw; - DilloUrl *page_url, *base_url; - dw::core::Widget *dw; /* this is duplicated in the stack */ - - /* -------------------------------------------------------------------*/ - /* Variables required at parsing time */ - /* -------------------------------------------------------------------*/ - size_t Buf_Consumed; /* amount of source from cache consumed */ - char *Start_Buf; - int Start_Ofs; - char *content_type, *charset; - bool stop_parser; - - size_t CurrTagOfs; - size_t OldTagOfs, OldTagLine; - - DilloHtmlDocumentType DocType; /* as given by DOCTYPE tag */ - float DocTypeVersion; /* HTML or XHTML version number */ - - misc::SimpleVector<DilloHtmlState> *stack; - - int InFlags; /* tracks which elements we are in */ - - Dstr *Stash; - bool_t StashSpace; - - int pre_column; /* current column, used in PRE tags with tabs */ - bool_t PreFirstChar; /* used to skip the first CR or CRLF in PRE tags */ - bool_t PrevWasCR; /* Flag to help parsing of "\r\n" in PRE tags */ - bool_t PrevWasOpenTag; /* Flag to help deferred parsing of white space */ - bool_t SPCPending; /* Flag to help deferred parsing of white space */ - bool_t PrevWasSPC; /* Flag to help handling collapsing white space */ - bool_t InVisitedLink; /* used to 'contrast_visited_colors' */ - bool_t ReqTagClose; /* Flag to help handling bad-formed HTML */ - bool_t CloseOneTag; /* Flag to help Html_tag_cleanup_at_close() */ - bool_t WordAfterLI; /* Flag to help ignoring the 1st <P> after <LI> */ - bool_t TagSoup; /* Flag to enable the parser's cleanup functions */ - char *NameVal; /* used for validation of "NAME" and "ID" in <A> */ - - /* element counters: used for validation purposes */ - uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE; - - Dstr *attr_data; /* Buffer for attribute value */ - - /* -------------------------------------------------------------------*/ - /* Variables required after parsing (for page functionality) */ - /* -------------------------------------------------------------------*/ - misc::SimpleVector<DilloHtmlForm*> *forms; - misc::SimpleVector<DilloUrl*> *links; - misc::SimpleVector<DilloLinkImage*> *images; - ImageMapsList maps; - - int32_t link_color; - int32_t visited_color; - -private: - bool_t parse_finished; - void freeParseData(); - void initDw(); /* Used by the constructor */ - -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(); - void finishParsing(int ClientKey); - int formNew(DilloHtmlMethod method, const DilloUrl *action, - DilloHtmlEnc enc, const char *charset); - inline DilloHtmlForm *getCurrentForm (); - void loadImages (const DilloUrl *pattern); -}; /* @@ -596,23 +410,6 @@ static int Html_add_new_linkimage(DilloHtml *html, } -/* - * Change one toplevel attribute. var should be an identifier. val is - * only evaluated once, so you can safely use a function call for it. - */ -#define HTML_SET_TOP_ATTR(html, var, val) \ - do { \ - StyleAttrs style_attrs; \ - Style *old_style; \ - \ - old_style = S_TOP(html)->style; \ - style_attrs = *old_style; \ - style_attrs.var = (val); \ - S_TOP(html)->style = \ - Style::create (HT2LT(html), &style_attrs); \ - old_style->unref (); \ - } while (FALSE) - /* diff --git a/src/html_common.hh b/src/html_common.hh new file mode 100644 index 00000000..8cae537b --- /dev/null +++ b/src/html_common.hh @@ -0,0 +1,226 @@ +#ifndef __HTML_COMMON_HH__ +#define __HTML_COMMON_HH__ + +#include "url.h" +#include "bw.h" + +#include "lout/misc.hh" +#include "dw/core.hh" +#include "dw/image.hh" + +#include "image.hh" + +#include "form.hh" + +/* + * Macros + */ + +// Dw to Textblock +#define DW2TB(dw) ((Textblock*)dw) +// "html struct" to "Layout" +#define HT2LT(html) ((Layout*)html->bw->render_layout) +// "Image" to "Dw Widget" +#define IM2DW(Image) ((Widget*)Image->dw) +// 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 + +/* + * Change one toplevel attribute. var should be an identifier. val is + * only evaluated once, so you can safely use a function call for it. + */ +#define HTML_SET_TOP_ATTR(html, var, val) \ + do { \ + StyleAttrs style_attrs; \ + Style *old_style; \ + \ + old_style = S_TOP(html)->style; \ + style_attrs = *old_style; \ + style_attrs.var = (val); \ + S_TOP(html)->style = \ + Style::create (HT2LT(html), &style_attrs); \ + old_style->unref (); \ + } while (FALSE) + +/* + * Typedefs + */ + +typedef struct _DilloLinkImage DilloLinkImage; +typedef struct _DilloHtmlState DilloHtmlState; + +typedef enum { + DT_NONE, + DT_HTML, + DT_XHTML +} DilloHtmlDocumentType; + +typedef enum { + DILLO_HTML_PARSE_MODE_INIT = 0, + DILLO_HTML_PARSE_MODE_STASH, + DILLO_HTML_PARSE_MODE_STASH_AND_BODY, + DILLO_HTML_PARSE_MODE_VERBATIM, + DILLO_HTML_PARSE_MODE_BODY, + DILLO_HTML_PARSE_MODE_PRE +} DilloHtmlParseMode; + +typedef enum { + DILLO_HTML_TABLE_MODE_NONE, /* no table at all */ + DILLO_HTML_TABLE_MODE_TOP, /* outside of <tr> */ + DILLO_HTML_TABLE_MODE_TR, /* inside of <tr>, outside of <td> */ + DILLO_HTML_TABLE_MODE_TD /* inside of <td> */ +} DilloHtmlTableMode; + +typedef enum { + HTML_LIST_NONE, + HTML_LIST_UNORDERED, + HTML_LIST_ORDERED +} DilloHtmlListMode; + +typedef enum { + IN_NONE = 0, + IN_HTML = 1 << 0, + IN_HEAD = 1 << 1, + IN_BODY = 1 << 2, + IN_FORM = 1 << 3, + IN_SELECT = 1 << 4, + IN_OPTION = 1 << 5, + IN_TEXTAREA = 1 << 6, + IN_MAP = 1 << 7, + IN_PRE = 1 << 8, + IN_BUTTON = 1 << 9, + IN_LI = 1 << 10, +} DilloHtmlProcessingState; + +/* + * Data Structures + */ + +struct _DilloLinkImage { + DilloUrl *url; + DilloImage *image; +}; + +struct _DilloHtmlState { + dw::core::style::Style *style, *table_cell_style; + DilloHtmlParseMode parse_mode; + DilloHtmlTableMode table_mode; + bool_t cell_text_align_set; + DilloHtmlListMode list_type; + int list_number; + + /* TagInfo index for the tag that's being processed */ + int tag_idx; + + dw::core::Widget *textblock, *table; + + /* This is used to align list items (especially in enumerated lists) */ + dw::core::Widget *ref_list_item; + + /* This is used for list items etc; if it is set to TRUE, breaks + have to be "handed over" (see Html_add_indented and + Html_eventually_pop_dw). */ + bool_t hand_over_break; +}; + +/* + * Classes + */ + +class DilloHtml { +private: + class HtmlLinkReceiver: public dw::core::Widget::LinkReceiver { + public: + DilloHtml *html; + + bool enter (dw::core::Widget *widget, int link, int img, int x, int y); + bool press (dw::core::Widget *widget, int link, int img, int x, int y, + dw::core::EventButton *event); + bool click (dw::core::Widget *widget, int link, int img, int x, int y, + dw::core::EventButton *event); + }; + HtmlLinkReceiver linkReceiver; + +public: //BUG: for now everything is public + + BrowserWindow *bw; + DilloUrl *page_url, *base_url; + dw::core::Widget *dw; /* this is duplicated in the stack */ + + /* -------------------------------------------------------------------*/ + /* Variables required at parsing time */ + /* -------------------------------------------------------------------*/ + size_t Buf_Consumed; /* amount of source from cache consumed */ + char *Start_Buf; + int Start_Ofs; + char *content_type, *charset; + bool stop_parser; + + size_t CurrTagOfs; + size_t OldTagOfs, OldTagLine; + + DilloHtmlDocumentType DocType; /* as given by DOCTYPE tag */ + float DocTypeVersion; /* HTML or XHTML version number */ + + lout::misc::SimpleVector<DilloHtmlState> *stack; + + int InFlags; /* tracks which elements we are in */ + + Dstr *Stash; + bool_t StashSpace; + + int pre_column; /* current column, used in PRE tags with tabs */ + bool_t PreFirstChar; /* used to skip the first CR or CRLF in PRE tags */ + bool_t PrevWasCR; /* Flag to help parsing of "\r\n" in PRE tags */ + bool_t PrevWasOpenTag; /* Flag to help deferred parsing of white space */ + bool_t SPCPending; /* Flag to help deferred parsing of white space */ + bool_t PrevWasSPC; /* Flag to help handling collapsing white space */ + bool_t InVisitedLink; /* used to 'contrast_visited_colors' */ + bool_t ReqTagClose; /* Flag to help handling bad-formed HTML */ + bool_t CloseOneTag; /* Flag to help Html_tag_cleanup_at_close() */ + bool_t WordAfterLI; /* Flag to help ignoring the 1st <P> after <LI> */ + bool_t TagSoup; /* Flag to enable the parser's cleanup functions */ + char *NameVal; /* used for validation of "NAME" and "ID" in <A> */ + + /* element counters: used for validation purposes */ + uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE; + + Dstr *attr_data; /* Buffer for attribute value */ + + /* -------------------------------------------------------------------*/ + /* Variables required after parsing (for page functionality) */ + /* -------------------------------------------------------------------*/ + lout::misc::SimpleVector<DilloHtmlForm*> *forms; + lout::misc::SimpleVector<DilloUrl*> *links; + lout::misc::SimpleVector<DilloLinkImage*> *images; + dw::ImageMapsList maps; + + int32_t link_color; + int32_t visited_color; + +private: + bool_t parse_finished; + void freeParseData(); + void initDw(); /* Used by the constructor */ + +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(); + void finishParsing(int ClientKey); + int formNew(DilloHtmlMethod method, const DilloUrl *action, + DilloHtmlEnc enc, const char *charset); + inline DilloHtmlForm *getCurrentForm (); + void loadImages (const DilloUrl *pattern); +}; + +#endif /* __HTML_COMMON_HH__ */ |