Relanding bug 377035 Allow tree as anonymous parent of treechildren r=Enn sr=roc

This commit is contained in:
neil@parkwaycc.co.uk 2007-05-17 13:55:03 -07:00
parent 3e6b4a6600
commit 073bc637e1
2 changed files with 18 additions and 22 deletions

View File

@ -536,6 +536,8 @@ nsTreeContentView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsAString& _re
NS_IMETHODIMP
nsTreeContentView::SetTree(nsITreeBoxObject* aTree)
{
ClearRows();
mBoxObject = aTree;
if (aTree && !mRoot) {
@ -556,9 +558,9 @@ nsTreeContentView::SetTree(nsITreeBoxObject* aTree)
nsCOMPtr<nsIDOMElement> bodyElement;
mBoxObject->GetTreeBody(getter_AddRefs(bodyElement));
if (bodyElement) {
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(bodyElement);
mBody = do_QueryInterface(bodyElement);
PRInt32 index = 0;
Serialize(bodyContent, -1, &index, mRows);
Serialize(mBody, -1, &index, mRows);
}
}
@ -818,18 +820,16 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument,
return;
}
// If we have a legal tag, go up to the tree and make sure that it's ours.
nsCOMPtr<nsIContent> parent = aContent;
nsINodeInfo *ni = nsnull;
do {
parent = parent->GetParent();
if (parent)
ni = parent->NodeInfo();
} while (parent && !ni->Equals(nsGkAtoms::tree, kNameSpaceID_XUL));
// If we have a legal tag, go up to the tree/select and make sure
// that it's ours.
if (parent != mRoot) {
// This is not for us, we can bail out.
return;
for (nsIContent* element = aContent; element != mBody; element = element->GetParent()) {
if (!element)
return; // this is not for us
nsIAtom *parentTag = element->Tag();
if ((element->IsNodeOfType(nsINode::eXUL) && parentTag == nsGkAtoms::tree) ||
(element->IsNodeOfType(nsINode::eHTML) && parentTag == nsGkAtoms::select))
return; // this is not for us
}
// Handle changes of the hidden attribute.
@ -989,7 +989,7 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument,
// If we have a legal tag, go up to the tree/select and make sure
// that it's ours.
for (nsIContent* element = aContainer; element != mRoot; element = element->GetParent()) {
for (nsIContent* element = aContainer; element != mBody; element = element->GetParent()) {
if (!element)
return; // this is not for us
nsIAtom *parentTag = element->Tag();
@ -1072,11 +1072,11 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
// If we have a legal tag, go up to the tree/select and make sure
// that it's ours.
for (nsIContent* element = aContainer; element != mRoot; element = element->GetParent()) {
for (nsIContent* element = aContainer; element != mBody; element = element->GetParent()) {
if (!element)
return; // this is not for us
nsIAtom *parentTag = element->Tag();
if ((element->IsNodeOfType(nsINode::eXUL) && parentTag == nsGkAtoms::tree) ||
if ((element->IsNodeOfType(nsINode::eXUL) && parentTag == nsGkAtoms::tree) ||
(element->IsNodeOfType(nsINode::eHTML) && parentTag == nsGkAtoms::select))
return; // this is not for us
}
@ -1093,12 +1093,6 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
mBoxObject->RowCountChanged(index + 1, -count);
}
}
else if (aContainer->Tag() == nsGkAtoms::tree) {
PRInt32 count = mRows.Count();
ClearRows();
if (count && mBoxObject)
mBoxObject->RowCountChanged(0, -count);
}
}
else if (tag == nsGkAtoms::treeitem ||
tag == nsGkAtoms::treeseparator ||
@ -1439,6 +1433,7 @@ nsTreeContentView::ClearRows()
Row::Destroy(mAllocator, (Row*)mRows[i]);
mRows.Clear();
mRoot = nsnull;
mBody = nsnull;
// Remove ourselves from mDocument's observers.
if (mDocument) {
mDocument->RemoveObserver(this);

View File

@ -132,6 +132,7 @@ class nsTreeContentView : public nsINativeTreeView,
nsCOMPtr<nsITreeBoxObject> mBoxObject;
nsCOMPtr<nsITreeSelection> mSelection;
nsCOMPtr<nsIContent> mRoot;
nsCOMPtr<nsIContent> mBody;
nsIDocument* mDocument; // WEAK
nsFixedSizeAllocator mAllocator;
nsVoidArray mRows;