Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
html_common.hh
Go to the documentation of this file.
1/*
2 * File: html_common.hh
3 *
4 * Copyright (C) 2008-2016 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright (C) 2008-2014 Johannes Hofmann <Johannes.Hofmann@gmx.de>
6 * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef __HTML_COMMON_HH__
15#define __HTML_COMMON_HH__
16
17#include "url.h"
18#include "bw.h"
19
20#include "lout/misc.hh"
21#include "dw/core.hh"
22#include "dw/image.hh"
23#include "dw/style.hh"
24
25#include "image.hh"
26
27#include "form.hh"
28
29#include "styleengine.hh"
30
31/*
32 * Macros
33 */
34
36#define HT2TB(html) ((Textblock*)(html->dw))
38#define HT2LT(html) ((Layout*)html->bw->render_layout)
40#define IM2DW(Image) ((Widget*)Image->dw)
42#define S_TOP(html) (html->stack->getRef(html->stack->size()-1))
43
45#define BUG_MSG(...) \
46 D_STMT_START { \
47 html->bugMessage(__VA_ARGS__); \
48 } D_STMT_END
49
50
51/*
52 * Typedefs
53 */
54
61
70
77
82
88
89typedef enum {
91 IN_HTML = 1 << 0,
92 IN_HEAD = 1 << 1,
93 IN_BODY = 1 << 2,
94 IN_FORM = 1 << 3,
95 IN_SELECT = 1 << 4,
96 IN_OPTION = 1 << 5,
97 IN_OPTGROUP = 1 << 6,
98 IN_TEXTAREA = 1 << 7,
99 IN_BUTTON = 1 << 8,
100 IN_MAP = 1 << 9,
101 IN_PRE = 1 << 10,
102 IN_LI = 1 << 11,
103 IN_MEDIA = 1 << 12,
104 IN_META_HACK = 1 << 13,
105 IN_A = 1 << 14,
106 IN_EOF = 1 << 15,
108
109/*
110 * Data Structures
111 */
112
117
140
141/*
142 * Classes
143 */
144
146private:
148 public:
150
151 bool enter (dw::core::Widget *widget, int link, int img, int x, int y);
152 bool press (dw::core::Widget *widget, int link, int img, int x, int y,
153 dw::core::EventButton *event);
154 bool click (dw::core::Widget *widget, int link, int img, int x, int y,
155 dw::core::EventButton *event);
156 };
158
159public: //BUG: for now everything is public
160
163 dw::core::Widget *dw; /* this is duplicated in the stack */
164
165 /* -------------------------------------------------------------------*/
166 /* Variables required at parsing time */
167 /* -------------------------------------------------------------------*/
172
174
175 DilloHtmlDocumentType DocType; /* as given by DOCTYPE tag */
176 float DocTypeVersion; /* HTML or XHTML version number */
177
178 /* vector of remote CSS resources, as given by the LINK element */
180
183
188
195 bool TagSoup;
203
210 /* -------------------------------------------------------------------*/
211 /* Variables required after parsing (for page functionality) */
212 /* -------------------------------------------------------------------*/
218
219private:
220 void freeParseData();
221 void initDw(); /* Used by the constructor */
222
223public:
224 DilloHtml(BrowserWindow *bw, const DilloUrl *url, const char *content_type);
225 ~DilloHtml();
226 void bugMessage(const char *format, ... );
228 void write(char *Buf, int BufSize, int Eof);
229 int getCurrLineNumber();
230 void finishParsing(int ClientKey);
231 int formNew(DilloHtmlMethod method, const DilloUrl *action,
232 DilloHtmlEnc enc, const char *charset);
233 DilloHtmlForm *getCurrentForm ();
235 void loadImages (const DilloUrl *pattern);
236 void addCssUrl(const DilloUrl *url);
237
238 // useful shortcuts
239 inline void startElement (int tag)
240 { styleEngine->startElement (tag, bw); }
241 inline void startElement (const char *tagname)
242 { styleEngine->startElement (tagname, bw); }
243
247 { return styleEngine->style (bw); }
250
251 inline void restyle () { styleEngine->restyle (bw); }
252
253};
254
255/*
256 * Parser functions
257 */
258
259int a_Html_tag_index(const char *tag);
260
261const char *a_Html_get_attr(DilloHtml *html,
262 const char *tag,
263 int tagsize,
264 const char *attrname);
265
267 const char *tag,
268 int tagsize,
269 const char *attrname,
270 const char *def);
271
273 const char *url_str, const char *base_url,
274 int use_base_url);
275
276void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize);
277DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize);
278
279char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize);
280void a_Html_pop_tag(DilloHtml *html, int TagIdx);
281void a_Html_stash_init(DilloHtml *html);
282int32_t a_Html_color_parse(DilloHtml *html, const char *str,
283 int32_t default_color);
285 const char *attr);
286void a_Html_tag_set_align_attr(DilloHtml *html, const char *tag, int tagsize);
288 const char *tag, int tagsize);
289
291
292#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:740
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:760
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:794
bool ReqTagClose
Flag to close the stack's top tag.
void freeParseData()
Free parsing data.
Definition html.cc:627
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:605
void connectSignals(dw::core::Widget *dw)
bool stop_parser
void bugMessage(const char *format,...)
Collect HTML error strings.
Definition html.cc:153
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:578
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:667
void finishParsing(int ClientKey)
Finish parsing a HTML page.
Definition html.cc:641
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:733
bool PrevWasOpenTag
Flag to help deferred parsing of white space.
void initDw()
Miscellaneous initializations for Dw.
Definition html.cc:522
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:689
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:536
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:684
void loadImages(const DilloUrl *pattern)
Load images if they were disabled.
Definition html.cc:702
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:115
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:4267
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:363
void a_Html_stash_init(DilloHtml *html)
Initialize the stash buffer.
Definition html.cc:843
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:172
DilloImage * a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
Definition html.cc:2133
CssLength 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:1433
int32_t a_Html_color_parse(DilloHtml *html, const char *str, int32_t default_color)
Parse a color attribute.
Definition html.cc:1458
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:318
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:2063
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
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:4281
int a_Html_tag_index(const char *tag)
Get 'tag' index.
Definition html.cc:3610
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:1070
void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
Tell cache to retrieve a stylesheet.
Definition html.cc:3247
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.