From 7e9d6c54cd989ec72d760b0938843d33c81dc835 Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Wed, 16 Dec 1998 17:05:14 +0000 Subject: [PATCH] WIP on collapsing borders git-svn-id: svn://10.0.0.236/trunk@16519 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/table/src/nsTableCellFrame.cpp | 46 +--------- .../layout/html/table/src/nsTableCellFrame.h | 2 - .../layout/html/table/src/nsTableFrame.cpp | 86 ++++++++++++++++--- mozilla/layout/html/table/src/nsTableFrame.h | 6 +- mozilla/layout/tables/nsTableCellFrame.cpp | 46 +--------- mozilla/layout/tables/nsTableCellFrame.h | 2 - mozilla/layout/tables/nsTableFrame.cpp | 86 ++++++++++++++++--- mozilla/layout/tables/nsTableFrame.h | 6 +- 8 files changed, 158 insertions(+), 122 deletions(-) diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 3e6a773072e..548245b17ef 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -68,12 +68,6 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, rect, *myColor, 0, 0); - //XXX: this could be calculated once and remembered - // get border padding values - //XXX: also check style for rule on rendering empty cells - /* - - */ // empty cells do not render their border PRBool renderBorder = PR_TRUE; if (PR_TRUE==GetContentEmpty()) @@ -729,45 +723,6 @@ nscoord nsTableCellFrame::GetBorderWidth(nsIFrame* aFrame, PRUint8 aEdge) const } -/** - * Given a style context and an edge, find the padding - * - **/ -nscoord nsTableCellFrame::GetPadding(nsIFrame* aFrame, PRUint8 aEdge) const -{ - nscoord result = 0; - - if (aFrame) - { - const nsStyleSpacing* spacing; - aFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)spacing); - nsMargin padding; - spacing->CalcPaddingFor(aFrame, padding); - switch (aEdge) - { - case NS_SIDE_TOP: - result = padding.top; - break; - - case NS_SIDE_RIGHT: - result = padding.right; - break; - - case NS_SIDE_BOTTOM: - result = padding.bottom; - break; - - case NS_SIDE_LEFT: - result = padding.left; - break; - - } - } - return result; -} - - - /** * Given an Edge, find the opposing edge (top<-->bottom, left<-->right) * @@ -876,6 +831,7 @@ void nsTableCellFrame::RecalcLayoutData(nsTableFrame* aTableFrame, mCalculated = NS_OK; } + /* ----- debugging methods ----- */ NS_METHOD nsTableCellFrame::List(FILE* out, PRInt32 aIndent, nsIListFilter *aFilter) const { diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h index 6bd3e74f288..dce0738f811 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.h +++ b/mozilla/layout/html/table/src/nsTableCellFrame.h @@ -137,8 +137,6 @@ private: nscoord GetBorderWidth(nsIFrame* aFrame, PRUint8 aEdge) const; - nscoord GetPadding(nsIFrame* aFrame, PRUint8 aEdge) const; - PRUint8 GetOpposingEdge(PRUint8 aEdge); void CalculateBorders(nsTableFrame* aTableFrame, diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index fbc069f03d4..51338353afd 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -1178,7 +1178,9 @@ void nsTableFrame::AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTable } } -void nsTableFrame::RecalcLayoutData() +/* compute all the collapsed borders between aStartRowIndex and aEndRowIndex, inclusive */ +void nsTableFrame::ComputeCollapsingBorders(PRInt32 aStartRowIndex, + PRInt32 aEndRowIndex) { nsCellMap *cellMap = GetCellMap(); if (nsnull==cellMap) @@ -1186,6 +1188,77 @@ void nsTableFrame::RecalcLayoutData() PRInt32 colCount = cellMap->GetColCount(); PRInt32 rowCount = cellMap->GetRowCount(); + if (aStartRowIndex>=rowCount) + { + NS_ASSERTION(PR_FALSE, "aStartRowIndex>=rowCount in ComputeCollapsingBorders"); + return; // we don't have the requested row yet + } + + // For every row between aStartRowIndex and aEndRowIndex (or the end of the table), + // walk across every edge and compute the border at that edge. + // Distribute half the computed border to the appropriate adjacent objects + // (always a cell frame or the table frame.) In the case of odd width, + // the object on the right/bottom gets the extra portion + PRInt32 rowIndex = aStartRowIndex; + for ( ; rowIndexGetColCount(); + PRInt32 rowCount = cellMap->GetRowCount(); + + // compute all the collapsing border values for the entire table + // XXX: it would be nice to make this incremental! + const nsStyleTable *tableStyle=nsnull; + GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); + if (NS_STYLE_BORDER_COLLAPSE==tableStyle->mBorderCollapse) + ComputeCollapsingBorders(0, rowCount-1); + + //XXX need to determine how much of what follows is really necessary + // it does collapsing margins between table elements PRInt32 row = 0; PRInt32 col = 0; @@ -3591,17 +3664,6 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext& aPresContext) } - - -// Subclass hook for style post processing -NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext& aPresContext) -{ -#ifdef NOISY_STYLE - printf("nsTableFrame::DidSetStyleContext \n"); -#endif - return NS_OK; -} - NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin& aMargin) { nsresult result = NS_ERROR_NOT_INITIALIZED; diff --git a/mozilla/layout/html/table/src/nsTableFrame.h b/mozilla/layout/html/table/src/nsTableFrame.h index 9c6b10ef4ef..32fbc182b63 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.h +++ b/mozilla/layout/html/table/src/nsTableFrame.h @@ -207,6 +207,10 @@ public: /** Calculate Layout Information */ void AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTableCell); + + /* compute all the collapsed borders between aStartRowIndex and aEndRowIndex, inclusive */ + void ComputeCollapsingBorders(PRInt32 aStartRowIndex, PRInt32 aEndRowIndex); + void RecalcLayoutData(); // Get cell margin information @@ -473,8 +477,6 @@ public: virtual void InvalidateColumnWidths(); protected: - /** do post processing to setting up style information for the frame */ - NS_IMETHOD DidSetStyleContext(nsIPresContext& aPresContext); /** Support methods for DidSetStyleContext */ void MapBorderMarginPadding(nsIPresContext& aPresContext); diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 3e6a773072e..548245b17ef 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -68,12 +68,6 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, rect, *myColor, 0, 0); - //XXX: this could be calculated once and remembered - // get border padding values - //XXX: also check style for rule on rendering empty cells - /* - - */ // empty cells do not render their border PRBool renderBorder = PR_TRUE; if (PR_TRUE==GetContentEmpty()) @@ -729,45 +723,6 @@ nscoord nsTableCellFrame::GetBorderWidth(nsIFrame* aFrame, PRUint8 aEdge) const } -/** - * Given a style context and an edge, find the padding - * - **/ -nscoord nsTableCellFrame::GetPadding(nsIFrame* aFrame, PRUint8 aEdge) const -{ - nscoord result = 0; - - if (aFrame) - { - const nsStyleSpacing* spacing; - aFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)spacing); - nsMargin padding; - spacing->CalcPaddingFor(aFrame, padding); - switch (aEdge) - { - case NS_SIDE_TOP: - result = padding.top; - break; - - case NS_SIDE_RIGHT: - result = padding.right; - break; - - case NS_SIDE_BOTTOM: - result = padding.bottom; - break; - - case NS_SIDE_LEFT: - result = padding.left; - break; - - } - } - return result; -} - - - /** * Given an Edge, find the opposing edge (top<-->bottom, left<-->right) * @@ -876,6 +831,7 @@ void nsTableCellFrame::RecalcLayoutData(nsTableFrame* aTableFrame, mCalculated = NS_OK; } + /* ----- debugging methods ----- */ NS_METHOD nsTableCellFrame::List(FILE* out, PRInt32 aIndent, nsIListFilter *aFilter) const { diff --git a/mozilla/layout/tables/nsTableCellFrame.h b/mozilla/layout/tables/nsTableCellFrame.h index 6bd3e74f288..dce0738f811 100644 --- a/mozilla/layout/tables/nsTableCellFrame.h +++ b/mozilla/layout/tables/nsTableCellFrame.h @@ -137,8 +137,6 @@ private: nscoord GetBorderWidth(nsIFrame* aFrame, PRUint8 aEdge) const; - nscoord GetPadding(nsIFrame* aFrame, PRUint8 aEdge) const; - PRUint8 GetOpposingEdge(PRUint8 aEdge); void CalculateBorders(nsTableFrame* aTableFrame, diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index fbc069f03d4..51338353afd 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -1178,7 +1178,9 @@ void nsTableFrame::AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTable } } -void nsTableFrame::RecalcLayoutData() +/* compute all the collapsed borders between aStartRowIndex and aEndRowIndex, inclusive */ +void nsTableFrame::ComputeCollapsingBorders(PRInt32 aStartRowIndex, + PRInt32 aEndRowIndex) { nsCellMap *cellMap = GetCellMap(); if (nsnull==cellMap) @@ -1186,6 +1188,77 @@ void nsTableFrame::RecalcLayoutData() PRInt32 colCount = cellMap->GetColCount(); PRInt32 rowCount = cellMap->GetRowCount(); + if (aStartRowIndex>=rowCount) + { + NS_ASSERTION(PR_FALSE, "aStartRowIndex>=rowCount in ComputeCollapsingBorders"); + return; // we don't have the requested row yet + } + + // For every row between aStartRowIndex and aEndRowIndex (or the end of the table), + // walk across every edge and compute the border at that edge. + // Distribute half the computed border to the appropriate adjacent objects + // (always a cell frame or the table frame.) In the case of odd width, + // the object on the right/bottom gets the extra portion + PRInt32 rowIndex = aStartRowIndex; + for ( ; rowIndexGetColCount(); + PRInt32 rowCount = cellMap->GetRowCount(); + + // compute all the collapsing border values for the entire table + // XXX: it would be nice to make this incremental! + const nsStyleTable *tableStyle=nsnull; + GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); + if (NS_STYLE_BORDER_COLLAPSE==tableStyle->mBorderCollapse) + ComputeCollapsingBorders(0, rowCount-1); + + //XXX need to determine how much of what follows is really necessary + // it does collapsing margins between table elements PRInt32 row = 0; PRInt32 col = 0; @@ -3591,17 +3664,6 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext& aPresContext) } - - -// Subclass hook for style post processing -NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext& aPresContext) -{ -#ifdef NOISY_STYLE - printf("nsTableFrame::DidSetStyleContext \n"); -#endif - return NS_OK; -} - NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin& aMargin) { nsresult result = NS_ERROR_NOT_INITIALIZED; diff --git a/mozilla/layout/tables/nsTableFrame.h b/mozilla/layout/tables/nsTableFrame.h index 9c6b10ef4ef..32fbc182b63 100644 --- a/mozilla/layout/tables/nsTableFrame.h +++ b/mozilla/layout/tables/nsTableFrame.h @@ -207,6 +207,10 @@ public: /** Calculate Layout Information */ void AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTableCell); + + /* compute all the collapsed borders between aStartRowIndex and aEndRowIndex, inclusive */ + void ComputeCollapsingBorders(PRInt32 aStartRowIndex, PRInt32 aEndRowIndex); + void RecalcLayoutData(); // Get cell margin information @@ -473,8 +477,6 @@ public: virtual void InvalidateColumnWidths(); protected: - /** do post processing to setting up style information for the frame */ - NS_IMETHOD DidSetStyleContext(nsIPresContext& aPresContext); /** Support methods for DidSetStyleContext */ void MapBorderMarginPadding(nsIPresContext& aPresContext);