From c1ed351049b22c7c929d1ee339e3b7745a3ed0cc Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Sun, 29 Aug 1999 00:46:41 +0000 Subject: [PATCH] Big tree improvements. --- layout/xul/base/src/nsTreeCellFrame.h | 2 ++ layout/xul/base/src/nsTreeFrame.cpp | 39 +++++++++++++++++++++ layout/xul/base/src/nsTreeFrame.h | 5 +++ layout/xul/base/src/nsTreeRowGroupFrame.cpp | 39 +++++++++++---------- 4 files changed, 67 insertions(+), 18 deletions(-) diff --git a/layout/xul/base/src/nsTreeCellFrame.h b/layout/xul/base/src/nsTreeCellFrame.h index 5ac8c9b603f..7676d43161f 100644 --- a/layout/xul/base/src/nsTreeCellFrame.h +++ b/layout/xul/base/src/nsTreeCellFrame.h @@ -82,6 +82,8 @@ protected: PRBool CanResize(nsPoint& aPoint); + NS_IMETHOD DidSetStyleContext(nsIPresContext* aPresContext) { return NS_OK; }; + protected: // Data members PRBool mIsHeader; // Whether or not we're a column header diff --git a/layout/xul/base/src/nsTreeFrame.cpp b/layout/xul/base/src/nsTreeFrame.cpp index 6df691b4056..4379902aaf0 100644 --- a/layout/xul/base/src/nsTreeFrame.cpp +++ b/layout/xul/base/src/nsTreeFrame.cpp @@ -31,6 +31,10 @@ #include "nsIDOMNodeList.h" #include "nsIDOMXULTreeElement.h" #include "nsTreeTwistyListener.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsIReflowCommand.h" +#include "nsHTMLParts.h" // // NS_NewTreeFrame @@ -315,6 +319,41 @@ nsTreeFrame::Reflow(nsIPresContext& aPresContext, return rv; } +NS_IMETHODIMP +nsTreeFrame::DidReflow(nsIPresContext& aPresContext, + nsDidReflowStatus aStatus) +{ + nsresult rv = nsTableFrame::DidReflow(aPresContext, aStatus); + if (mNeedsDirtyReflow) { + mNeedsDirtyReflow = PR_FALSE; + InvalidateCellMap(); + InvalidateColumnCache(); + InvalidateFirstPassCache(); + nsCOMPtr shell; + aPresContext.GetShell(getter_AddRefs(shell)); + nsFrameState frameState; + nsIFrame* tableParentFrame; + nsIReflowCommand* reflowCmd; + + // Mark the table frame as dirty + GetFrameState(&frameState); + frameState |= NS_FRAME_IS_DIRTY; + SetFrameState(frameState); + + // Target the reflow comamnd at its parent frame + GetParent(&tableParentFrame); + rv = NS_NewHTMLReflowCommand(&reflowCmd, tableParentFrame, + nsIReflowCommand::ReflowDirty); + if (NS_SUCCEEDED(rv)) { + // Add the reflow command + rv = shell->AppendReflowCommand(reflowCmd); + NS_RELEASE(reflowCmd); + } + } + + return rv; +} + NS_IMETHODIMP nsTreeFrame::Init(nsIPresContext& aPresContext, nsIContent* aContent, diff --git a/layout/xul/base/src/nsTreeFrame.h b/layout/xul/base/src/nsTreeFrame.h index 25eafb2a90b..20312aa3ce6 100644 --- a/layout/xul/base/src/nsTreeFrame.h +++ b/layout/xul/base/src/nsTreeFrame.h @@ -62,6 +62,10 @@ public: nsIStyleContext* aContext, nsIFrame* aPrevInFlow); + NS_IMETHOD DidReflow(nsIPresContext& aPresContext, + nsDidReflowStatus aStatus); + + void WillNeedDirtyReflow() { mNeedsDirtyReflow = PR_TRUE; }; protected: nsTreeFrame(); @@ -70,5 +74,6 @@ protected: protected: // Data Members PRBool mSlatedForReflow; // If set, don't waste time scheduling excess reflows. nsTreeTwistyListener* mTwistyListener; + PRBool mNeedsDirtyReflow; }; // class nsTreeFrame diff --git a/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/layout/xul/base/src/nsTreeRowGroupFrame.cpp index fd955ebcc2a..8a12b823f6a 100644 --- a/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -711,6 +711,12 @@ nsTreeRowGroupFrame::ReflowAfterRowLayout(nsIPresContext& aPresContext, if (rowCount < 0) rowCount = 0; + // Our page size is the # of rows instantiated. + PRInt32 pageRowCount; + GetRowCount(pageRowCount); + + rowCount -= (pageRowCount-2); + char ch[100]; sprintf(ch,"%d", rowCount); @@ -840,8 +846,6 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext& aPresContext) return mTopFrame; } - - // We don't have a top frame instantiated. Let's // try to make one. @@ -863,19 +867,20 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext& aPresContext) mFrameConstructor->CreateTreeWidgetContent(&aPresContext, this, nsnull, startContent, &mTopFrame, isAppend, PR_FALSE); + + // XXX Can be optimized if we detect that we're appending a row. + // Also the act of appending or inserting a row group is harmless. + nsTableFrame* tableFrame; nsTableFrame::GetTableFrame(this, tableFrame); - //tableFrame->InvalidateCellMap(); - tableFrame->InvalidateColumnCache(); + nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame; + treeFrame->WillNeedDirtyReflow(); //printf("Created a frame\n"); mBottomFrame = mTopFrame; const nsStyleDisplay *rowDisplay; mTopFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)rowDisplay); - if (NS_STYLE_DISPLAY_TABLE_ROW==rowDisplay->mDisplay) { - ((nsTableRowFrame *)mTopFrame)->InitChildren(); - } - else if (NS_STYLE_DISPLAY_TABLE_ROW_GROUP==rowDisplay->mDisplay && mContentChain) { + if (NS_STYLE_DISPLAY_TABLE_ROW_GROUP==rowDisplay->mDisplay && mContentChain) { // We have just instantiated a row group, and we have a content chain. This // means we need to potentially pass a sub-content chain to the instantiated // frame, so that it can also sync up with its children. @@ -883,7 +888,7 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext& aPresContext) } SetContentChain(nsnull); - return mTopFrame; + //return mTopFrame; } return nsnull; @@ -937,17 +942,15 @@ nsTreeRowGroupFrame::GetNextFrameForReflow(nsIPresContext& aPresContext, nsIFram } mFrameConstructor->CreateTreeWidgetContent(&aPresContext, this, prevFrame, nextContent, aResult, isAppend, PR_FALSE); + + // XXX Can be optimized if we detect that we're appending a row to the end of the tree. + // Also the act of appending or inserting a row group is harmless. + nsTableFrame* tableFrame; nsTableFrame::GetTableFrame(this, tableFrame); - //tableFrame->InvalidateCellMap(); - tableFrame->InvalidateColumnCache(); - - //printf("Created a frame\n"); - const nsStyleDisplay *rowDisplay; - (*aResult)->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)rowDisplay); - if (NS_STYLE_DISPLAY_TABLE_ROW==rowDisplay->mDisplay) { - ((nsTableRowFrame *)(*aResult))->InitChildren(); - } + nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame; + treeFrame->WillNeedDirtyReflow(); + *aResult = nsnull; } }