2 * Copyright (c) 2007 Henri Sivonen
3 * Copyright (c) 2007-2010 Mozilla Foundation
4 * Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla
5 * Foundation, and Opera Software ASA.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
28 * Please edit TreeBuilder.java instead and regenerate.
31 #ifndef nsHtml5TreeBuilder_h__
32 #define nsHtml5TreeBuilder_h__
36 #include "nsHtml5AtomTable.h"
39 #include "nsINameSpaceManager.h"
40 #include "nsIContent.h"
41 #include "nsIDocument.h"
42 #include "nsTraceRefcnt.h"
44 #include "nsHtml5DocumentMode.h"
45 #include "nsHtml5ArrayCopy.h"
46 #include "nsHtml5Parser.h"
47 #include "nsHtml5Atoms.h"
48 #include "nsHtml5ByteReadable.h"
49 #include "nsHtml5TreeOperation.h"
50 #include "nsHtml5PendingNotification.h"
51 #include "nsHtml5StateSnapshot.h"
52 #include "nsHtml5StackNode.h"
53 #include "nsHtml5TreeOpExecutor.h"
54 #include "nsHtml5StreamParser.h"
55 #include "nsAHtml5TreeBuilderState.h"
57 class nsHtml5StreamParser
;
59 class nsHtml5Tokenizer
;
60 class nsHtml5MetaScanner
;
61 class nsHtml5AttributeName
;
62 class nsHtml5ElementName
;
63 class nsHtml5HtmlAttributes
;
64 class nsHtml5UTF16Buffer
;
65 class nsHtml5StateSnapshot
;
66 class nsHtml5Portability
;
69 class nsHtml5TreeBuilder
: public nsAHtml5TreeBuilderState
72 static PRUnichar REPLACEMENT_CHARACTER
[];
73 static staticJArray
<const char*,PRInt32
> QUIRKY_PUBLIC_IDS
;
79 nsHtml5Tokenizer
* tokenizer
;
81 PRBool scriptingEnabled
;
85 PRInt32 contextNamespace
;
86 nsIContent
** contextNode
;
87 autoJArray
<nsHtml5StackNode
*,PRInt32
> stack
;
89 autoJArray
<nsHtml5StackNode
*,PRInt32
> listOfActiveFormattingElements
;
91 nsIContent
** formPointer
;
92 nsIContent
** headPointer
;
93 nsIContent
** deepTreeSurrogateParent
;
95 autoJArray
<PRUnichar
,PRInt32
> charBuffer
;
96 PRInt32 charBufferLen
;
100 void startTokenization(nsHtml5Tokenizer
* self
);
101 void doctype(nsIAtom
* name
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool forceQuirks
);
102 void comment(PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
103 void characters(const PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
104 void zeroOriginatingReplacementCharacter();
106 void endTokenization();
107 void startTag(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
, PRBool selfClosing
);
109 PRBool
isSpecialParentInForeign(nsHtml5StackNode
* stackNode
);
111 static nsString
* extractCharsetFromContent(nsString
* attributeValue
);
113 void checkMetaCharset(nsHtml5HtmlAttributes
* attributes
);
115 void endTag(nsHtml5ElementName
* elementName
);
117 PRInt32
findLastInTableScopeOrRootTbodyTheadTfoot();
118 PRInt32
findLast(nsIAtom
* name
);
119 PRInt32
findLastInTableScope(nsIAtom
* name
);
120 PRInt32
findLastInButtonScope(nsIAtom
* name
);
121 PRInt32
findLastInScope(nsIAtom
* name
);
122 PRInt32
findLastInListScope(nsIAtom
* name
);
123 PRInt32
findLastInScopeHn();
124 PRBool
hasForeignInScope();
125 void generateImpliedEndTagsExceptFor(nsIAtom
* name
);
126 void generateImpliedEndTags();
127 PRBool
isSecondOnStackBody();
128 void documentModeInternal(nsHtml5DocumentMode m
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool html4SpecificAdditionalErrorChecks
);
129 PRBool
isAlmostStandards(nsString
* publicIdentifier
, nsString
* systemIdentifier
);
130 PRBool
isQuirky(nsIAtom
* name
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool forceQuirks
);
131 void closeTheCell(PRInt32 eltPos
);
132 PRInt32
findLastInTableScopeTdTh();
133 void clearStackBackTo(PRInt32 eltPos
);
134 void resetTheInsertionMode();
135 void implicitlyCloseP();
136 PRBool
clearLastStackSlot();
137 PRBool
clearLastListSlot();
138 void push(nsHtml5StackNode
* node
);
139 void silentPush(nsHtml5StackNode
* node
);
140 void append(nsHtml5StackNode
* node
);
141 inline void insertMarker()
146 void clearTheListOfActiveFormattingElementsUpToTheLastMarker();
147 inline PRBool
isCurrent(nsIAtom
* name
)
149 return name
== stack
[currentPtr
]->name
;
152 void removeFromStack(PRInt32 pos
);
153 void removeFromStack(nsHtml5StackNode
* node
);
154 void removeFromListOfActiveFormattingElements(PRInt32 pos
);
155 PRBool
adoptionAgencyEndTag(nsIAtom
* name
);
156 void insertIntoStack(nsHtml5StackNode
* node
, PRInt32 position
);
157 void insertIntoListOfActiveFormattingElements(nsHtml5StackNode
* formattingClone
, PRInt32 bookmark
);
158 PRInt32
findInListOfActiveFormattingElements(nsHtml5StackNode
* node
);
159 PRInt32
findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom
* name
);
160 void maybeForgetEarlierDuplicateFormattingElement(nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
);
161 PRInt32
findLastOrRoot(nsIAtom
* name
);
162 PRInt32
findLastOrRoot(PRInt32 group
);
163 PRBool
addAttributesToBody(nsHtml5HtmlAttributes
* attributes
);
164 void addAttributesToHtml(nsHtml5HtmlAttributes
* attributes
);
165 void pushHeadPointerOntoStack();
166 void reconstructTheActiveFormattingElements();
167 void insertIntoFosterParent(nsIContent
** child
);
168 PRBool
isInStack(nsHtml5StackNode
* node
);
172 void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes
* attributes
);
173 void appendHtmlElementToDocumentAndPush();
174 void appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes
* attributes
);
175 void appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes
* attributes
);
176 void appendToCurrentNodeAndPushBodyElement();
177 void appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes
* attributes
);
178 void appendToCurrentNodeAndPushFormattingElementMayFoster(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
179 void appendToCurrentNodeAndPushElement(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
180 void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
181 void appendToCurrentNodeAndPushElementMayFosterNoScoping(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
182 void appendToCurrentNodeAndPushElementMayFosterCamelCase(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
183 void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
184 void appendVoidElementToCurrentMayFoster(PRInt32 ns
, nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
185 void appendVoidElementToCurrentMayFoster(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
186 void appendVoidElementToCurrentMayFosterCamelCase(PRInt32 ns
, nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
187 void appendVoidElementToCurrent(PRInt32 ns
, nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
188 void appendVoidFormToCurrent(nsHtml5HtmlAttributes
* attributes
);
190 void accumulateCharacters(const PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
191 void requestSuspension();
192 nsIContent
** createElement(PRInt32 ns
, nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
);
193 nsIContent
** createElement(PRInt32 ns
, nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
194 nsIContent
** createHtmlElementSetAsRoot(nsHtml5HtmlAttributes
* attributes
);
195 void detachFromParent(nsIContent
** element
);
196 PRBool
hasChildren(nsIContent
** element
);
197 void appendElement(nsIContent
** child
, nsIContent
** newParent
);
198 void appendChildrenToNewParent(nsIContent
** oldParent
, nsIContent
** newParent
);
199 void insertFosterParentedChild(nsIContent
** child
, nsIContent
** table
, nsIContent
** stackParent
);
200 void insertFosterParentedCharacters(PRUnichar
* buf
, PRInt32 start
, PRInt32 length
, nsIContent
** table
, nsIContent
** stackParent
);
201 void appendCharacters(nsIContent
** parent
, PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
202 void appendIsindexPrompt(nsIContent
** parent
);
203 void appendComment(nsIContent
** parent
, PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
204 void appendCommentToDocument(PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
205 void addAttributesToElement(nsIContent
** element
, nsHtml5HtmlAttributes
* attributes
);
206 void markMalformedIfScript(nsIContent
** elt
);
207 void start(PRBool fragmentMode
);
209 void appendDoctypeToDocument(nsIAtom
* name
, nsString
* publicIdentifier
, nsString
* systemIdentifier
);
210 void elementPushed(PRInt32 ns
, nsIAtom
* name
, nsIContent
** node
);
211 void elementPopped(PRInt32 ns
, nsIAtom
* name
, nsIContent
** node
);
213 PRBool
cdataSectionAllowed();
214 void setFragmentContext(nsIAtom
* context
, PRInt32 ns
, nsIContent
** node
, PRBool quirks
);
216 nsIContent
** currentNode();
218 PRBool
isScriptingEnabled();
219 void setScriptingEnabled(PRBool scriptingEnabled
);
220 void flushCharacters();
222 PRBool
charBufferContainsNonWhitespace();
224 nsAHtml5TreeBuilderState
* newSnapshot();
225 PRBool
snapshotMatches(nsAHtml5TreeBuilderState
* snapshot
);
226 void loadState(nsAHtml5TreeBuilderState
* snapshot
, nsHtml5AtomTable
* interner
);
228 PRInt32
findInArray(nsHtml5StackNode
* node
, jArray
<nsHtml5StackNode
*,PRInt32
> arr
);
230 nsIContent
** getFormPointer();
231 nsIContent
** getHeadPointer();
232 nsIContent
** getDeepTreeSurrogateParent();
233 jArray
<nsHtml5StackNode
*,PRInt32
> getListOfActiveFormattingElements();
234 jArray
<nsHtml5StackNode
*,PRInt32
> getStack();
236 PRInt32
getOriginalMode();
237 PRBool
isFramesetOk();
238 PRBool
isInForeign();
239 PRBool
isNeedToDropLF();
241 PRInt32
getListOfActiveFormattingElementsLength();
242 PRInt32
getStackLength();
243 static void initializeStatics();
244 static void releaseStatics();
246 #include "nsHtml5TreeBuilderHSupplement.h"
249 #define NS_HTML5TREE_BUILDER_OTHER 0
250 #define NS_HTML5TREE_BUILDER_A 1
251 #define NS_HTML5TREE_BUILDER_BASE 2
252 #define NS_HTML5TREE_BUILDER_BODY 3
253 #define NS_HTML5TREE_BUILDER_BR 4
254 #define NS_HTML5TREE_BUILDER_BUTTON 5
255 #define NS_HTML5TREE_BUILDER_CAPTION 6
256 #define NS_HTML5TREE_BUILDER_COL 7
257 #define NS_HTML5TREE_BUILDER_COLGROUP 8
258 #define NS_HTML5TREE_BUILDER_FORM 9
259 #define NS_HTML5TREE_BUILDER_FRAME 10
260 #define NS_HTML5TREE_BUILDER_FRAMESET 11
261 #define NS_HTML5TREE_BUILDER_IMAGE 12
262 #define NS_HTML5TREE_BUILDER_INPUT 13
263 #define NS_HTML5TREE_BUILDER_ISINDEX 14
264 #define NS_HTML5TREE_BUILDER_LI 15
265 #define NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND 16
266 #define NS_HTML5TREE_BUILDER_MATH 17
267 #define NS_HTML5TREE_BUILDER_META 18
268 #define NS_HTML5TREE_BUILDER_SVG 19
269 #define NS_HTML5TREE_BUILDER_HEAD 20
270 #define NS_HTML5TREE_BUILDER_HR 22
271 #define NS_HTML5TREE_BUILDER_HTML 23
272 #define NS_HTML5TREE_BUILDER_NOBR 24
273 #define NS_HTML5TREE_BUILDER_NOFRAMES 25
274 #define NS_HTML5TREE_BUILDER_NOSCRIPT 26
275 #define NS_HTML5TREE_BUILDER_OPTGROUP 27
276 #define NS_HTML5TREE_BUILDER_OPTION 28
277 #define NS_HTML5TREE_BUILDER_P 29
278 #define NS_HTML5TREE_BUILDER_PLAINTEXT 30
279 #define NS_HTML5TREE_BUILDER_SCRIPT 31
280 #define NS_HTML5TREE_BUILDER_SELECT 32
281 #define NS_HTML5TREE_BUILDER_STYLE 33
282 #define NS_HTML5TREE_BUILDER_TABLE 34
283 #define NS_HTML5TREE_BUILDER_TEXTAREA 35
284 #define NS_HTML5TREE_BUILDER_TITLE 36
285 #define NS_HTML5TREE_BUILDER_TR 37
286 #define NS_HTML5TREE_BUILDER_XMP 38
287 #define NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT 39
288 #define NS_HTML5TREE_BUILDER_TD_OR_TH 40
289 #define NS_HTML5TREE_BUILDER_DD_OR_DT 41
290 #define NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 42
291 #define NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET 43
292 #define NS_HTML5TREE_BUILDER_PRE_OR_LISTING 44
293 #define NS_HTML5TREE_BUILDER_B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U 45
294 #define NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL 46
295 #define NS_HTML5TREE_BUILDER_IFRAME 47
296 #define NS_HTML5TREE_BUILDER_EMBED_OR_IMG 48
297 #define NS_HTML5TREE_BUILDER_AREA_OR_WBR 49
298 #define NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU 50
299 #define NS_HTML5TREE_BUILDER_ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_NAV_OR_SECTION_OR_SUMMARY 51
300 #define NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR 52
301 #define NS_HTML5TREE_BUILDER_RT_OR_RP 53
302 #define NS_HTML5TREE_BUILDER_COMMAND 54
303 #define NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE 55
304 #define NS_HTML5TREE_BUILDER_MGLYPH_OR_MALIGNMARK 56
305 #define NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT 57
306 #define NS_HTML5TREE_BUILDER_ANNOTATION_XML 58
307 #define NS_HTML5TREE_BUILDER_FOREIGNOBJECT_OR_DESC 59
308 #define NS_HTML5TREE_BUILDER_NOEMBED 60
309 #define NS_HTML5TREE_BUILDER_FIELDSET 61
310 #define NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL 62
311 #define NS_HTML5TREE_BUILDER_OBJECT 63
312 #define NS_HTML5TREE_BUILDER_FONT 64
313 #define NS_HTML5TREE_BUILDER_KEYGEN 65
314 #define NS_HTML5TREE_BUILDER_INITIAL 0
315 #define NS_HTML5TREE_BUILDER_BEFORE_HTML 1
316 #define NS_HTML5TREE_BUILDER_BEFORE_HEAD 2
317 #define NS_HTML5TREE_BUILDER_IN_HEAD 3
318 #define NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT 4
319 #define NS_HTML5TREE_BUILDER_AFTER_HEAD 5
320 #define NS_HTML5TREE_BUILDER_IN_BODY 6
321 #define NS_HTML5TREE_BUILDER_IN_TABLE 7
322 #define NS_HTML5TREE_BUILDER_IN_CAPTION 8
323 #define NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP 9
324 #define NS_HTML5TREE_BUILDER_IN_TABLE_BODY 10
325 #define NS_HTML5TREE_BUILDER_IN_ROW 11
326 #define NS_HTML5TREE_BUILDER_IN_CELL 12
327 #define NS_HTML5TREE_BUILDER_IN_SELECT 13
328 #define NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE 14
329 #define NS_HTML5TREE_BUILDER_AFTER_BODY 15
330 #define NS_HTML5TREE_BUILDER_IN_FRAMESET 16
331 #define NS_HTML5TREE_BUILDER_AFTER_FRAMESET 17
332 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY 18
333 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET 19
334 #define NS_HTML5TREE_BUILDER_TEXT 20
335 #define NS_HTML5TREE_BUILDER_FRAMESET_OK 21
336 #define NS_HTML5TREE_BUILDER_CHARSET_INITIAL 0
337 #define NS_HTML5TREE_BUILDER_CHARSET_C 1
338 #define NS_HTML5TREE_BUILDER_CHARSET_H 2
339 #define NS_HTML5TREE_BUILDER_CHARSET_A 3
340 #define NS_HTML5TREE_BUILDER_CHARSET_R 4
341 #define NS_HTML5TREE_BUILDER_CHARSET_S 5
342 #define NS_HTML5TREE_BUILDER_CHARSET_E 6
343 #define NS_HTML5TREE_BUILDER_CHARSET_T 7
344 #define NS_HTML5TREE_BUILDER_CHARSET_EQUALS 8
345 #define NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED 9
346 #define NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED 10
347 #define NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED 11
348 #define NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK PR_INT32_MAX