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
;
78 nsHtml5Tokenizer
* tokenizer
;
80 PRBool scriptingEnabled
;
84 PRInt32 contextNamespace
;
85 nsIContent
** contextNode
;
86 autoJArray
<nsHtml5StackNode
*,PRInt32
> stack
;
88 autoJArray
<nsHtml5StackNode
*,PRInt32
> listOfActiveFormattingElements
;
90 nsIContent
** formPointer
;
91 nsIContent
** headPointer
;
92 nsIContent
** deepTreeSurrogateParent
;
94 autoJArray
<PRUnichar
,PRInt32
> charBuffer
;
95 PRInt32 charBufferLen
;
99 void startTokenization(nsHtml5Tokenizer
* self
);
100 void doctype(nsIAtom
* name
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool forceQuirks
);
101 void comment(PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
102 void characters(const PRUnichar
* buf
, PRInt32 start
, PRInt32 length
);
103 void zeroOriginatingReplacementCharacter();
105 void endTokenization();
106 void startTag(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
, PRBool selfClosing
);
108 PRBool
isSpecialParentInForeign(nsHtml5StackNode
* stackNode
);
110 static nsString
* extractCharsetFromContent(nsString
* attributeValue
);
112 void checkMetaCharset(nsHtml5HtmlAttributes
* attributes
);
114 void endTag(nsHtml5ElementName
* elementName
);
116 PRInt32
findLastInTableScopeOrRootTbodyTheadTfoot();
117 PRInt32
findLast(nsIAtom
* name
);
118 PRInt32
findLastInTableScope(nsIAtom
* name
);
119 PRInt32
findLastInButtonScope(nsIAtom
* name
);
120 PRInt32
findLastInScope(nsIAtom
* name
);
121 PRInt32
findLastInListScope(nsIAtom
* name
);
122 PRInt32
findLastInScopeHn();
123 void generateImpliedEndTagsExceptFor(nsIAtom
* name
);
124 void generateImpliedEndTags();
125 PRBool
isSecondOnStackBody();
126 void documentModeInternal(nsHtml5DocumentMode m
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool html4SpecificAdditionalErrorChecks
);
127 PRBool
isAlmostStandards(nsString
* publicIdentifier
, nsString
* systemIdentifier
);
128 PRBool
isQuirky(nsIAtom
* name
, nsString
* publicIdentifier
, nsString
* systemIdentifier
, PRBool forceQuirks
);
129 void closeTheCell(PRInt32 eltPos
);
130 PRInt32
findLastInTableScopeTdTh();
131 void clearStackBackTo(PRInt32 eltPos
);
132 void resetTheInsertionMode();
133 void implicitlyCloseP();
134 PRBool
clearLastStackSlot();
135 PRBool
clearLastListSlot();
136 void push(nsHtml5StackNode
* node
);
137 void silentPush(nsHtml5StackNode
* node
);
138 void append(nsHtml5StackNode
* node
);
139 inline void insertMarker()
144 void clearTheListOfActiveFormattingElementsUpToTheLastMarker();
145 inline PRBool
isCurrent(nsIAtom
* name
)
147 return name
== stack
[currentPtr
]->name
;
150 void removeFromStack(PRInt32 pos
);
151 void removeFromStack(nsHtml5StackNode
* node
);
152 void removeFromListOfActiveFormattingElements(PRInt32 pos
);
153 PRBool
adoptionAgencyEndTag(nsIAtom
* name
);
154 void insertIntoStack(nsHtml5StackNode
* node
, PRInt32 position
);
155 void insertIntoListOfActiveFormattingElements(nsHtml5StackNode
* formattingClone
, PRInt32 bookmark
);
156 PRInt32
findInListOfActiveFormattingElements(nsHtml5StackNode
* node
);
157 PRInt32
findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom
* name
);
158 void maybeForgetEarlierDuplicateFormattingElement(nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
);
159 PRInt32
findLastOrRoot(nsIAtom
* name
);
160 PRInt32
findLastOrRoot(PRInt32 group
);
161 PRBool
addAttributesToBody(nsHtml5HtmlAttributes
* attributes
);
162 void addAttributesToHtml(nsHtml5HtmlAttributes
* attributes
);
163 void pushHeadPointerOntoStack();
164 void reconstructTheActiveFormattingElements();
165 void insertIntoFosterParent(nsIContent
** child
);
166 PRBool
isInStack(nsHtml5StackNode
* node
);
170 void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes
* attributes
);
171 void appendHtmlElementToDocumentAndPush();
172 void appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes
* attributes
);
173 void appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes
* attributes
);
174 void appendToCurrentNodeAndPushBodyElement();
175 void appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes
* attributes
);
176 void appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
177 void appendToCurrentNodeAndPushElement(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
178 void appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
179 void appendToCurrentNodeAndPushElementMayFosterMathML(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
180 PRBool
annotationXmlEncodingPermitsHtml(nsHtml5HtmlAttributes
* attributes
);
181 void appendToCurrentNodeAndPushElementMayFosterSVG(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
182 void appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
183 void appendVoidElementToCurrentMayFoster(nsIAtom
* name
, nsHtml5HtmlAttributes
* attributes
, nsIContent
** form
);
184 void appendVoidElementToCurrentMayFoster(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
185 void appendVoidElementToCurrentMayFosterSVG(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
186 void appendVoidElementToCurrentMayFosterMathML(nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
187 void appendVoidElementToCurrent(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 inline PRBool
cdataSectionAllowed()
215 return isInForeign();
219 PRBool
isInForeign();
221 void setFragmentContext(nsIAtom
* context
, PRInt32 ns
, nsIContent
** node
, PRBool quirks
);
223 nsIContent
** currentNode();
225 PRBool
isScriptingEnabled();
226 void setScriptingEnabled(PRBool scriptingEnabled
);
227 void flushCharacters();
229 PRBool
charBufferContainsNonWhitespace();
231 nsAHtml5TreeBuilderState
* newSnapshot();
232 PRBool
snapshotMatches(nsAHtml5TreeBuilderState
* snapshot
);
233 void loadState(nsAHtml5TreeBuilderState
* snapshot
, nsHtml5AtomTable
* interner
);
235 PRInt32
findInArray(nsHtml5StackNode
* node
, jArray
<nsHtml5StackNode
*,PRInt32
> arr
);
237 nsIContent
** getFormPointer();
238 nsIContent
** getHeadPointer();
239 nsIContent
** getDeepTreeSurrogateParent();
240 jArray
<nsHtml5StackNode
*,PRInt32
> getListOfActiveFormattingElements();
241 jArray
<nsHtml5StackNode
*,PRInt32
> getStack();
243 PRInt32
getOriginalMode();
244 PRBool
isFramesetOk();
245 PRBool
isNeedToDropLF();
247 PRInt32
getListOfActiveFormattingElementsLength();
248 PRInt32
getStackLength();
249 static void initializeStatics();
250 static void releaseStatics();
252 #include "nsHtml5TreeBuilderHSupplement.h"
255 #define NS_HTML5TREE_BUILDER_OTHER 0
256 #define NS_HTML5TREE_BUILDER_A 1
257 #define NS_HTML5TREE_BUILDER_BASE 2
258 #define NS_HTML5TREE_BUILDER_BODY 3
259 #define NS_HTML5TREE_BUILDER_BR 4
260 #define NS_HTML5TREE_BUILDER_BUTTON 5
261 #define NS_HTML5TREE_BUILDER_CAPTION 6
262 #define NS_HTML5TREE_BUILDER_COL 7
263 #define NS_HTML5TREE_BUILDER_COLGROUP 8
264 #define NS_HTML5TREE_BUILDER_FORM 9
265 #define NS_HTML5TREE_BUILDER_FRAME 10
266 #define NS_HTML5TREE_BUILDER_FRAMESET 11
267 #define NS_HTML5TREE_BUILDER_IMAGE 12
268 #define NS_HTML5TREE_BUILDER_INPUT 13
269 #define NS_HTML5TREE_BUILDER_ISINDEX 14
270 #define NS_HTML5TREE_BUILDER_LI 15
271 #define NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND 16
272 #define NS_HTML5TREE_BUILDER_MATH 17
273 #define NS_HTML5TREE_BUILDER_META 18
274 #define NS_HTML5TREE_BUILDER_SVG 19
275 #define NS_HTML5TREE_BUILDER_HEAD 20
276 #define NS_HTML5TREE_BUILDER_HR 22
277 #define NS_HTML5TREE_BUILDER_HTML 23
278 #define NS_HTML5TREE_BUILDER_NOBR 24
279 #define NS_HTML5TREE_BUILDER_NOFRAMES 25
280 #define NS_HTML5TREE_BUILDER_NOSCRIPT 26
281 #define NS_HTML5TREE_BUILDER_OPTGROUP 27
282 #define NS_HTML5TREE_BUILDER_OPTION 28
283 #define NS_HTML5TREE_BUILDER_P 29
284 #define NS_HTML5TREE_BUILDER_PLAINTEXT 30
285 #define NS_HTML5TREE_BUILDER_SCRIPT 31
286 #define NS_HTML5TREE_BUILDER_SELECT 32
287 #define NS_HTML5TREE_BUILDER_STYLE 33
288 #define NS_HTML5TREE_BUILDER_TABLE 34
289 #define NS_HTML5TREE_BUILDER_TEXTAREA 35
290 #define NS_HTML5TREE_BUILDER_TITLE 36
291 #define NS_HTML5TREE_BUILDER_TR 37
292 #define NS_HTML5TREE_BUILDER_XMP 38
293 #define NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT 39
294 #define NS_HTML5TREE_BUILDER_TD_OR_TH 40
295 #define NS_HTML5TREE_BUILDER_DD_OR_DT 41
296 #define NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 42
297 #define NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET 43
298 #define NS_HTML5TREE_BUILDER_PRE_OR_LISTING 44
299 #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
300 #define NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL 46
301 #define NS_HTML5TREE_BUILDER_IFRAME 47
302 #define NS_HTML5TREE_BUILDER_EMBED_OR_IMG 48
303 #define NS_HTML5TREE_BUILDER_AREA_OR_WBR 49
304 #define NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU 50
305 #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
306 #define NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR 52
307 #define NS_HTML5TREE_BUILDER_RT_OR_RP 53
308 #define NS_HTML5TREE_BUILDER_COMMAND 54
309 #define NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK 55
310 #define NS_HTML5TREE_BUILDER_MGLYPH_OR_MALIGNMARK 56
311 #define NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT 57
312 #define NS_HTML5TREE_BUILDER_ANNOTATION_XML 58
313 #define NS_HTML5TREE_BUILDER_FOREIGNOBJECT_OR_DESC 59
314 #define NS_HTML5TREE_BUILDER_NOEMBED 60
315 #define NS_HTML5TREE_BUILDER_FIELDSET 61
316 #define NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL 62
317 #define NS_HTML5TREE_BUILDER_OBJECT 63
318 #define NS_HTML5TREE_BUILDER_FONT 64
319 #define NS_HTML5TREE_BUILDER_KEYGEN 65
320 #define NS_HTML5TREE_BUILDER_INITIAL 0
321 #define NS_HTML5TREE_BUILDER_BEFORE_HTML 1
322 #define NS_HTML5TREE_BUILDER_BEFORE_HEAD 2
323 #define NS_HTML5TREE_BUILDER_IN_HEAD 3
324 #define NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT 4
325 #define NS_HTML5TREE_BUILDER_AFTER_HEAD 5
326 #define NS_HTML5TREE_BUILDER_IN_BODY 6
327 #define NS_HTML5TREE_BUILDER_IN_TABLE 7
328 #define NS_HTML5TREE_BUILDER_IN_CAPTION 8
329 #define NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP 9
330 #define NS_HTML5TREE_BUILDER_IN_TABLE_BODY 10
331 #define NS_HTML5TREE_BUILDER_IN_ROW 11
332 #define NS_HTML5TREE_BUILDER_IN_CELL 12
333 #define NS_HTML5TREE_BUILDER_IN_SELECT 13
334 #define NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE 14
335 #define NS_HTML5TREE_BUILDER_AFTER_BODY 15
336 #define NS_HTML5TREE_BUILDER_IN_FRAMESET 16
337 #define NS_HTML5TREE_BUILDER_AFTER_FRAMESET 17
338 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY 18
339 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET 19
340 #define NS_HTML5TREE_BUILDER_TEXT 20
341 #define NS_HTML5TREE_BUILDER_FRAMESET_OK 21
342 #define NS_HTML5TREE_BUILDER_CHARSET_INITIAL 0
343 #define NS_HTML5TREE_BUILDER_CHARSET_C 1
344 #define NS_HTML5TREE_BUILDER_CHARSET_H 2
345 #define NS_HTML5TREE_BUILDER_CHARSET_A 3
346 #define NS_HTML5TREE_BUILDER_CHARSET_R 4
347 #define NS_HTML5TREE_BUILDER_CHARSET_S 5
348 #define NS_HTML5TREE_BUILDER_CHARSET_E 6
349 #define NS_HTML5TREE_BUILDER_CHARSET_T 7
350 #define NS_HTML5TREE_BUILDER_CHARSET_EQUALS 8
351 #define NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED 9
352 #define NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED 10
353 #define NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED 11
354 #define NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK PR_INT32_MAX