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 enum script_event_hook_type
{
81 struct script_event_hook
{
82 LIST_HEAD(struct script_event_hook
);
84 enum script_event_hook_type type
;
89 unicode_val_T accesskey
;
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. */
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
;
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
;
119 struct form_control
*form_control
;
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)
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.
153 int x
, y
; /* Co-ordinates on the document canvas,
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 */
175 signed int n
:24; /* This structure is size-critical */
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
200 struct uri_list ecmascript_imports
;
201 /** used by setTimeout */
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 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
;
216 /* for obtaining 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
;
231 /** @name Arrays with one item per rendered document's line.
233 struct link
**lines1
; /**< The first link on the line. */
234 struct link
**lines2
; /**< The last link on the line. */
237 struct search
*search
;
238 struct search
**slines1
;
239 struct search
**slines2
;
242 unsigned char buf
[7];
243 unsigned char buf_length
;
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.*/
253 unsigned int cache_id
; /**< Used to check cache entries. */
256 int width
, height
; /**< size of document */
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 */
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
);