Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3584 | sourcerer | 1 | /* |
2 | * This file is part of Hubbub. |
||
3 | * Licensed under the MIT License, |
||
4 | * http://www.opensource.org/licenses/mit-license.php |
||
5 | * Copyright 2008 John-Mark Bell |
||
6 | */ |
||
7 | |||
8 | #ifndef hubbub_treebuilder_internal_h_ |
||
9 | #define hubbub_treebuilder_internal_h_ |
||
10 | |||
11 | #include "treebuilder/treebuilder.h" |
||
12 | |||
13 | typedef enum |
||
14 | { |
||
15 | /* Special */ |
||
16 | ADDRESS, AREA, ARTICLE, ASIDE, BASE, BASEFONT, BGSOUND, BLOCKQUOTE, |
||
17 | BODY, BR, CENTER, COL, COLGROUP, COMMAND, DATAGRID, DD, DETAILS, |
||
18 | DIALOG, DIR, DIV, DL, DT, EMBED, FIELDSET, FIGURE, FOOTER, FORM, FRAME, |
||
19 | FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HR, IFRAME, IMAGE, IMG, |
||
20 | INPUT, ISINDEX, LI, LINK, LISTING, MENU, META, NAV, NOEMBED, NOFRAMES, |
||
21 | NOSCRIPT, OL, OPTGROUP, OPTION, P, PARAM, PLAINTEXT, PRE, SCRIPT, |
||
22 | SECTION, SELECT, SPACER, STYLE, TBODY, TEXTAREA, TFOOT, THEAD, TITLE, |
||
23 | TR, UL, WBR, |
||
24 | /* Scoping */ |
||
25 | APPLET, BUTTON, CAPTION, HTML, MARQUEE, OBJECT, TABLE, TD, TH, |
||
26 | /* Formatting */ |
||
27 | A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U, |
||
28 | /* Phrasing */ |
||
29 | /**< \todo Enumerate phrasing elements */ |
||
30 | LABEL, OUTPUT, RP, RT, RUBY, SPAN, SUB, SUP, VAR, XMP, |
||
31 | /* MathML */ |
||
32 | MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML, |
||
33 | /* SVG */ |
||
34 | SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */ |
||
35 | DESC, |
||
36 | UNKNOWN |
||
37 | } element_type; |
||
38 | |||
39 | /** |
||
40 | * Item on the element stack |
||
41 | */ |
||
42 | typedef struct element_context |
||
43 | { |
||
44 | hubbub_ns ns; /**< Element namespace */ |
||
45 | element_type type; /**< Element type */ |
||
46 | uint8_t *name; /**< Element name (interned) */ |
||
47 | |||
48 | bool tainted; /**< Only for tables. "Once the |
||
49 | * current table has been tainted, |
||
50 | * whitespace characters are inserted |
||
51 | * into the foster parent element |
||
52 | * instead of the current node." */ |
||
53 | |||
54 | void *node; /**< Node pointer */ |
||
55 | } element_context; |
||
56 | |||
57 | /** |
||
58 | * Entry in a formatting list |
||
59 | */ |
||
60 | typedef struct formatting_list_entry |
||
61 | { |
||
62 | element_context details; /**< Entry details */ |
||
63 | |||
64 | uint32_t stack_index; /**< Index into element stack */ |
||
65 | |||
66 | struct formatting_list_entry *prev; /**< Previous in list */ |
||
67 | struct formatting_list_entry *next; /**< Next in list */ |
||
68 | } formatting_list_entry; |
||
69 | |||
70 | /** |
||
71 | * Context for a tree builder |
||
72 | */ |
||
73 | typedef struct hubbub_treebuilder_context |
||
74 | { |
||
75 | insertion_mode mode; /**< The current insertion mode */ |
||
76 | insertion_mode second_mode; /**< The secondary insertion mode */ |
||
77 | |||
78 | #define ELEMENT_STACK_CHUNK 128 |
||
79 | element_context *element_stack; /**< Stack of open elements */ |
||
80 | uint32_t stack_alloc; /**< Number of stack slots allocated */ |
||
81 | uint32_t current_node; /**< Index of current node in stack */ |
||
82 | |||
83 | formatting_list_entry *formatting_list; /**< List of active formatting |
||
84 | * elements */ |
||
85 | formatting_list_entry *formatting_list_end; /**< End of active |
||
86 | * formatting list */ |
||
87 | |||
88 | void *head_element; /**< Pointer to HEAD element */ |
||
89 | |||
90 | void *form_element; /**< Pointer to most recently |
||
91 | * opened FORM element */ |
||
92 | |||
93 | void *document; /**< Pointer to the document node */ |
||
94 | |||
95 | bool enable_scripting; /**< Whether scripting is enabled */ |
||
96 | |||
97 | struct { |
||
98 | insertion_mode mode; /**< Insertion mode to return to */ |
||
99 | element_type type; /**< Type of node */ |
||
100 | } collect; /**< Context for character collecting */ |
||
101 | |||
102 | bool strip_leading_lr; /**< Whether to strip a LR from the |
||
103 | * start of the next character sequence |
||
104 | * received */ |
||
105 | |||
106 | bool in_table_foster; /**< Whether nodes that would be |
||
107 | * inserted into the current node should |
||
108 | * be foster parented */ |
||
109 | |||
110 | bool frameset_ok; /**< Whether to process a frameset */ |
||
111 | } hubbub_treebuilder_context; |
||
112 | |||
113 | /** |
||
114 | * Treebuilder object |
||
115 | */ |
||
116 | struct hubbub_treebuilder |
||
117 | { |
||
118 | hubbub_tokeniser *tokeniser; /**< Underlying tokeniser */ |
||
119 | |||
120 | hubbub_treebuilder_context context; /**< Our context */ |
||
121 | |||
122 | hubbub_tree_handler *tree_handler; /**< Callback table */ |
||
123 | |||
124 | hubbub_error_handler error_handler; /**< Error handler */ |
||
125 | void *error_pw; /**< Error handler data */ |
||
126 | |||
127 | hubbub_allocator_fn alloc; /**< Memory (de)allocation function */ |
||
128 | void *alloc_pw; /**< Client private data */ |
||
129 | }; |
||
130 | |||
131 | hubbub_error hubbub_treebuilder_token_handler( |
||
132 | const hubbub_token *token, void *pw); |
||
133 | |||
134 | hubbub_error process_characters_expect_whitespace( |
||
135 | hubbub_treebuilder *treebuilder, const hubbub_token *token, |
||
136 | bool insert_into_current_node); |
||
137 | hubbub_error process_comment_append(hubbub_treebuilder *treebuilder, |
||
138 | const hubbub_token *token, void *parent); |
||
139 | hubbub_error parse_generic_rcdata(hubbub_treebuilder *treebuilder, |
||
140 | const hubbub_token *token, bool rcdata); |
||
141 | |||
142 | uint32_t element_in_scope(hubbub_treebuilder *treebuilder, |
||
143 | element_type type, bool in_table); |
||
144 | hubbub_error reconstruct_active_formatting_list( |
||
145 | hubbub_treebuilder *treebuilder); |
||
146 | void clear_active_formatting_list_to_marker( |
||
147 | hubbub_treebuilder *treebuilder); |
||
148 | hubbub_error remove_node_from_dom(hubbub_treebuilder *treebuilder, |
||
149 | void *node); |
||
150 | hubbub_error insert_element(hubbub_treebuilder *treebuilder, |
||
151 | const hubbub_tag *tag_name, bool push); |
||
152 | void close_implied_end_tags(hubbub_treebuilder *treebuilder, |
||
153 | element_type except); |
||
154 | void reset_insertion_mode(hubbub_treebuilder *treebuilder); |
||
155 | hubbub_error append_text(hubbub_treebuilder *treebuilder, |
||
156 | const hubbub_string *string); |
||
157 | hubbub_error complete_script(hubbub_treebuilder *treebuilder); |
||
158 | |||
159 | element_type element_type_from_name(hubbub_treebuilder *treebuilder, |
||
160 | const hubbub_string *tag_name); |
||
161 | |||
162 | bool is_special_element(element_type type); |
||
163 | bool is_scoping_element(element_type type); |
||
164 | bool is_formatting_element(element_type type); |
||
165 | bool is_phrasing_element(element_type type); |
||
166 | |||
167 | hubbub_error element_stack_push(hubbub_treebuilder *treebuilder, |
||
168 | hubbub_ns ns, element_type type, void *node); |
||
169 | hubbub_error element_stack_pop(hubbub_treebuilder *treebuilder, |
||
170 | hubbub_ns *ns, element_type *type, void **node); |
||
171 | hubbub_error element_stack_pop_until(hubbub_treebuilder *treebuilder, |
||
172 | element_type type); |
||
173 | hubbub_error element_stack_remove(hubbub_treebuilder *treebuilder, |
||
174 | uint32_t index, hubbub_ns *ns, element_type *type, |
||
175 | void **removed); |
||
176 | uint32_t current_table(hubbub_treebuilder *treebuilder); |
||
177 | element_type current_node(hubbub_treebuilder *treebuilder); |
||
178 | element_type prev_node(hubbub_treebuilder *treebuilder); |
||
179 | |||
180 | hubbub_error formatting_list_append(hubbub_treebuilder *treebuilder, |
||
181 | hubbub_ns ns, element_type type, void *node, |
||
182 | uint32_t stack_index); |
||
183 | hubbub_error formatting_list_insert(hubbub_treebuilder *treebuilder, |
||
184 | formatting_list_entry *prev, formatting_list_entry *next, |
||
185 | hubbub_ns ns, element_type type, void *node, |
||
186 | uint32_t stack_index); |
||
187 | hubbub_error formatting_list_remove(hubbub_treebuilder *treebuilder, |
||
188 | formatting_list_entry *entry, |
||
189 | hubbub_ns *ns, element_type *type, void **node, |
||
190 | uint32_t *stack_index); |
||
191 | hubbub_error formatting_list_replace(hubbub_treebuilder *treebuilder, |
||
192 | formatting_list_entry *entry, |
||
193 | hubbub_ns ns, element_type type, void *node, |
||
194 | uint32_t stack_index, |
||
195 | hubbub_ns *ons, element_type *otype, void **onode, |
||
196 | uint32_t *ostack_index); |
||
197 | |||
198 | /* in_foreign_content.c */ |
||
199 | void adjust_mathml_attributes(hubbub_treebuilder *treebuilder, hubbub_tag *tag); |
||
200 | void adjust_svg_attributes(hubbub_treebuilder *treebuilder, |
||
201 | hubbub_tag *tag); |
||
202 | void adjust_svg_tagname(hubbub_treebuilder *treebuilder, |
||
203 | hubbub_tag *tag); |
||
204 | void adjust_foreign_attributes(hubbub_treebuilder *treebuilder, |
||
205 | hubbub_tag *tag); |
||
206 | |||
207 | /* in_body.c */ |
||
208 | hubbub_error aa_insert_into_foster_parent(hubbub_treebuilder *treebuilder, |
||
209 | void *node, void **inserted); |
||
210 | |||
211 | #ifndef NDEBUG |
||
212 | #include |
||
213 | |||
214 | void element_stack_dump(hubbub_treebuilder *treebuilder, FILE *fp); |
||
215 | void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp); |
||
216 | |||
217 | const char *element_type_to_name(element_type type); |
||
218 | |||
219 | #endif |
||
220 | |||
221 | #endif>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
||
222 |