2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2006-03-31 08:00:42 +00:00
|
|
|
/*
|
|
|
|
* Class that represents a prefix/namespace/localName triple; a single
|
|
|
|
* nodeinfo is shared by all elements in a document that have that
|
|
|
|
* prefix, namespace, and localName.
|
|
|
|
*/
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
#ifndef nsNodeInfo_h___
|
|
|
|
#define nsNodeInfo_h___
|
|
|
|
|
|
|
|
#include "nsINodeInfo.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2000-05-08 14:29:44 +00:00
|
|
|
#include "plhash.h"
|
2000-08-30 00:35:43 +00:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-08-16 15:07:55 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2006-07-11 09:26:13 +00:00
|
|
|
class nsFixedSizeAllocator;
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
class nsNodeInfo : public nsINodeInfo
|
|
|
|
{
|
|
|
|
public:
|
2008-03-28 14:09:00 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeInfo)
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
// nsINodeInfo
|
2003-11-15 05:27:37 +00:00
|
|
|
virtual nsresult GetNamespaceURI(nsAString& aNameSpaceURI) const;
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool NamespaceEquals(const nsAString& aNamespaceURI) const;
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
// nsNodeInfo
|
2003-10-30 13:47:29 +00:00
|
|
|
// Create objects with Create
|
|
|
|
public:
|
2011-05-05 16:26:32 +00:00
|
|
|
/*
|
|
|
|
* aName and aOwnerManager may not be null.
|
|
|
|
*/
|
|
|
|
static nsNodeInfo *Create(nsIAtom *aName, nsIAtom *aPrefix,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2011-06-14 07:56:49 +00:00
|
|
|
nsIAtom *aExtraName,
|
2011-05-05 16:26:32 +00:00
|
|
|
nsNodeInfoManager *aOwnerManager);
|
2003-10-30 13:47:29 +00:00
|
|
|
private:
|
2011-05-05 16:26:32 +00:00
|
|
|
nsNodeInfo(); // Unimplemented
|
|
|
|
nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
|
|
|
|
uint16_t aNodeType, nsIAtom *aExtraName,
|
2011-05-05 16:26:32 +00:00
|
|
|
nsNodeInfoManager *aOwnerManager);
|
2005-01-31 16:18:31 +00:00
|
|
|
protected:
|
|
|
|
virtual ~nsNodeInfo();
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2003-10-30 13:47:29 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Call before shutdown to clear the cache and free memory for this class.
|
|
|
|
*/
|
|
|
|
static void ClearCache();
|
|
|
|
|
|
|
|
private:
|
2006-07-11 09:26:13 +00:00
|
|
|
static nsFixedSizeAllocator* sNodeInfoPool;
|
2005-01-28 22:58:37 +00:00
|
|
|
|
2003-10-30 13:47:29 +00:00
|
|
|
/**
|
|
|
|
* This method gets called by Release() when it's time to delete
|
|
|
|
* this object, instead of always deleting the object we'll put the
|
|
|
|
* object in the cache unless the cache is already full.
|
|
|
|
*/
|
2012-08-16 15:07:55 +00:00
|
|
|
void LastRelease();
|
2000-05-08 14:29:44 +00:00
|
|
|
};
|
|
|
|
|
2012-08-16 15:07:55 +00:00
|
|
|
inline void
|
2012-08-22 15:56:38 +00:00
|
|
|
CheckValidNodeInfo(uint16_t aNodeType, nsIAtom *aName, int32_t aNamespaceID,
|
2012-08-16 15:07:55 +00:00
|
|
|
nsIAtom* aExtraName)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aNodeType == nsIDOMNode::ELEMENT_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::ATTRIBUTE_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::TEXT_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::CDATA_SECTION_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::COMMENT_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::DOCUMENT_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE ||
|
2012-09-28 06:57:33 +00:00
|
|
|
aNodeType == UINT16_MAX,
|
2012-08-16 15:07:55 +00:00
|
|
|
"Invalid nodeType");
|
|
|
|
NS_ABORT_IF_FALSE((aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) ==
|
|
|
|
!!aExtraName,
|
|
|
|
"Supply aExtraName for and only for PIs and doctypes");
|
|
|
|
NS_ABORT_IF_FALSE(aNodeType == nsIDOMNode::ELEMENT_NODE ||
|
|
|
|
aNodeType == nsIDOMNode::ATTRIBUTE_NODE ||
|
2012-09-28 06:57:33 +00:00
|
|
|
aNodeType == UINT16_MAX ||
|
2012-08-16 15:07:55 +00:00
|
|
|
aNamespaceID == kNameSpaceID_None,
|
|
|
|
"Only attributes and elements can be in a namespace");
|
|
|
|
NS_ABORT_IF_FALSE(aName && aName != nsGkAtoms::_empty, "Invalid localName");
|
|
|
|
NS_ABORT_IF_FALSE(((aNodeType == nsIDOMNode::TEXT_NODE) ==
|
|
|
|
(aName == nsGkAtoms::textTagName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::CDATA_SECTION_NODE) ==
|
|
|
|
(aName == nsGkAtoms::cdataTagName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::COMMENT_NODE) ==
|
|
|
|
(aName == nsGkAtoms::commentTagName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::DOCUMENT_NODE) ==
|
|
|
|
(aName == nsGkAtoms::documentNodeName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) ==
|
|
|
|
(aName == nsGkAtoms::documentFragmentNodeName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) ==
|
|
|
|
(aName == nsGkAtoms::documentTypeNodeName)) &&
|
|
|
|
((aNodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE) ==
|
|
|
|
(aName == nsGkAtoms::processingInstructionTagName)),
|
|
|
|
"Wrong localName for nodeType");
|
|
|
|
}
|
2011-06-14 07:56:49 +00:00
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
#endif /* nsNodeInfo_h___ */
|