From dba51b76a4cdb3f1305f7d395d6c5336dcbe3348 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Wed, 23 Jun 1999 09:07:59 +0000 Subject: [PATCH] More savory tree widget goodness. git-svn-id: svn://10.0.0.236/trunk@36547 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSFrameConstructor.cpp | 2 +- .../html/style/src/nsCSSFrameConstructor.cpp | 2 +- .../layout/html/table/src/nsTableFrame.cpp | 54 ++++++++------- .../html/table/src/nsTableRowGroupFrame.h | 6 +- mozilla/layout/tables/nsTableFrame.cpp | 54 ++++++++------- mozilla/layout/tables/nsTableRowGroupFrame.h | 6 +- .../xul/base/src/nsTreeRowGroupFrame.cpp | 68 +++++++++++++++++++ .../layout/xul/base/src/nsTreeRowGroupFrame.h | 20 ++++-- 8 files changed, 154 insertions(+), 58 deletions(-) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index e722450c5f1..3ab69d0bfc5 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -3027,7 +3027,7 @@ nsCSSFrameConstructor::CreateAnonymousXULContent(nsIPresContext* aPresContext, nsCOMPtr content = do_QueryInterface(node); content->SetParent(aContent); - + nsCOMPtr vertical = dont_AddRef(NS_NewAtom("align")); nsCOMPtr style = dont_AddRef(NS_NewAtom("style")); diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index e722450c5f1..3ab69d0bfc5 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -3027,7 +3027,7 @@ nsCSSFrameConstructor::CreateAnonymousXULContent(nsIPresContext* aPresContext, nsCOMPtr content = do_QueryInterface(node); content->SetParent(aContent); - + nsCOMPtr vertical = dont_AddRef(NS_NewAtom("align")); nsCOMPtr style = dont_AddRef(NS_NewAtom("style")); diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 847ecec0b1b..efb250ad96c 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -4205,8 +4205,8 @@ void nsTableFrame::DistributeSpaceToCells(nsIPresContext& aPresContext, nsIFrame* aRowGroupFrame) { // now that all of the rows have been resized, resize the cells - nsTableIterator iter2(*aRowGroupFrame, eTableLTR); - nsIFrame* rowFrame = iter2.First(); + nsTableRowGroupFrame* rowGroupFrame = (nsTableRowGroupFrame*)aRowGroupFrame; + nsIFrame * rowFrame = rowGroupFrame->GetFirstFrame(); while (nsnull!=rowFrame) { const nsStyleDisplay *rowDisplay; rowFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)rowDisplay)); @@ -4216,7 +4216,7 @@ void nsTableFrame::DistributeSpaceToCells(nsIPresContext& aPresContext, // The calling function, DistributeSpaceToRows, takes care of the recursive row // group descent, which is why there's no NS_STYLE_DISPLAY_TABLE_ROW_GROUP case // here. - rowFrame = iter2.Next(); + rowGroupFrame->GetNextFrame(rowFrame, &rowFrame); } } @@ -4229,9 +4229,8 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, { // the rows in rowGroupFrame need to be expanded by rowHeightDelta[i] // and the rowgroup itself needs to be expanded by SUM(row height deltas) - nsIFrame * rowFrame=nsnull; - nsTableIterator iter(*aRowGroupFrame, eTableLTR); - rowFrame = iter.First(); + nsTableRowGroupFrame* rowGroupFrame = (nsTableRowGroupFrame*)aRowGroupFrame; + nsIFrame * rowFrame = rowGroupFrame->GetFirstFrame(); nscoord y = 0; while (nsnull!=rowFrame) { @@ -4247,19 +4246,23 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, rowFrame->GetRect(rowRect); float percent = ((float)(rowRect.height)) / ((float)(aSumOfRowHeights)); nscoord excessForRow = NSToCoordRound((float)aExcess*percent); - nsRect newRowRect(rowRect.x, y, rowRect.width, excessForRow+rowRect.height); - rowFrame->SetRect(newRowRect); - if (NS_STYLE_BORDER_COLLAPSE==aTableStyle->mBorderCollapse) - { - nsBorderEdge *border = (nsBorderEdge *) - (mBorderEdges.mEdges[NS_SIDE_LEFT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); - border->mLength=newRowRect.height; - border = (nsBorderEdge *) - (mBorderEdges.mEdges[NS_SIDE_RIGHT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); - border->mLength=newRowRect.height; + + if (rowGroupFrame->RowsDesireExcessSpace()) { + nsRect newRowRect(rowRect.x, y, rowRect.width, excessForRow+rowRect.height); + rowFrame->SetRect(newRowRect); + if (NS_STYLE_BORDER_COLLAPSE==aTableStyle->mBorderCollapse) + { + nsBorderEdge *border = (nsBorderEdge *) + (mBorderEdges.mEdges[NS_SIDE_LEFT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); + border->mLength=newRowRect.height; + border = (nsBorderEdge *) + (mBorderEdges.mEdges[NS_SIDE_RIGHT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); + border->mLength=newRowRect.height; + } + // better if this were part of an overloaded row::SetRect + y += excessForRow+rowRect.height; } - // better if this were part of an overloaded row::SetRect - y += excessForRow+rowRect.height; + aExcessForRowGroup += excessForRow; } else @@ -4269,14 +4272,17 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, y += rowRect.height; } - rowFrame = iter.Next(); + rowGroupFrame->GetNextFrame(rowFrame, &rowFrame); } - nsRect rowGroupRect; - aRowGroupFrame->GetRect(rowGroupRect); - nsRect newRowGroupRect(rowGroupRect.x, aRowGroupYPos, rowGroupRect.width, aExcessForRowGroup+rowGroupRect.height); - aRowGroupFrame->SetRect(newRowGroupRect); - aRowGroupYPos += aExcessForRowGroup + rowGroupRect.height; + nsRect rowGroupRect; + aRowGroupFrame->GetRect(rowGroupRect); + if (rowGroupFrame->RowGroupDesiresExcessSpace()) { + nsRect newRowGroupRect(rowGroupRect.x, aRowGroupYPos, rowGroupRect.width, aExcessForRowGroup+rowGroupRect.height); + aRowGroupFrame->SetRect(newRowGroupRect); + aRowGroupYPos += aExcessForRowGroup + rowGroupRect.height; + } + else aRowGroupYPos += rowGroupRect.height; DistributeSpaceToCells(aPresContext, aReflowState, aRowGroupFrame); } diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.h b/mozilla/layout/html/table/src/nsTableRowGroupFrame.h index 7ea60d0c985..c95ae5909b4 100644 --- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.h +++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.h @@ -298,10 +298,14 @@ protected: virtual PRBool ExcludeFrameFromReflow(nsIFrame* aFrame) { return PR_FALSE; }; virtual nsIFrame* GetFirstFrameForReflow(nsIPresContext& aPresContext) { return mFrames.FirstChild(); }; virtual void GetNextFrameForReflow(nsIPresContext& aPresContext, nsIFrame* aFrame, nsIFrame** aResult) { aFrame->GetNextSibling(aResult); }; + void GetNextRowSibling(nsIFrame** aRowFrame); + +public: virtual nsIFrame* GetFirstFrame() { return mFrames.FirstChild(); }; virtual nsIFrame* GetLastFrame() { return mFrames.LastChild(); }; virtual void GetNextFrame(nsIFrame* aFrame, nsIFrame** aResult) { aFrame->GetNextSibling(aResult); }; - void GetNextRowSibling(nsIFrame** aRowFrame); + virtual PRBool RowsDesireExcessSpace() { return PR_TRUE; }; + virtual PRBool RowGroupDesiresExcessSpace() { return PR_TRUE; }; private: nsIAtom *mType; diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 847ecec0b1b..efb250ad96c 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -4205,8 +4205,8 @@ void nsTableFrame::DistributeSpaceToCells(nsIPresContext& aPresContext, nsIFrame* aRowGroupFrame) { // now that all of the rows have been resized, resize the cells - nsTableIterator iter2(*aRowGroupFrame, eTableLTR); - nsIFrame* rowFrame = iter2.First(); + nsTableRowGroupFrame* rowGroupFrame = (nsTableRowGroupFrame*)aRowGroupFrame; + nsIFrame * rowFrame = rowGroupFrame->GetFirstFrame(); while (nsnull!=rowFrame) { const nsStyleDisplay *rowDisplay; rowFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)rowDisplay)); @@ -4216,7 +4216,7 @@ void nsTableFrame::DistributeSpaceToCells(nsIPresContext& aPresContext, // The calling function, DistributeSpaceToRows, takes care of the recursive row // group descent, which is why there's no NS_STYLE_DISPLAY_TABLE_ROW_GROUP case // here. - rowFrame = iter2.Next(); + rowGroupFrame->GetNextFrame(rowFrame, &rowFrame); } } @@ -4229,9 +4229,8 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, { // the rows in rowGroupFrame need to be expanded by rowHeightDelta[i] // and the rowgroup itself needs to be expanded by SUM(row height deltas) - nsIFrame * rowFrame=nsnull; - nsTableIterator iter(*aRowGroupFrame, eTableLTR); - rowFrame = iter.First(); + nsTableRowGroupFrame* rowGroupFrame = (nsTableRowGroupFrame*)aRowGroupFrame; + nsIFrame * rowFrame = rowGroupFrame->GetFirstFrame(); nscoord y = 0; while (nsnull!=rowFrame) { @@ -4247,19 +4246,23 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, rowFrame->GetRect(rowRect); float percent = ((float)(rowRect.height)) / ((float)(aSumOfRowHeights)); nscoord excessForRow = NSToCoordRound((float)aExcess*percent); - nsRect newRowRect(rowRect.x, y, rowRect.width, excessForRow+rowRect.height); - rowFrame->SetRect(newRowRect); - if (NS_STYLE_BORDER_COLLAPSE==aTableStyle->mBorderCollapse) - { - nsBorderEdge *border = (nsBorderEdge *) - (mBorderEdges.mEdges[NS_SIDE_LEFT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); - border->mLength=newRowRect.height; - border = (nsBorderEdge *) - (mBorderEdges.mEdges[NS_SIDE_RIGHT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); - border->mLength=newRowRect.height; + + if (rowGroupFrame->RowsDesireExcessSpace()) { + nsRect newRowRect(rowRect.x, y, rowRect.width, excessForRow+rowRect.height); + rowFrame->SetRect(newRowRect); + if (NS_STYLE_BORDER_COLLAPSE==aTableStyle->mBorderCollapse) + { + nsBorderEdge *border = (nsBorderEdge *) + (mBorderEdges.mEdges[NS_SIDE_LEFT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); + border->mLength=newRowRect.height; + border = (nsBorderEdge *) + (mBorderEdges.mEdges[NS_SIDE_RIGHT].ElementAt(((nsTableRowFrame*)rowFrame)->GetRowIndex())); + border->mLength=newRowRect.height; + } + // better if this were part of an overloaded row::SetRect + y += excessForRow+rowRect.height; } - // better if this were part of an overloaded row::SetRect - y += excessForRow+rowRect.height; + aExcessForRowGroup += excessForRow; } else @@ -4269,14 +4272,17 @@ void nsTableFrame::DistributeSpaceToRows(nsIPresContext& aPresContext, y += rowRect.height; } - rowFrame = iter.Next(); + rowGroupFrame->GetNextFrame(rowFrame, &rowFrame); } - nsRect rowGroupRect; - aRowGroupFrame->GetRect(rowGroupRect); - nsRect newRowGroupRect(rowGroupRect.x, aRowGroupYPos, rowGroupRect.width, aExcessForRowGroup+rowGroupRect.height); - aRowGroupFrame->SetRect(newRowGroupRect); - aRowGroupYPos += aExcessForRowGroup + rowGroupRect.height; + nsRect rowGroupRect; + aRowGroupFrame->GetRect(rowGroupRect); + if (rowGroupFrame->RowGroupDesiresExcessSpace()) { + nsRect newRowGroupRect(rowGroupRect.x, aRowGroupYPos, rowGroupRect.width, aExcessForRowGroup+rowGroupRect.height); + aRowGroupFrame->SetRect(newRowGroupRect); + aRowGroupYPos += aExcessForRowGroup + rowGroupRect.height; + } + else aRowGroupYPos += rowGroupRect.height; DistributeSpaceToCells(aPresContext, aReflowState, aRowGroupFrame); } diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.h b/mozilla/layout/tables/nsTableRowGroupFrame.h index 7ea60d0c985..c95ae5909b4 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.h +++ b/mozilla/layout/tables/nsTableRowGroupFrame.h @@ -298,10 +298,14 @@ protected: virtual PRBool ExcludeFrameFromReflow(nsIFrame* aFrame) { return PR_FALSE; }; virtual nsIFrame* GetFirstFrameForReflow(nsIPresContext& aPresContext) { return mFrames.FirstChild(); }; virtual void GetNextFrameForReflow(nsIPresContext& aPresContext, nsIFrame* aFrame, nsIFrame** aResult) { aFrame->GetNextSibling(aResult); }; + void GetNextRowSibling(nsIFrame** aRowFrame); + +public: virtual nsIFrame* GetFirstFrame() { return mFrames.FirstChild(); }; virtual nsIFrame* GetLastFrame() { return mFrames.LastChild(); }; virtual void GetNextFrame(nsIFrame* aFrame, nsIFrame** aResult) { aFrame->GetNextSibling(aResult); }; - void GetNextRowSibling(nsIFrame** aRowFrame); + virtual PRBool RowsDesireExcessSpace() { return PR_TRUE; }; + virtual PRBool RowGroupDesiresExcessSpace() { return PR_TRUE; }; private: nsIAtom *mType; diff --git a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp index b2e8a1f00e3..db09cdb47b0 100644 --- a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -65,6 +65,74 @@ nsTreeRowGroupFrame::~nsTreeRowGroupFrame() { } +PRBool nsTreeRowGroupFrame::RowGroupDesiresExcessSpace() +{ + nsIFrame* parentFrame; + GetParent(&parentFrame); + const nsStyleDisplay *display; + parentFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display)); + if (display->mDisplay == NS_STYLE_DISPLAY_TABLE_ROW_GROUP) + return PR_FALSE; // Nested groups don't grow. + else return PR_TRUE; // The outermost group can grow. +} + +PRBool nsTreeRowGroupFrame::RowGroupReceivesExcessSpace() +{ + const nsStyleDisplay *display; + GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display)); + if (NS_STYLE_DISPLAY_TABLE_ROW_GROUP == display->mDisplay) + return PR_TRUE; + else return PR_FALSE; // Headers and footers don't get excess space. +} + +NS_IMETHODIMP +nsTreeRowGroupFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame) +{ + nsPoint tmp; + nsRect kidRect; + if (mScrollbar) { + mScrollbar->GetRect(kidRect); + if (kidRect.Contains(aPoint)) { + tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); + return mScrollbar->GetFrameForPoint(tmp, aFrame); + } + } + + return nsTableRowGroupFrame::GetFrameForPoint(aPoint, aFrame); +} + +void nsTreeRowGroupFrame::PaintChildren(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer) +{ + nsTableRowGroupFrame::PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + + if (mScrollbar) { + nsIView *pView; + + mScrollbar->GetView(&pView); + if (nsnull == pView) { + PRBool clipState; + nsRect kidRect; + mScrollbar->GetRect(kidRect); + nsRect damageArea(aDirtyRect); + // Translate damage area into kid's coordinate system + nsRect kidDamageArea(damageArea.x - kidRect.x, damageArea.y - kidRect.y, + damageArea.width, damageArea.height); + aRenderingContext.PushState(); + aRenderingContext.Translate(kidRect.x, kidRect.y); + mScrollbar->Paint(aPresContext, aRenderingContext, kidDamageArea, aWhichLayer); + if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && + GetShowFrameBorders()) { + aRenderingContext.SetColor(NS_RGB(255,0,0)); + aRenderingContext.DrawRect(0, 0, kidRect.width, kidRect.height); + } + aRenderingContext.PopState(clipState); + } + } +} + NS_IMETHODIMP nsTreeRowGroupFrame::ReflowBeforeRowLayout(nsIPresContext& aPresContext, nsHTMLReflowMetrics& aDesiredSize, diff --git a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h index 8bdd0c2b6a9..66ceb99c3c5 100644 --- a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h +++ b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h @@ -41,6 +41,12 @@ public: NS_IMETHOD TreeInsertFrames(nsIFrame* aPrevFrame, nsIFrame* aFrameList); + NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame); + void PaintChildren(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer); + PRBool ContinueReflow(nscoord y, nscoord height); PRBool IsFull() { return mIsFull; }; @@ -48,12 +54,18 @@ public: // Responses to changes void OnContentAdded(nsIPresContext& aPresContext); + virtual nsIFrame* GetFirstFrame(); + virtual nsIFrame* GetLastFrame(); + virtual void GetNextFrame(nsIFrame* aFrame, nsIFrame** aResult); + virtual PRBool RowsDesireExcessSpace() { return PR_FALSE; }; + virtual PRBool RowGroupDesiresExcessSpace(); + protected: nsTreeRowGroupFrame(); virtual ~nsTreeRowGroupFrame(); - virtual PRBool RowGroupReceivesExcessSpace() { return PR_FALSE; }; - + virtual PRBool RowGroupReceivesExcessSpace(); + NS_IMETHOD ReflowBeforeRowLayout(nsIPresContext& aPresContext, nsHTMLReflowMetrics& aDesiredSize, RowGroupReflowState& aReflowState, @@ -63,10 +75,6 @@ protected: virtual nsIFrame* GetFirstFrameForReflow(nsIPresContext& aPresContext); virtual void GetNextFrameForReflow(nsIPresContext& aPresContext, nsIFrame* aFrame, nsIFrame** aResult); - virtual nsIFrame* GetFirstFrame(); - virtual nsIFrame* GetLastFrame(); - virtual void GetNextFrame(nsIFrame* aFrame, nsIFrame** aResult); - void LocateFrame(nsIFrame* aStartFrame, nsIFrame** aResult); protected: // Data Members