Make getElementsByTagName do the right thing with prefixes. Bug 206053,

r=peterv, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2006-04-25 21:21:49 +00:00
Родитель 6adf279775
Коммит 811e8372a2
5 изменённых файлов: 58 добавлений и 11 удалений

Просмотреть файл

@ -68,10 +68,10 @@ class nsIURI;
class nsIPrincipal;
// IID for the nsINodeInfo interface
// b24fd4ad-7d94-40ea-b09b-9262f58bc28a
// 37840f19-f65f-4185-baff-c475d9e2b3f2
#define NS_INODEINFO_IID \
{ 0xb24fd4ad, 0x7d94, 0x40ea, \
{ 0xb0, 0x9b, 0x92, 0x62, 0xf5, 0x8b, 0xc2, 0x8a } }
{ 0x37840f19, 0xf65f, 0x4185, \
{ 0xba, 0xff, 0xc4, 0x75, 0xd9, 0xe2, 0xb3, 0xf2 } }
class nsINodeInfo : public nsISupports
{
@ -258,8 +258,25 @@ public:
virtual PRBool Equals(const nsAString& aName, const nsAString& aPrefix,
PRInt32 aNamespaceID) const = 0;
virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
// switch to UTF8 - this allows faster access for consumers
virtual PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const = 0;
PRBool QualifiedNameEquals(nsIAtom* aNameAtom) const
{
NS_PRECONDITION(aNameAtom, "Must have name atom");
if (!GetPrefixAtom())
return Equals(aNameAtom);
const char* utf8;
aNameAtom->GetUTF8String(&utf8);
return QualifiedNameEqualsInternal(nsDependentCString(utf8));
}
PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const
{
if (!GetPrefixAtom())
return mInner.mName->EqualsUTF8(aQualifiedName);
return QualifiedNameEqualsInternal(aQualifiedName);
}
/*
* Retrieve a pointer to the document that owns this node info.
@ -275,6 +292,9 @@ public:
virtual nsIPrincipal *GetDocumentPrincipal() const = 0;
protected:
virtual PRBool
QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const = 0;
/*
* nsNodeInfoInner is used for two things:
*

Просмотреть файл

@ -717,7 +717,7 @@ nsContentList::Match(nsIContent *aContent)
nsINodeInfo *ni = aContent->NodeInfo();
if (mMatchNameSpaceId == kNameSpaceID_Unknown) {
return (mMatchAll || ni->Equals(mMatchAtom));
return (mMatchAll || ni->QualifiedNameEquals(mMatchAtom));
}
return ((mMatchAll && ni->NamespaceEquals(mMatchNameSpaceId)) ||

Просмотреть файл

@ -169,11 +169,39 @@ class nsContentList : public nsBaseContentList,
public:
NS_DECL_ISUPPORTS_INHERITED
/**
* @param aDocument the document to which to add as an nsIDocumentObserver
* @param aMatchAtom an atom whose meaning depends on aMatchNameSpaceId
* @param aMatchNameSpaceId if kNameSpaceID_Unknown then aMatchAtom is the
* tagName to match. Otherwise we match nodes with
* aMatchNameSpaceId and a localName equal to
* aMatchAtom
* @param aRootContent The content node under which to limit our search.
* If not null, the root is aDocument.
* @param aDeep If false, then look only at children of the root, nothing
* deeper. If true, then look at the whole subtree rooted at
* our root.
*/
nsContentList(nsIDocument *aDocument,
nsIAtom* aMatchAtom,
PRInt32 aMatchNameSpaceId,
nsIContent* aRootContent = nsnull,
PRBool aDeep = PR_TRUE);
/**
* @param aDocument the document to which to add as an nsIDocumentObserver
* @param aFunc the function to be called to determine whether we match
* @param aData a string that will need to be passed back to aFunc
* @param aRootContent The content node under which to limit our search.
* If not null, the root is aDocument.
* @param aDeep If false, then look only at children of the root, nothing
* deeper. If true, then look at the whole subtree rooted at
* our root.
* @param aMatchAtom an atom to be passed back to aFunc
* @param aMatchNameSpaceId a namespace id to be passed back to aFunc
* @param aFuncMayDependOnAttr a boolean that indicates whether this list is
* sensitive to attribute changes.
*/
nsContentList(nsIDocument *aDocument,
nsContentListMatchFunc aFunc,
const nsAString& aData,

Просмотреть файл

@ -225,12 +225,10 @@ nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
}
PRBool
nsNodeInfo::QualifiedNameEquals(const nsACString& aQualifiedName) const
nsNodeInfo::QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const
{
NS_PRECONDITION(mInner.mPrefix, "Must have prefix");
if (!mInner.mPrefix)
return mInner.mName->EqualsUTF8(aQualifiedName);
nsACString::const_iterator start;
aQualifiedName.BeginReading(start);

Просмотреть файл

@ -66,7 +66,8 @@ public:
virtual PRBool Equals(const nsAString& aName, const nsAString& aPrefix,
PRInt32 aNamespaceID) const;
virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const;
virtual PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const;
virtual PRBool
QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const;
nsIPrincipal *GetDocumentPrincipal() const
{