if (IsTreeWidgetItem(aElement) && !IsOpen(aElement))
if (IsLazyWidgetItem(aElement) && !IsOpen(aElement))
nsXULTemplateBuilder::CreateContainerContents(nsIContent* aElement,                                              nsIRDFResource* aResource,                                              PRBool aNotify,                                              nsIContent** aContainer,                                              PRInt32* aNewIndexInContainer){    // Create the contents of a container by iterating over all of the    // "containment" arcs out of the element's resource.    nsresult rv;	// Compile the rules now, if they haven't been already.    if (! mRulesCompiled) {        rv = CompileRules();        if (NS_FAILED(rv)) return rv;    }        if (aContainer) {        *aContainer = nsnull;        *aNewIndexInContainer = -1;    }    // The tree widget is special. If the item isn't open, then just    // "pretend" that there aren't any contents here. We'll create    // them when OpenContainer() gets called.    if (IsTreeWidgetItem(aElement) && !IsOpen(aElement))        return NS_OK;    // See if the element's templates contents have been generated:    // this prevents a re-entrant call from triggering another    // generation.    nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);    if (xulcontent) {        PRBool contentsGenerated;        rv = xulcontent->GetLazyState(nsIXULContent::eContainerContentsBuilt, contentsGenerated);        if (NS_FAILED(rv)) return rv;        if (contentsGenerated)            return NS_OK;        // Now mark the element's contents as being generated so that        // any re-entrant calls don't trigger an infinite recursion.        rv = xulcontent->SetLazyState(nsIXULContent::eContainerContentsBuilt);    }    else {        // HTML is always needs to be generated.        //        // XXX Big ass-umption here -- I am assuming that this will        // _only_ ever get called (in the case of an HTML element)        // when the XUL builder is descending thru the graph and        // stumbles on a template that is rooted at an HTML element.        // (/me crosses fingers...)    }    // Forbid re-entrant updates while we propogate    AutoSentry guard(&mIsBuilding);    // Seed the rule network with assignments for the content and    // container variables    //    // XXXwaterson could this code be shared with    // nsXULTemplateBuilder::Propogate()?    Instantiation seed;    seed.AddAssignment(mContentVar, Value(aElement));    InstantiationSet instantiations;    instantiations.Append(seed);    // Propogate the assignments through the network    ClusterKeySet newkeys;    rv = mRules.GetRoot()->Propogate(instantiations, &newkeys);    if (NS_FAILED(rv)) return rv;    // Iterate through newly added keys to determine which rules fired    ClusterKeySet::ConstIterator last = newkeys.Last();    for (ClusterKeySet::ConstIterator key = newkeys.First(); key != last; ++key) {        MatchSet* matches;        mConflictSet.GetMatchesForClusterKey(*key, &matches);        if (! matches)            continue;        Match* match =             matches->FindMatchWithHighestPriority();        NS_ASSERTION(match != nsnull, "no best match in match set");        if (! match)            continue;        // Grab the template node        nsCOMPtr<nsIContent> tmpl;        match->mRule->GetContent(getter_AddRefs(tmpl));        BuildContentFromTemplate(tmpl, aElement, aElement, PR_TRUE,                                 VALUE_TO_IRDFRESOURCE(key->mMemberValue),                                 aNotify, match,                                 aContainer, aNewIndexInContainer);        // Remember this as the "last" match        matches->SetLastMatch(match);    }    return NS_OK;}