Hubbub  $Id$
internal.h
Go to the documentation of this file.
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 <jmb@netsurf-browser.org>
6  */
7 
8 #ifndef hubbub_treebuilder_internal_h_
9 #define hubbub_treebuilder_internal_h_
10 
12 
13 typedef enum
14 {
15 /* Special */
24 /* Scoping */
26 /* Formatting */
27  A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
28 /* Phrasing */
31 /* MathML */
33 /* SVG */
34  SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */
36  UNKNOWN
38 
42 typedef struct element_context
43 {
46  uint8_t *name;
48  bool tainted;
54  void *node;
56 
60 typedef struct formatting_list_entry
61 {
64  uint32_t stack_index;
69 
74 {
78 #define ELEMENT_STACK_CHUNK 128
80  uint32_t stack_alloc;
81  uint32_t current_node;
88  void *head_element;
90  void *form_element;
93  void *document;
97  struct {
110  bool frameset_ok;
112 
117 {
125  void *error_pw;
126 };
127 
129  const hubbub_token *token, void *pw);
130 
132  hubbub_treebuilder *treebuilder, const hubbub_token *token,
133  bool insert_into_current_node);
135  const hubbub_token *token, void *parent);
137  const hubbub_token *token, bool rcdata);
138 
139 uint32_t element_in_scope(hubbub_treebuilder *treebuilder,
140  element_type type, bool in_table);
142  hubbub_treebuilder *treebuilder);
144  hubbub_treebuilder *treebuilder);
146  void *node);
148  const hubbub_tag *tag_name, bool push);
149 void close_implied_end_tags(hubbub_treebuilder *treebuilder,
150  element_type except);
151 void reset_insertion_mode(hubbub_treebuilder *treebuilder);
153  const hubbub_string *string);
155 
157  const hubbub_string *tag_name);
158 
163 
165  hubbub_ns ns, element_type type, void *node);
167  hubbub_ns *ns, element_type *type, void **node);
171  uint32_t index, hubbub_ns *ns, element_type *type,
172  void **removed);
173 uint32_t current_table(hubbub_treebuilder *treebuilder);
176 
178  hubbub_ns ns, element_type type, void *node,
179  uint32_t stack_index);
182  hubbub_ns ns, element_type type, void *node,
183  uint32_t stack_index);
185  formatting_list_entry *entry,
186  hubbub_ns *ns, element_type *type, void **node,
187  uint32_t *stack_index);
189  formatting_list_entry *entry,
190  hubbub_ns ns, element_type type, void *node,
191  uint32_t stack_index,
192  hubbub_ns *ons, element_type *otype, void **onode,
193  uint32_t *ostack_index);
194 
195 /* in_foreign_content.c */
197 void adjust_svg_attributes(hubbub_treebuilder *treebuilder,
198  hubbub_tag *tag);
199 void adjust_svg_tagname(hubbub_treebuilder *treebuilder,
200  hubbub_tag *tag);
202  hubbub_tag *tag);
203 
204 /* in_body.c */
206  void *node, void **inserted);
207 
208 #ifndef NDEBUG
209 #include <stdio.h>
210 
211 void element_stack_dump(hubbub_treebuilder *treebuilder, FILE *fp);
212 void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp);
213 
215 
216 #endif
217 
218 #endif
219 
PLAINTEXT
@ PLAINTEXT
Definition: internal.h:21
process_comment_append
hubbub_error process_comment_append(hubbub_treebuilder *treebuilder, const hubbub_token *token, void *parent)
Process a comment token, appending it to the given parent.
Definition: treebuilder.c:479
adjust_foreign_attributes
void adjust_foreign_attributes(hubbub_treebuilder *treebuilder, hubbub_tag *tag)
Adjust foreign attributes.
Definition: in_foreign_content.c:227
formatting_list_entry::stack_index
uint32_t stack_index
Index into element stack.
Definition: internal.h:64
formatting_list_replace
hubbub_error formatting_list_replace(hubbub_treebuilder *treebuilder, formatting_list_entry *entry, hubbub_ns ns, element_type type, void *node, uint32_t stack_index, hubbub_ns *ons, element_type *otype, void **onode, uint32_t *ostack_index)
Remove an element from the list of active formatting elements.
Definition: treebuilder.c:1488
SMALL
@ SMALL
Definition: internal.h:27
element_context
Item on the element stack.
Definition: internal.h:43
element_stack_pop_until
hubbub_error element_stack_pop_until(hubbub_treebuilder *treebuilder, element_type type)
Pop elements until an element of type "element" has been popped.
Definition: treebuilder.c:1220
hubbub_treebuilder_token_handler
hubbub_error hubbub_treebuilder_token_handler(const hubbub_token *token, void *pw)
Handle tokeniser emitting a token.
Definition: treebuilder.c:323
H4
@ H4
Definition: internal.h:19
element_in_scope
uint32_t element_in_scope(hubbub_treebuilder *treebuilder, element_type type, bool in_table)
Determine if an element is in (table) scope.
Definition: treebuilder.c:558
TBODY
@ TBODY
Definition: internal.h:22
BASEFONT
@ BASEFONT
Definition: internal.h:16
hubbub_treebuilder::tokeniser
hubbub_tokeniser * tokeniser
Underlying tokeniser.
Definition: internal.h:118
hubbub_treebuilder_context::collect
struct hubbub_treebuilder_context::@9 collect
Context for character collecting.
element_stack_pop
hubbub_error element_stack_pop(hubbub_treebuilder *treebuilder, hubbub_ns *ns, element_type *type, void **node)
Pop an element off the stack of open elements.
Definition: treebuilder.c:1171
hubbub_treebuilder_context
struct hubbub_treebuilder_context hubbub_treebuilder_context
Context for a tree builder.
NOEMBED
@ NOEMBED
Definition: internal.h:21
MENU
@ MENU
Definition: internal.h:20
SUB
@ SUB
Definition: internal.h:30
element_context::name
uint8_t * name
Element name (interned)
Definition: internal.h:46
prev_node
element_type prev_node(hubbub_treebuilder *treebuilder)
Peek at the element below the top of the element stack.
Definition: treebuilder.c:1329
MO
@ MO
Definition: internal.h:32
reconstruct_active_formatting_list
hubbub_error reconstruct_active_formatting_list(hubbub_treebuilder *treebuilder)
Reconstruct the list of active formatting elements.
Definition: treebuilder.c:601
THEAD
@ THEAD
Definition: internal.h:23
SVG
@ SVG
Definition: internal.h:34
formatting_list_append
hubbub_error formatting_list_append(hubbub_treebuilder *treebuilder, hubbub_ns ns, element_type type, void *node, uint32_t stack_index)
Append an element to the end of the list of active formatting elements.
Definition: treebuilder.c:1350
RT
@ RT
Definition: internal.h:30
element_context::ns
hubbub_ns ns
Element namespace.
Definition: internal.h:44
hubbub_treebuilder::error_pw
void * error_pw
Error handler data.
Definition: internal.h:125
FOREIGNOBJECT
@ FOREIGNOBJECT
Definition: internal.h:34
element_type_to_name
const char * element_type_to_name(element_type type)
Convert an element type to a name.
Definition: treebuilder.c:1557
OPTGROUP
@ OPTGROUP
Definition: internal.h:21
MN
@ MN
Definition: internal.h:32
adjust_mathml_attributes
void adjust_mathml_attributes(hubbub_treebuilder *treebuilder, hubbub_tag *tag)
Adjust MathML attributes.
Definition: in_foreign_content.c:144
element_type_from_name
element_type element_type_from_name(hubbub_treebuilder *treebuilder, const hubbub_string *tag_name)
Convert an element name into an element type.
Definition: treebuilder.c:1045
CODE
@ CODE
Definition: internal.h:27
NOSCRIPT
@ NOSCRIPT
Definition: internal.h:21
P
@ P
Definition: internal.h:21
DIALOG
@ DIALOG
Definition: internal.h:18
VAR
@ VAR
Definition: internal.h:30
ARTICLE
@ ARTICLE
Definition: internal.h:16
hubbub_ns
hubbub_ns
Possible namespaces.
Definition: types.h:63
hubbub_token
Token data.
Definition: types.h:119
A
@ A
Definition: internal.h:27
adjust_svg_attributes
void adjust_svg_attributes(hubbub_treebuilder *treebuilder, hubbub_tag *tag)
Adjust SVG attributes.
Definition: in_foreign_content.c:169
H5
@ H5
Definition: internal.h:19
RUBY
@ RUBY
Definition: internal.h:30
MARQUEE
@ MARQUEE
Definition: internal.h:25
hubbub_string
Tokeniser string type.
Definition: types.h:76
PARAM
@ PARAM
Definition: internal.h:21
hubbub_treebuilder_context::stack_alloc
uint32_t stack_alloc
Number of stack slots allocated.
Definition: internal.h:80
H2
@ H2
Definition: internal.h:19
formatting_list_entry::prev
struct formatting_list_entry * prev
Previous in list.
Definition: internal.h:66
FIGCAPTION
@ FIGCAPTION
Definition: internal.h:18
adjust_svg_tagname
void adjust_svg_tagname(hubbub_treebuilder *treebuilder, hubbub_tag *tag)
Adjust SVG tagnmes.
Definition: in_foreign_content.c:199
hubbub_treebuilder_context::form_element
void * form_element
Pointer to most recently opened FORM element.
Definition: internal.h:90
clear_active_formatting_list_to_marker
void clear_active_formatting_list_to_marker(hubbub_treebuilder *treebuilder)
Clear the list of active formatting elements up to the last marker.
Definition: treebuilder.c:775
hubbub_treebuilder_context::mode
insertion_mode mode
The current insertion mode.
Definition: internal.h:75
BIG
@ BIG
Definition: internal.h:27
STRONG
@ STRONG
Definition: internal.h:27
TD
@ TD
Definition: internal.h:25
ANNOTATION_XML
@ ANNOTATION_XML
Definition: internal.h:32
element_stack_remove
hubbub_error element_stack_remove(hubbub_treebuilder *treebuilder, uint32_t index, hubbub_ns *ns, element_type *type, void **removed)
Remove a node from the stack of open elements.
Definition: treebuilder.c:1249
LI
@ LI
Definition: internal.h:20
HEADER
@ HEADER
Definition: internal.h:19
FRAMESET
@ FRAMESET
Definition: internal.h:19
INPUT
@ INPUT
Definition: internal.h:20
HTML
@ HTML
Definition: internal.h:25
NOBR
@ NOBR
Definition: internal.h:27
hubbub_treebuilder_context::strip_leading_lr
bool strip_leading_lr
Whether to strip a LR from the start of the next character sequence received.
Definition: internal.h:102
S
@ S
Definition: internal.h:27
aa_insert_into_foster_parent
hubbub_error aa_insert_into_foster_parent(hubbub_treebuilder *treebuilder, void *node, void **inserted)
Adoption agency: locate foster parent and insert node into it.
Definition: in_body.c:2225
MTEXT
@ MTEXT
Definition: internal.h:32
DIR
@ DIR
Definition: internal.h:18
HR
@ HR
Definition: internal.h:19
DD
@ DD
Definition: internal.h:17
hubbub_treebuilder_context::in_table_foster
bool in_table_foster
Whether nodes that would be inserted into the current node should be foster parented.
Definition: internal.h:106
hubbub_tree_handler
Hubbub tree handler.
Definition: tree.h:273
TH
@ TH
Definition: internal.h:25
FOOTER
@ FOOTER
Definition: internal.h:18
complete_script
hubbub_error complete_script(hubbub_treebuilder *treebuilder)
Script processing and execution.
Definition: treebuilder.c:984
BGSOUND
@ BGSOUND
Definition: internal.h:16
SPACER
@ SPACER
Definition: internal.h:22
META
@ META
Definition: internal.h:20
is_phrasing_element
bool is_phrasing_element(element_type type)
Determine if a node is a phrasing element.
Definition: treebuilder.c:1107
element_context
struct element_context element_context
Item on the element stack.
hubbub_treebuilder_context::formatting_list_end
formatting_list_entry * formatting_list_end
End of active formatting list.
Definition: internal.h:85
is_formatting_element
bool is_formatting_element(element_type type)
Determine if a node is a formatting element.
Definition: treebuilder.c:1096
hubbub_treebuilder_context
Context for a tree builder.
Definition: internal.h:74
IFRAME
@ IFRAME
Definition: internal.h:19
DESC
@ DESC
Definition: internal.h:35
formatting_list_entry
struct formatting_list_entry formatting_list_entry
Entry in a formatting list.
NAV
@ NAV
Definition: internal.h:20
hubbub_tokeniser
Tokeniser data structure.
Definition: tokeniser.c:165
H3
@ H3
Definition: internal.h:19
hubbub_treebuilder_context::type
element_type type
Type of node.
Definition: internal.h:99
element_type
element_type
Definition: internal.h:14
SPAN
@ SPAN
Definition: internal.h:30
MAIN
@ MAIN
Definition: internal.h:20
DIV
@ DIV
Definition: internal.h:18
hubbub_tag
Data for a tag.
Definition: types.h:108
COMMAND
@ COMMAND
Definition: internal.h:17
SUMMARY
@ SUMMARY
Definition: internal.h:22
COLGROUP
@ COLGROUP
Definition: internal.h:17
hubbub_treebuilder::tree_handler
hubbub_tree_handler * tree_handler
Callback table.
Definition: internal.h:122
SUP
@ SUP
Definition: internal.h:30
TABLE
@ TABLE
Definition: internal.h:25
OUTPUT
@ OUTPUT
Definition: internal.h:30
TFOOT
@ TFOOT
Definition: internal.h:23
RP
@ RP
Definition: internal.h:30
hubbub_error_handler
void(* hubbub_error_handler)(uint32_t line, uint32_t col, const char *message, void *pw)
Type of parse error handling function.
Definition: functypes.h:40
SECTION
@ SECTION
Definition: internal.h:22
formatting_list_entry
Entry in a formatting list.
Definition: internal.h:61
DL
@ DL
Definition: internal.h:18
hubbub_treebuilder_context::enable_scripting
bool enable_scripting
Whether scripting is enabled.
Definition: internal.h:95
BODY
@ BODY
Definition: internal.h:17
hubbub_treebuilder_context::head_element
void * head_element
Pointer to HEAD element.
Definition: internal.h:88
formatting_list_entry::details
element_context details
Entry details.
Definition: internal.h:62
ISINDEX
@ ISINDEX
Definition: internal.h:20
hubbub_error
hubbub_error
Definition: errors.h:18
TT
@ TT
Definition: internal.h:27
BASE
@ BASE
Definition: internal.h:16
type
element_type type
Definition: treebuilder.c:26
OBJECT
@ OBJECT
Definition: internal.h:25
DT
@ DT
Definition: internal.h:18
is_special_element
bool is_special_element(element_type type)
Determine if a node is a special element.
Definition: treebuilder.c:1074
FONT
@ FONT
Definition: internal.h:27
STYLE
@ STYLE
Definition: internal.h:22
FIGURE
@ FIGURE
Definition: internal.h:18
hubbub_treebuilder_context::formatting_list
formatting_list_entry * formatting_list
List of active formatting elements.
Definition: internal.h:83
append_text
hubbub_error append_text(hubbub_treebuilder *treebuilder, const hubbub_string *string)
Append text to the current node, inserting into the last child of the current node,...
Definition: treebuilder.c:1002
close_implied_end_tags
void close_implied_end_tags(hubbub_treebuilder *treebuilder, element_type except)
Close implied end tags.
Definition: treebuilder.c:887
formatting_list_entry::next
struct formatting_list_entry * next
Next in list.
Definition: internal.h:67
PRE
@ PRE
Definition: internal.h:22
hubbub_treebuilder::context
hubbub_treebuilder_context context
Our context.
Definition: internal.h:120
insert_element
hubbub_error insert_element(hubbub_treebuilder *treebuilder, const hubbub_tag *tag_name, bool push)
Create element and insert it into the DOM, potentially pushing it on the stack.
Definition: treebuilder.c:810
MATH
@ MATH
Definition: internal.h:32
hubbub_treebuilder_context::frameset_ok
bool frameset_ok
Whether to process a frameset.
Definition: internal.h:110
H1
@ H1
Definition: internal.h:19
is_scoping_element
bool is_scoping_element(element_type type)
Determine if a node is a scoping element.
Definition: treebuilder.c:1085
MALIGNMARK
@ MALIGNMARK
Definition: internal.h:32
process_characters_expect_whitespace
hubbub_error process_characters_expect_whitespace(hubbub_treebuilder *treebuilder, const hubbub_token *token, bool insert_into_current_node)
Process a character token in cases where we expect only whitespace.
Definition: treebuilder.c:433
ASIDE
@ ASIDE
Definition: internal.h:16
hubbub_treebuilder_context::document
void * document
Pointer to the document node.
Definition: internal.h:93
MGLYPH
@ MGLYPH
Definition: internal.h:32
APPLET
@ APPLET
Definition: internal.h:25
CENTER
@ CENTER
Definition: internal.h:17
insertion_mode
insertion_mode
The various treebuilder insertion modes.
Definition: modes.h:15
element_stack_push
hubbub_error element_stack_push(hubbub_treebuilder *treebuilder, hubbub_ns ns, element_type type, void *node)
Push an element onto the stack of open elements.
Definition: treebuilder.c:1134
hubbub_treebuilder::error_handler
hubbub_error_handler error_handler
Error handler.
Definition: internal.h:124
MS
@ MS
Definition: internal.h:32
formatting_list_dump
void formatting_list_dump(hubbub_treebuilder *treebuilder, FILE *fp)
Dump a formatting list to the given file pointer.
Definition: treebuilder.c:1539
STRIKE
@ STRIKE
Definition: internal.h:27
current_table
uint32_t current_table(hubbub_treebuilder *treebuilder)
Find the stack index of the current table.
Definition: treebuilder.c:1297
LINK
@ LINK
Definition: internal.h:20
BR
@ BR
Definition: internal.h:17
XMP
@ XMP
Definition: internal.h:30
element_stack_dump
void element_stack_dump(hubbub_treebuilder *treebuilder, FILE *fp)
Dump an element stack to the given file pointer.
Definition: treebuilder.c:1520
H6
@ H6
Definition: internal.h:19
FIELDSET
@ FIELDSET
Definition: internal.h:18
element_context::node
void * node
Node pointer.
Definition: internal.h:54
SELECT
@ SELECT
Definition: internal.h:22
BUTTON
@ BUTTON
Definition: internal.h:25
AREA
@ AREA
Definition: internal.h:16
COL
@ COL
Definition: internal.h:17
formatting_list_remove
hubbub_error formatting_list_remove(hubbub_treebuilder *treebuilder, formatting_list_entry *entry, hubbub_ns *ns, element_type *type, void **node, uint32_t *stack_index)
Remove an element from the list of active formatting elements.
Definition: treebuilder.c:1442
BLOCKQUOTE
@ BLOCKQUOTE
Definition: internal.h:16
reset_insertion_mode
void reset_insertion_mode(hubbub_treebuilder *treebuilder)
Reset the insertion mode.
Definition: treebuilder.c:921
U
@ U
Definition: internal.h:27
I
@ I
Definition: internal.h:27
TR
@ TR
Definition: internal.h:23
IMAGE
@ IMAGE
Definition: internal.h:20
LABEL
@ LABEL
Definition: internal.h:30
hubbub_treebuilder_context::second_mode
insertion_mode second_mode
The secondary insertion mode.
Definition: internal.h:76
SCRIPT
@ SCRIPT
Definition: internal.h:22
element_context::tainted
bool tainted
Only for tables.
Definition: internal.h:48
EM
@ EM
Definition: internal.h:27
formatting_list_insert
hubbub_error formatting_list_insert(hubbub_treebuilder *treebuilder, formatting_list_entry *prev, formatting_list_entry *next, hubbub_ns ns, element_type type, void *node, uint32_t stack_index)
Insert an element into the list of active formatting elements.
Definition: treebuilder.c:1390
current_node
element_type current_node(hubbub_treebuilder *treebuilder)
Peek at the top element of the element stack.
Definition: treebuilder.c:1317
UL
@ UL
Definition: internal.h:23
OL
@ OL
Definition: internal.h:21
treebuilder.h
LISTING
@ LISTING
Definition: internal.h:20
remove_node_from_dom
hubbub_error remove_node_from_dom(hubbub_treebuilder *treebuilder, void *node)
Remove a node from the DOM.
Definition: treebuilder.c:739
UNKNOWN
@ UNKNOWN
Definition: internal.h:36
hubbub_treebuilder
Treebuilder object.
Definition: internal.h:117
WBR
@ WBR
Definition: internal.h:23
HEAD
@ HEAD
Definition: internal.h:19
hubbub_treebuilder_context::element_stack
element_context * element_stack
Stack of open elements.
Definition: internal.h:79
ADDRESS
@ ADDRESS
Definition: internal.h:16
DATAGRID
@ DATAGRID
Definition: internal.h:17
element_context::type
element_type type
Element type.
Definition: internal.h:45
FORM
@ FORM
Definition: internal.h:19
hubbub_treebuilder_context::current_node
uint32_t current_node
Index of current node in stack.
Definition: internal.h:81
NOFRAMES
@ NOFRAMES
Definition: internal.h:21
B
@ B
Definition: internal.h:27
parse_generic_rcdata
hubbub_error parse_generic_rcdata(hubbub_treebuilder *treebuilder, const hubbub_token *token, bool rcdata)
Trigger parsing of generic (R)CDATA.
Definition: treebuilder.c:522
MI
@ MI
Definition: internal.h:32
TEXTAREA
@ TEXTAREA
Definition: internal.h:22
DETAILS
@ DETAILS
Definition: internal.h:17
IMG
@ IMG
Definition: internal.h:20
TITLE
@ TITLE
Definition: internal.h:23
FRAME
@ FRAME
Definition: internal.h:19
CAPTION
@ CAPTION
Definition: internal.h:25
EMBED
@ EMBED
Definition: internal.h:18
OPTION
@ OPTION
Definition: internal.h:21