Retry only for https protocol
[elinks.git] / src / document / document.h
blobdcce17cf1695df63cbb0015efb55982b3f8485e8
1 #ifndef EL__DOCUMENT_DOCUMENT_H
2 #define EL__DOCUMENT_DOCUMENT_H
4 #include "document/options.h"
5 #include "intl/charsets.h" /* unicode_val_T */
6 #include "main/object.h"
7 #include "main/timer.h"
8 #include "protocol/uri.h"
9 #include "util/color.h"
10 #include "util/lists.h"
11 #include "util/box.h"
13 struct cache_entry;
14 struct document_refresh;
15 struct form_control;
16 struct frame_desc;
17 struct frameset_desc;
18 struct module;
19 struct screen_char;
21 /** Nodes are used for marking areas of text on the document canvas as
22 * searchable. */
23 struct node {
24 LIST_HEAD(struct node);
26 struct box box;
30 /** The document line consisting of the chars ready to be copied to
31 * the terminal screen. */
32 struct line {
33 struct screen_char *chars;
34 int length;
37 /** Codepage status */
38 enum cp_status {
39 CP_STATUS_NONE,
40 CP_STATUS_SERVER,
41 CP_STATUS_ASSUMED,
42 CP_STATUS_IGNORED
46 struct point {
47 int x, y;
51 /* Tags are used for ``id''s or anchors in the document referenced by the
52 * fragment part of the URI. */
53 struct tag {
54 LIST_HEAD(struct tag);
56 int x, y;
57 unsigned char name[1]; /* must be last of struct. --Zas */
61 enum link_type {
62 LINK_HYPERTEXT,
63 LINK_MAP,
64 LINK_BUTTON,
65 LINK_CHECKBOX,
66 LINK_SELECT,
67 LINK_FIELD,
68 LINK_AREA,
71 enum script_event_hook_type {
72 SEVHOOK_ONCLICK,
73 SEVHOOK_ONDBLCLICK,
74 SEVHOOK_ONMOUSEOVER,
75 SEVHOOK_ONHOVER,
76 SEVHOOK_ONFOCUS,
77 SEVHOOK_ONMOUSEOUT,
78 SEVHOOK_ONBLUR,
81 struct script_event_hook {
82 LIST_HEAD(struct script_event_hook);
84 enum script_event_hook_type type;
85 unsigned char *src;
88 struct link {
89 unicode_val_T accesskey;
91 enum link_type type;
93 unsigned char *where;
94 unsigned char *target;
95 unsigned char *where_img;
97 /** The title of the link. This is in the document charset,
98 * and entities have already been decoded. */
99 unsigned char *title;
101 /** The set of characters belonging to this link (their coordinates
102 * in the document) - each character has own struct point. */
103 struct point *points;
104 int npoints;
106 int number;
108 /** This is supposed to be the colour-pair of the link, but the actual
109 * colours on the canvas can differ--e.g., with image links. */
110 struct color_pair color;
112 /*! XXX: They don't neccessary need to be link-specific, but we just
113 * don't support them for any other elements for now. Well, we don't
114 * even have a good place where to store them in that case. */
115 LIST_OF(struct script_event_hook) *event_hooks;
117 union {
118 unsigned char *name;
119 struct form_control *form_control;
120 } data;
123 #define get_link_index(document, link) (link - document->links)
125 #define link_is_textinput(link) \
126 ((link)->type == LINK_FIELD || (link)->type == LINK_AREA)
128 #define link_is_form(link) \
129 ((link)->type != LINK_HYPERTEXT && (link)->type != LINK_MAP)
131 #define get_link_form_control(link) \
132 (link_is_form(link) ? (link)->data.form_control : NULL)
134 #define get_link_name(link) \
135 (!link_is_form(link) ? (link)->data.name : NULL)
137 #ifdef CONFIG_UTF8
138 /** A searchable character on the document canvas.
140 * struct document.search is an array of struct search, initialised by
141 * get_src, q.v. The elements of the array roughly correspond to the document
142 * canvas, document.data; each element corresponds to a regular character, a
143 * run of one or more control characters, or the end of a line on the canvas.
145 * If an instance of struct search corresponds to a regular character, then that
146 * character is stored in @a c and @a n is equal to 1. If an instance of struct
147 * search corresponds to a run of control characters, then a space character ' '
148 * is stored in @a c and @a n is equal to to the length of the run. If an instance
149 * of struct search corresponds to the end of a line, then a space is stored in
150 * @a c and @a n is equal to 0.
152 struct search {
153 int x, y; /* Co-ordinates on the document canvas,
154 * document.data. */
156 signed int n; /* The number of characters on the
157 * document canvas to which this object
158 * corresponds. If the value is 0, then this
159 * object marks the end of a line. If the value
160 * is 1, then this object corresponds to a
161 * single character. If the value is greater
162 * than 1, then this object corresponds to a run
163 * of control characters. */
165 unicode_val_T c; /* The character on the document canvas to which
166 * this object corresponds or ' ' if that
167 * character is a control character or if this
168 * object marks the end of a line. */
170 /* RAM is cheap nowadays */
172 #else
173 struct search {
174 int x, y;
175 signed int n:24; /* This structure is size-critical */
176 unsigned char c;
178 #endif
180 struct document {
181 OBJECT_HEAD(struct document);
183 struct document_options options;
185 LIST_OF(struct form) forms;
186 LIST_OF(struct tag) tags;
187 LIST_OF(struct node) nodes;
189 #ifdef CONFIG_ECMASCRIPT
190 /** ECMAScript snippets to be executed during loading the document into
191 * a window. This currently involves @<script>s and onLoad handlers.
192 * Note that if you hit a string beginning by '^' here, it is followed
193 * by an external reference - you must wait with processing other items
194 * until it gets resolved and loaded. New items are guaranteed to
195 * always appear at the list end. */
196 LIST_OF(struct string_list_item) onload_snippets;
197 /** @todo FIXME: We should externally maybe using cache_entry store the
198 * dependencies between the various entries so nothing gets removed
199 * unneeded. */
200 struct uri_list ecmascript_imports;
201 /** used by setTimeout */
202 timer_id_T timeout;
203 #endif
204 #ifdef CONFIG_CSS
205 /** @todo FIXME: We should externally maybe using cache_entry store the
206 * dependencies between the various entries so nothing gets removed
207 * unneeded. */
208 struct uri_list css_imports;
209 /** Calculated from the id's of all the cache entries in #css_imports.
210 * Used for checking rerendering for available CSS imports. */
211 unsigned long css_magic;
212 #endif
214 struct uri *uri;
216 /* for obtaining IP */
217 void *querydns;
218 unsigned char *ip;
219 /** The title of the document. The charset of this string is
220 * document.options.cp. */
221 unsigned char *title;
222 struct cache_entry *cached;
224 struct frame_desc *frame;
225 struct frameset_desc *frame_desc; /**< @todo RENAME ME */
226 struct document_refresh *refresh;
228 struct line *data;
230 struct link *links;
231 /** @name Arrays with one item per rendered document's line.
232 * @{ */
233 struct link **lines1; /**< The first link on the line. */
234 struct link **lines2; /**< The last link on the line. */
235 /** @} */
237 struct search *search;
238 struct search **slines1;
239 struct search **slines2;
241 #ifdef CONFIG_UTF8
242 unsigned char buf[7];
243 unsigned char buf_length;
244 #endif
245 #ifdef CONFIG_COMBINE
246 /* base char + 5 combining chars = 6 */
247 unicode_val_T combi[UCS_MAX_LENGTH_COMBINED];
248 /* the number of combining characters. The base char is not counted. */
249 unsigned int combi_length;
250 /* Positions of the last base character.*/
251 int comb_x, comb_y;
252 #endif
253 unsigned int cache_id; /**< Used to check cache entries. */
255 int cp;
256 int width, height; /**< size of document */
257 int nlinks;
258 int nsearch;
260 struct {
261 color_T background;
262 } color;
264 enum cp_status cp_status;
265 unsigned int links_sorted:1; /**< whether links are already sorted */
268 #define document_has_frames(document_) ((document_) && (document_)->frame_desc)
270 /** Initializes a document and its canvas.
271 * @returns NULL on allocation failure.
272 * @relates document */
273 struct document *
274 init_document(struct cache_entry *cached, struct document_options *options);
276 /** Releases the document and all its resources.
277 * @relates document */
278 void done_document(struct document *document);
280 /** Free's the allocated members of the link. */
281 void done_link_members(struct link *link);
283 /** Calculates css magic from available CSS imports. Used for determining
284 * validity of formatted documents in the cache. */
285 unsigned long get_document_css_magic(struct document *document);
287 void update_cached_document_options(struct session *ses);
289 struct document *get_cached_document(struct cache_entry *cached, struct document_options *options);
291 /** Release a reference to the document.
292 * @relates document */
293 void release_document(struct document *document);
295 int get_format_cache_size(void);
296 int get_format_cache_used_count(void);
297 int get_format_cache_refresh_count(void);
299 void shrink_format_cache(int);
301 extern struct module document_module;
303 /** @todo FIXME: support for entities and all Unicode characters.
304 * (Unpaired surrogates should be rejected, so that the ECMAScript
305 * interface can convert the access key to UTF-16.)
306 * For now, we only support simple printable character. */
307 #define accesskey_string_to_unicode(s) (((s)[0] && !(s)[1] && isprint((s)[0])) ? (s)[0] : 0)
309 int find_tag(struct document *document, unsigned char *name, int namelen);
311 #endif