Bug 784: Add html_context->doc_cp and parse attributes with it.
[elinks.git] / src / document / html / internal.h
blob419da38fdfbda7a219b07e8084a050f76884460e
2 #ifndef EL__DOCUMENT_HTML_INTERNAL_H
3 #define EL__DOCUMENT_HTML_INTERNAL_H
5 #include "document/css/stylesheet.h"
6 #include "document/html/parser.h"
7 #include "util/lists.h"
9 struct document_options;
10 struct uri;
12 /* For parser/parse.c: */
14 void process_head(struct html_context *html_context, unsigned char *head);
15 void put_chrs(struct html_context *html_context, unsigned char *start, int len);
17 enum html_whitespace_state {
18 /* Either we are starting a new "block" or the last segment of the
19 * current "block" is ending with whitespace and we should eat any
20 * leading whitespace of the next segment passed to put_chrs().
21 * This prevents HTML whitespace from indenting new blocks by one
22 * or creating two consecutive segments of whitespace in the middle
23 * of a block. */
24 HTML_SPACE_SUPPRESS,
26 /* Do not do anything special. */
27 HTML_SPACE_NORMAL,
29 /* We should add a space when we start the next segment if it doesn't
30 * already start with whitespace. This is used in an "x </y> z"
31 * scenario when the parser hits </y>: it renders "x" and sets this,
32 * so that it will then render " z". XXX: Then we could of course
33 * render "x " and set -1. But we test for this value in parse_html()
34 * if we hit an opening tag of an element and potentially
35 * put_chrs(" "). That needs more investigation yet. --pasky */
36 HTML_SPACE_ADD,
39 struct html_context {
40 #ifdef CONFIG_CSS
41 /* The default stylesheet is initially merged into it. When parsing CSS
42 * from <style>-tags and external stylesheets if enabled is merged
43 * added to it. */
44 struct css_stylesheet css_styles;
45 #endif
47 /* These are global per-document base values, alterable by the <base>
48 * element. */
49 struct uri *base_href;
50 unsigned char *base_target;
52 struct document_options *options;
54 /* doc_cp is the charset of the document, i.e. part->document->cp.
55 * It is copied here because part->document is NULL sometimes. */
56 int doc_cp;
58 /* For:
59 * html/parser/parse.c
60 * html/parser/stack.c
61 * html/parser.c */
62 struct list_head stack;
64 /* For parser/parse.c: */
65 unsigned char *eoff; /* For parser/forms.c too */
66 int line_breax; /* This is for ln_break. */
67 int position; /* This is the position on the document canvas relative
68 * to the current line and is maintained by put_chrs. */
69 enum html_whitespace_state putsp; /* This is for the put_chrs
70 * state-machine. */
71 int was_li;
73 unsigned int quote_level; /* Nesting level of <q> tags. See @html_quote
74 * for why this is unsigned. */
76 unsigned int was_br:1;
77 unsigned int was_xmp:1;
78 unsigned int was_style:1;
79 unsigned int has_link_lines:1;
80 unsigned int was_body:1; /* For META refresh inside <body>. */
81 unsigned int was_body_background:1; /* For <HTML> with style. */
83 /* For html/parser.c, html/renderer.c */
84 int margin;
86 /* For parser/forms.c: */
87 unsigned char *startf;
89 /* For:
90 * html/parser/parse.c
91 * html/parser.c
92 * html/renderer.c
93 * html/tables.c */
94 int table_level;
96 /* For:
97 * html/parser/forms.c
98 * html/parser/link.c
99 * html/parser/parse.c
100 * html/parser/stack.c
101 * html/parser.c */
102 struct part *part;
104 /* For:
105 * html/parser/forms.c
106 * html/parser/link.c
107 * html/parser/parse.c
108 * html/parser.c */
109 /* Note that this is for usage by put_chrs only; anywhere else in
110 * the parser, one should use put_chrs. */
111 void (*put_chars_f)(struct html_context *, unsigned char *, int);
113 /* For:
114 * html/parser/forms.c
115 * html/parser/link.c
116 * html/parser/parse.c
117 * html/parser/stack.c
118 * html/parser.c */
119 void (*line_break_f)(struct html_context *);
121 /* For:
122 * html/parser/forms.c
123 * html/parser/parse.c
124 * html/parser.c */
125 void *(*special_f)(struct html_context *, enum html_special_type, ...);
128 #define html_top ((struct html_element *) html_context->stack.next)
129 #define html_bottom ((struct html_element *) html_context->stack.prev)
130 #define format (html_top->attr)
131 #define par_format (html_top->parattr)
133 #define html_is_preformatted() (format.style.attr & AT_PREFORMATTED)
135 #define get_html_max_width() \
136 int_max(par_format.width - (par_format.leftmargin + par_format.rightmargin), 0)
138 /* For parser/link.c: */
140 void html_focusable(struct html_context *html_context, unsigned char *a);
141 void html_skip(struct html_context *html_context, unsigned char *a);
142 unsigned char *get_target(struct document_options *options, unsigned char *a);
144 void
145 import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri,
146 unsigned char *url, int len);
148 #endif