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"
14 struct document_refresh
;
21 /** Nodes are used for marking areas of text on the document canvas as
24 LIST_HEAD(struct node
);
30 /** The document line consisting of the chars ready to be copied to
31 * the terminal screen. */
33 struct screen_char
*chars
;
37 /** Codepage status */
51 /* Tags are used for ``id''s or anchors in the document referenced by the
52 * fragment part of the URI. */
54 LIST_HEAD(struct tag
);
57 unsigned char name
[1]; /* must be last of struct. --Zas */
71 struct script_event_hook
{
72 LIST_HEAD(struct script_event_hook
);
74 enum script_event_hook_type
{
87 unicode_val_T accesskey
;
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. */
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
;
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
;
117 struct form_control
*form_control
;
126 int w
, h
; // in actual pixels! -1 in case of unknown size
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)
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.
161 int x
, y
; /* Co-ordinates on the document canvas,
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 */
183 signed int n
:24; /* This structure is size-critical */
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
208 struct uri_list ecmascript_imports
;
209 /** used by setTimeout */
213 /** @todo FIXME: We should externally maybe using cache_entry store the
214 * dependencies between the various entries so nothing gets removed
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
;
222 /** @todo FIXME: We should externally maybe using cache_entry store the
223 * dependencies between the various entries so nothing gets removed
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
;
233 /* for obtaining 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
;
249 /** @name Arrays with one item per rendered document's line.
251 struct link
**lines1
; /**< The first link on the line. */
252 struct link
**lines2
; /**< The last link on the line. */
257 struct image
*images
;
260 struct search
*search
;
261 struct search
**slines1
;
262 struct search
**slines2
;
265 unsigned char buf
[7];
266 unsigned char buf_length
;
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.*/
276 unsigned int cache_id
; /**< Used to check cache entries. */
279 int width
, height
; /**< size of document */
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 */
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
);