From 362b2ca5812a4256f92b2c032aa6b84fb1dbe71f Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Fri, 28 Jul 2006 19:57:15 +0000 Subject: [PATCH] Store the tree view as a member rather than a property b=344085 r+sr=roc --- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 45 +----------- .../xul/base/src/tree/src/nsTreeBoxObject.cpp | 68 +++++++------------ .../base/src/tree/src/nsTreeContentView.cpp | 2 +- .../xul/base/src/tree/src/nsTreeContentView.h | 4 +- 4 files changed, 30 insertions(+), 89 deletions(-) diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index a94093d873c1..0281be3864f4 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -374,11 +374,8 @@ nsTreeBodyFrame::EnsureView() EnsureBoxObject(); nsCOMPtr box = do_QueryInterface(mTreeBoxObject); if (box) { - nsCOMPtr suppView; - box->GetPropertyAsSupports(NS_LITERAL_STRING("view").get(), - getter_AddRefs(suppView)); - nsCOMPtr treeView(do_QueryInterface(suppView)); - + nsCOMPtr treeView; + mTreeBoxObject->GetView(getter_AddRefs(treeView)); if (treeView) { nsXPIDLString rowStr; box->GetProperty(NS_LITERAL_STRING("topRow").get(), @@ -399,35 +396,6 @@ nsTreeBodyFrame::EnsureView() box->RemoveProperty(NS_LITERAL_STRING("topRow").get()); } } - - if (!mView) { - // If we don't have a box object yet, or no view was set on it, - // look for a XULTreeBuilder or create a content view. - - nsCOMPtr xulele = do_QueryInterface(mContent->GetParent()); - if (xulele) { - nsCOMPtr view; - - // See if there is a XUL tree builder associated with - // the parent element. - nsCOMPtr builder; - xulele->GetBuilder(getter_AddRefs(builder)); - if (builder) - view = do_QueryInterface(builder); - - if (!view) { - // No tree builder, create a tree content view. - nsCOMPtr contentView; - NS_NewTreeContentView(getter_AddRefs(contentView)); - if (contentView) - view = do_QueryInterface(contentView); - } - - // Hook up the view. - if (view) - SetView(view); - } - } } } @@ -495,9 +463,6 @@ NS_IMETHODIMP nsTreeBodyFrame::SetView(nsITreeView * aView) { // First clear out the old view. EnsureBoxObject(); - nsCOMPtr box = do_QueryInterface(mTreeBoxObject); - - NS_NAMED_LITERAL_STRING(view, "view"); if (mView) { nsCOMPtr sel; @@ -505,9 +470,6 @@ NS_IMETHODIMP nsTreeBodyFrame::SetView(nsITreeView * aView) if (sel) sel->SetTree(nsnull); mView->SetTree(nsnull); - mView = nsnull; - if (box) - box->RemoveProperty(view.get()); // Only reset the top row index and delete the columns if we had an old non-null view. mTopRowIndex = 0; @@ -542,9 +504,6 @@ NS_IMETHODIMP nsTreeBodyFrame::SetView(nsITreeView * aView) mView->SetTree(mTreeBoxObject); mView->GetRowCount(&mRowCount); - if (box) - box->SetPropertyAsSupports(view.get(), mView); - ScrollParts parts = GetScrollParts(); // The scrollbar will need to be updated. InvalidateScrollbars(parts); diff --git a/layout/xul/base/src/tree/src/nsTreeBoxObject.cpp b/layout/xul/base/src/tree/src/nsTreeBoxObject.cpp index 4f265479e7da..43e84c8779b0 100644 --- a/layout/xul/base/src/tree/src/nsTreeBoxObject.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBoxObject.cpp @@ -40,6 +40,9 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" +#include "nsIDOMXULElement.h" +#include "nsIXULTemplateBuilder.h" +#include "nsTreeContentView.h" #include "nsITreeView.h" #include "nsITreeSelection.h" #include "nsBoxObject.h" @@ -62,15 +65,13 @@ public: nsITreeBoxObject* GetTreeBody(); - // Override SetPropertyAsSupports for security check - NS_IMETHOD SetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports* aValue); - //NS_PIBOXOBJECT interfaces virtual void Clear(); virtual void ClearCachedValues(); protected: nsITreeBoxObject* mTreeBody; + nsCOMPtr mView; }; /* Implementation file */ @@ -83,19 +84,14 @@ nsTreeBoxObject::Clear() ClearCachedValues(); // Drop the view's ref to us. - NS_NAMED_LITERAL_STRING(viewString, "view"); - nsCOMPtr suppView; - GetPropertyAsSupports(viewString.get(), getter_AddRefs(suppView)); - nsCOMPtr treeView(do_QueryInterface(suppView)); - if (treeView) { + if (mView) { nsCOMPtr sel; - treeView->GetSelection(getter_AddRefs(sel)); + mView->GetSelection(getter_AddRefs(sel)); if (sel) sel->SetTree(nsnull); - treeView->SetTree(nsnull); // Break the circular ref between the view and us. + mView->SetTree(nsnull); // Break the circular ref between the view and us. } - - SetPropertyAsSupports(viewString.get(), nsnull); + mView = nsnull; nsBoxObject::Clear(); } @@ -165,9 +161,22 @@ nsTreeBoxObject::GetTreeBody() NS_IMETHODIMP nsTreeBoxObject::GetView(nsITreeView * *aView) { - nsITreeBoxObject* body = GetTreeBody(); - if (body) - return body->GetView(aView); + if (!mView && GetTreeBody()) { + nsCOMPtr xulele = do_QueryInterface(mContent); + if (xulele) { + // See if there is a XUL tree builder associated with the element + nsCOMPtr builder; + xulele->GetBuilder(getter_AddRefs(builder)); + if (builder) + mView = do_QueryInterface(builder); + else // No tree builder, create a tree content view. + NS_NewTreeContentView(getter_AddRefs(mView)); + NS_ENSURE_TRUE(mView, NS_ERROR_UNEXPECTED); + + mTreeBody->SetView(mView); + } + } + NS_IF_ADDREF(*aView = mView); return NS_OK; } @@ -185,40 +194,15 @@ CanTrustView(nsISupports* aValue) return PR_TRUE; } -NS_IMETHODIMP -nsTreeBoxObject::SetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports* aValue) -{ - NS_ENSURE_ARG(aPropertyName); - - if (nsDependentString(aPropertyName).EqualsLiteral("view") && - !CanTrustView(aValue)) - return NS_ERROR_DOM_SECURITY_ERR; - - return nsBoxObject::SetPropertyAsSupports(aPropertyName, aValue); -} - NS_IMETHODIMP nsTreeBoxObject::SetView(nsITreeView * aView) { if (!CanTrustView(aView)) return NS_ERROR_DOM_SECURITY_ERR; + mView = aView; nsITreeBoxObject* body = GetTreeBody(); - if (body) { + if (body) body->SetView(aView); - - // only return if the body frame was able to store the view, - // else we need to cache the property below - nsCOMPtr view; - body->GetView(getter_AddRefs(view)); - if (view) - return NS_OK; - } - - nsCOMPtr suppView(do_QueryInterface(aView)); - if (suppView) - SetPropertyAsSupports(NS_LITERAL_STRING("view").get(), suppView); - else - RemoveProperty(NS_LITERAL_STRING("view").get()); return NS_OK; } diff --git a/layout/xul/base/src/tree/src/nsTreeContentView.cpp b/layout/xul/base/src/tree/src/nsTreeContentView.cpp index f100191028fb..975ef21b8fce 100644 --- a/layout/xul/base/src/tree/src/nsTreeContentView.cpp +++ b/layout/xul/base/src/tree/src/nsTreeContentView.cpp @@ -150,7 +150,7 @@ nsTreeContentView::~nsTreeContentView(void) } nsresult -NS_NewTreeContentView(nsITreeContentView** aResult) +NS_NewTreeContentView(nsITreeView** aResult) { *aResult = new nsTreeContentView; if (! *aResult) diff --git a/layout/xul/base/src/tree/src/nsTreeContentView.h b/layout/xul/base/src/tree/src/nsTreeContentView.h index 76b817e6d642..90411a85c2d3 100644 --- a/layout/xul/base/src/tree/src/nsTreeContentView.h +++ b/layout/xul/base/src/tree/src/nsTreeContentView.h @@ -48,7 +48,7 @@ #include "nsITreeContentView.h" #include "nsITreeSelection.h" -nsresult NS_NewTreeContentView(nsITreeContentView** aResult); +nsresult NS_NewTreeContentView(nsITreeView** aResult); class nsTreeContentView : public nsINativeTreeView, public nsITreeContentView, @@ -59,8 +59,6 @@ class nsTreeContentView : public nsINativeTreeView, ~nsTreeContentView(void); - friend nsresult NS_NewTreeContentView(nsITreeContentView** aResult); - NS_DECL_ISUPPORTS NS_DECL_NSITREEVIEW