2 * Copyright (c) 2007 Henri Sivonen
3 * Copyright (c) 2007-2017 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
35 #include "mozilla/ImportScanner.h"
36 #include "mozilla/Likely.h"
37 #include "nsAHtml5TreeBuilderState.h"
39 #include "nsContentUtils.h"
40 #include "nsGkAtoms.h"
41 #include "nsHtml5ArrayCopy.h"
42 #include "nsHtml5AtomTable.h"
43 #include "nsHtml5DocumentMode.h"
44 #include "nsHtml5Highlighter.h"
45 #include "nsHtml5OplessBuilder.h"
46 #include "nsHtml5Parser.h"
47 #include "nsHtml5PlainTextUtils.h"
48 #include "nsHtml5StackNode.h"
49 #include "nsHtml5StateSnapshot.h"
50 #include "nsHtml5StreamParser.h"
51 #include "nsHtml5String.h"
52 #include "nsHtml5TreeOperation.h"
53 #include "nsHtml5TreeOpExecutor.h"
54 #include "nsHtml5ViewSourceUtils.h"
55 #include "nsIContent.h"
56 #include "nsIContentHandle.h"
57 #include "nsNameSpaceManager.h"
58 #include "nsTraceRefcnt.h"
60 class nsHtml5StreamParser
;
62 class nsHtml5AttributeName
;
63 class nsHtml5ElementName
;
64 class nsHtml5Tokenizer
;
65 class nsHtml5UTF16Buffer
;
66 class nsHtml5StateSnapshot
;
67 class nsHtml5Portability
;
69 class nsHtml5TreeBuilder
: public nsAHtml5TreeBuilderState
{
71 static char16_t REPLACEMENT_CHARACTER
[];
74 static const int32_t OTHER
= 0;
76 static const int32_t A
= 1;
78 static const int32_t BASE
= 2;
80 static const int32_t BODY
= 3;
82 static const int32_t BR
= 4;
84 static const int32_t BUTTON
= 5;
86 static const int32_t CAPTION
= 6;
88 static const int32_t COL
= 7;
90 static const int32_t COLGROUP
= 8;
92 static const int32_t FORM
= 9;
94 static const int32_t FRAME
= 10;
96 static const int32_t FRAMESET
= 11;
98 static const int32_t IMAGE
= 12;
100 static const int32_t INPUT
= 13;
102 static const int32_t RT_OR_RP
= 14;
104 static const int32_t LI
= 15;
106 static const int32_t LINK_OR_BASEFONT_OR_BGSOUND
= 16;
108 static const int32_t MATH
= 17;
110 static const int32_t META
= 18;
112 static const int32_t SVG
= 19;
114 static const int32_t HEAD
= 20;
116 static const int32_t HR
= 22;
118 static const int32_t HTML
= 23;
120 static const int32_t NOBR
= 24;
122 static const int32_t NOFRAMES
= 25;
124 static const int32_t NOSCRIPT
= 26;
126 static const int32_t OPTGROUP
= 27;
128 static const int32_t OPTION
= 28;
130 static const int32_t P
= 29;
132 static const int32_t PLAINTEXT
= 30;
134 static const int32_t SCRIPT
= 31;
136 static const int32_t SELECT
= 32;
138 static const int32_t STYLE
= 33;
140 static const int32_t TABLE
= 34;
142 static const int32_t TEXTAREA
= 35;
144 static const int32_t TITLE
= 36;
146 static const int32_t TR
= 37;
148 static const int32_t XMP
= 38;
150 static const int32_t TBODY_OR_THEAD_OR_TFOOT
= 39;
152 static const int32_t TD_OR_TH
= 40;
154 static const int32_t DD_OR_DT
= 41;
156 static const int32_t H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6
= 42;
158 static const int32_t MARQUEE_OR_APPLET
= 43;
160 static const int32_t PRE_OR_LISTING
= 44;
163 B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U
=
166 static const int32_t UL_OR_OL_OR_DL
= 46;
168 static const int32_t IFRAME
= 47;
170 static const int32_t EMBED
= 48;
172 static const int32_t AREA_OR_WBR
= 49;
174 static const int32_t DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU
= 50;
177 ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIALOG_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SEARCH_OR_SECTION_OR_SUMMARY
=
180 static const int32_t RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR
= 52;
182 static const int32_t RB_OR_RTC
= 53;
184 static const int32_t PARAM_OR_SOURCE_OR_TRACK
= 55;
186 static const int32_t MGLYPH_OR_MALIGNMARK
= 56;
188 static const int32_t MI_MO_MN_MS_MTEXT
= 57;
190 static const int32_t ANNOTATION_XML
= 58;
192 static const int32_t FOREIGNOBJECT_OR_DESC
= 59;
194 static const int32_t NOEMBED
= 60;
196 static const int32_t FIELDSET
= 61;
198 static const int32_t OUTPUT
= 62;
200 static const int32_t OBJECT
= 63;
202 static const int32_t FONT
= 64;
204 static const int32_t KEYGEN
= 65;
206 static const int32_t TEMPLATE
= 66;
208 static const int32_t IMG
= 67;
211 static const int32_t IN_ROW
= 0;
213 static const int32_t IN_TABLE_BODY
= 1;
215 static const int32_t IN_TABLE
= 2;
217 static const int32_t IN_CAPTION
= 3;
219 static const int32_t IN_CELL
= 4;
221 static const int32_t FRAMESET_OK
= 5;
223 static const int32_t IN_BODY
= 6;
225 static const int32_t IN_HEAD
= 7;
227 static const int32_t IN_HEAD_NOSCRIPT
= 8;
229 static const int32_t IN_COLUMN_GROUP
= 9;
231 static const int32_t IN_SELECT_IN_TABLE
= 10;
233 static const int32_t IN_SELECT
= 11;
235 static const int32_t AFTER_BODY
= 12;
237 static const int32_t IN_FRAMESET
= 13;
239 static const int32_t AFTER_FRAMESET
= 14;
241 static const int32_t INITIAL
= 15;
243 static const int32_t BEFORE_HTML
= 16;
245 static const int32_t BEFORE_HEAD
= 17;
247 static const int32_t AFTER_HEAD
= 18;
249 static const int32_t AFTER_AFTER_BODY
= 19;
251 static const int32_t AFTER_AFTER_FRAMESET
= 20;
253 static const int32_t TEXT
= 21;
255 static const int32_t IN_TEMPLATE
= 22;
257 static const int32_t CHARSET_INITIAL
= 0;
259 static const int32_t CHARSET_C
= 1;
261 static const int32_t CHARSET_H
= 2;
263 static const int32_t CHARSET_A
= 3;
265 static const int32_t CHARSET_R
= 4;
267 static const int32_t CHARSET_S
= 5;
269 static const int32_t CHARSET_E
= 6;
271 static const int32_t CHARSET_T
= 7;
273 static const int32_t CHARSET_EQUALS
= 8;
275 static const int32_t CHARSET_SINGLE_QUOTED
= 9;
277 static const int32_t CHARSET_DOUBLE_QUOTED
= 10;
279 static const int32_t CHARSET_UNQUOTED
= 11;
281 static staticJArray
<const char*, int32_t> QUIRKY_PUBLIC_IDS
;
282 static const int32_t NOT_FOUND_ON_STACK
= INT32_MAX
;
285 int32_t originalMode
;
289 nsHtml5Tokenizer
* tokenizer
;
292 bool scriptingEnabled
;
295 RefPtr
<nsAtom
> contextName
;
296 int32_t contextNamespace
;
297 nsIContentHandle
* contextNode
;
298 autoJArray
<int32_t, int32_t> templateModeStack
;
299 int32_t templateModePtr
;
300 autoJArray
<nsHtml5StackNode
*, int32_t> stackNodes
;
301 int32_t stackNodesIdx
;
302 int32_t numStackNodes
;
303 autoJArray
<nsHtml5StackNode
*, int32_t> stack
;
305 autoJArray
<nsHtml5StackNode
*, int32_t> listOfActiveFormattingElements
;
307 nsIContentHandle
* formPointer
;
308 nsIContentHandle
* headPointer
;
311 autoJArray
<char16_t
, int32_t> charBuffer
;
312 int32_t charBufferLen
;
317 inline nsHtml5ContentCreatorFunction
htmlCreator(
318 mozilla::dom::HTMLContentCreatorFunction htmlCreator
) {
319 nsHtml5ContentCreatorFunction creator
;
320 creator
.html
= htmlCreator
;
324 inline nsHtml5ContentCreatorFunction
svgCreator(
325 mozilla::dom::SVGContentCreatorFunction svgCreator
) {
326 nsHtml5ContentCreatorFunction creator
;
327 creator
.svg
= svgCreator
;
332 void startTokenization(nsHtml5Tokenizer
* self
);
333 void doctype(nsAtom
* name
, nsHtml5String publicIdentifier
,
334 nsHtml5String systemIdentifier
, bool forceQuirks
);
335 void comment(char16_t
* buf
, int32_t start
, int32_t length
);
336 void characters(const char16_t
* buf
, int32_t start
, int32_t length
);
337 void zeroOriginatingReplacementCharacter();
338 void zeroOrReplacementCharacter();
340 void endTokenization();
341 void startTag(nsHtml5ElementName
* elementName
,
342 nsHtml5HtmlAttributes
* attributes
, bool selfClosing
);
345 void startTagTitleInHead(nsHtml5ElementName
* elementName
,
346 nsHtml5HtmlAttributes
* attributes
);
347 void startTagGenericRawText(nsHtml5ElementName
* elementName
,
348 nsHtml5HtmlAttributes
* attributes
);
349 void startTagScriptInHead(nsHtml5ElementName
* elementName
,
350 nsHtml5HtmlAttributes
* attributes
);
351 void startTagTemplateInHead(nsHtml5ElementName
* elementName
,
352 nsHtml5HtmlAttributes
* attributes
);
353 bool isTemplateContents();
354 bool isTemplateModeStackEmpty();
355 bool isSpecialParentInForeign(nsHtml5StackNode
* stackNode
);
358 static nsHtml5String
extractCharsetFromContent(nsHtml5String attributeValue
,
359 nsHtml5TreeBuilder
* tb
);
362 void checkMetaCharset(nsHtml5HtmlAttributes
* attributes
);
365 void endTag(nsHtml5ElementName
* elementName
);
368 void endTagTemplateInHead();
369 int32_t findLastInTableScopeOrRootTemplateTbodyTheadTfoot();
370 int32_t findLast(nsAtom
* name
);
371 int32_t findLastInTableScope(nsAtom
* name
);
372 int32_t findLastInButtonScope(nsAtom
* name
);
373 int32_t findLastInScope(nsAtom
* name
);
374 int32_t findLastInListScope(nsAtom
* name
);
375 int32_t findLastInScopeHn();
376 void generateImpliedEndTagsExceptFor(nsAtom
* name
);
377 void generateImpliedEndTags();
378 void generateImpliedEndTagsThoroughly();
379 bool isSecondOnStackBody();
380 void documentModeInternal(nsHtml5DocumentMode m
,
381 nsHtml5String publicIdentifier
,
382 nsHtml5String systemIdentifier
);
383 bool isAlmostStandards(nsHtml5String publicIdentifier
,
384 nsHtml5String systemIdentifier
);
385 bool isQuirky(nsAtom
* name
, nsHtml5String publicIdentifier
,
386 nsHtml5String systemIdentifier
, bool forceQuirks
);
387 void closeTheCell(int32_t eltPos
);
388 int32_t findLastInTableScopeTdTh();
389 void clearStackBackTo(int32_t eltPos
);
390 void resetTheInsertionMode();
391 void implicitlyCloseP();
392 bool debugOnlyClearLastStackSlot();
393 bool debugOnlyClearLastListSlot();
394 void pushTemplateMode(int32_t mode
);
395 void push(nsHtml5StackNode
* node
);
396 void silentPush(nsHtml5StackNode
* node
);
397 void append(nsHtml5StackNode
* node
);
398 inline void insertMarker() { append(nullptr); }
400 void clearTheListOfActiveFormattingElementsUpToTheLastMarker();
401 inline bool isCurrent(nsAtom
* name
) {
402 return stack
[currentPtr
]->ns
== kNameSpaceID_XHTML
&&
403 name
== stack
[currentPtr
]->name
;
406 void removeFromStack(int32_t pos
);
407 void removeFromStack(nsHtml5StackNode
* node
);
408 void removeFromListOfActiveFormattingElements(int32_t pos
);
409 bool adoptionAgencyEndTag(nsAtom
* name
);
410 void insertIntoStack(nsHtml5StackNode
* node
, int32_t position
);
411 void insertIntoListOfActiveFormattingElements(
412 nsHtml5StackNode
* formattingClone
, int32_t bookmark
);
413 int32_t findInListOfActiveFormattingElements(nsHtml5StackNode
* node
);
414 int32_t findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(
416 void maybeForgetEarlierDuplicateFormattingElement(
417 nsAtom
* name
, nsHtml5HtmlAttributes
* attributes
);
418 int32_t findLastOrRoot(nsAtom
* name
);
419 int32_t findLastOrRoot(int32_t group
);
420 bool addAttributesToBody(nsHtml5HtmlAttributes
* attributes
);
421 void addAttributesToHtml(nsHtml5HtmlAttributes
* attributes
);
422 void pushHeadPointerOntoStack();
423 void reconstructTheActiveFormattingElements();
426 void notifyUnusedStackNode(int32_t idxInStackNodes
);
429 nsHtml5StackNode
* getUnusedStackNode();
430 nsHtml5StackNode
* createStackNode(
431 int32_t flags
, int32_t ns
, nsAtom
* name
, nsIContentHandle
* node
,
432 nsAtom
* popName
, nsHtml5HtmlAttributes
* attributes
,
433 mozilla::dom::HTMLContentCreatorFunction htmlCreator
);
434 nsHtml5StackNode
* createStackNode(nsHtml5ElementName
* elementName
,
435 nsIContentHandle
* node
);
436 nsHtml5StackNode
* createStackNode(nsHtml5ElementName
* elementName
,
437 nsIContentHandle
* node
,
438 nsHtml5HtmlAttributes
* attributes
);
439 nsHtml5StackNode
* createStackNode(nsHtml5ElementName
* elementName
,
440 nsIContentHandle
* node
, nsAtom
* popName
);
441 nsHtml5StackNode
* createStackNode(nsHtml5ElementName
* elementName
,
442 nsAtom
* popName
, nsIContentHandle
* node
);
443 nsHtml5StackNode
* createStackNode(nsHtml5ElementName
* elementName
,
444 nsIContentHandle
* node
, nsAtom
* popName
,
445 bool markAsIntegrationPoint
);
446 void insertIntoFosterParent(nsIContentHandle
* child
);
447 nsIContentHandle
* createAndInsertFosterParentedElement(
448 int32_t ns
, nsAtom
* name
, nsHtml5HtmlAttributes
* attributes
,
449 nsHtml5ContentCreatorFunction creator
);
450 nsIContentHandle
* createAndInsertFosterParentedElement(
451 int32_t ns
, nsAtom
* name
, nsHtml5HtmlAttributes
* attributes
,
452 nsIContentHandle
* form
, nsHtml5ContentCreatorFunction creator
);
453 bool isInStack(nsHtml5StackNode
* node
);
454 void popTemplateMode();
456 void popForeign(int32_t origPos
, int32_t eltPos
);
459 void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes
* attributes
);
460 void appendHtmlElementToDocumentAndPush();
461 void appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes
* attributes
);
462 void appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes
* attributes
);
463 void appendToCurrentNodeAndPushBodyElement();
464 void appendToCurrentNodeAndPushFormElementMayFoster(
465 nsHtml5HtmlAttributes
* attributes
);
466 void appendToCurrentNodeAndPushFormattingElementMayFoster(
467 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
468 void appendToCurrentNodeAndPushElement(nsHtml5ElementName
* elementName
,
469 nsHtml5HtmlAttributes
* attributes
);
470 void appendToCurrentNodeAndPushElementMayFoster(
471 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
472 void appendToCurrentNodeAndPushElementMayFosterMathML(
473 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
474 bool annotationXmlEncodingPermitsHtml(nsHtml5HtmlAttributes
* attributes
);
475 void appendToCurrentNodeAndPushElementMayFosterSVG(
476 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
477 void appendToCurrentNodeAndPushElementMayFoster(
478 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
,
479 nsIContentHandle
* form
);
480 void appendVoidElementToCurrentMayFoster(nsHtml5ElementName
* elementName
,
481 nsHtml5HtmlAttributes
* attributes
,
482 nsIContentHandle
* form
);
483 void appendVoidElementToCurrentMayFoster(nsHtml5ElementName
* elementName
,
484 nsHtml5HtmlAttributes
* attributes
);
485 void appendVoidElementToCurrentMayFosterSVG(
486 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
487 void appendVoidElementToCurrentMayFosterMathML(
488 nsHtml5ElementName
* elementName
, nsHtml5HtmlAttributes
* attributes
);
489 void appendVoidInputToCurrent(nsHtml5HtmlAttributes
* attributes
,
490 nsIContentHandle
* form
);
491 void appendVoidFormToCurrent(nsHtml5HtmlAttributes
* attributes
);
494 void accumulateCharacters(const char16_t
* buf
, int32_t start
, int32_t length
);
495 void requestSuspension();
496 nsIContentHandle
* createElement(int32_t ns
, nsAtom
* name
,
497 nsHtml5HtmlAttributes
* attributes
,
498 nsIContentHandle
* intendedParent
,
499 nsHtml5ContentCreatorFunction creator
);
500 nsIContentHandle
* createElement(int32_t ns
, nsAtom
* name
,
501 nsHtml5HtmlAttributes
* attributes
,
502 nsIContentHandle
* form
,
503 nsIContentHandle
* intendedParent
,
504 nsHtml5ContentCreatorFunction creator
);
505 nsIContentHandle
* createHtmlElementSetAsRoot(
506 nsHtml5HtmlAttributes
* attributes
);
507 void detachFromParent(nsIContentHandle
* element
);
508 bool hasChildren(nsIContentHandle
* element
);
509 void appendElement(nsIContentHandle
* child
, nsIContentHandle
* newParent
);
510 void appendChildrenToNewParent(nsIContentHandle
* oldParent
,
511 nsIContentHandle
* newParent
);
512 void insertFosterParentedChild(nsIContentHandle
* child
,
513 nsIContentHandle
* table
,
514 nsIContentHandle
* stackParent
);
515 nsIContentHandle
* createAndInsertFosterParentedElement(
516 int32_t ns
, nsAtom
* name
, nsHtml5HtmlAttributes
* attributes
,
517 nsIContentHandle
* form
, nsIContentHandle
* table
,
518 nsIContentHandle
* stackParent
, nsHtml5ContentCreatorFunction creator
);
520 void insertFosterParentedCharacters(char16_t
* buf
, int32_t start
,
521 int32_t length
, nsIContentHandle
* table
,
522 nsIContentHandle
* stackParent
);
523 void appendCharacters(nsIContentHandle
* parent
, char16_t
* buf
, int32_t start
,
525 void appendComment(nsIContentHandle
* parent
, char16_t
* buf
, int32_t start
,
527 void appendCommentToDocument(char16_t
* buf
, int32_t start
, int32_t length
);
528 void addAttributesToElement(nsIContentHandle
* element
,
529 nsHtml5HtmlAttributes
* attributes
);
530 void markMalformedIfScript(nsIContentHandle
* elt
);
531 void start(bool fragmentMode
);
533 void appendDoctypeToDocument(nsAtom
* name
, nsHtml5String publicIdentifier
,
534 nsHtml5String systemIdentifier
);
535 void elementPushed(int32_t ns
, nsAtom
* name
, nsIContentHandle
* node
);
536 void elementPopped(int32_t ns
, nsAtom
* name
, nsIContentHandle
* node
);
539 inline bool cdataSectionAllowed() { return isInForeign(); }
543 bool isInForeignButNotHtmlOrMathTextIntegrationPoint();
546 void setFragmentContext(nsAtom
* context
, int32_t ns
, nsIContentHandle
* node
,
550 nsIContentHandle
* currentNode();
553 bool isScriptingEnabled();
554 void setScriptingEnabled(bool scriptingEnabled
);
555 void setForceNoQuirks(bool forceNoQuirks
);
556 void setIsSrcdocDocument(bool isSrcdocDocument
);
557 void flushCharacters();
560 bool charBufferContainsNonWhitespace();
563 nsAHtml5TreeBuilderState
* newSnapshot();
564 bool snapshotMatches(nsAHtml5TreeBuilderState
* snapshot
);
565 void loadState(nsAHtml5TreeBuilderState
* snapshot
);
568 int32_t findInArray(nsHtml5StackNode
* node
,
569 jArray
<nsHtml5StackNode
*, int32_t> arr
);
570 nsIContentHandle
* nodeFromStackWithBlinkCompat(int32_t stackPos
);
573 nsIContentHandle
* getFormPointer() override
;
574 nsIContentHandle
* getHeadPointer() override
;
575 jArray
<nsHtml5StackNode
*, int32_t> getListOfActiveFormattingElements()
577 jArray
<nsHtml5StackNode
*, int32_t> getStack() override
;
578 jArray
<int32_t, int32_t> getTemplateModeStack() override
;
579 int32_t getMode() override
;
580 int32_t getOriginalMode() override
;
581 bool isFramesetOk() override
;
582 bool isNeedToDropLF() override
;
583 bool isQuirks() override
;
584 int32_t getListOfActiveFormattingElementsLength() override
;
585 int32_t getStackLength() override
;
586 int32_t getTemplateModeStackLength() override
;
587 static void initializeStatics();
588 static void releaseStatics();
590 #include "nsHtml5TreeBuilderHSupplement.h"