1 #ifndef EL__DOCUMENT_DOCUMENT_H 2 #define EL__DOCUMENT_DOCUMENT_H 3 4 #include "document/options.h" 5 #include "intl/charsets.h" /* unicode_val_T */ 6 #include "main/object.h" 7 #include "protocol/uri.h" 8 #include "util/color.h" 9 #include "util/lists.h" 10 #include "util/box.h" 11 12 struct cache_entry; 13 struct document_refresh; 14 struct form_control; 15 struct frame_desc; 16 struct frameset_desc; 17 struct module; 18 struct screen_char; 19 20 /* Nodes are used for marking areas of text on the document canvas as 21 * searchable. */ 22 struct node { 23 LIST_HEAD(struct node); 24 25 struct box box; 26 }; 27 28 29 /* The document line consisting of the chars ready to be copied to the terminal 30 * screen. */ 31 struct line { 32 struct screen_char *chars; 33 int length; 34 }; 35 36 /* Codepage status */ 37 enum cp_status { 38 CP_STATUS_NONE, 39 CP_STATUS_SERVER, 40 CP_STATUS_ASSUMED, 41 CP_STATUS_IGNORED 42 }; 43 44 45 struct point { 46 int x, y; 47 }; 48 49 50 enum link_type { 51 LINK_HYPERTEXT, 52 LINK_MAP, 53 LINK_BUTTON, 54 LINK_CHECKBOX, 55 LINK_SELECT, 56 LINK_FIELD, 57 LINK_AREA, 58 }; 59 60 struct script_event_hook { 61 LIST_HEAD(struct script_event_hook); 62 63 enum script_event_hook_type { 64 SEVHOOK_ONCLICK, 65 SEVHOOK_ONDBLCLICK, 66 SEVHOOK_ONMOUSEOVER, 67 SEVHOOK_ONHOVER, 68 SEVHOOK_ONFOCUS, 69 SEVHOOK_ONMOUSEOUT, 70 SEVHOOK_ONBLUR, 71 } type; 72 unsigned char *src; 73 }; 74 75 struct link { 76 unicode_val_T accesskey; 77 78 enum link_type type; 79 80 unsigned char *where; 81 unsigned char *target; 82 unsigned char *where_img; 83 unsigned char *title; 84 85 /* The set of characters belonging to this link (their coordinates 86 * in the document) - each character has own {struct point}. */ 87 struct point *points; 88 int npoints; 89 90 int number; 91 92 /* This is supposed to be the colour-pair of the link, but the actual 93 * colours on the canvas can differ--e.g., with image links. */ 94 struct color_pair color; 95 96 /* XXX: They don't neccessary need to be link-specific, but we just 97 * don't support them for any other elements for now. Well, we don't 98 * even have a good place where to store them in that case. */ 99 struct list_head *event_hooks; /* -> struct script_event_hook */ 100 101 union { 102 unsigned char *name; 103 struct form_control *form_control; 104 } data; 105 }; 106 107 #define get_link_index(document, link) (link - document->links) 108 109 #define link_is_textinput(link) \ 110 ((link)->type == LINK_FIELD || (link)->type == LINK_AREA) 111 112 #define link_is_form(link) \ 113 ((link)->type != LINK_HYPERTEXT && (link)->type != LINK_MAP) 114 115 #define get_link_form_control(link) \ 116 (link_is_form(link) ? (link)->data.form_control : NULL) 117 118 #define get_link_name(link) \ 119 (!link_is_form(link) ? (link)->data.name : NULL) 120 121 122 struct search { 123 int x, y; 124 signed int n:24; /* This structure is size-critical */ 125 unsigned char c; 126 }; 127 128 129 struct document { 130 OBJECT_HEAD(struct document); 131 132 struct document_options options; 133 134 struct list_head forms; /* -> struct form */ 135 struct list_head tags; /* -> struct tag */ 136 struct list_head nodes; /* -> struct node */ 137 138 #ifdef CONFIG_ECMASCRIPT 139 /* ECMAScript snippets to be executed during loading the document into 140 * a window. This currently involves <script>s and onLoad handlers. 141 * Note that if you hit a string beginning by '^' here, it is followed 142 * by an external reference - you must wait with processing other items 143 * until it gets resolved and loaded. New items are guaranteed to 144 * always appear at the list end. */ 145 struct list_head onload_snippets; /* -> struct string_list_item */ 146 /* FIXME: We should externally maybe using cache_entry store the 147 * dependencies between the various entries so nothing gets removed 148 * unneeded. */ 149 struct uri_list ecmascript_imports; 150 #endif 151 #ifdef CONFIG_CSS 152 /* FIXME: We should externally maybe using cache_entry store the 153 * dependencies between the various entries so nothing gets removed 154 * unneeded. */ 155 struct uri_list css_imports; 156 /* Calculated from the id's of all the cache entries in css_imports. 157 * Used for checking rerendering for available CSS imports. */ 158 unsigned long css_magic; 159 #endif 160 161 struct uri *uri; 162 unsigned char *title; 163 164 struct frame_desc *frame; 165 struct frameset_desc *frame_desc; /* RENAME ME */ 166 struct document_refresh *refresh; 167 168 struct line *data; 169 170 struct link *links; 171 /* Arrays with one item per rendered document's line. */ 172 struct link **lines1; /* The first link on the line. */ 173 struct link **lines2; /* The last link on the line. */ 174 175 struct search *search; 176 struct search **slines1; 177 struct search **slines2; 178 179 unsigned int id; /* Used to check cache entries. */ 180 181 int cp; 182 int width, height; /* size of document */ 183 int nlinks; 184 int nsearch; 185 color_T bgcolor; 186 187 enum cp_status cp_status; 188 }; 189 190 #define document_has_frames(document_) ((document_) && (document_)->frame_desc) 191 192 /* Initializes a document and its canvas. */ 193 /* Return NULL on allocation failure. */ 194 struct document * 195 init_document(struct cache_entry *cached, struct document_options *options); 196 197 /* Releases the document and all its resources. */ 198 void done_document(struct document *document); 199 200 /* Free's the allocated members of the link. */ 201 void done_link_members(struct link *link); 202 203 /* Calculates css magic from available CSS imports. Used for determining 204 * validity of formatted documents in the cache. */ 205 unsigned long get_document_css_magic(struct document *document); 206 207 void update_cached_document_options(void); 208 209 struct document *get_cached_document(struct cache_entry *cached, struct document_options *options); 210 211 /* Release a reference to the document. */ 212 void release_document(struct document *document); 213 214 int get_format_cache_size(void); 215 int get_format_cache_used_count(void); 216 int get_format_cache_refresh_count(void); 217 218 void shrink_format_cache(int); 219 220 extern struct module document_module; 221 222 /* FIXME: support for entities and all Unicode characters. 223 * For now, we only support simple printable character. */ 224 #define accesskey_string_to_unicode(s) (((s)[0] && !(s)[1] && isprint((s)[0])) ? (s)[0] : 0) 225 226 #endif 227