PageRenderTime 45ms CodeModel.GetById 15ms app.highlight 25ms RepoModel.GetById 2ms app.codeStats 0ms

/parser/html/nsHtml5TreeBuilder.h

http://github.com/zpao/v8monkey
C Header | 361 lines | 318 code | 15 blank | 28 comment | 1 complexity | a1060c092fd3bb2fd8330716f507c9da MD5 | raw file
  1/*
  2 * Copyright (c) 2007 Henri Sivonen
  3 * Copyright (c) 2007-2011 Mozilla Foundation
  4 * Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla 
  5 * Foundation, and Opera Software ASA.
  6 *
  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:
 13 *
 14 * The above copyright notice and this permission notice shall be included in 
 15 * all copies or substantial portions of the Software.
 16 *
 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.
 24 */
 25
 26/*
 27 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
 28 * Please edit TreeBuilder.java instead and regenerate.
 29 */
 30
 31#ifndef nsHtml5TreeBuilder_h__
 32#define nsHtml5TreeBuilder_h__
 33
 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 "nsHtml5TreeOperation.h"
 49#include "nsHtml5PendingNotification.h"
 50#include "nsHtml5StateSnapshot.h"
 51#include "nsHtml5StackNode.h"
 52#include "nsHtml5TreeOpExecutor.h"
 53#include "nsHtml5StreamParser.h"
 54#include "nsAHtml5TreeBuilderState.h"
 55#include "nsHtml5Highlighter.h"
 56#include "nsHtml5ViewSourceUtils.h"
 57
 58class nsHtml5StreamParser;
 59
 60class nsHtml5Tokenizer;
 61class nsHtml5MetaScanner;
 62class nsHtml5AttributeName;
 63class nsHtml5ElementName;
 64class nsHtml5HtmlAttributes;
 65class nsHtml5UTF16Buffer;
 66class nsHtml5StateSnapshot;
 67class nsHtml5Portability;
 68
 69
 70class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState
 71{
 72  private:
 73    static PRUnichar REPLACEMENT_CHARACTER[];
 74    static staticJArray<const char*,PRInt32> QUIRKY_PUBLIC_IDS;
 75    PRInt32 mode;
 76    PRInt32 originalMode;
 77    bool framesetOk;
 78  protected:
 79    nsHtml5Tokenizer* tokenizer;
 80  private:
 81    bool scriptingEnabled;
 82    bool needToDropLF;
 83    bool fragment;
 84    nsIAtom* contextName;
 85    PRInt32 contextNamespace;
 86    nsIContent** contextNode;
 87    autoJArray<nsHtml5StackNode*,PRInt32> stack;
 88    PRInt32 currentPtr;
 89    autoJArray<nsHtml5StackNode*,PRInt32> listOfActiveFormattingElements;
 90    PRInt32 listPtr;
 91    nsIContent** formPointer;
 92    nsIContent** headPointer;
 93    nsIContent** deepTreeSurrogateParent;
 94  protected:
 95    autoJArray<PRUnichar,PRInt32> charBuffer;
 96    PRInt32 charBufferLen;
 97  private:
 98    bool quirks;
 99  public:
100    void startTokenization(nsHtml5Tokenizer* self);
101    void doctype(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier, bool forceQuirks);
102    void comment(PRUnichar* buf, PRInt32 start, PRInt32 length);
103    void characters(const PRUnichar* buf, PRInt32 start, PRInt32 length);
104    void zeroOriginatingReplacementCharacter();
105    void eof();
106    void endTokenization();
107    void startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, bool selfClosing);
108  private:
109    bool isSpecialParentInForeign(nsHtml5StackNode* stackNode);
110  public:
111    static nsString* extractCharsetFromContent(nsString* attributeValue);
112  private:
113    void checkMetaCharset(nsHtml5HtmlAttributes* attributes);
114  public:
115    void endTag(nsHtml5ElementName* elementName);
116  private:
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    void generateImpliedEndTagsExceptFor(nsIAtom* name);
125    void generateImpliedEndTags();
126    bool isSecondOnStackBody();
127    void documentModeInternal(nsHtml5DocumentMode m, nsString* publicIdentifier, nsString* systemIdentifier, bool html4SpecificAdditionalErrorChecks);
128    bool isAlmostStandards(nsString* publicIdentifier, nsString* systemIdentifier);
129    bool isQuirky(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier, bool forceQuirks);
130    void closeTheCell(PRInt32 eltPos);
131    PRInt32 findLastInTableScopeTdTh();
132    void clearStackBackTo(PRInt32 eltPos);
133    void resetTheInsertionMode();
134    void implicitlyCloseP();
135    bool clearLastStackSlot();
136    bool clearLastListSlot();
137    void push(nsHtml5StackNode* node);
138    void silentPush(nsHtml5StackNode* node);
139    void append(nsHtml5StackNode* node);
140    inline void insertMarker()
141    {
142      append(nsnull);
143    }
144
145    void clearTheListOfActiveFormattingElementsUpToTheLastMarker();
146    inline bool isCurrent(nsIAtom* name)
147    {
148      return name == stack[currentPtr]->name;
149    }
150
151    void removeFromStack(PRInt32 pos);
152    void removeFromStack(nsHtml5StackNode* node);
153    void removeFromListOfActiveFormattingElements(PRInt32 pos);
154    bool adoptionAgencyEndTag(nsIAtom* name);
155    void insertIntoStack(nsHtml5StackNode* node, PRInt32 position);
156    void insertIntoListOfActiveFormattingElements(nsHtml5StackNode* formattingClone, PRInt32 bookmark);
157    PRInt32 findInListOfActiveFormattingElements(nsHtml5StackNode* node);
158    PRInt32 findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom* name);
159    void maybeForgetEarlierDuplicateFormattingElement(nsIAtom* name, nsHtml5HtmlAttributes* attributes);
160    PRInt32 findLastOrRoot(nsIAtom* name);
161    PRInt32 findLastOrRoot(PRInt32 group);
162    bool addAttributesToBody(nsHtml5HtmlAttributes* attributes);
163    void addAttributesToHtml(nsHtml5HtmlAttributes* attributes);
164    void pushHeadPointerOntoStack();
165    void reconstructTheActiveFormattingElements();
166    void insertIntoFosterParent(nsIContent** child);
167    bool isInStack(nsHtml5StackNode* node);
168    void pop();
169    void silentPop();
170    void popOnEof();
171    void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes* attributes);
172    void appendHtmlElementToDocumentAndPush();
173    void appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes);
174    void appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes* attributes);
175    void appendToCurrentNodeAndPushBodyElement();
176    void appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes* attributes);
177    void appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
178    void appendToCurrentNodeAndPushElement(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
179    void appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
180    void appendToCurrentNodeAndPushElementMayFosterMathML(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
181    bool annotationXmlEncodingPermitsHtml(nsHtml5HtmlAttributes* attributes);
182    void appendToCurrentNodeAndPushElementMayFosterSVG(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
183    void appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent** form);
184    void appendVoidElementToCurrentMayFoster(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
185    void appendVoidElementToCurrentMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
186    void appendVoidElementToCurrentMayFosterSVG(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
187    void appendVoidElementToCurrentMayFosterMathML(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
188    void appendVoidElementToCurrent(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
189    void appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes);
190  protected:
191    void accumulateCharacters(const PRUnichar* buf, PRInt32 start, PRInt32 length);
192    void requestSuspension();
193    nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes);
194    nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
195    nsIContent** createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* attributes);
196    void detachFromParent(nsIContent** element);
197    bool hasChildren(nsIContent** element);
198    void appendElement(nsIContent** child, nsIContent** newParent);
199    void appendChildrenToNewParent(nsIContent** oldParent, nsIContent** newParent);
200    void insertFosterParentedChild(nsIContent** child, nsIContent** table, nsIContent** stackParent);
201    void insertFosterParentedCharacters(PRUnichar* buf, PRInt32 start, PRInt32 length, nsIContent** table, nsIContent** stackParent);
202    void appendCharacters(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
203    void appendIsindexPrompt(nsIContent** parent);
204    void appendComment(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
205    void appendCommentToDocument(PRUnichar* buf, PRInt32 start, PRInt32 length);
206    void addAttributesToElement(nsIContent** element, nsHtml5HtmlAttributes* attributes);
207    void markMalformedIfScript(nsIContent** elt);
208    void start(bool fragmentMode);
209    void end();
210    void appendDoctypeToDocument(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier);
211    void elementPushed(PRInt32 ns, nsIAtom* name, nsIContent** node);
212    void elementPopped(PRInt32 ns, nsIAtom* name, nsIContent** node);
213  public:
214    inline bool cdataSectionAllowed()
215    {
216      return isInForeign();
217    }
218
219  private:
220    bool isInForeign();
221    bool isInForeignButNotHtmlOrMathTextIntegrationPoint();
222  public:
223    void setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent** node, bool quirks);
224  protected:
225    nsIContent** currentNode();
226  public:
227    bool isScriptingEnabled();
228    void setScriptingEnabled(bool scriptingEnabled);
229    void flushCharacters();
230  private:
231    bool charBufferContainsNonWhitespace();
232  public:
233    nsAHtml5TreeBuilderState* newSnapshot();
234    bool snapshotMatches(nsAHtml5TreeBuilderState* snapshot);
235    void loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTable* interner);
236  private:
237    PRInt32 findInArray(nsHtml5StackNode* node, jArray<nsHtml5StackNode*,PRInt32> arr);
238  public:
239    nsIContent** getFormPointer();
240    nsIContent** getHeadPointer();
241    nsIContent** getDeepTreeSurrogateParent();
242    jArray<nsHtml5StackNode*,PRInt32> getListOfActiveFormattingElements();
243    jArray<nsHtml5StackNode*,PRInt32> getStack();
244    PRInt32 getMode();
245    PRInt32 getOriginalMode();
246    bool isFramesetOk();
247    bool isNeedToDropLF();
248    bool isQuirks();
249    PRInt32 getListOfActiveFormattingElementsLength();
250    PRInt32 getStackLength();
251    static void initializeStatics();
252    static void releaseStatics();
253
254#include "nsHtml5TreeBuilderHSupplement.h"
255};
256
257#define NS_HTML5TREE_BUILDER_OTHER 0
258#define NS_HTML5TREE_BUILDER_A 1
259#define NS_HTML5TREE_BUILDER_BASE 2
260#define NS_HTML5TREE_BUILDER_BODY 3
261#define NS_HTML5TREE_BUILDER_BR 4
262#define NS_HTML5TREE_BUILDER_BUTTON 5
263#define NS_HTML5TREE_BUILDER_CAPTION 6
264#define NS_HTML5TREE_BUILDER_COL 7
265#define NS_HTML5TREE_BUILDER_COLGROUP 8
266#define NS_HTML5TREE_BUILDER_FORM 9
267#define NS_HTML5TREE_BUILDER_FRAME 10
268#define NS_HTML5TREE_BUILDER_FRAMESET 11
269#define NS_HTML5TREE_BUILDER_IMAGE 12
270#define NS_HTML5TREE_BUILDER_INPUT 13
271#define NS_HTML5TREE_BUILDER_ISINDEX 14
272#define NS_HTML5TREE_BUILDER_LI 15
273#define NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND 16
274#define NS_HTML5TREE_BUILDER_MATH 17
275#define NS_HTML5TREE_BUILDER_META 18
276#define NS_HTML5TREE_BUILDER_SVG 19
277#define NS_HTML5TREE_BUILDER_HEAD 20
278#define NS_HTML5TREE_BUILDER_HR 22
279#define NS_HTML5TREE_BUILDER_HTML 23
280#define NS_HTML5TREE_BUILDER_NOBR 24
281#define NS_HTML5TREE_BUILDER_NOFRAMES 25
282#define NS_HTML5TREE_BUILDER_NOSCRIPT 26
283#define NS_HTML5TREE_BUILDER_OPTGROUP 27
284#define NS_HTML5TREE_BUILDER_OPTION 28
285#define NS_HTML5TREE_BUILDER_P 29
286#define NS_HTML5TREE_BUILDER_PLAINTEXT 30
287#define NS_HTML5TREE_BUILDER_SCRIPT 31
288#define NS_HTML5TREE_BUILDER_SELECT 32
289#define NS_HTML5TREE_BUILDER_STYLE 33
290#define NS_HTML5TREE_BUILDER_TABLE 34
291#define NS_HTML5TREE_BUILDER_TEXTAREA 35
292#define NS_HTML5TREE_BUILDER_TITLE 36
293#define NS_HTML5TREE_BUILDER_TR 37
294#define NS_HTML5TREE_BUILDER_XMP 38
295#define NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT 39
296#define NS_HTML5TREE_BUILDER_TD_OR_TH 40
297#define NS_HTML5TREE_BUILDER_DD_OR_DT 41
298#define NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 42
299#define NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET 43
300#define NS_HTML5TREE_BUILDER_PRE_OR_LISTING 44
301#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
302#define NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL 46
303#define NS_HTML5TREE_BUILDER_IFRAME 47
304#define NS_HTML5TREE_BUILDER_EMBED_OR_IMG 48
305#define NS_HTML5TREE_BUILDER_AREA_OR_WBR 49
306#define NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU 50
307#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
308#define NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR 52
309#define NS_HTML5TREE_BUILDER_RT_OR_RP 53
310#define NS_HTML5TREE_BUILDER_COMMAND 54
311#define NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK 55
312#define NS_HTML5TREE_BUILDER_MGLYPH_OR_MALIGNMARK 56
313#define NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT 57
314#define NS_HTML5TREE_BUILDER_ANNOTATION_XML 58
315#define NS_HTML5TREE_BUILDER_FOREIGNOBJECT_OR_DESC 59
316#define NS_HTML5TREE_BUILDER_NOEMBED 60
317#define NS_HTML5TREE_BUILDER_FIELDSET 61
318#define NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL 62
319#define NS_HTML5TREE_BUILDER_OBJECT 63
320#define NS_HTML5TREE_BUILDER_FONT 64
321#define NS_HTML5TREE_BUILDER_KEYGEN 65
322#define NS_HTML5TREE_BUILDER_MENUITEM 66
323#define NS_HTML5TREE_BUILDER_INITIAL 0
324#define NS_HTML5TREE_BUILDER_BEFORE_HTML 1
325#define NS_HTML5TREE_BUILDER_BEFORE_HEAD 2
326#define NS_HTML5TREE_BUILDER_IN_HEAD 3
327#define NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT 4
328#define NS_HTML5TREE_BUILDER_AFTER_HEAD 5
329#define NS_HTML5TREE_BUILDER_IN_BODY 6
330#define NS_HTML5TREE_BUILDER_IN_TABLE 7
331#define NS_HTML5TREE_BUILDER_IN_CAPTION 8
332#define NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP 9
333#define NS_HTML5TREE_BUILDER_IN_TABLE_BODY 10
334#define NS_HTML5TREE_BUILDER_IN_ROW 11
335#define NS_HTML5TREE_BUILDER_IN_CELL 12
336#define NS_HTML5TREE_BUILDER_IN_SELECT 13
337#define NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE 14
338#define NS_HTML5TREE_BUILDER_AFTER_BODY 15
339#define NS_HTML5TREE_BUILDER_IN_FRAMESET 16
340#define NS_HTML5TREE_BUILDER_AFTER_FRAMESET 17
341#define NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY 18
342#define NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET 19
343#define NS_HTML5TREE_BUILDER_TEXT 20
344#define NS_HTML5TREE_BUILDER_FRAMESET_OK 21
345#define NS_HTML5TREE_BUILDER_CHARSET_INITIAL 0
346#define NS_HTML5TREE_BUILDER_CHARSET_C 1
347#define NS_HTML5TREE_BUILDER_CHARSET_H 2
348#define NS_HTML5TREE_BUILDER_CHARSET_A 3
349#define NS_HTML5TREE_BUILDER_CHARSET_R 4
350#define NS_HTML5TREE_BUILDER_CHARSET_S 5
351#define NS_HTML5TREE_BUILDER_CHARSET_E 6
352#define NS_HTML5TREE_BUILDER_CHARSET_T 7
353#define NS_HTML5TREE_BUILDER_CHARSET_EQUALS 8
354#define NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED 9
355#define NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED 10
356#define NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED 11
357#define NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK PR_INT32_MAX
358
359
360#endif
361