2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsINodeInfo is an interface to node info, such as name, prefix, namespace
|
|
|
|
* ID and possibly other data that is shared between nodes (elements
|
|
|
|
* and attributes) that have the same name, prefix and namespace ID within
|
|
|
|
* the same document.
|
|
|
|
*
|
|
|
|
* nsNodeInfoManager's are internal objects that manage a list of
|
|
|
|
* nsINodeInfo's, every document object should hold a strong reference to
|
|
|
|
* a nsNodeInfoManager and every nsINodeInfo also holds a strong reference
|
|
|
|
* to their owning manager. When a nsINodeInfo is no longer used it will
|
|
|
|
* automatically remove itself from its owner manager, and when all
|
|
|
|
* nsINodeInfo's have been removed from a nsNodeInfoManager and all external
|
|
|
|
* references are released the nsNodeInfoManager deletes itself.
|
|
|
|
*
|
|
|
|
* -- jst@netscape.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsINodeInfo_h___
|
|
|
|
#define nsINodeInfo_h___
|
|
|
|
|
2012-08-06 05:02:08 -07:00
|
|
|
#include "nsCOMPtr.h" // for member
|
|
|
|
#include "nsIAtom.h" // for member (in nsCOMPtr)
|
|
|
|
#include "nsINameSpaceManager.h" // for kNameSpaceID_*
|
|
|
|
#include "nsISupports.h" // for base class
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIURI;
|
|
|
|
class nsIPrincipal;
|
2012-08-06 05:02:08 -07:00
|
|
|
class nsNodeInfoManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// IID for the nsINodeInfo interface
|
|
|
|
#define NS_INODEINFO_IID \
|
2011-05-05 09:26:33 -07:00
|
|
|
{ 0xc5188ea1, 0x0a9c, 0x43e6, \
|
|
|
|
{ 0x95, 0x90, 0xcc, 0x43, 0x6b, 0xe9, 0xcf, 0xa0 } }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsINodeInfo : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODEINFO_IID)
|
|
|
|
|
|
|
|
nsINodeInfo()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mInner(nullptr, nullptr, kNameSpaceID_None, 0, nullptr),
|
|
|
|
mOwnerManager(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the name from this node as a string, this does not include the prefix.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return "body" and for the XML
|
|
|
|
* element "<html:body>" this will return "body".
|
|
|
|
*/
|
|
|
|
void GetName(nsAString& aName) const
|
|
|
|
{
|
|
|
|
mInner.mName->ToString(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the name from this node as an atom, this does not include the prefix.
|
|
|
|
* This function never returns a null atom.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return the "body" atom and for
|
|
|
|
* the XML element "<html:body>" this will return the "body" atom.
|
|
|
|
*/
|
|
|
|
nsIAtom* NameAtom() const
|
|
|
|
{
|
|
|
|
return mInner.mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the qualified name from this node as a string, the qualified name
|
|
|
|
* includes the prefix, if one exists.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return "body" and for the XML
|
|
|
|
* element "<html:body>" this will return "html:body".
|
|
|
|
*/
|
2011-05-05 09:26:33 -07:00
|
|
|
const nsString& QualifiedName() const {
|
|
|
|
return mQualifiedName;
|
2011-05-05 09:26:32 -07:00
|
|
|
}
|
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
/*
|
|
|
|
* Returns the node's nodeName as defined in DOM Core
|
|
|
|
*/
|
|
|
|
const nsString& NodeName() const {
|
|
|
|
return mNodeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the node's localName as defined in DOM Core
|
|
|
|
*/
|
|
|
|
const nsString& LocalName() const {
|
|
|
|
return mLocalName;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
/*
|
|
|
|
* Get the prefix from this node as a string.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return a null string and for
|
|
|
|
* the XML element "<html:body>" this will return the string "html".
|
|
|
|
*/
|
|
|
|
void GetPrefix(nsAString& aPrefix) const
|
|
|
|
{
|
|
|
|
if (mInner.mPrefix) {
|
|
|
|
mInner.mPrefix->ToString(aPrefix);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the prefix from this node as an atom.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return a null atom and for
|
|
|
|
* the XML element "<html:body>" this will return the "html" atom.
|
|
|
|
*/
|
|
|
|
nsIAtom* GetPrefixAtom() const
|
|
|
|
{
|
|
|
|
return mInner.mPrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the namespace URI for a node, if the node has a namespace URI.
|
|
|
|
*/
|
2013-01-29 14:53:52 -08:00
|
|
|
virtual void GetNamespaceURI(nsAString& aNameSpaceURI) const = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the namespace ID for a node if the node has a namespace, if not this
|
|
|
|
* returns kNameSpaceID_None.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t NamespaceID() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mInner.mNamespaceID;
|
|
|
|
}
|
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
/*
|
|
|
|
* Get the nodetype for the node. Returns the values specified in nsIDOMNode
|
|
|
|
* for nsIDOMNode.nodeType
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t NodeType() const
|
2011-06-14 00:56:49 -07:00
|
|
|
{
|
|
|
|
return mInner.mNodeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the extra name, used by PIs and DocTypes, for the node.
|
|
|
|
*/
|
|
|
|
nsIAtom* GetExtraName() const
|
|
|
|
{
|
|
|
|
return mInner.mExtraName;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Get and set the ID attribute atom for this node.
|
|
|
|
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
|
|
|
|
* for the definition of an ID attribute.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsIAtom* GetIDAttributeAtom() const
|
|
|
|
{
|
|
|
|
return mIDAttributeAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetIDAttributeAtom(nsIAtom* aID)
|
|
|
|
{
|
|
|
|
mIDAttributeAtom = aID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the owning node info manager. Only to be used inside Gecko, you can't
|
|
|
|
* really do anything with the pointer outside Gecko anyway.
|
|
|
|
*/
|
|
|
|
nsNodeInfoManager *NodeInfoManager() const
|
|
|
|
{
|
|
|
|
return mOwnerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility functions that can be used to check if a nodeinfo holds a specific
|
|
|
|
* name, name and prefix, name and prefix and namespace ID, or just
|
|
|
|
* namespace ID.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(nsINodeInfo *aNodeInfo) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return aNodeInfo == this || aNodeInfo->Equals(mInner.mName, mInner.mPrefix,
|
|
|
|
mInner.mNamespaceID);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NameAndNamespaceEquals(nsINodeInfo *aNodeInfo) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return aNodeInfo == this || aNodeInfo->Equals(mInner.mName,
|
|
|
|
mInner.mNamespaceID);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(nsIAtom *aNameAtom) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mInner.mName == aNameAtom;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool Equals(nsIAtom *aNameAtom, int32_t aNamespaceID) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return ((mInner.mName == aNameAtom) &&
|
|
|
|
(mInner.mNamespaceID == aNamespaceID));
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNamespaceID) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return ((mInner.mName == aNameAtom) &&
|
|
|
|
(mInner.mPrefix == aPrefixAtom) &&
|
|
|
|
(mInner.mNamespaceID == aNamespaceID));
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool NamespaceEquals(int32_t aNamespaceID) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mInner.mNamespaceID == aNamespaceID;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(const nsAString& aName) const
|
2011-05-05 09:26:33 -07:00
|
|
|
{
|
|
|
|
return mInner.mName->Equals(aName);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(const nsAString& aName, const nsAString& aPrefix) const
|
2011-05-05 09:26:33 -07:00
|
|
|
{
|
|
|
|
return mInner.mName->Equals(aName) &&
|
|
|
|
(mInner.mPrefix ? mInner.mPrefix->Equals(aPrefix) : aPrefix.IsEmpty());
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool Equals(const nsAString& aName, int32_t aNamespaceID) const
|
2011-05-05 09:26:33 -07:00
|
|
|
{
|
|
|
|
return mInner.mNamespaceID == aNamespaceID &&
|
|
|
|
mInner.mName->Equals(aName);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(const nsAString& aName, const nsAString& aPrefix,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNamespaceID) const
|
2011-05-05 09:26:33 -07:00
|
|
|
{
|
|
|
|
return mInner.mName->Equals(aName) && mInner.mNamespaceID == aNamespaceID &&
|
|
|
|
(mInner.mPrefix ? mInner.mPrefix->Equals(aPrefix) : aPrefix.IsEmpty());
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool QualifiedNameEquals(nsIAtom* aNameAtom) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNameAtom, "Must have name atom");
|
|
|
|
if (!GetPrefixAtom())
|
|
|
|
return Equals(aNameAtom);
|
|
|
|
|
2011-05-05 09:26:32 -07:00
|
|
|
return aNameAtom->Equals(mQualifiedName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool QualifiedNameEquals(const nsAString& aQualifiedName) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-05 09:26:32 -07:00
|
|
|
return mQualifiedName == aQualifiedName;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve a pointer to the document that owns this node info.
|
|
|
|
*/
|
|
|
|
nsIDocument* GetDocument() const
|
|
|
|
{
|
2011-06-14 17:58:57 -07:00
|
|
|
return mDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/*
|
|
|
|
* nsNodeInfoInner is used for two things:
|
|
|
|
*
|
|
|
|
* 1. as a member in nsNodeInfo for holding the name, prefix and
|
|
|
|
* namespace ID
|
|
|
|
* 2. as the hash key in the hash table in nsNodeInfoManager
|
|
|
|
*
|
|
|
|
* nsNodeInfoInner does not do any kind of reference counting,
|
|
|
|
* that's up to the user of this class. Since nsNodeInfoInner is
|
|
|
|
* typically used as a member of nsNodeInfo, the hash table doesn't
|
|
|
|
* need to delete the keys. When the value (nsNodeInfo) is deleted
|
|
|
|
* the key is automatically deleted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsNodeInfoInner
|
|
|
|
{
|
|
|
|
public:
|
2010-07-23 02:49:57 -07:00
|
|
|
nsNodeInfoInner()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mName(nullptr), mPrefix(nullptr), mNamespaceID(kNameSpaceID_Unknown),
|
|
|
|
mNodeType(0), mNameString(nullptr), mExtraName(nullptr)
|
2010-07-23 02:49:57 -07:00
|
|
|
{
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
|
|
|
|
uint16_t aNodeType, nsIAtom* aExtraName)
|
2010-07-23 02:49:57 -07:00
|
|
|
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID),
|
2012-07-30 07:20:58 -07:00
|
|
|
mNodeType(aNodeType), mNameString(nullptr), mExtraName(aExtraName)
|
2010-07-23 02:49:57 -07:00
|
|
|
{
|
|
|
|
}
|
2011-06-14 00:56:49 -07:00
|
|
|
nsNodeInfoInner(const nsAString& aTmpName, nsIAtom *aPrefix,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mName(nullptr), mPrefix(aPrefix), mNamespaceID(aNamespaceID),
|
|
|
|
mNodeType(aNodeType), mNameString(&aTmpName), mExtraName(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* mName;
|
|
|
|
nsIAtom* mPrefix;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mNamespaceID;
|
|
|
|
uint16_t mNodeType; // As defined by nsIDOMNode.nodeType
|
2010-07-23 02:49:57 -07:00
|
|
|
const nsAString* mNameString;
|
2011-06-14 00:56:49 -07:00
|
|
|
nsIAtom* mExtraName; // Only used by PIs and DocTypes
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// nsNodeInfoManager needs to pass mInner to the hash table.
|
|
|
|
friend class nsNodeInfoManager;
|
|
|
|
|
2011-06-14 17:58:57 -07:00
|
|
|
nsIDocument* mDocument; // Weak. Cache of mOwnerManager->mDocument
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNodeInfoInner mInner;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> mIDAttributeAtom;
|
|
|
|
nsNodeInfoManager* mOwnerManager; // Strong reference!
|
2011-05-05 09:26:32 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Members for various functions of mName+mPrefix that we can be
|
|
|
|
* asked to compute.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Qualified name
|
|
|
|
nsString mQualifiedName;
|
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
// nodeName for the node.
|
|
|
|
nsString mNodeName;
|
|
|
|
|
|
|
|
// localName for the node. This is either equal to mInner.mName, or a
|
|
|
|
// void string, depending on mInner.mNodeType.
|
|
|
|
nsString mLocalName;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsINodeInfo, NS_INODEINFO_IID)
|
|
|
|
|
|
|
|
#endif /* nsINodeInfo_h___ */
|