Backing the rest of this out to see whether it affects Tp.

This commit is contained in:
bzbarsky%mit.edu 2003-06-22 03:33:33 +00:00
parent 35e16c1704
commit 16ff7adf5e
3 changed files with 76 additions and 94 deletions

View File

@ -3354,6 +3354,8 @@ nsGenericContainerElement::SetAttr(nsINodeInfo* aNodeInfo,
PRBool modification = PR_FALSE;
nsAutoString oldValue;
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if (!mAttributes) {
mAttributes = new nsAutoVoidArray();
NS_ENSURE_TRUE(mAttributes, NS_ERROR_OUT_OF_MEMORY);
@ -3362,43 +3364,35 @@ nsGenericContainerElement::SetAttr(nsINodeInfo* aNodeInfo,
nsCOMPtr<nsIAtom> name = aNodeInfo->GetNameAtom();
PRInt32 nameSpaceID = aNodeInfo->GetNamespaceID();
nsGenericAttribute* attr = nsnull;
PRInt32 index;
PRInt32 count = mAttributes->Count();
for (index = 0; index < count; index++) {
attr = (nsGenericAttribute*)mAttributes->ElementAt(index);
if (attr->mNodeInfo == aNodeInfo) {
if (attr->mValue.Equals(aValue)) {
// Do nothing if the value is not changing
return NS_OK;
}
// stash away the old value
oldValue = attr->mValue;
break;
}
}
// Begin the update _before_ changing the attr value
if (aNotify && mDocument) {
if (aNotify && (nsnull != mDocument)) {
mDocument->BeginUpdate();
mDocument->AttributeWillChange(this, nameSpaceID, name);
}
if (index < count) { // found our attr in the list
NS_ASSERTION(attr, "How did we get here with a null attr pointer?");
modification = PR_TRUE;
attr->mValue = aValue;
} else { // didn't find it
attr = new nsGenericAttribute(aNodeInfo, aValue);
NS_ENSURE_TRUE(attr, NS_ERROR_OUT_OF_MEMORY);
if (!mAttributes->AppendElement(attr)) {
return NS_ERROR_OUT_OF_MEMORY;
nsGenericAttribute* attr;
PRInt32 index;
PRInt32 count = mAttributes->Count();
for (index = 0; index < count; index++) {
attr = (nsGenericAttribute*)mAttributes->ElementAt(index);
if (attr->mNodeInfo == aNodeInfo) {
oldValue = attr->mValue;
modification = PR_TRUE;
attr->mValue = aValue;
rv = NS_OK;
break;
}
}
if (mDocument) {
if (index >= count) { // didn't find it
attr = new nsGenericAttribute(aNodeInfo, aValue);
NS_ENSURE_TRUE(attr, NS_ERROR_OUT_OF_MEMORY);
mAttributes->AppendElement(attr);
rv = NS_OK;
}
if (mDocument && NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIBindingManager> bindingManager;
mDocument->GetBindingManager(getter_AddRefs(bindingManager));
nsCOMPtr<nsIXBLBinding> binding;
@ -3448,7 +3442,7 @@ nsGenericContainerElement::SetAttr(nsINodeInfo* aNodeInfo,
}
}
return NS_OK;
return rv;
}
nsresult

View File

@ -580,13 +580,19 @@ nsSVGAttributes::SetAttr(nsINodeInfo* aNodeInfo,
PRBool aNotify)
{
NS_ENSURE_ARG_POINTER(aNodeInfo);
PRBool modification = PR_FALSE;
nsAutoString oldValue;
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIDocument> document;
if (mContent)
mContent->GetDocument(getter_AddRefs(document));
nsSVGAttribute* attr = nsnull;
if (aNotify && document) {
document->BeginUpdate();
}
nsSVGAttribute* attr;
PRInt32 index;
PRInt32 count;
@ -595,47 +601,32 @@ nsSVGAttributes::SetAttr(nsINodeInfo* aNodeInfo,
attr = ElementAt(index);
if (attr->GetNodeInfo() == aNodeInfo) {
attr->GetValue()->GetValueString(oldValue);
if (oldValue.Equals(aValue)) {
// Do nothing if the value is not changing
return NS_OK;
}
modification = PR_TRUE;
attr->GetValue()->SetValueString(aValue);
rv = NS_OK;
break;
}
}
if (index >= count) { // didn't find it
PRInt32 nameSpaceID = aNodeInfo->GetNamespaceID();
nsCOMPtr<nsIAtom> name = aNodeInfo->GetNameAtom();
// Send the notification before making any updates
if (aNotify && document) {
document->BeginUpdate();
document->AttributeWillChange(mContent, nameSpaceID, name);
}
nsresult rv = NS_OK;
PRBool modification = PR_FALSE;
if (index < count) { // found the attr in the list
NS_ASSERTION(attr, "How did we get here with a null attr pointer?");
modification = PR_TRUE;
attr->GetValue()->SetValueString(aValue);
} else { // didn't find it
// GetMappedAttribute and nsSVGAttribute::Create both addref, so we release
// after this if block. It's safe to use attr after the Release(), since
// AppendElement also addrefs it.
if (GetMappedAttribute(aNodeInfo, &attr)) {
AppendElement(attr);
attr->GetValue()->SetValueString(aValue);
}
else {
rv = nsSVGAttribute::Create(aNodeInfo, aValue, &attr);
NS_ENSURE_TRUE(attr, rv);
AppendElement(attr);
}
AppendElement(attr);
attr->Release();
rv = NS_OK;
}
if (document && NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIAtom> name = aNodeInfo->GetNameAtom();
PRInt32 nameSpaceID = aNodeInfo->GetNamespaceID();
nsCOMPtr<nsIBindingManager> bindingManager;
document->GetBindingManager(getter_AddRefs(bindingManager));
nsCOMPtr<nsIXBLBinding> binding;

View File

@ -2436,48 +2436,32 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
nsCOMPtr<nsIAtom> attrName = aNodeInfo->GetNameAtom();
PRInt32 attrns = aNodeInfo->GetNamespaceID();
nsresult rv = EnsureAttributes();
if (NS_FAILED(rv)) return rv;
nsAutoString oldValue;
nsXULAttribute* attr = FindLocalAttribute(aNodeInfo);
nsXULPrototypeAttribute *protoattr = nsnull;
if (attr) {
attr->GetValue(oldValue);
} else {
// Don't have it locally, but might be shadowing a prototype attribute.
protoattr = FindPrototypeAttribute(aNodeInfo);
if (protoattr) {
protoattr->mValue.GetValue(oldValue);
}
}
if ((attr || protoattr) && oldValue.Equals(aValue)) {
// do nothing if there is no change
return NS_OK;
}
// Send the update notification _before_ changing anything
if (mDocument && aNotify) {
mDocument->BeginUpdate();
// XXXwaterson should likely also be conditioned on aNotify. Do we
// need to BeginUpdate() here as well?
if (mDocument) {
mDocument->AttributeWillChange(this, attrns, attrName);
}
// Check to see if the CLASS attribute is being set. If so, we need to
// rebuild our class list.
nsresult rv = EnsureAttributes();
if (NS_FAILED(rv)) return rv;
// XXX Class and Style attribute setting should be checking for the XUL namespace!
// Check to see if the CLASS attribute is being set. If so, we need to rebuild our
// class list.
if (aNodeInfo->Equals(nsXULAtoms::clazz, kNameSpaceID_None)) {
Attributes()->UpdateClassList(aValue);
}
// Check to see if the STYLE attribute is being set. If so, we need to
// create a new style rule based off the value of this attribute, and we
// need to let the document know about the StyleRule change.
// XXXbz this should not be checking for mDocument; it should get
// the document off the nodeinfo
if (aNodeInfo->Equals(nsXULAtoms::style, kNameSpaceID_None) && mDocument) {
// Check to see if the STYLE attribute is being set. If so, we need to create a new
// style rule based off the value of this attribute, and we need to let the document
// know about the StyleRule change.
if (aNodeInfo->Equals(nsXULAtoms::style, kNameSpaceID_None) &&
(mDocument != nsnull)) {
nsCOMPtr <nsIURI> docURL;
mDocument->GetBaseURL(getter_AddRefs(docURL));
Attributes()->UpdateStyleRule(docURL, aValue);
// XXX Some kind of special document update might need to happen here.
}
nsCOMPtr<nsIAtom> tag;
@ -2485,21 +2469,33 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
if (tag == nsXULAtoms::window &&
aNodeInfo->Equals(nsXULAtoms::hidechrome)) {
nsAutoString val(aValue);
nsAutoString val;
val.Assign(aValue);
HideWindowChrome(val.EqualsIgnoreCase("true"));
}
// XXX need to check if they're changing an event handler: if so, then we need
// to unhook the old one.
// Save whether this is a modification before we muck with the attr pointer.
PRBool modification = attr || protoattr;
nsXULAttribute* attr = FindLocalAttribute(aNodeInfo);
PRBool modification;
nsAutoString oldValue;
if (attr) {
attr->GetValue(oldValue);
attr->SetValueInternal(aValue);
modification = PR_TRUE;
}
else {
// Need to create a local attr
// Don't have it locally, but might be shadowing a prototype attribute.
nsXULPrototypeAttribute *protoattr = FindPrototypeAttribute(aNodeInfo);
if (protoattr) {
protoattr->mValue.GetValue(oldValue);
modification = PR_TRUE;
} else {
modification = PR_FALSE;
}
rv = nsXULAttribute::Create(NS_STATIC_CAST(nsIStyledContent*, this),
aNodeInfo, aValue, &attr);
if (NS_FAILED(rv)) return rv;
@ -2560,7 +2556,8 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
mDocument->AttributeChanged(this, attrns, attrName, modHint,
StyleHintFor(NodeInfo()));
mDocument->EndUpdate();
// XXXwaterson do we need to mDocument->EndUpdate() here?
}
}