michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Implementation of DOM Core's nsIDOMDocumentType node. michael@0: */ michael@0: michael@0: #include "mozilla/dom/DocumentType.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsDOMString.h" michael@0: #include "nsNodeInfoManager.h" michael@0: #include "nsIXPConnect.h" michael@0: #include "xpcpublic.h" michael@0: #include "nsWrapperCacheInlines.h" michael@0: #include "mozilla/dom/DocumentTypeBinding.h" michael@0: michael@0: nsresult michael@0: NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, michael@0: nsNodeInfoManager *aNodeInfoManager, michael@0: nsIAtom *aName, michael@0: const nsAString& aPublicId, michael@0: const nsAString& aSystemId, michael@0: const nsAString& aInternalSubset) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aDocType); michael@0: mozilla::ErrorResult rv; michael@0: *aDocType = NS_NewDOMDocumentType(aNodeInfoManager, aName, aPublicId, michael@0: aSystemId, aInternalSubset, rv).take(); michael@0: return rv.ErrorCode(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager, michael@0: nsIAtom *aName, michael@0: const nsAString& aPublicId, michael@0: const nsAString& aSystemId, michael@0: const nsAString& aInternalSubset, michael@0: mozilla::ErrorResult& rv) michael@0: { michael@0: if (!aName) { michael@0: rv.Throw(NS_ERROR_INVALID_POINTER); michael@0: return nullptr; michael@0: } michael@0: michael@0: already_AddRefed ni = michael@0: aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr, michael@0: kNameSpaceID_None, michael@0: nsIDOMNode::DOCUMENT_TYPE_NODE, michael@0: aName); michael@0: michael@0: nsRefPtr docType = michael@0: new mozilla::dom::DocumentType(ni, aPublicId, aSystemId, aInternalSubset); michael@0: return docType.forget(); michael@0: } michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: JSObject* michael@0: DocumentType::WrapNode(JSContext *cx) michael@0: { michael@0: return DocumentTypeBinding::Wrap(cx, this); michael@0: } michael@0: michael@0: DocumentType::DocumentType(already_AddRefed& aNodeInfo, michael@0: const nsAString& aPublicId, michael@0: const nsAString& aSystemId, michael@0: const nsAString& aInternalSubset) : michael@0: DocumentTypeForward(aNodeInfo), michael@0: mPublicId(aPublicId), michael@0: mSystemId(aSystemId), michael@0: mInternalSubset(aInternalSubset) michael@0: { michael@0: NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE, michael@0: "Bad NodeType in aNodeInfo"); michael@0: } michael@0: michael@0: DocumentType::~DocumentType() michael@0: { michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS_INHERITED(DocumentType, nsGenericDOMDataNode, nsIDOMNode, michael@0: nsIDOMDocumentType) michael@0: michael@0: bool michael@0: DocumentType::IsNodeOfType(uint32_t aFlags) const michael@0: { michael@0: // Don't claim to be eDATA_NODE since we're just inheriting michael@0: // nsGenericDOMDataNode for convinience. Doctypes aren't really michael@0: // data nodes (they have a null .nodeValue and don't implement michael@0: // nsIDOMCharacterData) michael@0: return !(aFlags & ~eCONTENT); michael@0: } michael@0: michael@0: const nsTextFragment* michael@0: DocumentType::GetText() michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DocumentType::GetName(nsAString& aName) michael@0: { michael@0: aName = NodeName(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DocumentType::GetPublicId(nsAString& aPublicId) michael@0: { michael@0: aPublicId = mPublicId; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DocumentType::GetSystemId(nsAString& aSystemId) michael@0: { michael@0: aSystemId = mSystemId; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DocumentType::GetInternalSubset(nsAString& aInternalSubset) michael@0: { michael@0: aInternalSubset = mInternalSubset; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DocumentType::MozRemove() michael@0: { michael@0: Remove(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsGenericDOMDataNode* michael@0: DocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const michael@0: { michael@0: already_AddRefed ni = nsCOMPtr(aNodeInfo).forget(); michael@0: return new DocumentType(ni, mPublicId, mSystemId, mInternalSubset); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: