Bug 377035 Allow <tree> to be anonymous parent of <treechildren> r=Enn sr=roc
authorneil@parkwaycc.co.uk
Wed, 09 May 2007 01:54:24 -0700
changeset 1308 df0fc8a849e19ea9dbafbd551e90a8d18af27477
parent 1307 37e175cfe51213d41f527ec05e2c85062f60fa68
child 1309 7acc820959ead6182933526411b815601fd4206b
push idunknown
push userunknown
push dateunknown
reviewersEnn, roc
bugs377035
milestone1.9a5pre
Bug 377035 Allow <tree> to be anonymous parent of <treechildren> r=Enn sr=roc
layout/xul/base/src/tree/src/nsTreeContentView.cpp
layout/xul/base/src/tree/src/nsTreeContentView.h
--- a/layout/xul/base/src/tree/src/nsTreeContentView.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeContentView.cpp
@@ -551,19 +551,19 @@ nsTreeContentView::SetTree(nsITreeBoxObj
     if (document) {
       document->AddObserver(this);
       mDocument = document;
     }
 
     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);
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::ToggleOpenState(PRInt32 aIndex)
@@ -813,28 +813,26 @@ nsTreeContentView::AttributeChanged(nsID
         tag != nsGkAtoms::treerow &&
         tag != nsGkAtoms::treecell)
       return;
   }
   else {
     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.
   if (aAttribute == nsGkAtoms::hidden &&
      (tag == nsGkAtoms::treeitem || tag == nsGkAtoms::treeseparator)) {
     PRBool hidden = aContent->AttrValueIs(kNameSpaceID_None,
                                           nsGkAtoms::hidden,
                                           nsGkAtoms::_true, eCaseMatters);
@@ -984,17 +982,17 @@ nsTreeContentView::ContentInserted(nsIDo
   }
   else {
     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 != 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) ||
         (element->IsNodeOfType(nsINode::eHTML) && parentTag == nsGkAtoms::select))
       return; // this is not for us
   }
 
@@ -1067,21 +1065,21 @@ nsTreeContentView::ContentRemoved(nsIDoc
   }
   else {
     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 != 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
   }
 
   if (tag == nsGkAtoms::treechildren) {
     PRInt32 index = FindContent(aContainer);
     if (index >= 0) {
       Row* row = (Row*)mRows[index];
@@ -1434,16 +1432,17 @@ nsTreeContentView::RemoveRow(PRInt32 aIn
 
 void
 nsTreeContentView::ClearRows()
 {
   for (PRInt32 i = 0; i < mRows.Count(); i++)
     Row::Destroy(mAllocator, (Row*)mRows[i]);
   mRows.Clear();
   mRoot = nsnull;
+  mBody = nsnull;
   // Remove ourselves from mDocument's observers.
   if (mDocument) {
     mDocument->RemoveObserver(this);
     mDocument = nsnull;
   }
 } 
 
 void
--- a/layout/xul/base/src/tree/src/nsTreeContentView.h
+++ b/layout/xul/base/src/tree/src/nsTreeContentView.h
@@ -127,16 +127,17 @@ class nsTreeContentView : public nsINati
 
     // Content helpers.
     nsIContent* GetCell(nsIContent* aContainer, nsITreeColumn* aCol);
 
   private:
     nsCOMPtr<nsITreeBoxObject>          mBoxObject;
     nsCOMPtr<nsITreeSelection>          mSelection;
     nsCOMPtr<nsIContent>                mRoot;
+    nsCOMPtr<nsIContent>                mBody;
     nsIDocument*                        mDocument;      // WEAK
     nsFixedSizeAllocator                mAllocator;
     nsVoidArray                         mRows;
 
     PRPackedBool                        mUpdateSelection;
 };
 
 #endif // nsTreeContentView_h__