From b2049ca98f6dc3200be0fa0cf2eb2aa34d03edd0 Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Mon, 6 Dec 2004 21:14:20 +0000 Subject: [PATCH] landing patch for bug 272406 "External instance data not handled correctly" patch by smaug@welho.com r=darin --- extensions/xforms/nsXFormsInstanceElement.cpp | 46 ++++++++++++------- extensions/xforms/nsXFormsInstanceElement.h | 2 + 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/extensions/xforms/nsXFormsInstanceElement.cpp b/extensions/xforms/nsXFormsInstanceElement.cpp index 9acfddc91d24..37aacef18c70 100644 --- a/extensions/xforms/nsXFormsInstanceElement.cpp +++ b/extensions/xforms/nsXFormsInstanceElement.cpp @@ -59,6 +59,7 @@ NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsInstanceElement, nsXFormsInstanceElement::nsXFormsInstanceElement() : mElement(nsnull) + , mIgnoreAttributeChanges(PR_FALSE) { } @@ -77,12 +78,10 @@ NS_IMETHODIMP nsXFormsInstanceElement::AttributeSet(nsIAtom *aName, const nsAString &aNewValue) { - if (aName == nsXFormsAtoms::src) { - // Note that this will fail if encountered during document construction, - // because we won't be in the document yet, so CreateInstanceDocument - // won't find a document to work with. That's ok, we'll fix things after - // our children are appended and we're in the document (DoneAddingChildren) + if (mIgnoreAttributeChanges) + return NS_OK; + if (aName == nsXFormsAtoms::src) { LoadExternalInstance(aNewValue); } @@ -92,21 +91,33 @@ nsXFormsInstanceElement::AttributeSet(nsIAtom *aName, NS_IMETHODIMP nsXFormsInstanceElement::AttributeRemoved(nsIAtom *aName) { + if (mIgnoreAttributeChanges) + return NS_OK; + if (aName == nsXFormsAtoms::src) { - // We no longer have an external instance to use. - // Reset our instance document to whatever inline content we have. + // We no longer have an external instance to use. Reset our instance + // document to whatever inline content we have. return CloneInlineInstance(); } return NS_OK; } +NS_IMETHODIMP +nsXFormsInstanceElement::BeginAddingChildren() +{ + // Ignore attribute changes during document construction. Attributes will be + // handled in the DoneAddingChildren. + mIgnoreAttributeChanges = PR_TRUE; + return NS_OK; +} + NS_IMETHODIMP nsXFormsInstanceElement::DoneAddingChildren() { - // By the time this is called, we should be inserted in the document - // and have all of our child elements, so this is our first opportunity - // to create the instance document. + // By the time this is called, we should be inserted in the document and have + // all of our child elements, so this is our first opportunity to create the + // instance document. nsAutoString src; mElement->GetAttribute(NS_LITERAL_STRING("src"), src); @@ -118,22 +129,25 @@ nsXFormsInstanceElement::DoneAddingChildren() LoadExternalInstance(src); } + // Now, observe changes to the "src" attribute. + mIgnoreAttributeChanges = PR_FALSE; return NS_OK; } NS_IMETHODIMP nsXFormsInstanceElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper) { - aWrapper->SetNotificationMask (nsIXTFElement::NOTIFY_PARENT_CHANGED | - nsIXTFElement::NOTIFY_ATTRIBUTE_SET | - nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED | - nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN); + aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_ATTRIBUTE_SET | + nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED | + nsIXTFElement::NOTIFY_BEGIN_ADDING_CHILDREN | + nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN); + // XXX observe nsIXTFElement::NOTIFY_PARENT_CHANGED ?? nsCOMPtr node; aWrapper->GetElementNode(getter_AddRefs(node)); - // It's ok to keep a weak pointer to mElement. mElement will have an - // owning reference to this object, so as long as we null out mElement in + // It's ok to keep a weak pointer to mElement. mElement will have an owning + // reference to this object, so as long as we null out mElement in // OnDestroyed, it will always be valid. mElement = node; diff --git a/extensions/xforms/nsXFormsInstanceElement.h b/extensions/xforms/nsXFormsInstanceElement.h index 38bfb235573a..bb192ed444f3 100644 --- a/extensions/xforms/nsXFormsInstanceElement.h +++ b/extensions/xforms/nsXFormsInstanceElement.h @@ -66,6 +66,7 @@ public: NS_IMETHOD OnDestroyed(); NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aNewValue); NS_IMETHOD AttributeRemoved(nsIAtom *aName); + NS_IMETHOD BeginAddingChildren(); NS_IMETHOD DoneAddingChildren(); NS_IMETHOD OnCreated(nsIXTFGenericElementWrapper *aWrapper); @@ -89,6 +90,7 @@ private: nsCOMPtr mDocument; nsIDOMElement *mElement; + PRBool mIgnoreAttributeChanges; }; NS_HIDDEN_(nsresult)