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 : #include "nsIDOMCDATASection.h"
39 : #include "nsGenericDOMDataNode.h"
40 : #include "nsGkAtoms.h"
41 : #include "nsIDocument.h"
42 : #include "nsContentUtils.h"
43 :
44 : class nsXMLCDATASection : public nsGenericDOMDataNode,
45 : public nsIDOMCDATASection
46 : {
47 : public:
48 : nsXMLCDATASection(already_AddRefed<nsINodeInfo> aNodeInfo);
49 : virtual ~nsXMLCDATASection();
50 :
51 : // nsISupports
52 : NS_DECL_ISUPPORTS_INHERITED
53 :
54 : // nsIDOMNode
55 263 : NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::)
56 :
57 : // nsIDOMCharacterData
58 20 : NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::)
59 :
60 : // nsIDOMText
61 0 : NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::)
62 :
63 : // nsIDOMCDATASection
64 : // Empty interface
65 :
66 : // nsINode
67 : virtual bool IsNodeOfType(PRUint32 aFlags) const;
68 :
69 : virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo,
70 : bool aCloneText) const;
71 :
72 : virtual nsXPCClassInfo* GetClassInfo();
73 : #ifdef DEBUG
74 : virtual void List(FILE* out, PRInt32 aIndent) const;
75 : virtual void DumpContent(FILE* out, PRInt32 aIndent,bool aDumpAll) const;
76 : #endif
77 : };
78 :
79 : nsresult
80 42 : NS_NewXMLCDATASection(nsIContent** aInstancePtrResult,
81 : nsNodeInfoManager *aNodeInfoManager)
82 : {
83 42 : NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
84 :
85 42 : *aInstancePtrResult = nsnull;
86 :
87 84 : nsCOMPtr<nsINodeInfo> ni;
88 : ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::cdataTagName,
89 : nsnull, kNameSpaceID_None,
90 42 : nsIDOMNode::CDATA_SECTION_NODE);
91 42 : NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
92 :
93 84 : nsXMLCDATASection *instance = new nsXMLCDATASection(ni.forget());
94 42 : if (!instance) {
95 0 : return NS_ERROR_OUT_OF_MEMORY;
96 : }
97 :
98 42 : NS_ADDREF(*aInstancePtrResult = instance);
99 :
100 42 : return NS_OK;
101 : }
102 :
103 87 : nsXMLCDATASection::nsXMLCDATASection(already_AddRefed<nsINodeInfo> aNodeInfo)
104 87 : : nsGenericDOMDataNode(aNodeInfo)
105 : {
106 87 : NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE,
107 : "Bad NodeType in aNodeInfo");
108 87 : }
109 :
110 174 : nsXMLCDATASection::~nsXMLCDATASection()
111 : {
112 348 : }
113 :
114 :
115 23 : DOMCI_NODE_DATA(CDATASection, nsXMLCDATASection)
116 :
117 : // QueryInterface implementation for nsXMLCDATASection
118 3666 : NS_INTERFACE_TABLE_HEAD(nsXMLCDATASection)
119 3666 : NS_NODE_INTERFACE_TABLE4(nsXMLCDATASection, nsIDOMNode, nsIDOMCharacterData,
120 : nsIDOMText, nsIDOMCDATASection)
121 2565 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CDATASection)
122 2533 : NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
123 :
124 1918 : NS_IMPL_ADDREF_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
125 1918 : NS_IMPL_RELEASE_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
126 :
127 :
128 : bool
129 653 : nsXMLCDATASection::IsNodeOfType(PRUint32 aFlags) const
130 : {
131 653 : return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE));
132 : }
133 :
134 : nsGenericDOMDataNode*
135 45 : nsXMLCDATASection::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
136 : {
137 90 : nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
138 90 : nsXMLCDATASection *it = new nsXMLCDATASection(ni.forget());
139 45 : if (it && aCloneText) {
140 45 : it->mText = mText;
141 : }
142 :
143 45 : return it;
144 : }
145 :
146 : #ifdef DEBUG
147 : void
148 0 : nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
149 : {
150 : PRInt32 index;
151 0 : for (index = aIndent; --index >= 0; ) fputs(" ", out);
152 :
153 0 : fprintf(out, "CDATASection refcount=%d<", mRefCnt.get());
154 :
155 0 : nsAutoString tmp;
156 0 : ToCString(tmp, 0, mText.GetLength());
157 0 : fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
158 :
159 0 : fputs(">\n", out);
160 0 : }
161 :
162 : void
163 0 : nsXMLCDATASection::DumpContent(FILE* out, PRInt32 aIndent,
164 : bool aDumpAll) const {
165 0 : }
166 : #endif
|