Fix handling of id attrs to not assume that they are named "id" as much. Bug

208744, r=caillon, sr=peterv
This commit is contained in:
bzbarsky%mit.edu 2003-10-21 16:16:42 +00:00
Родитель 0f42747ce0
Коммит 321b58e88d
22 изменённых файлов: 142 добавлений и 38 удалений

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

@ -202,6 +202,20 @@ public:
*/
NS_IMETHOD RemoveChildAt(PRUint32 aIndex, PRBool aNotify) = 0;
/**
* Returns an atom holding the name of the attribute of type ID on
* this content node (if applicable). Returns null for non-element
* content nodes.
*/
NS_IMETHOD_(nsIAtom*) GetIDAttributeName() const = 0;
/**
* Returns an atom holding the name of the "class" attribute on this
* content node (if applicable). Returns null for non-element
* content nodes.
*/
NS_IMETHOD_(nsIAtom*) GetClassAttributeName() const = 0;
/**
* Normalizes an attribute string into an atom that represents the
* qualified attribute name of the attribute. This method is intended

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

@ -201,7 +201,7 @@ public:
* for the definition of an ID attribute.
*
*/
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) const = 0;
NS_IMETHOD_(nsIAtom*) GetIDAttributeAtom() const = 0;
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult) = 0;
/*

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

@ -682,6 +682,18 @@ nsGenericDOMDataNode::GetNameSpaceID(PRInt32* aID) const
return NS_OK;
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericDOMDataNode::GetIDAttributeName() const
{
return nsnull;
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericDOMDataNode::GetClassAttributeName() const
{
return nsnull;
}
NS_IMETHODIMP
nsGenericDOMDataNode::NormalizeAttrString(const nsAString& aStr,
nsINodeInfo** aNodeInfo)

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

@ -177,6 +177,8 @@ public:
NS_IMETHOD_(PRBool) IsNativeAnonymous() const;
NS_IMETHOD_(void) SetNativeAnonymous(PRBool aAnonymous);
NS_IMETHOD GetNameSpaceID(PRInt32* aID) const;
NS_IMETHOD_(nsIAtom*) GetIDAttributeName() const;
NS_IMETHOD_(nsIAtom*) GetClassAttributeName() const;
NS_IMETHOD NormalizeAttrString(const nsAString& aStr,
nsINodeInfo** aNodeInfo);
NS_IMETHOD SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,

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

@ -2135,6 +2135,18 @@ nsGenericElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
return NS_OK;
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericElement::GetIDAttributeName() const
{
return mNodeInfo->GetIDAttributeAtom();
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericElement::GetClassAttributeName() const
{
return nsnull;
}
NS_IMETHODIMP
nsGenericElement::Compact()
{

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

@ -373,6 +373,8 @@ public:
NS_IMETHOD GetNameSpaceID(PRInt32* aNameSpaceID) const;
NS_IMETHOD GetTag(nsIAtom** aResult) const;
NS_IMETHOD_(nsINodeInfo *) GetNodeInfo() const;
NS_IMETHOD_(nsIAtom*) GetIDAttributeName() const;
NS_IMETHOD_(nsIAtom*) GetClassAttributeName() const;
NS_IMETHOD RangeAdd(nsIDOMRange* aRange);
NS_IMETHOD RangeRemove(nsIDOMRange* aRange);
NS_IMETHOD GetRangeList(nsVoidArray** aResult) const;

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

@ -149,13 +149,10 @@ nsNodeInfo::GetNamespaceURI(nsAString& aNameSpaceURI) const
}
NS_IMETHODIMP
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult) const
NS_IMETHODIMP_(nsIAtom*)
nsNodeInfo::GetIDAttributeAtom() const
{
*aResult = mIDAttributeAtom;
NS_IF_ADDREF(*aResult);
return NS_OK;
return mIDAttributeAtom;
}
NS_IMETHODIMP

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

@ -55,7 +55,7 @@ public:
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_(nsIAtom*) GetIDAttributeAtom() const;
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult);
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager** aNodeInfoManager) const;
NS_IMETHOD_(PRBool) Equals(const nsAString& aName) const;

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

@ -107,6 +107,16 @@ public:
return nsnull;
}
NS_IMETHOD_(nsIAtom *) GetIDAttributeName() const
{
return nsnull;
}
NS_IMETHOD_(nsIAtom *) GetClassAttributeName() const
{
return nsnull;
}
NS_IMETHOD NormalizeAttrString(const nsAString& aStr,
nsINodeInfo** aNodeInfo)
{

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

@ -2273,6 +2273,18 @@ nsGenericHTMLElement::GetClasses(nsVoidArray& aArray) const
return NS_OK;
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericHTMLElement::GetIDAttributeName() const
{
return nsHTMLAtoms::id;
}
NS_IMETHODIMP_(nsIAtom*)
nsGenericHTMLElement::GetClassAttributeName() const
{
return nsHTMLAtoms::kClass;
}
NS_IMETHODIMP_(PRBool)
nsGenericHTMLElement::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const
{

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

@ -223,6 +223,8 @@ public:
NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const;
NS_IMETHOD GetID(nsIAtom** aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
NS_IMETHOD_(nsIAtom*) GetIDAttributeName() const;
NS_IMETHOD_(nsIAtom*) GetClassAttributeName() const;
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
NS_IMETHOD GetInlineStyleRule(nsIStyleRule** aStyleRule);

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

@ -1435,6 +1435,7 @@ nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
if (!IsXHTML() && aAttribute == nsHTMLAtoms::name &&
aNameSpaceID == kNameSpaceID_None) {
@ -1450,7 +1451,7 @@ nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
return rv;
}
}
} else if (aAttribute == nsHTMLAtoms::id &&
} else if (aAttribute == aContent->GetIDAttributeName() &&
aNameSpaceID == kNameSpaceID_None) {
nsresult rv = RemoveFromIdTable(aContent);
@ -1467,6 +1468,7 @@ nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
if (!IsXHTML() && aAttribute == nsHTMLAtoms::name &&
aNameSpaceID == kNameSpaceID_None) {
@ -1482,11 +1484,13 @@ nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
return rv;
}
}
} else if (aAttribute == nsHTMLAtoms::id &&
} else if (aAttribute == aContent->GetIDAttributeName() &&
aNameSpaceID == kNameSpaceID_None) {
nsAutoString value;
aContent->GetAttr(aNameSpaceID, nsHTMLAtoms::id, value);
aContent->GetAttr(aNameSpaceID,
aContent->GetIDAttributeName(),
value);
if (!value.IsEmpty()) {
nsresult rv = AddToIdTable(value, aContent);
@ -3497,12 +3501,14 @@ nsHTMLDocument::RemoveFromNameTable(const nsAString& aName,
nsresult
nsHTMLDocument::RemoveFromIdTable(nsIContent *aContent)
{
if (!aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::id)) {
nsIAtom* idAttr = aContent->GetIDAttributeName();
if (!idAttr || !aContent->HasAttr(kNameSpaceID_None, idAttr)) {
return NS_OK;
}
nsAutoString value;
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
aContent->GetAttr(kNameSpaceID_None, idAttr, value);
if (value.IsEmpty()) {
return NS_OK;
@ -3582,13 +3588,15 @@ nsHTMLDocument::RegisterNamedItems(nsIContent *aContent)
UpdateNameTableEntry(value, aContent);
}
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
if (!value.IsEmpty()) {
nsresult rv = UpdateIdTableEntry(value, aContent);
if (NS_FAILED(rv)) {
return rv;
nsIAtom* idAttr = aContent->GetIDAttributeName();
if (idAttr) {
aContent->GetAttr(kNameSpaceID_None, idAttr, value);
if (!value.IsEmpty()) {
nsresult rv = UpdateIdTableEntry(value, aContent);
if (NS_FAILED(rv)) {
return rv;
}
}
}
@ -3624,10 +3632,13 @@ FindNamedItems(const nsAString& aName, nsIContent *aContent,
}
if (!aEntry.mIdContent) {
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
nsIAtom* idAttr = aContent->GetIDAttributeName();
if (idAttr) {
aContent->GetAttr(kNameSpaceID_None, idAttr, value);
if (value.Equals(aName)) {
aEntry.mIdContent = aContent;
if (value.Equals(aName)) {
aEntry.mIdContent = aContent;
}
}
}

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

@ -3759,7 +3759,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
// case sensitivity: bug 93371
PRBool isCaseSensitive = data.mCompatMode != eCompatibility_NavQuirks;
nsAtomList* IDList = aSelector->mIDList;
if (nsnull == IDList || aAttribute == nsHTMLAtoms::id) {
if (nsnull == IDList ||
(aAttribute && aAttribute == data.mContent->GetIDAttributeName())) {
result = PR_TRUE;
}
else if (nsnull != data.mContentID) {
@ -3790,7 +3791,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
}
}
if (result && aAttribute != nsHTMLAtoms::kClass) {
if (result &&
(!aAttribute || aAttribute != data.mContent->GetClassAttributeName())) {
nsAtomList* classList = aSelector->mClassList;
while (nsnull != classList) {
if (localTrue == (!data.mStyledContent->HasClass(classList->mAtom, isCaseSensitive))) {

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

@ -299,6 +299,12 @@ nsSVGElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
return NS_OK;
}
NS_IMETHODIMP_(nsIAtom*)
nsSVGElement::GetIDAttributeName() const
{
return nsSVGAtoms::id;
}
NS_IMETHODIMP
nsSVGElement::NormalizeAttrString(const nsAString& aStr,
nsINodeInfo** aNodeInfo)

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

@ -84,6 +84,7 @@ public:
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify,
PRBool aDeepSetDocument);
NS_IMETHOD RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
NS_IMETHOD_(nsIAtom *) GetIDAttributeName() const;
NS_IMETHOD NormalizeAttrString(const nsAString& aStr,
nsINodeInfo** aNodeInfo);
NS_IMETHOD SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,

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

@ -533,14 +533,13 @@ nsXMLElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
NS_IMETHODIMP
nsXMLElement::GetID(nsIAtom** aResult) const
{
nsCOMPtr<nsIAtom> atom;
nsresult rv = mNodeInfo->GetIDAttributeAtom(getter_AddRefs(atom));
nsIAtom* atom = GetIDAttributeName();
*aResult = nsnull;
if (NS_SUCCEEDED(rv) && atom) {
nsresult rv = NS_OK;
if (atom) {
nsAutoString value;
rv = nsGenericContainerElement::GetAttr(kNameSpaceID_None, atom,
value);
rv = nsGenericContainerElement::GetAttr(kNameSpaceID_None, atom, value);
if (NS_SUCCEEDED(rv)) {
*aResult = NS_NewAtom(value);
}

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

@ -1059,6 +1059,8 @@ MathMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo* aNodeInfo,
{
static const char kMathMLStyleSheetURI[] = "resource://gre/res/mathml.css";
aNodeInfo->SetIDAttributeAtom(nsHTMLAtoms::id);
// this bit of code is to load mathml.css on demand
nsIDocument* doc = aNodeInfo->GetDocument();
if (doc) {

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

@ -3580,6 +3580,18 @@ nsXULElement::HasAttributeDependentStyle(const nsIAtom* aAttribute) const
return PR_FALSE;
}
NS_IMETHODIMP_(nsIAtom *)
nsXULElement::GetIDAttributeName() const
{
return nsXULAtoms::id;
}
NS_IMETHODIMP_(nsIAtom *)
nsXULElement::GetClassAttributeName() const
{
return nsXULAtoms::clazz;
}
// Controllers Methods
NS_IMETHODIMP
nsXULElement::GetControllers(nsIControllers** aResult)

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

@ -426,6 +426,8 @@ public:
NS_IMETHOD GetNameSpaceID(PRInt32* aNameSpeceID) const;
NS_IMETHOD GetTag(nsIAtom** aResult) const;
NS_IMETHOD_(nsINodeInfo *) GetNodeInfo() const;
NS_IMETHOD_(nsIAtom *) GetIDAttributeName() const;
NS_IMETHOD_(nsIAtom *) GetClassAttributeName() const;
NS_IMETHOD NormalizeAttrString(const nsAString& aStr, nsINodeInfo** aNodeInfo);
NS_IMETHOD SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, const nsAString& aValue, PRBool aNotify);
NS_IMETHOD SetAttr(nsINodeInfo *aNodeInfo, const nsAString& aValue, PRBool aNotify);

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

@ -812,6 +812,15 @@ XULContentSinkImpl::HandleStartElement(const PRUnichar *aName,
break;
}
// Set the ID attribute atom on the node info object for this node
if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
if (IDAttr) {
rv = nodeInfo->SetIDAttributeAtom(IDAttr);
}
}
return rv;
}

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

@ -357,12 +357,7 @@ MBool txIdPattern::matches(Node* aNode, txIMatchContext* aContext)
return MB_FALSE;
}
nsINodeInfo *ni = content->GetNodeInfo();
if (!ni) {
return MB_FALSE;
}
nsCOMPtr<nsIAtom> idAttr;
ni->GetIDAttributeAtom(getter_AddRefs(idAttr));
nsIAtom* idAttr = content->GetIDAttributeName();
if (!idAttr) {
return MB_FALSE; // no ID for this element defined, can't match
}

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

@ -3759,7 +3759,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
// case sensitivity: bug 93371
PRBool isCaseSensitive = data.mCompatMode != eCompatibility_NavQuirks;
nsAtomList* IDList = aSelector->mIDList;
if (nsnull == IDList || aAttribute == nsHTMLAtoms::id) {
if (nsnull == IDList ||
(aAttribute && aAttribute == data.mContent->GetIDAttributeName())) {
result = PR_TRUE;
}
else if (nsnull != data.mContentID) {
@ -3790,7 +3791,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
}
}
if (result && aAttribute != nsHTMLAtoms::kClass) {
if (result &&
(!aAttribute || aAttribute != data.mContent->GetClassAttributeName())) {
nsAtomList* classList = aSelector->mClassList;
while (nsnull != classList) {
if (localTrue == (!data.mStyledContent->HasClass(classList->mAtom, isCaseSensitive))) {