Fix compilation using --enable-html-highlight.
[elinks.git] / src / document / document.h
blob6b762257dd7fc00ccc9b7c3c21ef7f6be3d37d7a
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;
94 unsigned char *title;
96 /** The set of characters belonging to this link (their coordinates
97 * in the document) - each character has own struct point. */
98 struct point *points;
99 int npoints;
101 int number;
103 /** This is supposed to be the colour-pair of the link, but the actual
104 * colours on the canvas can differ--e.g., with image links. */
105 struct color_pair color;
107 /*! XXX: They don't neccessary need to be link-specific, but we just
108 * don't support them for any other elements for now. Well, we don't
109 * even have a good place where to store them in that case. */
110 LIST_OF(struct script_event_hook) *event_hooks;
112 union {
113 unsigned char *name;
114 struct form_control *form_control;
115 } data;
118 #define get_link_index(document, link) (link - document->links)
120 #define link_is_textinput(link) \
121 ((link)->type == LINK_FIELD || (link)->type == LINK_AREA)
123 #define link_is_form(link) \
124 ((link)->type != LINK_HYPERTEXT && (link)->type != LINK_MAP)
126 #define get_link_form_control(link) \
127 (link_is_form(link) ? (link)->data.form_control : NULL)
129 #define get_link_name(link) \
130 (!link_is_form(link) ? (link)->data.name : NULL)
132 #ifdef CONFIG_UTF8
133 struct search {
134 int x, y;
135 signed int n; /* RAM is cheap nowadays */
136 unicode_val_T c;
138 #else
139 struct search {
140 int x, y;
141 signed int n:24; /* This structure is size-critical */
142 unsigned char c;
144 #endif
146 struct document {
147 OBJECT_HEAD(struct document);
149 struct document_options options;
151 LIST_OF(struct form) forms;
152 LIST_OF(struct tag) tags;
153 LIST_OF(struct node) nodes;
155 #ifdef CONFIG_ECMASCRIPT
156 /** ECMAScript snippets to be executed during loading the document into
157 * a window. This currently involves @<script>s and onLoad handlers.
158 * Note that if you hit a string beginning by '^' here, it is followed
159 * by an external reference - you must wait with processing other items
160 * until it gets resolved and loaded. New items are guaranteed to
161 * always appear at the list end. */
162 LIST_OF(struct string_list_item) onload_snippets;
163 /** @todo FIXME: We should externally maybe using cache_entry store the
164 * dependencies between the various entries so nothing gets removed
165 * unneeded. */
166 struct uri_list ecmascript_imports;
167 /** used by setTimeout */
168 timer_id_T timeout;
169 #endif
170 #ifdef CONFIG_CSS
171 /** @todo FIXME: We should externally maybe using cache_entry store the
172 * dependencies between the various entries so nothing gets removed
173 * unneeded. */
174 struct uri_list css_imports;
175 /** Calculated from the id's of all the cache entries in #css_imports.
176 * Used for checking rerendering for available CSS imports. */
177 unsigned long css_magic;
178 #endif
180 struct uri *uri;
181 unsigned char *title;
182 struct cache_entry *cached;
184 struct frame_desc *frame;
185 struct frameset_desc *frame_desc; /**< @todo RENAME ME */
186 struct document_refresh *refresh;
188 struct line *data;
190 struct link *links;
191 /** @name Arrays with one item per rendered document's line.
192 * @{ */
193 struct link **lines1; /**< The first link on the line. */
194 struct link **lines2; /**< The last link on the line. */
195 /** @} */
197 struct search *search;
198 struct search **slines1;
199 struct search **slines2;
201 #ifdef CONFIG_UTF8
202 unsigned char buf[7];
203 unsigned char buf_length;
204 #endif
205 unsigned int id; /**< Used to check cache entries. */
207 int cp;
208 int width, height; /**< size of document */
209 int nlinks;
210 int nsearch;
211 color_T bgcolor;
213 enum cp_status cp_status;
214 unsigned int links_sorted:1; /**< whether links are already sorted */
217 #define document_has_frames(document_) ((document_) && (document_)->frame_desc)
219 /** Initializes a document and its canvas.
220 * @returns NULL on allocation failure.
221 * @relates document */
222 struct document *
223 init_document(struct cache_entry *cached, struct document_options *options);
225 /** Releases the document and all its resources.
226 * @relates document */
227 void done_document(struct document *document);
229 /** Free's the allocated members of the link. */
230 void done_link_members(struct link *link);
232 /** Calculates css magic from available CSS imports. Used for determining
233 * validity of formatted documents in the cache. */
234 unsigned long get_document_css_magic(struct document *document);
236 void update_cached_document_options(void);
238 struct document *get_cached_document(struct cache_entry *cached, struct document_options *options);
240 /** Release a reference to the document.
241 * @relates document */
242 void release_document(struct document *document);
244 int get_format_cache_size(void);
245 int get_format_cache_used_count(void);
246 int get_format_cache_refresh_count(void);
248 void shrink_format_cache(int);
250 extern struct module document_module;
252 /** @todo FIXME: support for entities and all Unicode characters.
253 * (Unpaired surrogates should be rejected, so that the ECMAScript
254 * interface can convert the access key to UTF-16.)
255 * For now, we only support simple printable character. */
256 #define accesskey_string_to_unicode(s) (((s)[0] && !(s)[1] && isprint((s)[0])) ? (s)[0] : 0)
258 int find_tag(struct document *document, unsigned char *name, int namelen);
260 #endif