Store the tree view as a member rather than a property b=344085 r+sr=roc

This commit is contained in:
neil%parkwaycc.co.uk 2006-07-28 19:57:15 +00:00
parent bc458f05fe
commit 362b2ca581
4 changed files with 30 additions and 89 deletions

View File

@ -374,11 +374,8 @@ nsTreeBodyFrame::EnsureView()
EnsureBoxObject();
nsCOMPtr<nsIBoxObject> box = do_QueryInterface(mTreeBoxObject);
if (box) {
nsCOMPtr<nsISupports> suppView;
box->GetPropertyAsSupports(NS_LITERAL_STRING("view").get(),
getter_AddRefs(suppView));
nsCOMPtr<nsITreeView> treeView(do_QueryInterface(suppView));
nsCOMPtr<nsITreeView> 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<nsIDOMXULElement> xulele = do_QueryInterface(mContent->GetParent());
if (xulele) {
nsCOMPtr<nsITreeView> view;
// See if there is a XUL tree builder associated with
// the parent element.
nsCOMPtr<nsIXULTemplateBuilder> builder;
xulele->GetBuilder(getter_AddRefs(builder));
if (builder)
view = do_QueryInterface(builder);
if (!view) {
// No tree builder, create a tree content view.
nsCOMPtr<nsITreeContentView> 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<nsIBoxObject> box = do_QueryInterface(mTreeBoxObject);
NS_NAMED_LITERAL_STRING(view, "view");
if (mView) {
nsCOMPtr<nsITreeSelection> 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);

View File

@ -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<nsITreeView> mView;
};
/* Implementation file */
@ -83,19 +84,14 @@ nsTreeBoxObject::Clear()
ClearCachedValues();
// Drop the view's ref to us.
NS_NAMED_LITERAL_STRING(viewString, "view");
nsCOMPtr<nsISupports> suppView;
GetPropertyAsSupports(viewString.get(), getter_AddRefs(suppView));
nsCOMPtr<nsITreeView> treeView(do_QueryInterface(suppView));
if (treeView) {
if (mView) {
nsCOMPtr<nsITreeSelection> 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<nsIDOMXULElement> xulele = do_QueryInterface(mContent);
if (xulele) {
// See if there is a XUL tree builder associated with the element
nsCOMPtr<nsIXULTemplateBuilder> 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<nsITreeView> view;
body->GetView(getter_AddRefs(view));
if (view)
return NS_OK;
}
nsCOMPtr<nsISupports> suppView(do_QueryInterface(aView));
if (suppView)
SetPropertyAsSupports(NS_LITERAL_STRING("view").get(), suppView);
else
RemoveProperty(NS_LITERAL_STRING("view").get());
return NS_OK;
}

View File

@ -150,7 +150,7 @@ nsTreeContentView::~nsTreeContentView(void)
}
nsresult
NS_NewTreeContentView(nsITreeContentView** aResult)
NS_NewTreeContentView(nsITreeView** aResult)
{
*aResult = new nsTreeContentView;
if (! *aResult)

View File

@ -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