зеркало из https://github.com/mozilla/gecko-dev.git
Fixing bug 116551. DeCOMtaminating nsINodeInfo, inlining most of the trivial methods and leaving some as virtuals, move some of the members from nsNodeInfo to nsINodeInfo. r=sicking@bigfoot.com, sr=waterson@netscape.com
This commit is contained in:
Родитель
b76ff0aead
Коммит
ae54304ade
|
@ -57,10 +57,12 @@
|
|||
#define nsINodeInfo_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsAWritableString.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsAString.h"
|
||||
#include "domstubs.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
// Forward declarations
|
||||
class nsIAtom;
|
||||
class nsINodeInfoManager;
|
||||
class nsINameSpaceManager;
|
||||
class nsIDocument;
|
||||
|
@ -84,13 +86,23 @@ class nsINodeInfo : public nsISupports
|
|||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_INODEINFO_IID)
|
||||
|
||||
nsINodeInfo()
|
||||
: mInner(nsnull, nsnull, kNameSpaceID_None)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* 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".
|
||||
*/
|
||||
NS_IMETHOD GetName(nsAWritableString& aName) = 0;
|
||||
nsresult GetName(nsAString& aName) const
|
||||
{
|
||||
mInner.mName->ToString(aName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the name from this node as an atom, this does not include the prefix.
|
||||
|
@ -99,7 +111,13 @@ public:
|
|||
* For the HTML element "<body>" this will return the "body" atom and for
|
||||
* the XML element "<html:body>" this will return the "body" atom.
|
||||
*/
|
||||
NS_IMETHOD GetNameAtom(nsIAtom*& aAtom) = 0;
|
||||
nsresult GetNameAtom(nsIAtom*& aAtom) const
|
||||
{
|
||||
aAtom = mInner.mName;
|
||||
NS_ADDREF(aAtom);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the qualified name from this node as a string, the qualified name
|
||||
|
@ -108,7 +126,7 @@ public:
|
|||
* For the HTML element "<body>" this will return "body" and for the XML
|
||||
* element "<html:body>" this will return "html:body".
|
||||
*/
|
||||
NS_IMETHOD GetQualifiedName(nsAWritableString& aQualifiedName) = 0;
|
||||
NS_IMETHOD GetQualifiedName(nsAString& aQualifiedName) const = 0;
|
||||
|
||||
/*
|
||||
* Get the local name from this node as a string, GetLocalName() gets the
|
||||
|
@ -119,7 +137,7 @@ public:
|
|||
* For the HTML element "<body>" in a HTML document this will return a null
|
||||
* string and for the XML element "<html:body>" this will return "body".
|
||||
*/
|
||||
NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) = 0;
|
||||
NS_IMETHOD GetLocalName(nsAString& aLocalName) const = 0;
|
||||
|
||||
/*
|
||||
* Get the prefix from this node as a string.
|
||||
|
@ -127,7 +145,16 @@ public:
|
|||
* For the HTML element "<body>" this will return a null string and for
|
||||
* the XML element "<html:body>" this will return the string "html".
|
||||
*/
|
||||
NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) = 0;
|
||||
nsresult GetPrefix(nsAString& aPrefix) const
|
||||
{
|
||||
if (mInner.mPrefix) {
|
||||
mInner.mPrefix->ToString(aPrefix);
|
||||
} else {
|
||||
SetDOMStringToNull(aPrefix);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the prefix from this node as an atom.
|
||||
|
@ -135,7 +162,13 @@ public:
|
|||
* For the HTML element "<body>" this will return a null atom and for
|
||||
* the XML element "<html:body>" this will return the "html" atom.
|
||||
*/
|
||||
NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom) = 0;
|
||||
nsresult GetPrefixAtom(nsIAtom*& aAtom) const
|
||||
{
|
||||
aAtom = mInner.mPrefix;
|
||||
NS_IF_ADDREF(aAtom);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the namespace URI for a node, if the node has a namespace URI.
|
||||
|
@ -146,7 +179,7 @@ public:
|
|||
* xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return
|
||||
* the string "http://www.w3.org/1999/xhtml".
|
||||
*/
|
||||
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI) = 0;
|
||||
NS_IMETHOD GetNamespaceURI(nsAString& aNameSpaceURI) const = 0;
|
||||
|
||||
/*
|
||||
* Get the namespace ID for a node if the node has a namespace, if not this
|
||||
|
@ -158,7 +191,12 @@ public:
|
|||
* xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return
|
||||
* the namespace ID for "http://www.w3.org/1999/xhtml".
|
||||
*/
|
||||
NS_IMETHOD GetNamespaceID(PRInt32& aResult) = 0;
|
||||
nsresult GetNamespaceID(PRInt32& aNameSpaceID) const
|
||||
{
|
||||
aNameSpaceID = mInner.mNamespaceID;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get and set the ID attribute atom for this node.
|
||||
|
@ -166,35 +204,64 @@ public:
|
|||
* for the definition of an ID attribute.
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) = 0;
|
||||
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) const = 0;
|
||||
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult) = 0;
|
||||
|
||||
/*
|
||||
* Get the owning node info manager, this will never return null.
|
||||
*/
|
||||
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0;
|
||||
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) const = 0;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) Equals(nsINodeInfo *aNodeInfo) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName,
|
||||
const nsAReadableString& aPrefix) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, PRInt32 aNamespaceID) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
|
||||
PRInt32 aNamespaceID) = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName,
|
||||
const nsAReadableString& aPrefix,
|
||||
PRInt32 aNamespaceID) = 0;
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(PRInt32 aNamespaceID) = 0;
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAReadableString& aNamespaceURI) = 0;
|
||||
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAReadableString& aQualifiedName) = 0;
|
||||
PRBool Equals(nsINodeInfo *aNodeInfo) const
|
||||
{
|
||||
return aNodeInfo == this || aNodeInfo->Equals(mInner.mName, mInner.mPrefix,
|
||||
mInner.mNamespaceID);
|
||||
}
|
||||
|
||||
PRBool Equals(nsIAtom *aNameAtom) const
|
||||
{
|
||||
return mInner.mName == aNameAtom;
|
||||
}
|
||||
|
||||
PRBool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) const
|
||||
{
|
||||
return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom);
|
||||
}
|
||||
|
||||
PRBool Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID) const
|
||||
{
|
||||
return ((mInner.mName == aNameAtom) &&
|
||||
(mInner.mNamespaceID == aNamespaceID));
|
||||
}
|
||||
|
||||
PRBool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
|
||||
PRInt32 aNamespaceID) const
|
||||
{
|
||||
return ((mInner.mName == aNameAtom) &&
|
||||
(mInner.mPrefix == aPrefixAtom) &&
|
||||
(mInner.mNamespaceID == aNamespaceID));
|
||||
}
|
||||
|
||||
PRBool NamespaceEquals(PRInt32 aNamespaceID) const
|
||||
{
|
||||
return mInner.mNamespaceID == aNamespaceID;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName) const = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName,
|
||||
const nsAString& aPrefix) const = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName,
|
||||
PRInt32 aNamespaceID) const = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName,
|
||||
const nsAString& aPrefix,
|
||||
PRInt32 aNamespaceID) const = 0;
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
|
||||
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAString& aQualifiedName) const = 0;
|
||||
|
||||
/*
|
||||
* This is a convinience method that creates a new nsINodeInfo that differs
|
||||
|
@ -211,7 +278,40 @@ public:
|
|||
/*
|
||||
* Retrieve a pointer to the document that owns this node info.
|
||||
*/
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aDocument) = 0;
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aDocument) const = 0;
|
||||
|
||||
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:
|
||||
nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID)
|
||||
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID)
|
||||
{
|
||||
}
|
||||
|
||||
nsIAtom* mName;
|
||||
nsIAtom* mPrefix;
|
||||
PRInt32 mNamespaceID;
|
||||
};
|
||||
|
||||
// nsNodeInfoManager needs to pass mInner to the hash table.
|
||||
friend class nsNodeInfoManager;
|
||||
|
||||
nsNodeInfoInner mInner;
|
||||
};
|
||||
|
||||
|
||||
|
@ -238,17 +338,15 @@ public:
|
|||
*/
|
||||
NS_IMETHOD GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0;
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0;
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName,
|
||||
const nsAReadableString& aPrefix,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, const nsAString& aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0;
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName,
|
||||
const nsAReadableString& aPrefix,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, const nsAString& aPrefix,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo) = 0;
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aQualifiedName,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aQualifiedName,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo) = 0;
|
||||
|
||||
/*
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
|
||||
nsNodeInfo::nsNodeInfo()
|
||||
: mInner(), mOwnerManager(nsnull)
|
||||
: nsINodeInfo(), mOwnerManager(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
@ -91,37 +91,14 @@ nsNodeInfo::Init(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID,
|
|||
|
||||
// nsISupports
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsNodeInfo, nsINodeInfo);
|
||||
NS_IMPL_ISUPPORTS1(nsNodeInfo, nsINodeInfo);
|
||||
|
||||
|
||||
// nsINodeInfo
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetName(nsAWritableString& aName)
|
||||
nsNodeInfo::GetQualifiedName(nsAString& aQualifiedName) const
|
||||
{
|
||||
NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mInner.mName->ToString(aName);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetNameAtom(nsIAtom*& aAtom)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(mInner.mName, "nsNodeInfo not initialized!");
|
||||
|
||||
aAtom = mInner.mName;
|
||||
NS_IF_ADDREF(aAtom);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetQualifiedName(nsAWritableString& aQualifiedName)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (mInner.mPrefix) {
|
||||
mInner.mPrefix->ToString(aQualifiedName);
|
||||
|
||||
|
@ -140,10 +117,8 @@ nsNodeInfo::GetQualifiedName(nsAWritableString& aQualifiedName)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetLocalName(nsAWritableString& aLocalName)
|
||||
nsNodeInfo::GetLocalName(nsAString& aLocalName) const
|
||||
{
|
||||
NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
#ifdef STRICT_DOM_LEVEL2_LOCALNAME
|
||||
if (mInner.mNamespaceID > 0) {
|
||||
return mInner.mName->ToString(aLocalName);
|
||||
|
@ -159,32 +134,8 @@ nsNodeInfo::GetLocalName(nsAWritableString& aLocalName)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetPrefix(nsAWritableString& aPrefix)
|
||||
nsNodeInfo::GetNamespaceURI(nsAString& aNameSpaceURI) const
|
||||
{
|
||||
if (mInner.mPrefix) {
|
||||
mInner.mPrefix->ToString(aPrefix);
|
||||
} else {
|
||||
SetDOMStringToNull(aPrefix);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetPrefixAtom(nsIAtom*& aAtom)
|
||||
{
|
||||
aAtom = mInner.mPrefix;
|
||||
NS_IF_ADDREF(aAtom);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetNamespaceURI(nsAWritableString& aNameSpaceURI)
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mInner.mNamespaceID > 0) {
|
||||
|
@ -203,19 +154,9 @@ nsNodeInfo::GetNamespaceURI(nsAWritableString& aNameSpaceURI)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetNamespaceID(PRInt32& aResult)
|
||||
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult) const
|
||||
{
|
||||
aResult = mInner.mNamespaceID;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = mInner.mIDAttributeAtom;
|
||||
*aResult = mIDAttributeAtom;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -225,7 +166,7 @@ NS_IMETHODIMP
|
|||
nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID)
|
||||
{
|
||||
NS_ENSURE_ARG(aID);
|
||||
mInner.mIDAttributeAtom = aID;
|
||||
mIDAttributeAtom = aID;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -233,10 +174,8 @@ nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager)
|
||||
nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) const
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
aNodeInfoManager = mOwnerManager;
|
||||
|
||||
NS_ADDREF(aNodeInfoManager);
|
||||
|
@ -246,26 +185,8 @@ nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager)
|
|||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(nsINodeInfo *aNodeInfo)
|
||||
nsNodeInfo::Equals(const nsAString& aName) const
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNodeInfo);
|
||||
|
||||
return aNodeInfo->Equals(mInner.mName, mInner.mPrefix, mInner.mNamespaceID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(nsIAtom *aNameAtom)
|
||||
{
|
||||
return mInner.mName == aNameAtom;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(const nsAReadableString& aName)
|
||||
{
|
||||
if (!mInner.mName) return PR_FALSE;
|
||||
|
||||
const PRUnichar *name;
|
||||
mInner.mName->GetUnicode(&name);
|
||||
|
||||
|
@ -274,39 +195,28 @@ nsNodeInfo::Equals(const nsAReadableString& aName)
|
|||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom)
|
||||
nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix) const
|
||||
{
|
||||
return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix)
|
||||
{
|
||||
if (!mInner.mName) return PR_FALSE;
|
||||
|
||||
const PRUnichar *name, *prefix = nsnull;
|
||||
const PRUnichar *name;
|
||||
mInner.mName->GetUnicode(&name);
|
||||
|
||||
if (mInner.mPrefix)
|
||||
mInner.mPrefix->GetUnicode(&prefix);
|
||||
if (!aName.Equals(name)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return aName.Equals(name) && aPrefix.Equals(prefix);
|
||||
if (!mInner.mPrefix) {
|
||||
return aPrefix.IsEmpty();
|
||||
}
|
||||
|
||||
mInner.mPrefix->GetUnicode(&name);
|
||||
|
||||
return aPrefix.Equals(name);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID)
|
||||
nsNodeInfo::Equals(const nsAString& aName, PRInt32 aNamespaceID) const
|
||||
{
|
||||
return (mInner.mName == aNameAtom) && (mInner.mNamespaceID == aNamespaceID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(const nsAReadableString& aName, PRInt32 aNamespaceID)
|
||||
{
|
||||
if (!mInner.mName) return PR_FALSE;
|
||||
|
||||
const PRUnichar *name;
|
||||
mInner.mName->GetUnicode(&name);
|
||||
|
||||
|
@ -315,43 +225,25 @@ nsNodeInfo::Equals(const nsAReadableString& aName, PRInt32 aNamespaceID)
|
|||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
|
||||
PRInt32 aNamespaceID)
|
||||
nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix,
|
||||
PRInt32 aNamespaceID) const
|
||||
{
|
||||
return (mInner.mName == aNameAtom) &&
|
||||
(mInner.mPrefix == aPrefixAtom) &&
|
||||
(mInner.mNamespaceID == aNamespaceID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
PRInt32 aNamespaceID)
|
||||
{
|
||||
if (!mInner.mName) return PR_FALSE;
|
||||
|
||||
const PRUnichar *name, *prefix = nsnull;
|
||||
PRUnichar nullChar = '\0';
|
||||
const PRUnichar *name, *prefix = &nullChar;
|
||||
mInner.mName->GetUnicode(&name);
|
||||
|
||||
if (mInner.mPrefix)
|
||||
if (mInner.mPrefix) {
|
||||
mInner.mPrefix->GetUnicode(&prefix);
|
||||
}
|
||||
|
||||
return aName.Equals(name) && aPrefix.Equals(prefix) &&
|
||||
(mInner.mNamespaceID == aNamespaceID);
|
||||
return ((mInner.mNamespaceID == aNamespaceID) && aName.Equals(name) &&
|
||||
aPrefix.Equals(prefix));
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::NamespaceEquals(PRInt32 aNamespaceID)
|
||||
nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
|
||||
{
|
||||
return mInner.mNamespaceID == aNamespaceID;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::NamespaceEquals(const nsAReadableString& aNamespaceURI)
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
nsCOMPtr<nsINameSpaceManager> nsmgr;
|
||||
|
||||
NS_ENSURE_SUCCESS(mOwnerManager->GetNamespaceManager(*getter_AddRefs(nsmgr)),
|
||||
|
@ -360,46 +252,60 @@ nsNodeInfo::NamespaceEquals(const nsAReadableString& aNamespaceURI)
|
|||
PRInt32 nsid;
|
||||
nsmgr->GetNameSpaceID(aNamespaceURI, nsid);
|
||||
|
||||
return mInner.mNamespaceID == nsid;
|
||||
return nsINodeInfo::NamespaceEquals(nsid);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsNodeInfo::QualifiedNameEquals(const nsAReadableString& aQualifiedName)
|
||||
nsNodeInfo::QualifiedNameEquals(const nsAString& aQualifiedName) const
|
||||
{
|
||||
const nsPromiseFlatString& flatName = PromiseFlatString(aQualifiedName);
|
||||
const PRUnichar *qname = flatName.get();
|
||||
PRUint32 i = 0;
|
||||
|
||||
if (mInner.mPrefix) {
|
||||
const PRUnichar *prefix;
|
||||
mInner.mPrefix->GetUnicode(&prefix);
|
||||
|
||||
i = nsCRT::strlen(prefix);
|
||||
|
||||
if (nsCRT::strncmp(qname, prefix, i))
|
||||
return PR_FALSE;
|
||||
|
||||
if (*(qname + i) != PRUnichar(':'))
|
||||
return PR_FALSE;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
const PRUnichar *name;
|
||||
mInner.mName->GetUnicode(&name);
|
||||
|
||||
if (nsCRT::strcmp(qname + i, name))
|
||||
return PR_FALSE;
|
||||
if (!mInner.mPrefix) {
|
||||
return aQualifiedName.Equals(name);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
nsAString::const_iterator start;
|
||||
aQualifiedName.BeginReading(start);
|
||||
|
||||
nsAString::const_iterator colon(start);
|
||||
|
||||
const PRUnichar *prefix;
|
||||
mInner.mPrefix->GetUnicode(&prefix);
|
||||
|
||||
PRUint32 len = nsCRT::strlen(prefix);
|
||||
|
||||
if (len >= aQualifiedName.Length()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
colon.advance(len);
|
||||
|
||||
// If the character at the prefix length index is not a colon,
|
||||
// aQualifiedName is not equal to this string.
|
||||
if (*colon != ':') {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Compare the prefix to the string from the start to the colon
|
||||
if (!Substring(start, colon).Equals(prefix)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
++colon; // Skip the ':'
|
||||
|
||||
nsAString::const_iterator end;
|
||||
aQualifiedName.EndReading(end);
|
||||
|
||||
// Compare the local name to the string between the colon and the
|
||||
// end of aQualifiedName
|
||||
return Substring(colon, end).Equals(name);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::NameChanged(nsIAtom *aName, nsINodeInfo*& aResult)
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mOwnerManager->GetNodeInfo(aName, mInner.mPrefix, mInner.mNamespaceID,
|
||||
aResult);
|
||||
}
|
||||
|
@ -408,60 +314,13 @@ nsNodeInfo::NameChanged(nsIAtom *aName, nsINodeInfo*& aResult)
|
|||
NS_IMETHODIMP
|
||||
nsNodeInfo::PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult)
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mOwnerManager->GetNodeInfo(mInner.mName, aPrefix, mInner.mNamespaceID,
|
||||
aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfo::GetDocument(nsIDocument*& aDocument)
|
||||
nsNodeInfo::GetDocument(nsIDocument*& aDocument) const
|
||||
{
|
||||
NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mOwnerManager->GetDocument(aDocument);
|
||||
}
|
||||
|
||||
|
||||
PLHashNumber
|
||||
nsNodeInfoInner::GetHashValue(const void *key)
|
||||
{
|
||||
#ifdef NS_DEBUG // Just to shut down a compiler warning
|
||||
NS_WARN_IF_FALSE(key, "Null key passed to nsNodeInfo::GetHashValue!");
|
||||
#endif
|
||||
|
||||
if (key) {
|
||||
const nsNodeInfoInner *node = (const nsNodeInfoInner *)key;
|
||||
|
||||
// Is this an acceptable hash value?
|
||||
return (PLHashNumber(NS_PTR_TO_INT32(node->mName)) & 0xffff) >> 8;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PRIntn
|
||||
nsNodeInfoInner::KeyCompare(const void *key1, const void *key2)
|
||||
{
|
||||
#ifdef NS_DEBUG // Just to shut down a compiler warning
|
||||
NS_WARN_IF_FALSE(key1 && key2, "Null key passed to nsNodeInfo::KeyCompare!");
|
||||
#endif
|
||||
|
||||
if (!key1 || !key2) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
const nsNodeInfoInner *node1 = (const nsNodeInfoInner *)key1;
|
||||
const nsNodeInfoInner *node2 = (const nsNodeInfoInner *)key2;
|
||||
|
||||
if (node1->mName == node2->mName &&
|
||||
node1->mPrefix == node2->mPrefix &&
|
||||
node1->mNamespaceID == node2->mNamespaceID) {
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,37 +45,6 @@
|
|||
#include "nsIAtom.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
/*
|
||||
* 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 a member of
|
||||
* nsNodeInfo the hash table doesn't need to delete the keys, when the
|
||||
* value (nsNodeInfo) the key is automatically deleted.
|
||||
*/
|
||||
|
||||
struct nsNodeInfoInner
|
||||
{
|
||||
nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID)
|
||||
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) { }
|
||||
|
||||
nsNodeInfoInner()
|
||||
: mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) { }
|
||||
|
||||
static PRIntn PR_CALLBACK KeyCompare(const void *key1, const void *key2);
|
||||
static PLHashNumber PR_CALLBACK GetHashValue(const void *key);
|
||||
|
||||
nsIAtom* mName;
|
||||
nsIAtom* mPrefix;
|
||||
PRInt32 mNamespaceID;
|
||||
nsCOMPtr<nsIAtom> mIDAttributeAtom;
|
||||
};
|
||||
|
||||
|
||||
class nsNodeInfoManager;
|
||||
|
||||
class nsNodeInfo : public nsINodeInfo
|
||||
|
@ -84,37 +53,25 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsINodeInfo
|
||||
NS_IMETHOD GetName(nsAWritableString& aName);
|
||||
NS_IMETHOD GetNameAtom(nsIAtom*& aAtom);
|
||||
NS_IMETHOD GetQualifiedName(nsAWritableString& aQualifiedName);
|
||||
NS_IMETHOD GetLocalName(nsAWritableString& aLocalName);
|
||||
NS_IMETHOD GetPrefix(nsAWritableString& aPrefix);
|
||||
NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom);
|
||||
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI);
|
||||
NS_IMETHOD GetNamespaceID(PRInt32& aResult);
|
||||
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult);
|
||||
NS_IMETHOD GetQualifiedName(nsAString &aQualifiedName) const;
|
||||
NS_IMETHOD GetLocalName(nsAString& aLocalName) const;
|
||||
NS_IMETHOD GetNamespaceURI(nsAString& aNameSpaceURI) const;
|
||||
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) const;
|
||||
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult);
|
||||
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager);
|
||||
NS_IMETHOD_(PRBool) Equals(nsINodeInfo *aNodeInfo);
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom);
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName);
|
||||
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom);
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName,
|
||||
const nsAReadableString& aPrefix);
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID);
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, PRInt32 aNamespaceID);
|
||||
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
|
||||
PRInt32 aNamespaceID);
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
PRInt32 aNamespaceID);
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(PRInt32 aNamespaceID);
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAReadableString& aNamespaceURI);
|
||||
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAReadableString& aQualifiedName);
|
||||
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) const;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName) const;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName,
|
||||
const nsAString& aPrefix) const;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName,
|
||||
PRInt32 aNamespaceID) const;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsAString& aName, const nsAString& aPrefix,
|
||||
PRInt32 aNamespaceID) const;
|
||||
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const;
|
||||
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAString& aQualifiedName) const;
|
||||
|
||||
NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult);
|
||||
NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult);
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aDocument);
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aDocument) const;
|
||||
|
||||
// nsNodeInfo
|
||||
nsNodeInfo();
|
||||
|
@ -131,9 +88,7 @@ public:
|
|||
nsNodeInfoManager *aOwnerManager);
|
||||
|
||||
protected:
|
||||
friend class nsNodeInfoManager; // The NodeInfoManager needs to pass this
|
||||
// to the hash table.
|
||||
nsNodeInfoInner mInner;
|
||||
nsCOMPtr<nsIAtom> mIDAttributeAtom;
|
||||
|
||||
nsNodeInfoManager* mOwnerManager; // Strong reference!
|
||||
};
|
||||
|
|
|
@ -60,6 +60,35 @@ nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult)
|
|||
}
|
||||
|
||||
|
||||
PLHashNumber
|
||||
nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
||||
{
|
||||
NS_ASSERTION(key, "Null key passed to nsNodeInfo::GetHashValue!");
|
||||
|
||||
const nsINodeInfo::nsNodeInfoInner *node =
|
||||
NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key);
|
||||
|
||||
// Is this an acceptable hash value?
|
||||
return (PLHashNumber(NS_PTR_TO_INT32(node->mName)) & 0xffff) >> 8;
|
||||
}
|
||||
|
||||
|
||||
PRIntn
|
||||
nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2)
|
||||
{
|
||||
NS_ASSERTION(key1 && key2, "Null key passed to NodeInfoInnerKeyCompare!");
|
||||
|
||||
const nsINodeInfo::nsNodeInfoInner *node1 =
|
||||
NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key1);
|
||||
const nsINodeInfo::nsNodeInfoInner *node2 =
|
||||
NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key2);
|
||||
|
||||
return (node1->mName == node2->mName &&
|
||||
node1->mPrefix == node2->mPrefix &&
|
||||
node1->mNamespaceID == node2->mNamespaceID);
|
||||
}
|
||||
|
||||
|
||||
nsNodeInfoManager::nsNodeInfoManager()
|
||||
: mDocument(nsnull)
|
||||
{
|
||||
|
@ -78,8 +107,8 @@ nsNodeInfoManager::nsNodeInfoManager()
|
|||
|
||||
gNodeManagerCount++;
|
||||
|
||||
mNodeInfoHash = PL_NewHashTable(32, nsNodeInfoInner::GetHashValue,
|
||||
nsNodeInfoInner::KeyCompare,
|
||||
mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue,
|
||||
NodeInfoInnerKeyCompare,
|
||||
PL_CompareValues, nsnull, nsnull);
|
||||
|
||||
#ifdef DEBUG_jst
|
||||
|
@ -145,7 +174,7 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aName);
|
||||
|
||||
nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);
|
||||
nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);
|
||||
|
||||
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
||||
|
||||
|
@ -176,7 +205,7 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix,
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG(aName.Length());
|
||||
|
@ -189,8 +218,9 @@ nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix,
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo)
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAString& aName,
|
||||
const nsAString& aPrefix, PRInt32 aNamespaceID,
|
||||
nsINodeInfo*& aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG(aName.Length());
|
||||
|
||||
|
@ -209,8 +239,9 @@ nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadable
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAString& aName,
|
||||
const nsAString& aPrefix,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG(aName.Length());
|
||||
|
@ -238,8 +269,8 @@ nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadable
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aQualifiedName,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
nsNodeInfoManager::GetNodeInfo(const nsAString& aQualifiedName,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG(aQualifiedName.Length());
|
||||
|
|
|
@ -58,15 +58,15 @@ public:
|
|||
NS_IMETHOD DropDocumentReference();
|
||||
NS_IMETHOD GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, const nsAString& aPrefix,
|
||||
PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aName, const nsAString& aPrefix,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD GetNodeInfo(const nsAReadableString& aQualifiedName,
|
||||
const nsAReadableString& aNamespaceURI,
|
||||
NS_IMETHOD GetNodeInfo(const nsAString& aQualifiedName,
|
||||
const nsAString& aNamespaceURI,
|
||||
nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager);
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aDocument);
|
||||
|
@ -80,6 +80,11 @@ public:
|
|||
static nsresult GetAnonymousManager(nsINodeInfoManager*& aNodeInfoManager);
|
||||
|
||||
private:
|
||||
static PRIntn PR_CALLBACK NodeInfoInnerKeyCompare(const void *key1,
|
||||
const void *key2);
|
||||
static PLHashNumber PR_CALLBACK GetNodeInfoInnerHashValue(const void *key);
|
||||
|
||||
|
||||
PLHashTable *mNodeInfoHash;
|
||||
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager;
|
||||
nsIDocument *mDocument; // WEAK
|
||||
|
|
Загрузка…
Ссылка в новой задаче