void nsTreeContentView::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild) { NS_ASSERTION(aChild, "null ptr"); // Make sure this notification concerns us. // First check the tag to see if it's one that we care about. // Don't allow non-XUL nodes. if (!aChild->IsXULElement() || !aContainer->IsXULElement()) return; if (!aChild->IsAnyOfXULElements(nsGkAtoms::treeitem, nsGkAtoms::treeseparator, nsGkAtoms::treechildren, nsGkAtoms::treerow, nsGkAtoms::treecell)) { return; } // If we have a legal tag, go up to the tree/select and make sure // that it's ours. for (nsIContent* element = aContainer; element != mBody; element = element->GetParent()) { if (!element) return; // this is not for us if (element->IsXULElement(nsGkAtoms::tree)) return; // this is not for us } // Lots of codepaths under here that do all sorts of stuff, so be safe. nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this); if (aChild->IsXULElement(nsGkAtoms::treechildren)) { int32_t index = FindContent(aContainer); if (index >= 0) { Row* row = mRows[index].get(); row->SetEmpty(false); if (mBoxObject) mBoxObject->InvalidateRow(index); if (row->IsContainer() && row->IsOpen()) { int32_t count = EnsureSubtree(index); if (mBoxObject) mBoxObject->RowCountChanged(index + 1, count); } } } else if (aChild->IsAnyOfXULElements(nsGkAtoms::treeitem, nsGkAtoms::treeseparator)) { InsertRowFor(aContainer, aChild); } else if (aChild->IsXULElement(nsGkAtoms::treerow)) { int32_t index = FindContent(aContainer); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } else if (aChild->IsXULElement(nsGkAtoms::treecell)) { nsCOMPtr<nsIContent> parent = aContainer->GetParent(); if (parent) { int32_t index = FindContent(parent); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } } }