[wip] Initial stab on inline images support, with many problems
[elinks/images.git] / src / document / document.h
blobfffdf65dd03a06fae1ac21ca8fa77c68dfcbf6b9
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 struct script_event_hook {
72 LIST_HEAD(struct script_event_hook);
74 enum script_event_hook_type {
75 SEVHOOK_ONCLICK,
76 SEVHOOK_ONDBLCLICK,
77 SEVHOOK_ONMOUSEOVER,
78 SEVHOOK_ONHOVER,
79 SEVHOOK_ONFOCUS,
80 SEVHOOK_ONMOUSEOUT,
81 SEVHOOK_ONBLUR,
82 } type;
83 unsigned char *src;
86 struct link {
87 unicode_val_T accesskey;
89 enum link_type type;
91 unsigned char *where;
92 unsigned char *target;
93 unsigned char *where_img;
95 /** The title of the link. This is in the document charset,
96 * and entities have already been decoded. */
97 unsigned char *title;
99 /** The set of characters belonging to this link (their coordinates
100 * in the document) - each character has own struct point. */
101 struct point *points;
102 int npoints;
104 int number;
106 /** This is supposed to be the colour-pair of the link, but the actual
107 * colours on the canvas can differ--e.g., with image links. */
108 struct color_pair color;
110 /*! XXX: They don't neccessary need to be link-specific, but we just
111 * don't support them for any other elements for now. Well, we don't
112 * even have a good place where to store them in that case. */
113 LIST_OF(struct script_event_hook) *event_hooks;
115 union {
116 unsigned char *name;
117 struct form_control *form_control;
118 } data;
121 #ifdef CONFIG_IMAGES
122 struct image {
123 struct point pos;
125 struct uri *uri;
126 int w, h; // in actual pixels! -1 in case of unknown size
128 #endif
130 #define get_link_index(document, link) (link - document->links)
131 #define get_image_index(document, image) (image - document->images)
133 #define link_is_textinput(link) \
134 ((link)->type == LINK_FIELD || (link)->type == LINK_AREA)
136 #define link_is_form(link) \
137 ((link)->type != LINK_HYPERTEXT && (link)->type != LINK_MAP)
139 #define get_link_form_control(link) \
140 (link_is_form(link) ? (link)->data.form_control : NULL)
142 #define get_link_name(link) \
143 (!link_is_form(link) ? (link)->data.name : NULL)
145 #ifdef CONFIG_UTF8
146 /** A searchable character on the document canvas.
148 * struct document.search is an array of struct search, initialised by
149 * get_src, q.v. The elements of the array roughly correspond to the document
150 * canvas, document.data; each element corresponds to a regular character, a
151 * run of one or more control characters, or the end of a line on the canvas.
153 * If an instance of struct search corresponds to a regular character, then that
154 * character is stored in @a c and @a n is equal to 1. If an instance of struct
155 * search corresponds to a run of control characters, then a space character ' '
156 * is stored in @a c and @a n is equal to to the length of the run. If an instance
157 * of struct search corresponds to the end of a line, then a space is stored in
158 * @a c and @a n is equal to 0.
160 struct search {
161 int x, y; /* Co-ordinates on the document canvas,
162 * document.data. */
164 signed int n; /* The number of characters on the
165 * document canvas to which this object
166 * corresponds. If the value is 0, then this
167 * object marks the end of a line. If the value
168 * is 1, then this object corresponds to a
169 * single character. If the value is greater
170 * than 1, then this object corresponds to a run
171 * of control characters. */
173 unicode_val_T c; /* The character on the document canvas to which
174 * this object corresponds or ' ' if that
175 * character is a control character or if this
176 * object marks the end of a line. */
178 /* RAM is cheap nowadays */
180 #else
181 struct search {
182 int x, y;
183 signed int n:24; /* This structure is size-critical */
184 unsigned char c;
186 #endif
188 struct document {
189 OBJECT_HEAD(struct document);
191 struct document_options options;
193 LIST_OF(struct form) forms;
194 LIST_OF(struct tag) tags;
195 LIST_OF(struct node) nodes;
197 #ifdef CONFIG_ECMASCRIPT
198 /** ECMAScript snippets to be executed during loading the document into
199 * a window. This currently involves @<script>s and onLoad handlers.
200 * Note that if you hit a string beginning by '^' here, it is followed
201 * by an external reference - you must wait with processing other items
202 * until it gets resolved and loaded. New items are guaranteed to
203 * always appear at the list end. */
204 LIST_OF(struct string_list_item) onload_snippets;
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 ecmascript_imports;
209 /** used by setTimeout */
210 timer_id_T timeout;
211 #endif
212 #ifdef CONFIG_CSS
213 /** @todo FIXME: We should externally maybe using cache_entry store the
214 * dependencies between the various entries so nothing gets removed
215 * unneeded. */
216 struct uri_list css_imports;
217 /** Calculated from the id's of all the cache entries in #css_imports.
218 * Used for checking rerendering for available CSS imports. */
219 unsigned long css_magic;
220 #endif
221 #ifdef CONFIG_IMAGES
222 /** @todo FIXME: We should externally maybe using cache_entry store the
223 * dependencies between the various entries so nothing gets removed
224 * unneeded. */
225 struct uri_list image_imports;
226 /** Calculated from the id's of all the cache entries in #image_imports.
227 * Used for checking rerendering when more images are loaded. */
228 unsigned long images_magic;
229 #endif
231 struct uri *uri;
233 /* for obtaining IP */
234 void *querydns;
235 unsigned char *ip;
236 /** The title of the document. The charset of this string is
237 * document.options.cp. */
238 unsigned char *title;
239 struct cache_entry *cached;
241 struct frame_desc *frame;
242 struct frameset_desc *frame_desc; /**< @todo RENAME ME */
243 struct document_refresh *refresh;
245 struct line *data;
247 int nlinks;
248 struct link *links;
249 /** @name Arrays with one item per rendered document's line.
250 * @{ */
251 struct link **lines1; /**< The first link on the line. */
252 struct link **lines2; /**< The last link on the line. */
253 /** @} */
255 #ifdef CONFIG_IMAGES
256 int nimages;
257 struct image *images;
258 #endif
260 struct search *search;
261 struct search **slines1;
262 struct search **slines2;
264 #ifdef CONFIG_UTF8
265 unsigned char buf[7];
266 unsigned char buf_length;
267 #endif
268 #ifdef CONFIG_COMBINE
269 /* base char + 5 combining chars = 6 */
270 unicode_val_T combi[UCS_MAX_LENGTH_COMBINED];
271 /* the number of combining characters. The base char is not counted. */
272 unsigned int combi_length;
273 /* Positions of the last base character.*/
274 int comb_x, comb_y;
275 #endif
276 unsigned int cache_id; /**< Used to check cache entries. */
278 int cp;
279 int width, height; /**< size of document */
280 int nsearch;
282 struct {
283 color_T background;
284 } color;
286 enum cp_status cp_status;
287 unsigned int links_sorted:1; /**< whether links are already sorted */
290 #define document_has_frames(document_) ((document_) && (document_)->frame_desc)
292 /** Initializes a document and its canvas.
293 * @returns NULL on allocation failure.
294 * @relates document */
295 struct document *
296 init_document(struct cache_entry *cached, struct document_options *options);
298 /** Releases the document and all its resources.
299 * @relates document */
300 void done_document(struct document *document);
302 /** Free's the allocated members of the link. */
303 void done_link_members(struct link *link);
305 /** Calculates css magic from available CSS imports. Used for determining
306 * validity of formatted documents in the cache. */
307 unsigned long get_document_css_magic(struct document *document);
309 /** Calculates img magic from available images. Used for determining
310 * validity of formatted documents in the cache. */
311 unsigned long get_document_images_magic(struct document *document);
313 void update_cached_document_options(struct session *ses);
315 struct document *get_cached_document(struct cache_entry *cached, struct document_options *options);
317 /** Release a reference to the document.
318 * @relates document */
319 void release_document(struct document *document);
321 int get_format_cache_size(void);
322 int get_format_cache_used_count(void);
323 int get_format_cache_refresh_count(void);
325 void shrink_format_cache(int);
327 extern struct module document_module;
329 /** @todo FIXME: support for entities and all Unicode characters.
330 * (Unpaired surrogates should be rejected, so that the ECMAScript
331 * interface can convert the access key to UTF-16.)
332 * For now, we only support simple printable character. */
333 #define accesskey_string_to_unicode(s) (((s)[0] && !(s)[1] && isprint((s)[0])) ? (s)[0] : 0)
335 int find_tag(struct document *document, unsigned char *name, int namelen);
337 #endif