HTMLElementFactory.cpp (2520B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/Assertions.h" 8 #include "mozilla/dom/CustomElementRegistry.h" 9 #include "mozilla/dom/Element.h" 10 #include "mozilla/dom/NodeInfo.h" 11 #include "nsContentCreatorFunctions.h" 12 #include "nsError.h" 13 #include "nsGenericHTMLElement.h" 14 #include "nsHTMLTags.h" 15 #include "nsNodeInfoManager.h" 16 17 using namespace mozilla; 18 using namespace mozilla::dom; 19 20 //---------------------------------------------------------------------- 21 22 nsGenericHTMLElement* NS_NewHTMLNOTUSEDElement( 23 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 24 FromParser aFromParser) { 25 MOZ_ASSERT_UNREACHABLE("The element ctor should never be called"); 26 return nullptr; 27 } 28 29 #define HTML_TAG(_tag, _classname, _interfacename) \ 30 NS_NewHTML##_classname##Element, 31 #define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement, 32 static const HTMLContentCreatorFunction sHTMLContentCreatorFunctions[] = { 33 NS_NewHTMLUnknownElement, 34 #include "nsHTMLTagList.h" 35 #undef HTML_TAG 36 #undef HTML_OTHER 37 NS_NewHTMLUnknownElement}; 38 39 nsresult NS_NewHTMLElement(Element** aResult, 40 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 41 FromParser aFromParser, nsAtom* aIsAtom, 42 mozilla::dom::CustomElementDefinition* aDefinition) { 43 RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo; 44 45 MOZ_ASSERT( 46 nodeInfo->NamespaceEquals(kNameSpaceID_XHTML), 47 "Trying to create HTML elements that don't have the XHTML namespace"); 48 49 return nsContentUtils::NewXULOrHTMLElement(aResult, nodeInfo, aFromParser, 50 aIsAtom, aDefinition); 51 } 52 53 already_AddRefed<nsGenericHTMLElement> CreateHTMLElement( 54 uint32_t aNodeType, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 55 FromParser aFromParser) { 56 MOZ_ASSERT(aNodeType <= NS_HTML_TAG_MAX || aNodeType == eHTMLTag_userdefined, 57 "aNodeType is out of bounds"); 58 59 HTMLContentCreatorFunction cb = sHTMLContentCreatorFunctions[aNodeType]; 60 61 MOZ_ASSERT(cb != NS_NewHTMLNOTUSEDElement, 62 "Don't know how to construct tag element!"); 63 64 RefPtr<nsGenericHTMLElement> result = cb(std::move(aNodeInfo), aFromParser); 65 66 return result.forget(); 67 }