nsXULContentBuilder::Rebuild(nsIContent* aElement)
nsXULContentBuilder::Rebuild()
nsXULContentBuilder::Rebuild(nsIContent* aElement){    NS_PRECONDITION(aElement != nsnull, "null ptr");    if (! aElement)        return NS_ERROR_NULL_POINTER;    // First, make sure that the element is in the right widget -- ours.    if (! IsElementInWidget(aElement))        return NS_OK;    // Forbid re-entrant rebuilds    if (mIsBuilding)        return NS_OK;    AutoLatch latch(&mIsBuilding);    nsresult rv;    // Next, see if it's a XUL element whose contents have never even    // been generated. If so, short-circuit and bail; there's nothing    // for us to "rebuild" yet. They'll get built correctly the next    // time somebody asks for them.     nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);    if (xulcontent) {        PRBool containerContentsBuilt = PR_FALSE;        xulcontent->GetLazyState(nsIXULContent::eContainerContentsBuilt, containerContentsBuilt);        if (! containerContentsBuilt)            return NS_OK;    }    // If we get here, then we've tried to generate content for this    // element. Remove it.    rv = RemoveGeneratedContent(aElement);    if (NS_FAILED(rv)) return rv;    if (aElement == mRoot) {        // Nuke the content support map and conflict set completely.        mContentSupportMap.Clear();        mTemplateMap.Clear();        mConflictSet.Clear();        rv = CompileRules();        if (NS_FAILED(rv)) return rv;    }    // Forces the XUL element to remember that it needs to    // re-generate its children next time around.    if (xulcontent) {        xulcontent->SetLazyState(nsIXULContent::eChildrenMustBeRebuilt);        xulcontent->ClearLazyState(nsIXULContent::eTemplateContentsBuilt);        xulcontent->ClearLazyState(nsIXULContent::eContainerContentsBuilt);    }    // Now, regenerate both the template- and container-generated    // contents for the current element...    nsCOMPtr<nsIContent> container;    PRInt32 newIndex;    CreateTemplateAndContainerContents(aElement, getter_AddRefs(container), &newIndex);    if (container) {        nsCOMPtr<nsIDocument> doc;        mRoot->GetDocument(*getter_AddRefs(doc));        NS_ASSERTION(doc != nsnull, "root element has no document");        if (! doc)            return NS_ERROR_UNEXPECTED;        doc->ContentAppended(container, newIndex);    }    return NS_OK;}