Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
html_common.hh
Go to the documentation of this file.
1#ifndef __HTML_COMMON_HH__
2#define __HTML_COMMON_HH__
3
4#include "url.h"
5#include "bw.h"
6
7#include "lout/misc.hh"
8#include "dw/core.hh"
9#include "dw/image.hh"
10#include "dw/style.hh"
11
12#include "image.hh"
13
14#include "form.hh"
15
16#include "styleengine.hh"
17
18/*
19 * Macros
20 */
21
23#define HT2TB(html) ((Textblock*)(html->dw))
25#define HT2LT(html) ((Layout*)html->bw->render_layout)
27#define IM2DW(Image) ((Widget*)Image->dw)
29#define S_TOP(html) (html->stack->getRef(html->stack->size()-1))
30
32#define BUG_MSG(...) \
33 D_STMT_START { \
34 html->bugMessage(__VA_ARGS__); \
35 } D_STMT_END
36
37
38/*
39 * Typedefs
40 */
41
48
57
64
69
75
76typedef enum {
78 IN_HTML = 1 << 0,
79 IN_HEAD = 1 << 1,
80 IN_BODY = 1 << 2,
81 IN_FORM = 1 << 3,
82 IN_SELECT = 1 << 4,
83 IN_OPTION = 1 << 5,
84 IN_OPTGROUP = 1 << 6,
85 IN_TEXTAREA = 1 << 7,
86 IN_BUTTON = 1 << 8,
87 IN_MAP = 1 << 9,
88 IN_PRE = 1 << 10,
89 IN_LI = 1 << 11,
90 IN_MEDIA = 1 << 12,
91 IN_META_HACK = 1 << 13,
92 IN_A = 1 << 14,
93 IN_EOF = 1 << 15,
95
96/*
97 * Data Structures
98 */
99
104
127
128/*
129 * Classes
130 */
131
133private:
135 public:
137
138 bool enter (dw::core::Widget *widget, int link, int img, int x, int y);
139 bool press (dw::core::Widget *widget, int link, int img, int x, int y,
140 dw::core::EventButton *event);
141 bool click (dw::core::Widget *widget, int link, int img, int x, int y,
142 dw::core::EventButton *event);
143 };
145
146public: //BUG: for now everything is public
147
150 dw::core::Widget *dw; /* this is duplicated in the stack */
151
152 /* -------------------------------------------------------------------*/
153 /* Variables required at parsing time */
154 /* -------------------------------------------------------------------*/
159
161
162 DilloHtmlDocumentType DocType; /* as given by DOCTYPE tag */
163 float DocTypeVersion; /* HTML or XHTML version number */
164
165 /* vector of remote CSS resources, as given by the LINK element */
167
170
175
182 bool TagSoup;
190
197 /* -------------------------------------------------------------------*/
198 /* Variables required after parsing (for page functionality) */
199 /* -------------------------------------------------------------------*/
205
206private:
207 void freeParseData();
208 void initDw(); /* Used by the constructor */
209
210public:
211 DilloHtml(BrowserWindow *bw, const DilloUrl *url, const char *content_type);
212 ~DilloHtml();
213 void bugMessage(const char *format, ... );
215 void write(char *Buf, int BufSize, int Eof);
216 int getCurrLineNumber();
217 void finishParsing(int ClientKey);
218 int formNew(DilloHtmlMethod method, const DilloUrl *action,
219 DilloHtmlEnc enc, const char *charset);
220 DilloHtmlForm *getCurrentForm ();
222 void loadImages (const DilloUrl *pattern);
223 void addCssUrl(const DilloUrl *url);
224
225 // useful shortcuts
226 inline void startElement (int tag)
227 { styleEngine->startElement (tag, bw); }
228 inline void startElement (const char *tagname)
229 { styleEngine->startElement (tagname, bw); }
230
234 { return styleEngine->style (bw); }
237
238 inline void restyle () { styleEngine->restyle (bw); }
239
240};
241
242/*
243 * Parser functions
244 */
245
246int a_Html_tag_index(const char *tag);
247
248const char *a_Html_get_attr(DilloHtml *html,
249 const char *tag,
250 int tagsize,
251 const char *attrname);
252
254 const char *tag,
255 int tagsize,
256 const char *attrname,
257 const char *def);
258
260 const char *url_str, const char *base_url,
261 int use_base_url);
262
263void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize);
264DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize);
265
266char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize);
267void a_Html_pop_tag(DilloHtml *html, int TagIdx);
268void a_Html_stash_init(DilloHtml *html);
269int32_t a_Html_color_parse(DilloHtml *html, const char *str,
270 int32_t default_color);
272 const char *attr);
273void a_Html_tag_set_align_attr(DilloHtml *html, const char *tag, int tagsize);
275 const char *tag, int tagsize);
276
278
279#endif /* __HTML_COMMON_HH__ */
bool enter(dw::core::Widget *widget, int link, int img, int x, int y)
Called, when a link is entered, left, or the position has changed.
Definition html.cc:739
bool press(dw::core::Widget *widget, int link, int img, int x, int y, dw::core::EventButton *event)
Handle the "press" signal.
Definition html.cc:759
bool click(dw::core::Widget *widget, int link, int img, int x, int y, dw::core::EventButton *event)
Handle the "click" signal.
Definition html.cc:793
bool ReqTagClose
Flag to close the stack's top tag.
void freeParseData()
Free parsing data.
Definition html.cc:626
int InFlags
tracks which elements we are in
DilloHtmlDocumentType DocType
DilloUrl * base_url
int getCurrLineNumber()
Return the line number of the tag/word being processed by the parser.
Definition html.cc:604
void connectSignals(dw::core::Widget *dw)
bool stop_parser
void bugMessage(const char *format,...)
Collect HTML error strings.
Definition html.cc:152
lout::misc::SimpleVector< DilloHtmlState > * stack
void write(char *Buf, int BufSize, int Eof)
Process the newly arrived html and put it into the page structure.
Definition html.cc:577
dw::core::style::Style * backgroundStyle()
char * Start_Buf
int formNew(DilloHtmlMethod method, const DilloUrl *action, DilloHtmlEnc enc, const char *charset)
Allocate and insert form information.
Definition html.cc:666
void finishParsing(int ClientKey)
Finish parsing a HTML page.
Definition html.cc:640
bool PreFirstChar
used to skip the first CR or CRLF in PRE tags
void startElement(int tag)
size_t CurrOfs
void addCssUrl(const DilloUrl *url)
Save URL in a vector (may be loaded later).
Definition html.cc:732
bool PrevWasOpenTag
Flag to help deferred parsing of white space.
void initDw()
Miscellaneous initializations for Dw.
Definition html.cc:521
bool PrevWasCR
Flag to help parsing of "\r\n" in PRE tags.
float DocTypeVersion
Dstr * Stash
bool TagSoup
Flag to enable the parser's cleanup functions.
bool_t unloadedImages()
Definition html.cc:688
int pre_column
current column, used in PRE tags with tabs
DilloUrl * page_url
lout::misc::SimpleVector< DilloHtmlInput * > * inputs_outside_form
bool PrevWasHtmlClose
set when </html> is found
void restyle()
uchar_t Num_BODY
dw::core::style::Style * wordStyle()
bool StashSpace
BrowserWindow * bw
int32_t non_css_visited_color
as provided by vlink attribute in BODY
size_t OldLine
bool loadCssFromStash
current stash content should be loaded as CSS
lout::misc::SimpleVector< DilloHtmlForm * > * forms
dw::ImageMapsList maps
~DilloHtml()
Free memory used by the DilloHtml class.
Definition html.cc:535
uchar_t Num_TITLE
dw::core::style::Style * style()
size_t OldOfs
uchar_t Num_HTML
element counters: used for validation purposes.
lout::misc::SimpleVector< DilloUrl * > * links
dw::core::Widget * dw
int32_t non_css_link_color
as provided by link attribute in BODY
char * content_type
Dstr * attr_data
Buffer for attribute value.
bool PrevWasBodyClose
set when </body> is found
void startElement(const char *tagname)
lout::misc::SimpleVector< DilloUrl * > * cssUrls
int32_t visited_color
as computed according to CSS
uchar_t Num_HEAD
char * charset
bool InVisitedLink
used to 'contrast_visited_colors'
StyleEngine * styleEngine
lout::misc::SimpleVector< DilloHtmlImage * > * images
HtmlLinkReceiver linkReceiver
DilloHtmlForm * getCurrentForm()
Get the current form.
Definition html.cc:683
void loadImages(const DilloUrl *pattern)
Load images if they were disabled.
Definition html.cc:701
This class provides the glue between HTML parser and CSS subsystem.
void restyle(BrowserWindow *bw)
Recompute all style information from scratch This is used to take into account CSS styles for the HTM...
void startElement(int tag, BrowserWindow *bw)
tell the styleEngine that a new html element has started.
dw::core::style::Style * style(BrowserWindow *bw)
dw::core::style::Style * wordStyle(BrowserWindow *bw)
dw::core::style::Style * backgroundStyle(BrowserWindow *bw)
Similar to StyleEngine::style(), but with backgroundColor set.
Represents a list of client-side image maps.
Definition image.hh:24
Represents a button press or release event.
Definition events.hh:58
The base class of all dillo widgets.
Definition widget.hh:44
Simple (simpler than container::untyped::Vector and container::typed::Vector) template based vector.
Definition misc.hh:95
unsigned char uchar_t
Definition d_size.h:17
unsigned char bool_t
Definition d_size.h:21
const char * a_Html_get_attr(DilloHtml *html, const char *tag, int tagsize, const char *attrname)
Call Html_get_attr2 telling it to parse entities and strip the result.
Definition html.cc:4266
void a_Html_pop_tag(DilloHtml *html, int TagIdx)
bool a_Html_tag_set_valign_attr(DilloHtml *html, const char *tag, int tagsize)
Evaluates the VALIGN attribute (top|bottom|middle|baseline) and sets the style in style_attrs.
Definition html.cc:362
void a_Html_stash_init(DilloHtml *html)
Initialize the stash buffer.
Definition html.cc:842
DilloHtmlTableMode
@ DILLO_HTML_TABLE_MODE_TD
inside of
@ DILLO_HTML_TABLE_MODE_NONE
no table at all
@ DILLO_HTML_TABLE_MODE_TR
inside of , outside of
@ DILLO_HTML_TABLE_MODE_TOP
outside of
DilloUrl * a_Html_url_new(DilloHtml *html, const char *url_str, const char *base_url, int use_base_url)
Wrapper for a_Url_new that adds an error detection message.
Definition html.cc:171
DilloImage * a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
Definition html.cc:2132
int32_t a_Html_color_parse(DilloHtml *html, const char *str, int32_t default_color)
Parse a color attribute.
Definition html.cc:1457
void a_Html_tag_set_align_attr(DilloHtml *html, const char *tag, int tagsize)
Evaluates the ALIGN attribute (left|center|right|justify) and sets the style at the top of the stack.
Definition html.cc:317
DilloHtmlParseMode
@ DILLO_HTML_PARSE_MODE_PRE
@ DILLO_HTML_PARSE_MODE_VERBATIM
@ DILLO_HTML_PARSE_MODE_BODY
@ DILLO_HTML_PARSE_MODE_INIT
@ DILLO_HTML_PARSE_MODE_STASH_AND_BODY
@ DILLO_HTML_PARSE_MODE_STASH
void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
Read image-associated tag attributes and create new image.
Definition html.cc:2062
DilloHtmlProcessingState
@ IN_OPTGROUP
@ IN_HEAD
@ IN_BUTTON
@ IN_LI
@ IN_MEDIA
@ IN_OPTION
@ IN_PRE
@ IN_BODY
@ IN_MAP
@ IN_TEXTAREA
@ IN_NONE
@ IN_META_HACK
@ IN_SELECT
@ IN_A
@ IN_HTML
@ IN_FORM
@ IN_EOF
DilloHtmlListMode
@ HTML_LIST_ORDERED
@ HTML_LIST_UNORDERED
@ HTML_LIST_NONE
dw::core::style::Length a_Html_parse_length(DilloHtml *html, const char *attr)
Returns a length or a percentage, or UNDEF_LENGTH in case of an error, or if attr is NULL.
Definition html.cc:1432
DilloHtmlTableBorderMode
@ DILLO_HTML_TABLE_BORDER_COLLAPSE
@ DILLO_HTML_TABLE_BORDER_SEPARATE
char * a_Html_get_attr_wdef(DilloHtml *html, const char *tag, int tagsize, const char *attrname, const char *def)
"a_Html_get_attr with default" Call a_Html_get_attr() and dStrdup() the returned string.
Definition html.cc:4280
int a_Html_tag_index(const char *tag)
Get 'tag' index.
Definition html.cc:3609
DilloHtmlDocumentType
@ DT_UNRECOGNIZED
@ DT_NONE
@ DT_XHTML
@ DT_HTML
char * a_Html_parse_entities(DilloHtml *html, const char *token, int toksize)
Parse all the entities in a token.
Definition html.cc:1069
void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
Tell cache to retrieve a stylesheet.
Definition html.cc:3246
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:428
Dw is in this namespace, or sub namespaces of this one.
DilloHtmlMethod
Definition form.hh:10
DilloHtmlEnc
Definition form.hh:16
The DilloImage data-structure and methods.
Contains the specific data for a single window.
Definition bw.h:27
DilloImage * image
DilloUrl * url
DilloHtmlTableMode table_mode
bool hand_over_break
This is used for list items etc.
DilloHtmlTableBorderMode table_border_mode
dw::core::Widget * table
DilloHtmlListMode list_type
dw::core::Widget * ref_list_item
This is used to align list items (especially in enumerated lists)
DilloHtmlParseMode parse_mode
int tag_idx
TagInfo index for the tag that's being processed.
Definition url.h:88
Definition dlib.h:102
Parse and normalize all URL's inside Dillo.