1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/DocumentType.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * Implementation of DOM Core's nsIDOMDocumentType node. 1.11 + */ 1.12 + 1.13 +#include "mozilla/dom/DocumentType.h" 1.14 +#include "nsGkAtoms.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsDOMString.h" 1.17 +#include "nsNodeInfoManager.h" 1.18 +#include "nsIXPConnect.h" 1.19 +#include "xpcpublic.h" 1.20 +#include "nsWrapperCacheInlines.h" 1.21 +#include "mozilla/dom/DocumentTypeBinding.h" 1.22 + 1.23 +nsresult 1.24 +NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, 1.25 + nsNodeInfoManager *aNodeInfoManager, 1.26 + nsIAtom *aName, 1.27 + const nsAString& aPublicId, 1.28 + const nsAString& aSystemId, 1.29 + const nsAString& aInternalSubset) 1.30 +{ 1.31 + NS_ENSURE_ARG_POINTER(aDocType); 1.32 + mozilla::ErrorResult rv; 1.33 + *aDocType = NS_NewDOMDocumentType(aNodeInfoManager, aName, aPublicId, 1.34 + aSystemId, aInternalSubset, rv).take(); 1.35 + return rv.ErrorCode(); 1.36 +} 1.37 + 1.38 +already_AddRefed<mozilla::dom::DocumentType> 1.39 +NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager, 1.40 + nsIAtom *aName, 1.41 + const nsAString& aPublicId, 1.42 + const nsAString& aSystemId, 1.43 + const nsAString& aInternalSubset, 1.44 + mozilla::ErrorResult& rv) 1.45 +{ 1.46 + if (!aName) { 1.47 + rv.Throw(NS_ERROR_INVALID_POINTER); 1.48 + return nullptr; 1.49 + } 1.50 + 1.51 + already_AddRefed<nsINodeInfo> ni = 1.52 + aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr, 1.53 + kNameSpaceID_None, 1.54 + nsIDOMNode::DOCUMENT_TYPE_NODE, 1.55 + aName); 1.56 + 1.57 + nsRefPtr<mozilla::dom::DocumentType> docType = 1.58 + new mozilla::dom::DocumentType(ni, aPublicId, aSystemId, aInternalSubset); 1.59 + return docType.forget(); 1.60 +} 1.61 + 1.62 +namespace mozilla { 1.63 +namespace dom { 1.64 + 1.65 +JSObject* 1.66 +DocumentType::WrapNode(JSContext *cx) 1.67 +{ 1.68 + return DocumentTypeBinding::Wrap(cx, this); 1.69 +} 1.70 + 1.71 +DocumentType::DocumentType(already_AddRefed<nsINodeInfo>& aNodeInfo, 1.72 + const nsAString& aPublicId, 1.73 + const nsAString& aSystemId, 1.74 + const nsAString& aInternalSubset) : 1.75 + DocumentTypeForward(aNodeInfo), 1.76 + mPublicId(aPublicId), 1.77 + mSystemId(aSystemId), 1.78 + mInternalSubset(aInternalSubset) 1.79 +{ 1.80 + NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE, 1.81 + "Bad NodeType in aNodeInfo"); 1.82 +} 1.83 + 1.84 +DocumentType::~DocumentType() 1.85 +{ 1.86 +} 1.87 + 1.88 +NS_IMPL_ISUPPORTS_INHERITED(DocumentType, nsGenericDOMDataNode, nsIDOMNode, 1.89 + nsIDOMDocumentType) 1.90 + 1.91 +bool 1.92 +DocumentType::IsNodeOfType(uint32_t aFlags) const 1.93 +{ 1.94 + // Don't claim to be eDATA_NODE since we're just inheriting 1.95 + // nsGenericDOMDataNode for convinience. Doctypes aren't really 1.96 + // data nodes (they have a null .nodeValue and don't implement 1.97 + // nsIDOMCharacterData) 1.98 + return !(aFlags & ~eCONTENT); 1.99 +} 1.100 + 1.101 +const nsTextFragment* 1.102 +DocumentType::GetText() 1.103 +{ 1.104 + return nullptr; 1.105 +} 1.106 + 1.107 +NS_IMETHODIMP 1.108 +DocumentType::GetName(nsAString& aName) 1.109 +{ 1.110 + aName = NodeName(); 1.111 + return NS_OK; 1.112 +} 1.113 + 1.114 +NS_IMETHODIMP 1.115 +DocumentType::GetPublicId(nsAString& aPublicId) 1.116 +{ 1.117 + aPublicId = mPublicId; 1.118 + 1.119 + return NS_OK; 1.120 +} 1.121 + 1.122 +NS_IMETHODIMP 1.123 +DocumentType::GetSystemId(nsAString& aSystemId) 1.124 +{ 1.125 + aSystemId = mSystemId; 1.126 + 1.127 + return NS_OK; 1.128 +} 1.129 + 1.130 +NS_IMETHODIMP 1.131 +DocumentType::GetInternalSubset(nsAString& aInternalSubset) 1.132 +{ 1.133 + aInternalSubset = mInternalSubset; 1.134 + return NS_OK; 1.135 +} 1.136 + 1.137 +NS_IMETHODIMP 1.138 +DocumentType::MozRemove() 1.139 +{ 1.140 + Remove(); 1.141 + return NS_OK; 1.142 +} 1.143 + 1.144 +nsGenericDOMDataNode* 1.145 +DocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const 1.146 +{ 1.147 + already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget(); 1.148 + return new DocumentType(ni, mPublicId, mSystemId, mInternalSubset); 1.149 +} 1.150 + 1.151 +} // namespace dom 1.152 +} // namespace mozilla 1.153 +