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