Disable mochitest bug484107. (r=mrbkap, b=596134)
[mozilla-central.git] / parser / html / nsHtml5TreeBuilder.h
blob2fceefd157e8f232bc4212f9abd277f01dff293d
1 /*
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__
34 #include "prtypes.h"
35 #include "nsIAtom.h"
36 #include "nsHtml5AtomTable.h"
37 #include "nsITimer.h"
38 #include "nsString.h"
39 #include "nsINameSpaceManager.h"
40 #include "nsIContent.h"
41 #include "nsIDocument.h"
42 #include "nsTraceRefcnt.h"
43 #include "jArray.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
71 private:
72 static PRUnichar REPLACEMENT_CHARACTER[];
73 static jArray<const char*,PRInt32> QUIRKY_PUBLIC_IDS;
74 PRInt32 mode;
75 PRInt32 originalMode;
76 PRBool framesetOk;
77 PRBool inForeign;
78 protected:
79 nsHtml5Tokenizer* tokenizer;
80 private:
81 PRBool scriptingEnabled;
82 PRBool needToDropLF;
83 PRBool fragment;
84 nsIAtom* contextName;
85 PRInt32 contextNamespace;
86 nsIContent** contextNode;
87 jArray<nsHtml5StackNode*,PRInt32> stack;
88 PRInt32 currentPtr;
89 jArray<nsHtml5StackNode*,PRInt32> listOfActiveFormattingElements;
90 PRInt32 listPtr;
91 nsIContent** formPointer;
92 nsIContent** headPointer;
93 protected:
94 jArray<PRUnichar,PRInt32> charBuffer;
95 PRInt32 charBufferLen;
96 private:
97 PRBool quirks;
98 public:
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();
104 void eof();
105 void endTokenization();
106 void startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, PRBool selfClosing);
107 static nsString* extractCharsetFromContent(nsString* attributeValue);
108 private:
109 void checkMetaCharset(nsHtml5HtmlAttributes* attributes);
110 public:
111 void endTag(nsHtml5ElementName* elementName);
112 private:
113 PRInt32 findLastInTableScopeOrRootTbodyTheadTfoot();
114 PRInt32 findLast(nsIAtom* name);
115 PRInt32 findLastInTableScope(nsIAtom* name);
116 PRInt32 findLastInScope(nsIAtom* name);
117 PRInt32 findLastInListScope(nsIAtom* name);
118 PRInt32 findLastInScopeHn();
119 PRBool hasForeignInScope();
120 void generateImpliedEndTagsExceptFor(nsIAtom* name);
121 void generateImpliedEndTags();
122 PRBool isSecondOnStackBody();
123 void documentModeInternal(nsHtml5DocumentMode m, nsString* publicIdentifier, nsString* systemIdentifier, PRBool html4SpecificAdditionalErrorChecks);
124 PRBool isAlmostStandards(nsString* publicIdentifier, nsString* systemIdentifier);
125 PRBool isQuirky(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier, PRBool forceQuirks);
126 void closeTheCell(PRInt32 eltPos);
127 PRInt32 findLastInTableScopeTdTh();
128 void clearStackBackTo(PRInt32 eltPos);
129 void resetTheInsertionMode();
130 void implicitlyCloseP();
131 PRBool clearLastStackSlot();
132 PRBool clearLastListSlot();
133 void push(nsHtml5StackNode* node);
134 void silentPush(nsHtml5StackNode* node);
135 void append(nsHtml5StackNode* node);
136 inline void insertMarker()
138 append(nsnull);
141 void clearTheListOfActiveFormattingElementsUpToTheLastMarker();
142 inline PRBool isCurrent(nsIAtom* name)
144 return name == stack[currentPtr]->name;
147 void removeFromStack(PRInt32 pos);
148 void removeFromStack(nsHtml5StackNode* node);
149 void removeFromListOfActiveFormattingElements(PRInt32 pos);
150 void adoptionAgencyEndTag(nsIAtom* name);
151 void insertIntoStack(nsHtml5StackNode* node, PRInt32 position);
152 void insertIntoListOfActiveFormattingElements(nsHtml5StackNode* formattingClone, PRInt32 bookmark);
153 PRInt32 findInListOfActiveFormattingElements(nsHtml5StackNode* node);
154 PRInt32 findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom* name);
155 PRInt32 findLastOrRoot(nsIAtom* name);
156 PRInt32 findLastOrRoot(PRInt32 group);
157 PRBool addAttributesToBody(nsHtml5HtmlAttributes* attributes);
158 void addAttributesToHtml(nsHtml5HtmlAttributes* attributes);
159 void pushHeadPointerOntoStack();
160 void reconstructTheActiveFormattingElements();
161 void insertIntoFosterParent(nsIContent** child);
162 PRBool isInStack(nsHtml5StackNode* node);
163 void pop();
164 void silentPop();
165 void popOnEof();
166 void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes* attributes);
167 void appendHtmlElementToDocumentAndPush();
168 void appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes);
169 void appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes* attributes);
170 void appendToCurrentNodeAndPushBodyElement();
171 void appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes* attributes);
172 void appendToCurrentNodeAndPushFormattingElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
173 void appendToCurrentNodeAndPushElement(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
174 void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
175 void appendToCurrentNodeAndPushElementMayFosterNoScoping(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
176 void appendToCurrentNodeAndPushElementMayFosterCamelCase(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
177 void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent** form);
178 void appendVoidElementToCurrentMayFoster(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
179 void appendVoidElementToCurrentMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
180 void appendVoidElementToCurrentMayFosterCamelCase(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
181 void appendVoidElementToCurrent(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
182 void appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes);
183 protected:
184 void accumulateCharacters(const PRUnichar* buf, PRInt32 start, PRInt32 length);
185 void accumulateCharacter(PRUnichar c);
186 void requestSuspension();
187 nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes);
188 nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
189 nsIContent** createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* attributes);
190 void detachFromParent(nsIContent** element);
191 PRBool hasChildren(nsIContent** element);
192 void appendElement(nsIContent** child, nsIContent** newParent);
193 void appendChildrenToNewParent(nsIContent** oldParent, nsIContent** newParent);
194 void insertFosterParentedChild(nsIContent** child, nsIContent** table, nsIContent** stackParent);
195 void insertFosterParentedCharacters(PRUnichar* buf, PRInt32 start, PRInt32 length, nsIContent** table, nsIContent** stackParent);
196 void appendCharacters(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
197 void appendIsindexPrompt(nsIContent** parent);
198 void appendComment(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
199 void appendCommentToDocument(PRUnichar* buf, PRInt32 start, PRInt32 length);
200 void addAttributesToElement(nsIContent** element, nsHtml5HtmlAttributes* attributes);
201 void markMalformedIfScript(nsIContent** elt);
202 void start(PRBool fragmentMode);
203 void end();
204 void appendDoctypeToDocument(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier);
205 void elementPushed(PRInt32 ns, nsIAtom* name, nsIContent** node);
206 void elementPopped(PRInt32 ns, nsIAtom* name, nsIContent** node);
207 public:
208 void setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent** node, PRBool quirks);
209 protected:
210 nsIContent** currentNode();
211 public:
212 PRBool isScriptingEnabled();
213 void setScriptingEnabled(PRBool scriptingEnabled);
214 void flushCharacters();
215 private:
216 PRBool charBufferContainsNonWhitespace();
217 public:
218 nsAHtml5TreeBuilderState* newSnapshot();
219 PRBool snapshotMatches(nsAHtml5TreeBuilderState* snapshot);
220 void loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTable* interner);
221 private:
222 PRInt32 findInArray(nsHtml5StackNode* node, jArray<nsHtml5StackNode*,PRInt32> arr);
223 public:
224 nsIContent** getFormPointer();
225 nsIContent** getHeadPointer();
226 jArray<nsHtml5StackNode*,PRInt32> getListOfActiveFormattingElements();
227 jArray<nsHtml5StackNode*,PRInt32> getStack();
228 PRInt32 getMode();
229 PRInt32 getOriginalMode();
230 PRBool isFramesetOk();
231 PRBool isInForeign();
232 PRBool isNeedToDropLF();
233 PRBool isQuirks();
234 PRInt32 getListOfActiveFormattingElementsLength();
235 PRInt32 getStackLength();
236 static void initializeStatics();
237 static void releaseStatics();
239 #include "nsHtml5TreeBuilderHSupplement.h"
242 #ifdef nsHtml5TreeBuilder_cpp__
243 PRUnichar nsHtml5TreeBuilder::REPLACEMENT_CHARACTER[] = { 0xfffd };
244 jArray<const char*,PRInt32> nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS = nsnull;
245 #endif
247 #define NS_HTML5TREE_BUILDER_OTHER 0
248 #define NS_HTML5TREE_BUILDER_A 1
249 #define NS_HTML5TREE_BUILDER_BASE 2
250 #define NS_HTML5TREE_BUILDER_BODY 3
251 #define NS_HTML5TREE_BUILDER_BR 4
252 #define NS_HTML5TREE_BUILDER_BUTTON 5
253 #define NS_HTML5TREE_BUILDER_CAPTION 6
254 #define NS_HTML5TREE_BUILDER_COL 7
255 #define NS_HTML5TREE_BUILDER_COLGROUP 8
256 #define NS_HTML5TREE_BUILDER_FORM 9
257 #define NS_HTML5TREE_BUILDER_FRAME 10
258 #define NS_HTML5TREE_BUILDER_FRAMESET 11
259 #define NS_HTML5TREE_BUILDER_IMAGE 12
260 #define NS_HTML5TREE_BUILDER_INPUT 13
261 #define NS_HTML5TREE_BUILDER_ISINDEX 14
262 #define NS_HTML5TREE_BUILDER_LI 15
263 #define NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND 16
264 #define NS_HTML5TREE_BUILDER_MATH 17
265 #define NS_HTML5TREE_BUILDER_META 18
266 #define NS_HTML5TREE_BUILDER_SVG 19
267 #define NS_HTML5TREE_BUILDER_HEAD 20
268 #define NS_HTML5TREE_BUILDER_HR 22
269 #define NS_HTML5TREE_BUILDER_HTML 23
270 #define NS_HTML5TREE_BUILDER_NOBR 24
271 #define NS_HTML5TREE_BUILDER_NOFRAMES 25
272 #define NS_HTML5TREE_BUILDER_NOSCRIPT 26
273 #define NS_HTML5TREE_BUILDER_OPTGROUP 27
274 #define NS_HTML5TREE_BUILDER_OPTION 28
275 #define NS_HTML5TREE_BUILDER_P 29
276 #define NS_HTML5TREE_BUILDER_PLAINTEXT 30
277 #define NS_HTML5TREE_BUILDER_SCRIPT 31
278 #define NS_HTML5TREE_BUILDER_SELECT 32
279 #define NS_HTML5TREE_BUILDER_STYLE 33
280 #define NS_HTML5TREE_BUILDER_TABLE 34
281 #define NS_HTML5TREE_BUILDER_TEXTAREA 35
282 #define NS_HTML5TREE_BUILDER_TITLE 36
283 #define NS_HTML5TREE_BUILDER_TR 37
284 #define NS_HTML5TREE_BUILDER_XMP 38
285 #define NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT 39
286 #define NS_HTML5TREE_BUILDER_TD_OR_TH 40
287 #define NS_HTML5TREE_BUILDER_DD_OR_DT 41
288 #define NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 42
289 #define NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET 43
290 #define NS_HTML5TREE_BUILDER_PRE_OR_LISTING 44
291 #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
292 #define NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL 46
293 #define NS_HTML5TREE_BUILDER_IFRAME 47
294 #define NS_HTML5TREE_BUILDER_EMBED_OR_IMG 48
295 #define NS_HTML5TREE_BUILDER_AREA_OR_SPACER_OR_WBR 49
296 #define NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU 50
297 #define NS_HTML5TREE_BUILDER_ADDRESS_OR_DIR_OR_ARTICLE_OR_ASIDE_OR_DATAGRID_OR_DETAILS_OR_HGROUP_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_NAV_OR_SECTION 51
298 #define NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR 52
299 #define NS_HTML5TREE_BUILDER_RT_OR_RP 53
300 #define NS_HTML5TREE_BUILDER_COMMAND 54
301 #define NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE 55
302 #define NS_HTML5TREE_BUILDER_MGLYPH_OR_MALIGNMARK 56
303 #define NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT 57
304 #define NS_HTML5TREE_BUILDER_ANNOTATION_XML 58
305 #define NS_HTML5TREE_BUILDER_FOREIGNOBJECT_OR_DESC 59
306 #define NS_HTML5TREE_BUILDER_NOEMBED 60
307 #define NS_HTML5TREE_BUILDER_FIELDSET 61
308 #define NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL 62
309 #define NS_HTML5TREE_BUILDER_OBJECT 63
310 #define NS_HTML5TREE_BUILDER_FONT 64
311 #define NS_HTML5TREE_BUILDER_KEYGEN 65
312 #define NS_HTML5TREE_BUILDER_INITIAL 0
313 #define NS_HTML5TREE_BUILDER_BEFORE_HTML 1
314 #define NS_HTML5TREE_BUILDER_BEFORE_HEAD 2
315 #define NS_HTML5TREE_BUILDER_IN_HEAD 3
316 #define NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT 4
317 #define NS_HTML5TREE_BUILDER_AFTER_HEAD 5
318 #define NS_HTML5TREE_BUILDER_IN_BODY 6
319 #define NS_HTML5TREE_BUILDER_IN_TABLE 7
320 #define NS_HTML5TREE_BUILDER_IN_CAPTION 8
321 #define NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP 9
322 #define NS_HTML5TREE_BUILDER_IN_TABLE_BODY 10
323 #define NS_HTML5TREE_BUILDER_IN_ROW 11
324 #define NS_HTML5TREE_BUILDER_IN_CELL 12
325 #define NS_HTML5TREE_BUILDER_IN_SELECT 13
326 #define NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE 14
327 #define NS_HTML5TREE_BUILDER_AFTER_BODY 15
328 #define NS_HTML5TREE_BUILDER_IN_FRAMESET 16
329 #define NS_HTML5TREE_BUILDER_AFTER_FRAMESET 17
330 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY 18
331 #define NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET 19
332 #define NS_HTML5TREE_BUILDER_TEXT 20
333 #define NS_HTML5TREE_BUILDER_FRAMESET_OK 21
334 #define NS_HTML5TREE_BUILDER_CHARSET_INITIAL 0
335 #define NS_HTML5TREE_BUILDER_CHARSET_C 1
336 #define NS_HTML5TREE_BUILDER_CHARSET_H 2
337 #define NS_HTML5TREE_BUILDER_CHARSET_A 3
338 #define NS_HTML5TREE_BUILDER_CHARSET_R 4
339 #define NS_HTML5TREE_BUILDER_CHARSET_S 5
340 #define NS_HTML5TREE_BUILDER_CHARSET_E 6
341 #define NS_HTML5TREE_BUILDER_CHARSET_T 7
342 #define NS_HTML5TREE_BUILDER_CHARSET_EQUALS 8
343 #define NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED 9
344 #define NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED 10
345 #define NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED 11
346 #define NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK PR_INT32_MAX
349 #endif