DocumentType.cpp (2808B)
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 /* 8 * Implementation of DOM Core's DocumentType node. 9 */ 10 11 #include "mozilla/dom/DocumentType.h" 12 13 #include "mozilla/dom/DocumentTypeBinding.h" 14 #include "nsCOMPtr.h" 15 #include "nsDOMString.h" 16 #include "nsGkAtoms.h" 17 #include "nsNodeInfoManager.h" 18 #include "nsWrapperCacheInlines.h" 19 #include "xpcpublic.h" 20 21 already_AddRefed<mozilla::dom::DocumentType> NS_NewDOMDocumentType( 22 nsNodeInfoManager* aNodeInfoManager, nsAtom* aName, 23 const nsAString& aPublicId, const nsAString& aSystemId, 24 const nsAString& aInternalSubset) { 25 MOZ_ASSERT(aName, "Must have a name"); 26 27 RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfoManager->GetNodeInfo( 28 nsGkAtoms::documentTypeNodeName, nullptr, kNameSpaceID_None, 29 nsINode::DOCUMENT_TYPE_NODE, aName); 30 31 RefPtr<mozilla::dom::DocumentType> docType = 32 new (aNodeInfoManager) mozilla::dom::DocumentType( 33 ni.forget(), aPublicId, aSystemId, aInternalSubset); 34 return docType.forget(); 35 } 36 37 namespace mozilla::dom { 38 39 JSObject* DocumentType::WrapNode(JSContext* cx, 40 JS::Handle<JSObject*> aGivenProto) { 41 return DocumentType_Binding::Wrap(cx, this, aGivenProto); 42 } 43 44 DocumentType::DocumentType(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 45 const nsAString& aPublicId, 46 const nsAString& aSystemId, 47 const nsAString& aInternalSubset) 48 : CharacterData(std::move(aNodeInfo)), 49 mPublicId(aPublicId), 50 mSystemId(aSystemId), 51 mInternalSubset(aInternalSubset) { 52 MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE, 53 "Bad NodeType in aNodeInfo"); 54 MOZ_ASSERT(!IsCharacterData()); 55 } 56 57 DocumentType::~DocumentType() = default; 58 59 const CharacterDataBuffer* DocumentType::GetCharacterDataBuffer() const { 60 return nullptr; 61 } 62 63 void DocumentType::GetName(nsAString& aName) const { aName = NodeName(); } 64 65 void DocumentType::GetPublicId(nsAString& aPublicId) const { 66 aPublicId = mPublicId; 67 } 68 69 void DocumentType::GetSystemId(nsAString& aSystemId) const { 70 aSystemId = mSystemId; 71 } 72 73 void DocumentType::GetInternalSubset(nsAString& aInternalSubset) const { 74 aInternalSubset = mInternalSubset; 75 } 76 77 already_AddRefed<CharacterData> DocumentType::CloneDataNode( 78 mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const { 79 return do_AddRef(new (aNodeInfo->NodeInfoManager()) DocumentType( 80 do_AddRef(aNodeInfo), mPublicId, mSystemId, mInternalSubset)); 81 } 82 83 } // namespace mozilla::dom