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.org 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 : * Class that represents a prefix/namespace/localName triple; a single
40 : * nodeinfo is shared by all elements in a document that have that
41 : * prefix, namespace, and localName.
42 : */
43 :
44 : #ifndef nsNodeInfo_h___
45 : #define nsNodeInfo_h___
46 :
47 : #include "nsINodeInfo.h"
48 : #include "nsNodeInfoManager.h"
49 : #include "plhash.h"
50 : #include "nsIAtom.h"
51 : #include "nsCOMPtr.h"
52 :
53 : class nsFixedSizeAllocator;
54 :
55 : class nsNodeInfo : public nsINodeInfo
56 : {
57 : public:
58 11980 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
59 1118986 : NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeInfo)
60 :
61 : // nsINodeInfo
62 : virtual nsresult GetNamespaceURI(nsAString& aNameSpaceURI) const;
63 : virtual bool NamespaceEquals(const nsAString& aNamespaceURI) const;
64 :
65 : // nsNodeInfo
66 : // Create objects with Create
67 : public:
68 : /*
69 : * aName and aOwnerManager may not be null.
70 : */
71 : static nsNodeInfo *Create(nsIAtom *aName, nsIAtom *aPrefix,
72 : PRInt32 aNamespaceID, PRUint16 aNodeType,
73 : nsIAtom *aExtraName,
74 : nsNodeInfoManager *aOwnerManager);
75 : private:
76 : nsNodeInfo(); // Unimplemented
77 : nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented
78 : nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID,
79 : PRUint16 aNodeType, nsIAtom *aExtraName,
80 : nsNodeInfoManager *aOwnerManager);
81 : protected:
82 : virtual ~nsNodeInfo();
83 :
84 : public:
85 : /**
86 : * Call before shutdown to clear the cache and free memory for this class.
87 : */
88 : static void ClearCache();
89 :
90 : private:
91 : static nsFixedSizeAllocator* sNodeInfoPool;
92 :
93 : /**
94 : * This method gets called by Release() when it's time to delete
95 : * this object, instead of always deleting the object we'll put the
96 : * object in the cache unless the cache is already full.
97 : */
98 : void LastRelease();
99 : };
100 :
101 : #define CHECK_VALID_NODEINFO(_nodeType, _name, _namespaceID, _extraName) \
102 : NS_ABORT_IF_FALSE(_nodeType == nsIDOMNode::ELEMENT_NODE || \
103 : _nodeType == nsIDOMNode::ATTRIBUTE_NODE || \
104 : _nodeType == nsIDOMNode::TEXT_NODE || \
105 : _nodeType == nsIDOMNode::CDATA_SECTION_NODE || \
106 : _nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || \
107 : _nodeType == nsIDOMNode::COMMENT_NODE || \
108 : _nodeType == nsIDOMNode::DOCUMENT_NODE || \
109 : _nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE || \
110 : _nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE || \
111 : _nodeType == PR_UINT16_MAX, \
112 : "Invalid nodeType"); \
113 : NS_ABORT_IF_FALSE((_nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || \
114 : _nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == \
115 : (_extraName != nsnull), \
116 : "Supply aExtraName for and only for PIs and doctypes"); \
117 : NS_ABORT_IF_FALSE(_nodeType == nsIDOMNode::ELEMENT_NODE || \
118 : _nodeType == nsIDOMNode::ATTRIBUTE_NODE || \
119 : _nodeType == PR_UINT16_MAX || \
120 : aNamespaceID == kNameSpaceID_None, \
121 : "Only attributes and elements can be in a namespace"); \
122 : NS_ABORT_IF_FALSE(_name && _name != nsGkAtoms::_empty, "Invalid localName");\
123 : NS_ABORT_IF_FALSE(((_nodeType == nsIDOMNode::TEXT_NODE) == \
124 : (_name == nsGkAtoms::textTagName)) && \
125 : ((_nodeType == nsIDOMNode::CDATA_SECTION_NODE) == \
126 : (_name == nsGkAtoms::cdataTagName)) && \
127 : ((_nodeType == nsIDOMNode::COMMENT_NODE) == \
128 : (_name == nsGkAtoms::commentTagName)) && \
129 : ((_nodeType == nsIDOMNode::DOCUMENT_NODE) == \
130 : (_name == nsGkAtoms::documentNodeName)) && \
131 : ((_nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) == \
132 : (_name == nsGkAtoms::documentFragmentNodeName)) && \
133 : ((_nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == \
134 : (_name == nsGkAtoms::documentTypeNodeName)) && \
135 : ((_nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE) ==\
136 : (_name == nsGkAtoms::processingInstructionTagName)), \
137 : "Wrong localName for nodeType");
138 :
139 : #endif /* nsNodeInfo_h___ */
|