From 918eb7c220d93f60e3d27224c1c45c175df71350 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 21 Aug 2001 06:14:38 +0000 Subject: [PATCH] Fix for 95422. r/sr=the usuals (brendan et al) --- content/xbl/src/nsXBLPrototypeBinding.cpp | 98 ++++++++++++----------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index da4ab77e160..97bacf79ec4 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -643,59 +643,61 @@ nsXBLPrototypeBinding::AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceI nsCOMPtr realElement; LocateInstance(aChangedElement, content, aAnonymousContent, element, getter_AddRefs(realElement)); - xblAttr->GetDstAttribute(getter_AddRefs(dstAttr)); + if (realElement) { + xblAttr->GetDstAttribute(getter_AddRefs(dstAttr)); - if (aRemoveFlag) - realElement->UnsetAttr(aNameSpaceID, dstAttr, PR_TRUE); - else { - PRBool attrPresent = PR_TRUE; - nsAutoString value; - // Check to see if the src attribute is xbl:text. If so, then we need to obtain the - // children of the real element and get the text nodes' values. - if (aAttribute == kXBLTextAtom) { - nsXBLBinding::GetTextData(aChangedElement, value); - value.StripChar('\n'); - value.StripChar('\r'); - nsAutoString stripVal(value); - stripVal.StripWhitespace(); - if (stripVal.IsEmpty()) - attrPresent = PR_FALSE; - } + if (aRemoveFlag) + realElement->UnsetAttr(aNameSpaceID, dstAttr, PR_TRUE); else { - nsresult result = aChangedElement->GetAttr(aNameSpaceID, aAttribute, value); - attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE || - result == NS_CONTENT_ATTR_HAS_VALUE); + PRBool attrPresent = PR_TRUE; + nsAutoString value; + // Check to see if the src attribute is xbl:text. If so, then we need to obtain the + // children of the real element and get the text nodes' values. + if (aAttribute == kXBLTextAtom) { + nsXBLBinding::GetTextData(aChangedElement, value); + value.StripChar('\n'); + value.StripChar('\r'); + nsAutoString stripVal(value); + stripVal.StripWhitespace(); + if (stripVal.IsEmpty()) + attrPresent = PR_FALSE; + } + else { + nsresult result = aChangedElement->GetAttr(aNameSpaceID, aAttribute, value); + attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE || + result == NS_CONTENT_ATTR_HAS_VALUE); + } + + if (attrPresent) + realElement->SetAttr(aNameSpaceID, dstAttr, value, PR_TRUE); } - if (attrPresent) - realElement->SetAttr(aNameSpaceID, dstAttr, value, PR_TRUE); - } - - // See if we're the tag in XUL, and see if value is being - // set or unset on us. We may also be a tag that is having - // xbl:text set on us. - nsCOMPtr tag; - realElement->GetTag(*getter_AddRefs(tag)); - if (dstAttr.get() == kXBLTextAtom || (tag.get() == kHTMLAtom) && (dstAttr.get() == kValueAtom)) { - // Flush out all our kids. - PRInt32 childCount; - realElement->ChildCount(childCount); - for (PRInt32 i = 0; i < childCount; i++) - realElement->RemoveChildAt(0, PR_TRUE); + // See if we're the tag in XUL, and see if value is being + // set or unset on us. We may also be a tag that is having + // xbl:text set on us. + nsCOMPtr tag; + realElement->GetTag(*getter_AddRefs(tag)); + if (dstAttr.get() == kXBLTextAtom || (tag.get() == kHTMLAtom) && (dstAttr.get() == kValueAtom)) { + // Flush out all our kids. + PRInt32 childCount; + realElement->ChildCount(childCount); + for (PRInt32 i = 0; i < childCount; i++) + realElement->RemoveChildAt(0, PR_TRUE); - if (!aRemoveFlag) { - // Construct a new text node and insert it. - nsAutoString value; - aChangedElement->GetAttr(aNameSpaceID, aAttribute, value); - if (!value.IsEmpty()) { - nsCOMPtr textNode; - nsCOMPtr doc; - aChangedElement->GetDocument(*getter_AddRefs(doc)); - nsCOMPtr domDoc(do_QueryInterface(doc)); - domDoc->CreateTextNode(value, getter_AddRefs(textNode)); - nsCOMPtr dummy; - nsCOMPtr domElement(do_QueryInterface(realElement)); - domElement->AppendChild(textNode, getter_AddRefs(dummy)); + if (!aRemoveFlag) { + // Construct a new text node and insert it. + nsAutoString value; + aChangedElement->GetAttr(aNameSpaceID, aAttribute, value); + if (!value.IsEmpty()) { + nsCOMPtr textNode; + nsCOMPtr doc; + aChangedElement->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr domDoc(do_QueryInterface(doc)); + domDoc->CreateTextNode(value, getter_AddRefs(textNode)); + nsCOMPtr dummy; + nsCOMPtr domElement(do_QueryInterface(realElement)); + domElement->AppendChild(textNode, getter_AddRefs(dummy)); + } } } }