Fix timing issues wrt. model placement. Bug 283737, r=smaug+me, a=mkaply, patch by aaronr@us.ibm.com, NPOTB

git-svn-id: svn://10.0.0.236/trunk@173506 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
allan%beaufour.dk
2005-05-17 11:30:43 +00:00
parent 9edef9e18b
commit 89c8cacb04
5 changed files with 118 additions and 5 deletions

View File

@@ -1273,6 +1273,8 @@ nsXFormsModelElement::MaybeNotifyCompletion()
NS_STATIC_CAST(nsXFormsModelElement *, models->ElementAt(i));
nsXFormsUtils::DispatchEvent(model->mElement, eEvent_ModelConstructDone);
}
nsXFormsModelElement::ProcessDeferredBinds(domDoc);
}
nsresult
@@ -1497,6 +1499,74 @@ nsXFormsModelElement::Startup()
sModelPropsList[eModel_p3ptype] = nsXFormsAtoms::p3ptype;
}
static void
DeleteBindList(void *aObject,
nsIAtom *aPropertyName,
void *aPropertyValue,
void *aData)
{
delete NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *, aPropertyValue);
}
/* static */ nsresult
nsXFormsModelElement::DeferElementBind(nsIDOMDocument *aDoc,
nsIXFormsControl *aControl)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
if (!doc || !aControl) {
return NS_ERROR_FAILURE;
}
nsCOMArray<nsIXFormsControl> *deferredBindList =
NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *,
doc->GetProperty(nsXFormsAtoms::deferredBindListProperty));
if (!deferredBindList) {
deferredBindList = new nsCOMArray<nsIXFormsControl>(16);
NS_ENSURE_TRUE(deferredBindList, NS_ERROR_OUT_OF_MEMORY);
doc->SetProperty(nsXFormsAtoms::deferredBindListProperty, deferredBindList,
DeleteBindList);
}
// always append to the end of the list. We need to keep the elements in
// document order when we process the binds later. Otherwise we have trouble
// when an element is trying to bind and should use its parent as a context
// for the xpath evaluation but the parent isn't bound yet.
deferredBindList->AppendObject(aControl);
return NS_OK;
}
/* static */ void
nsXFormsModelElement::ProcessDeferredBinds(nsIDOMDocument *aDoc)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
if (!doc) {
return;
}
doc->SetProperty(nsXFormsAtoms::readyForBindProperty, doc);
nsCOMArray<nsIXFormsControl> *deferredBindList =
NS_STATIC_CAST(nsCOMArray<nsIXFormsControl> *,
doc->GetProperty(nsXFormsAtoms::deferredBindListProperty));
if (deferredBindList) {
for (int i = 0; i < deferredBindList->Count(); ++i) {
nsIXFormsControl *control = deferredBindList->ObjectAt(i);
if (control) {
control->Bind();
control->Refresh();
}
}
doc->DeleteProperty(nsXFormsAtoms::deferredBindListProperty);
}
}
nsresult
NS_NewXFormsModelElement(nsIXTFElement **aResult)
{