1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #define NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH 512
8 nsHtml5OplessBuilder
* mBuilder
;
9 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10 // If mBuilder is not null, the tree op machinery is not in use and
11 // the fields below aren't in use, either.
12 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13 nsHtml5Highlighter
* mViewSource
;
14 nsTArray
<nsHtml5TreeOperation
> mOpQueue
;
15 nsTArray
<nsHtml5SpeculativeLoad
> mSpeculativeLoadQueue
;
16 nsAHtml5TreeOpSink
* mOpSink
;
17 nsAutoArrayPtr
<nsIContent
*> mHandles
;
19 nsTArray
<nsAutoArrayPtr
<nsIContent
*> > mOldHandles
;
20 nsHtml5TreeOpStage
* mSpeculativeLoadStage
;
21 bool mCurrentHtmlScriptIsAsyncOrDefer
;
22 bool mPreventScriptExecution
;
27 // DocumentModeHandler
29 * Tree builder uses this to report quirkiness of the document
31 void documentMode(nsHtml5DocumentMode m
);
33 nsIContentHandle
* getDocumentFragmentForTemplate(nsIContentHandle
* aTemplate
);
35 nsIContentHandle
* getFormPointerForContext(nsIContentHandle
* aContext
);
38 * Using nsIContent** instead of nsIContent* is the parser deals with DOM
39 * nodes in a way that works off the main thread. Non-main-thread code
40 * can't refcount or otherwise touch nsIContent objects in any way.
41 * Yet, the off-the-main-thread code needs to have a way to hold onto a
42 * particular node and repeatedly operate on the same node.
44 * The way this works is that the off-the-main-thread code has an
45 * nsIContent** for each DOM node and a given nsIContent** is only ever
46 * actually dereferenced into an actual nsIContent* on the main thread.
47 * When the off-the-main-thread code requests a new node, it gets an
48 * nsIContent** immediately and a tree op is enqueued for later allocating
49 * an actual nsIContent object and writing a pointer to it into the memory
50 * location pointed to by the nsIContent**.
52 * Since tree ops are in a queue, the node creating tree op will always
53 * run before tree ops that try to further operate on the node that the
54 * nsIContent** is a handle to.
56 * On-the-main-thread parts of the parser use nsIContent* instead of
57 * nsIContent**. Since both cases share the same parser core, the parser
58 * core casts both to nsIContentHandle*.
60 nsIContentHandle
* AllocateContentHandle();
62 void accumulateCharactersForced(const char16_t
* aBuf
, int32_t aStart
, int32_t aLength
)
64 accumulateCharacters(aBuf
, aStart
, aLength
);
67 void MarkAsBrokenAndRequestSuspension(nsresult aRv
)
69 mBuilder
->MarkAsBroken(aRv
);
75 explicit nsHtml5TreeBuilder(nsHtml5OplessBuilder
* aBuilder
);
77 nsHtml5TreeBuilder(nsAHtml5TreeOpSink
* aOpSink
,
78 nsHtml5TreeOpStage
* aStage
);
80 ~nsHtml5TreeBuilder();
82 void StartPlainTextViewSource(const nsAutoString
& aTitle
);
84 void StartPlainText();
86 void StartPlainTextBody();
90 void SetOpSink(nsAHtml5TreeOpSink
* aOpSink
)
100 bool Flush(bool aDiscretionary
= false);
104 void SetDocumentCharset(nsACString
& aCharset
, int32_t aCharsetSource
);
108 void NeedsCharsetSwitchTo(const nsACString
& aEncoding
,
110 int32_t aLineNumber
);
112 void MaybeComplainAboutCharset(const char* aMsgId
,
114 int32_t aLineNumber
);
116 void AddSnapshotToScript(nsAHtml5TreeBuilderState
* aSnapshot
, int32_t aLine
);
120 void SetPreventScriptExecution(bool aPrevent
)
122 mPreventScriptExecution
= aPrevent
;
130 void EnableViewSource(nsHtml5Highlighter
* aHighlighter
);
132 void errStrayStartTag(nsIAtom
* aName
);
134 void errStrayEndTag(nsIAtom
* aName
);
136 void errUnclosedElements(int32_t aIndex
, nsIAtom
* aName
);
138 void errUnclosedElementsImplied(int32_t aIndex
, nsIAtom
* aName
);
140 void errUnclosedElementsCell(int32_t aIndex
);
142 void errStrayDoctype();
144 void errAlmostStandardsDoctype();
146 void errQuirkyDoctype();
148 void errNonSpaceInTrailer();
150 void errNonSpaceAfterFrameset();
152 void errNonSpaceInFrameset();
154 void errNonSpaceAfterBody();
156 void errNonSpaceInColgroupInFragment();
158 void errNonSpaceInNoscriptInHead();
160 void errFooBetweenHeadAndBody(nsIAtom
* aName
);
162 void errStartTagWithoutDoctype();
164 void errNoSelectInTableScope();
166 void errStartSelectWhereEndSelectExpected();
168 void errStartTagWithSelectOpen(nsIAtom
* aName
);
170 void errBadStartTagInHead(nsIAtom
* aName
);
176 void errFooSeenWhenFooOpen(nsIAtom
* aName
);
178 void errHeadingWhenHeadingOpen();
180 void errFramesetStart();
182 void errNoCellToClose();
184 void errStartTagInTable(nsIAtom
* aName
);
186 void errFormWhenFormOpen();
188 void errTableSeenWhileTableOpen();
190 void errStartTagInTableBody(nsIAtom
* aName
);
192 void errEndTagSeenWithoutDoctype();
194 void errEndTagAfterBody();
196 void errEndTagSeenWithSelectOpen(nsIAtom
* aName
);
198 void errGarbageInColgroup();
202 void errNoElementToCloseButEndTagSeen(nsIAtom
* aName
);
204 void errHtmlStartTagInForeignContext(nsIAtom
* aName
);
206 void errTableClosedWhileCaptionOpen();
208 void errNoTableRowToClose();
210 void errNonSpaceInTable();
212 void errUnclosedChildrenInRuby();
214 void errStartTagSeenWithoutRuby(nsIAtom
* aName
);
216 void errSelfClosing();
218 void errNoCheckUnclosedElementsOnStack();
220 void errEndTagDidNotMatchCurrentOpenElement(nsIAtom
* aName
, nsIAtom
* aOther
);
222 void errEndTagViolatesNestingRules(nsIAtom
* aName
);
224 void errEndWithUnclosedElements(nsIAtom
* aName
);
226 void MarkAsBroken(nsresult aRv
);