1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /*
39 : * Implementation of DOM Core's nsIDOMDocumentType node.
40 : */
41 :
42 : #include "nsDOMDocumentType.h"
43 : #include "nsDOMAttributeMap.h"
44 : #include "nsIDOMNamedNodeMap.h"
45 : #include "nsGkAtoms.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsContentUtils.h"
48 : #include "nsDOMString.h"
49 : #include "nsNodeInfoManager.h"
50 : #include "nsIDocument.h"
51 : #include "nsIXPConnect.h"
52 : #include "nsIDOMDocument.h"
53 : #include "xpcpublic.h"
54 : #include "nsWrapperCacheInlines.h"
55 :
56 : nsresult
57 32 : NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
58 : nsNodeInfoManager *aNodeInfoManager,
59 : nsIAtom *aName,
60 : const nsAString& aPublicId,
61 : const nsAString& aSystemId,
62 : const nsAString& aInternalSubset)
63 : {
64 32 : NS_ENSURE_ARG_POINTER(aDocType);
65 32 : NS_ENSURE_ARG_POINTER(aName);
66 :
67 : nsCOMPtr<nsINodeInfo> ni =
68 : aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nsnull,
69 : kNameSpaceID_None,
70 : nsIDOMNode::DOCUMENT_TYPE_NODE,
71 64 : aName);
72 32 : NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
73 :
74 : *aDocType = new nsDOMDocumentType(ni.forget(), aPublicId, aSystemId,
75 64 : aInternalSubset);
76 32 : NS_ADDREF(*aDocType);
77 :
78 32 : return NS_OK;
79 : }
80 :
81 32 : nsDOMDocumentType::nsDOMDocumentType(already_AddRefed<nsINodeInfo> aNodeInfo,
82 : const nsAString& aPublicId,
83 : const nsAString& aSystemId,
84 : const nsAString& aInternalSubset) :
85 : nsDOMDocumentTypeForward(aNodeInfo),
86 : mPublicId(aPublicId),
87 : mSystemId(aSystemId),
88 32 : mInternalSubset(aInternalSubset)
89 : {
90 32 : NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
91 : "Bad NodeType in aNodeInfo");
92 32 : }
93 :
94 64 : nsDOMDocumentType::~nsDOMDocumentType()
95 : {
96 128 : }
97 :
98 1 : DOMCI_NODE_DATA(DocumentType, nsDOMDocumentType)
99 :
100 : // QueryInterface implementation for nsDOMDocumentType
101 621 : NS_INTERFACE_TABLE_HEAD(nsDOMDocumentType)
102 621 : NS_NODE_INTERFACE_TABLE2(nsDOMDocumentType, nsIDOMNode, nsIDOMDocumentType)
103 553 : NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsDOMDocumentType)
104 72 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DocumentType)
105 70 : NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
106 :
107 :
108 227 : NS_IMPL_ADDREF_INHERITED(nsDOMDocumentType, nsGenericDOMDataNode)
109 227 : NS_IMPL_RELEASE_INHERITED(nsDOMDocumentType, nsGenericDOMDataNode)
110 :
111 : bool
112 73 : nsDOMDocumentType::IsNodeOfType(PRUint32 aFlags) const
113 : {
114 : // Don't claim to be eDATA_NODE since we're just inheriting
115 : // nsGenericDOMDataNode for convinience. Doctypes aren't really
116 : // data nodes (they have a null .nodeValue and don't implement
117 : // nsIDOMCharacterData)
118 73 : return !(aFlags & ~eCONTENT);
119 : }
120 :
121 : const nsTextFragment*
122 0 : nsDOMDocumentType::GetText()
123 : {
124 0 : return nsnull;
125 : }
126 :
127 : NS_IMETHODIMP
128 9 : nsDOMDocumentType::GetName(nsAString& aName)
129 : {
130 9 : aName = NodeName();
131 9 : return NS_OK;
132 : }
133 :
134 : NS_IMETHODIMP
135 21 : nsDOMDocumentType::GetPublicId(nsAString& aPublicId)
136 : {
137 21 : aPublicId = mPublicId;
138 :
139 21 : return NS_OK;
140 : }
141 :
142 : NS_IMETHODIMP
143 21 : nsDOMDocumentType::GetSystemId(nsAString& aSystemId)
144 : {
145 21 : aSystemId = mSystemId;
146 :
147 21 : return NS_OK;
148 : }
149 :
150 : NS_IMETHODIMP
151 21 : nsDOMDocumentType::GetInternalSubset(nsAString& aInternalSubset)
152 : {
153 21 : aInternalSubset = mInternalSubset;
154 21 : return NS_OK;
155 : }
156 :
157 : nsGenericDOMDataNode*
158 0 : nsDOMDocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
159 : {
160 0 : nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
161 : return new nsDOMDocumentType(ni.forget(), mPublicId, mSystemId,
162 0 : mInternalSubset);
163 : }
164 :
|