1 2 #ifndef EL__DOCUMENT_HTML_PARSER_H 3 #define EL__DOCUMENT_HTML_PARSER_H 4 5 #include "intl/charsets.h" /* unicode_val_T */ 6 #include "util/align.h" 7 #include "util/color.h" 8 #include "util/lists.h" 9 10 struct document_options; 11 struct form_control; 12 struct frameset_desc; 13 struct html_context; 14 struct memory_list; 15 struct menu_item; 16 struct part; 17 struct string; 18 struct uri; 19 20 /* XXX: This is just terible - this interface is from 75% only for other HTML 21 * files - there's lack of any well defined interface and it's all randomly 22 * mixed up :/. */ 23 24 enum format_attr { 25 AT_BOLD = 1, 26 AT_ITALIC = 2, 27 AT_UNDERLINE = 4, 28 AT_FIXED = 8, 29 AT_GRAPHICS = 16, 30 AT_SUBSCRIPT = 32, 31 AT_SUPERSCRIPT = 64, 32 AT_PREFORMATTED = 128, 33 AT_UPDATE_SUB = 256, 34 AT_UPDATE_SUP = 512, 35 }; 36 37 struct text_attrib_style { 38 enum format_attr attr; 39 color_T fg; 40 color_T bg; 41 }; 42 43 struct text_attrib { 44 struct text_attrib_style style; 45 46 int fontsize; 47 unsigned char *link; 48 unsigned char *target; 49 unsigned char *image; 50 unsigned char *title; 51 struct form_control *form; 52 color_T clink; 53 color_T vlink; 54 #ifdef CONFIG_BOOKMARKS 55 color_T bookmark_link; 56 #endif 57 color_T image_link; 58 59 unsigned char *select; 60 int select_disabled; 61 unsigned int tabindex; 62 unicode_val_T accesskey; 63 64 unsigned char *onclick; 65 unsigned char *ondblclick; 66 unsigned char *onmouseover; 67 unsigned char *onhover; 68 unsigned char *onfocus; 69 unsigned char *onmouseout; 70 unsigned char *onblur; 71 }; 72 73 /* This enum is pretty ugly, yes ;). */ 74 enum format_list_flag { 75 P_NONE = 0, 76 77 P_NUMBER = 1, 78 P_alpha = 2, 79 P_ALPHA = 3, 80 P_roman = 4, 81 P_ROMAN = 5, 82 83 P_STAR = 1, 84 P_O = 2, 85 P_PLUS = 3, 86 87 P_LISTMASK = 7, 88 89 P_COMPACT = 8, 90 }; 91 92 struct par_attrib { 93 enum format_align align; 94 int leftmargin; 95 int rightmargin; 96 int width; 97 int list_level; 98 unsigned list_number; 99 int dd_margin; 100 enum format_list_flag flags; 101 color_T bgcolor; 102 }; 103 104 /* HTML parser stack mortality info */ 105 enum html_element_mortality_type { 106 /* Elements of this type can not be removed from the stack. This type 107 * is created by the renderer when formatting an HTML part. */ 108 ELEMENT_IMMORTAL, 109 /* Elements of this type can only be removed by elements of the start 110 * type. This type is created whenever an HTML state is created using 111 * init_html_parser_state(). */ 112 /* The element has been created by*/ 113 ELEMENT_DONT_KILL, 114 /* These elements can safely be removed from the stack by both */ 115 ELEMENT_KILLABLE, 116 /* These elements not only cannot bear any other elements inside but 117 * any attempt to do so will cause them to terminate. This is so deadly 118 * that it affects even invisible elements. Ie. <title>foo<body>. */ 119 ELEMENT_WEAK, 120 }; 121 122 struct html_element { 123 LIST_HEAD(struct html_element); 124 125 enum html_element_mortality_type type; 126 127 struct text_attrib attr; 128 struct par_attrib parattr; 129 int invisible; 130 unsigned char *name; 131 int namelen; 132 unsigned char *options; 133 /* See document/html/parser/parse.c's element_info.linebreak 134 * description. */ 135 int linebreak; 136 struct frameset_desc *frameset; 137 138 /* For the needs of CSS engine. A wannabe bitmask. */ 139 enum html_element_pseudo_class { 140 ELEMENT_LINK = 1, 141 ELEMENT_VISITED = 2, 142 } pseudo_class; 143 }; 144 #define is_inline_element(e) (e->linebreak == 0) 145 #define is_block_element(e) (e->linebreak > 0) 146 147 enum html_special_type { 148 SP_TAG, 149 SP_FORM, 150 SP_CONTROL, 151 SP_TABLE, 152 SP_USED, 153 SP_FRAMESET, 154 SP_FRAME, 155 SP_NOWRAP, 156 SP_CACHE_CONTROL, 157 SP_CACHE_EXPIRES, 158 SP_REFRESH, 159 SP_STYLESHEET, 160 SP_COLOR_LINK_LINES, 161 SP_SCRIPT, 162 }; 163 164 /* Interface for the renderer */ 165 166 struct html_context * 167 init_html_parser(struct uri *uri, struct document_options *options, 168 unsigned char *start, unsigned char *end, 169 struct string *head, struct string *title, 170 void (*put_chars)(struct html_context *, unsigned char *, int), 171 void (*line_break)(struct html_context *), 172 void *(*special)(struct html_context *, enum html_special_type, 173 ...)); 174 175 void done_html_parser(struct html_context *html_context); 176 struct html_element *init_html_parser_state(struct html_context *html_context, enum html_element_mortality_type type, int align, int margin, int width); 177 void done_html_parser_state(struct html_context *html_context, 178 struct html_element *element); 179 180 /* Interface for the table handling */ 181 182 int get_bgcolor(struct html_context *html_context, unsigned char *a, color_T *rgb); 183 void set_fragment_identifier(struct html_context *html_context, 184 unsigned char *attr_name, unsigned char *attr); 185 void add_fragment_identifier(struct html_context *html_context, 186 struct part *, unsigned char *attr); 187 188 /* Interface for the viewer */ 189 190 int 191 get_image_map(unsigned char *head, unsigned char *pos, unsigned char *eof, 192 struct menu_item **menu, struct memory_list **ml, struct uri *uri, 193 struct document_options *options, unsigned char *target_base, 194 int to, int def, int hdef); 195 196 /* For html/parser/forms.c,general.c,link.c,parse.c,stack.c */ 197 198 /* Ensure that there are at least n successive line-breaks at the current 199 * position, but don't add more than necessary to bring the current number 200 * of successive line-breaks above n. 201 * 202 * For example, there should be two line-breaks after a <br>, but multiple 203 * successive <br>'s warrant still only two line-breaks. ln_break will be 204 * called with n = 2 for each of multiple successive <br>'s, but ln_break 205 * will only add two line-breaks for the entire run of <br>'s. */ 206 void ln_break(struct html_context *html_context, int n); 207 208 int get_color(struct html_context *html_context, unsigned char *a, unsigned char *c, color_T *rgb); 209 210 #endif 211