/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsHtml5FragmentFastPath.h" #include #include #include #include #include "mozAutoDocUpdate.h" #include "mozilla/Array.h" #include "mozilla/ErrorResult.h" #include "mozilla/RandomNum.h" #include "mozilla/Span.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/TextUtils.h" #include "mozilla/Try.h" #include "mozilla/Utf16.h" #include "mozilla/Vector.h" #include "mozilla/glean/DomMetrics.h" #include "mozilla/dom/Comment.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/FromParser.h" #include "mozilla/dom/MutationObservers.h" #include "mozilla/dom/NodeInfo.h" #include "mozilla/htmlaccel/htmlaccelEnabled.h" #ifdef MOZ_MAY_HAVE_HTMLACCEL # include "mozilla/htmlaccel/htmlaccelNotInline.h" #endif #include "nsContentUtils.h" #include "nsDocElementCreatedNotificationRunner.h" #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" #include "nsHtml5AttributeName.h" #include "nsHtml5ElementName.h" #include "nsHtml5Portability.h" #include "nsHtml5String.h" #include "nsNodeInfoManager.h" #include "nsString.h" #include "nsTextNode.h" using namespace mozilla; using namespace mozilla::dom; namespace { // What an element may contain, chosen so that no supported nesting triggers // an implied end tag, foster parenting or the adoption agency algorithm. enum class ContentModel : uint8_t { Flow, Phrasing, // Only
  • elements, plus text. ListItems, // Whatever the parent may contain (for ). Inherit, }; struct TagInfo { nsStaticAtom* mName; bool mVoid; // Whether the element may appear in phrasing content, and not only in flow // content. bool mPhrasing; ContentModel mChildren; }; // The supported tags are the HTML elements for which the "in body" insertion // mode does nothing but insert an element and pop it at its end tag, given the // content models that the parser enforces. Their start tags are handled like // this (https://html.spec.whatwg.org/#parsing-main-inbody): // // A start tag whose tag name is one of: "address", "article", "aside", // "blockquote", "center", "details", "dialog", "dir", "div", "dl", // "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "main", // "menu", "nav", "ol", "p", "search", "section", "summary", "ul" // If the stack of open elements has a p element in button scope, then // close a p element. // Insert an HTML element for the token. // // A start tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6" // If the stack of open elements has a p element in button scope, then // close a p element. // If the current node is an HTML element whose tag name is one of "h1", // "h2", "h3", "h4", "h5", or "h6", then this is a parse error; pop the // current node off the stack of open elements. // Insert an HTML element for the token. // // These tags aren't phrasing content, and

    and the headings may only // contain phrasing content, so neither a

    nor a heading is ever open // around them. // // A start tag whose tag name is "li" // 1. Set the frameset-ok flag to "not ok". // 2. Initialize node to be the current node (the bottommost node of the // stack). // 3. Loop: If node is an li element, then run these substeps: // 1. Generate implied end tags, except for li elements. // 2. If the current node is not an li element, then this is a parse // error. // 3. Pop elements from the stack of open elements until an li element // has been popped from the stack. // 4. Jump to the step labeled done below. // 4. If node is in the special category, but is not an address, div, or p // element, then jump to the step labeled done below. // 5. Otherwise, set node to the previous entry in the stack of open // elements and return to the step labeled loop. // 6. Done: If the stack of open elements has a p element in button scope, // then close a p element. // 7. Finally, insert an HTML element for the token. // // An

  • is only allowed outside of other
  • elements, or as a child of a //