diff --git a/mozilla/layout/html/table/src/nsTableCell.cpp b/mozilla/layout/html/table/src/nsTableCell.cpp index 3ab50d58f20..60405ae1878 100644 --- a/mozilla/layout/html/table/src/nsTableCell.cpp +++ b/mozilla/layout/html/table/src/nsTableCell.cpp @@ -36,13 +36,14 @@ static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLETEXT_SID); static NS_DEFINE_IID(kStyleBorderSID, NS_STYLETEXT_SID); #ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; +static PRBool gsDebug = PR_TRUE; static PRBool gsNoisyRefs = PR_FALSE; #else static const PRBool gsDebug = PR_FALSE; static const PRBool gsNoisyRefs = PR_FALSE; #endif +// nsTableContent checks aTag nsTableCell::nsTableCell(nsIAtom* aTag) : nsTableContent(aTag), mRow(0), @@ -63,6 +64,7 @@ nsTableCell::nsTableCell(PRBool aImplicit) mImplicit = aImplicit; } +// nsTableContent checks aTag nsTableCell::nsTableCell (nsIAtom* aTag, int aRowSpan, int aColSpan) : nsTableContent(aTag), mRow(0), @@ -80,12 +82,14 @@ nsTableCell::~nsTableCell() NS_IF_RELEASE(mRow); } +// for debugging only nsrefcnt nsTableCell::AddRef(void) { if (gsNoisyRefs) printf("Add Ref: %x, nsTableCell cnt = %d \n",this, mRefCnt+1); return ++mRefCnt; } +// for debugging only nsrefcnt nsTableCell::Release(void) { if (gsNoisyRefs==PR_TRUE) printf("Release: %x, nsTableCell cnt = %d \n",this, mRefCnt-1); @@ -129,11 +133,13 @@ void nsTableCell::SetRow (nsTableRow * aRow) int nsTableCell::GetColIndex () { + NS_ASSERTION(0<=mColIndex, "bad column index"); return mColIndex; } void nsTableCell::SetColIndex (int aColIndex) { + NS_ASSERTION(0<=aColIndex, "illegal negative column index."); mColIndex = aColIndex; } @@ -151,6 +157,7 @@ nsIFrame* nsTableCell::CreateFrame(nsIPresContext* aPresContext, void nsTableCell::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) { + NS_PRECONDITION(nsnull!=aAttribute, "bad attribute arg"); nsHTMLValue val; if ((aAttribute == nsHTMLAtoms::align) && ParseDivAlignParam(aValue, val)) { @@ -277,6 +284,9 @@ void nsTableCell::MapBorderMarginPaddingInto(nsIStyleContext* aContext, void nsTableCell::MapAttributesInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) { + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + nsHTMLValue value; // align: enum diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 4d90bd1475f..4925281e2ca 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -66,9 +66,14 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); + nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myBorder, 0); - + /* + printf("painting borders, size = %d %d %d %d\n", + myBorder->mSize.left, myBorder->mSize.top, + myBorder->mSize.right, myBorder->mSize.bottom); + */ // for debug... if (nsIFrame::GetShowFrameBorders()) { diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index d8e5c25ddcd..2efa9daef97 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -39,7 +39,7 @@ #ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; +static PRBool gsDebug = PR_TRUE; static PRBool gsDebugCLD = PR_FALSE; static PRBool gsTiming = PR_FALSE; static PRBool gsDebugMBP = PR_FALSE; @@ -135,6 +135,26 @@ struct InnerTableReflowState { +/* ----------- SpanInfo ---------- */ + +struct SpanInfo +{ + PRInt32 span; + PRInt32 cellMinWidth; + PRInt32 cellDesiredWidth; + + SpanInfo(PRInt32 aSpan, PRInt32 aMinWidth, PRInt32 aDesiredWidth) + { + span = aSpan; + cellMinWidth = aMinWidth; + cellDesiredWidth = aDesiredWidth; + }; + + ~SpanInfo() {}; +}; + + + /* ----------- nsTableFrame ---------- */ @@ -1623,6 +1643,7 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, NS_ASSERTION(nsnull==mPrevInFlow, "never ever call me on a continuing frame!"); if (gsDebug==PR_TRUE) printf (" AssignFixedColumnWidths\n"); + nsVoidArray *spanList=nsnull; for (PRInt32 colIndex = 0; colIndexCount(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } + for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); @@ -1675,8 +1722,10 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, nsSize * cellMinSize = data->GetMaxElementSize(); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); if (gsDebug==PR_TRUE) - printf (" for cell %d min = %d,%d and des = %d,%d\n", cellIndex, cellMinSize->width, cellMinSize->height, + printf (" for cell %d with colspan=%d, min = %d,%d and des = %d,%d\n", + cellIndex, colSpan, cellMinSize->width, cellMinSize->height, cellDesiredSize->width, cellDesiredSize->height); PRBool haveCellWidth = PR_FALSE; @@ -1750,23 +1799,24 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, // regardless of the width specification, keep track of the // min/max column widths - /* TODO: must distribute COLSPAN'd cell widths between columns, - * either here or in the subsequent Balance***ColumnWidth - * routines - */ - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; + if (1AppendElement(spanInfo); + } if (gsDebug) { printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); } - /* take colspan into account? */ - /* - PRInt32 colSpan = col->GetColSpan(); - cellIndex += colSpan-1; - */ } #if 0 @@ -1797,6 +1847,8 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, printf (" after this col, minTableWidth = %d and maxTableWidth = %d\n", aMinTableWidth, aMaxTableWidth); } // end Step 1 for fixed-width columns + if (nsnull!=spanList) + delete spanList; return PR_TRUE; } @@ -1930,6 +1982,7 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, NS_ASSERTION(nsnull==mPrevInFlow, "never ever call me on a continuing frame!"); PRBool result = PR_TRUE; + nsVoidArray *spanList=nsnull; nsVoidArray *columnLayoutData = GetColumnLayoutData(); PRInt32 numCols = columnLayoutData->Count(); for (PRInt32 colIndex = 0; colIndexCount(); if (gsDebug==PR_TRUE) printf (" for col %d\n", colIndex); - /* TODO: must distribute COLSPAN'd cell widths between columns, either here - * or in the prior Balance***ColumnWidth routines - */ // XXX Need columnFrame to ask the style question nsStylePosition* colPosition = nsnull; if (PR_TRUE==IsProportionalWidth(colPosition)) { + // first, deal with any cells that span into this column from a pervious column + if (nsnull!=spanList) + { + PRInt32 spanCount = spanList->Count(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } + for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); NS_ASSERTION(nsnull != data, "bad data"); + + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); + // distribute a portion of the spanning cell's min and max width to this column nsSize * cellMinSize = data->GetMaxElementSize(); NS_ASSERTION(nsnull != cellMinSize, "bad cellMinSize"); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (PR_TRUE==gsDebug) + printf("factoring in cell %d with colSpan=%d\n factoring in min=%d and desired=%d\n", + cellIndex, colSpan, cellMinWidth, cellDesiredWidth); + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; if (gsDebug==PR_TRUE) printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); + if (1AppendElement(spanInfo); + } } if (gsDebug==PR_TRUE) @@ -2022,6 +2111,8 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, } } } + if (nsnull!=spanList) + delete spanList; return result; } @@ -2035,6 +2126,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext PRBool result = PR_TRUE; PRInt32 maxOfAllMinColWidths = 0; + nsVoidArray *spanList=nsnull; nsVoidArray *columnLayoutData = GetColumnLayoutData(); PRInt32 numCols = columnLayoutData->Count(); for (PRInt32 colIndex = 0; colIndexCount(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); NS_ASSERTION(nsnull != data, "bad data"); + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); nsSize * cellMinSize = data->GetMaxElementSize(); NS_ASSERTION(nsnull != cellMinSize, "bad cellMinSize"); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; - /* + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; + if (1AppendElement(spanInfo); + } if (gsDebug==PR_TRUE) printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); - */ } if (gsDebug==PR_TRUE) @@ -2101,7 +2225,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext } else #endif - if (AutoColumnWidths()) + if (AutoColumnWidths()) { PRInt32 W = aMaxWidth - aMinTableWidth; PRInt32 D = aMaxTableWidth - aMinTableWidth; @@ -2149,6 +2273,9 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext mColumnWidths[colIndex] = maxOfAllMinColWidths; } + if (nsnull!=spanList) + delete spanList; + return result; } diff --git a/mozilla/layout/html/table/src/nsTablePart.cpp b/mozilla/layout/html/table/src/nsTablePart.cpp index 812cb62103d..dd4e2618604 100644 --- a/mozilla/layout/html/table/src/nsTablePart.cpp +++ b/mozilla/layout/html/table/src/nsTablePart.cpp @@ -34,6 +34,7 @@ #include "nsIStyleContext.h" #include "nsHTMLAtoms.h" #include "nsStyleConsts.h" +#include "nsUnitConversion.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); @@ -76,15 +77,11 @@ CellData::~CellData() * * BUGS: *
    - *
  • Enabling css1 margins on tables, rows, cells causes things to not - * fit. why? *
  • centering (etc.) is leaking into table cell's from the outer environment *
* * TODO: *
    - *
  • as table border gets wider, the table gets narrower (somebody is over - * subtracting the table border. *
  • colspan creating empty cells on rows w/o matching cells *
  • draw table borders ala navigator *
  • border sizing @@ -92,25 +89,15 @@ CellData::~CellData() *
  • draw cell borders ala navigator *
  • cellspacing *
  • colspan not the last cell - *
  • rowspan *
  • floaters in table cells *
      *
    • rowspan truncation (rowspan sticking out past the bottom of the table) *
    • effect on subsequent row structure *
    - *
  • eliminate TableRow and TableRowLayoutDelegate's *
  • inherit table border color ala nav4 (use inherited text color) when * the border is enabled and the bordercolor value nsnull. *
* - * HTML4: - *
    - *
  • borders - *
  • table frame - *
  • colgroup - *
  • col - *
  • thead, tfoot, tbody - *
* * CSS1: *
    @@ -132,19 +119,10 @@ CellData::~CellData() *
  • watch it *
* - * Eventually: - *
    - *
  • splitting tables across pages - *
- * - * And the hardest of all: - *
    - *
  • column sizing - *
*/ /** constructor - * I do not addref aTag because my superclass does that for me + * I do not check or addref aTag because my superclass does that for me */ nsTablePart::nsTablePart(nsIAtom* aTag) : nsHTMLContainer(aTag), @@ -155,9 +133,9 @@ nsTablePart::nsTablePart(nsIAtom* aTag) } /** constructor - * I do not addref aTag because my superclass does that for me + * I do not check or addref aTag because my superclass does that for me */ -nsTablePart::nsTablePart (nsIAtom* aTag, int aColumnCount) +nsTablePart::nsTablePart (nsIAtom* aTag, PRInt32 aColumnCount) : nsHTMLContainer(aTag), mColCount(aColumnCount), mSpecifiedColCount(0), @@ -175,20 +153,14 @@ nsTablePart::~nsTablePart() } } -/** - */ -/* -nsTablePart::void compact() { - compact(); -} -*/ - +// for debugging only nsrefcnt nsTablePart::AddRef(void) { if (gsNoisyRefs==PR_TRUE) printf("Add Ref: nsTablePart cnt = %d \n",mRefCnt+1); return ++mRefCnt; } +// for debugging only nsrefcnt nsTablePart::Release(void) { if (gsNoisyRefs==PR_TRUE) printf("Release: nsTablePart cnt = %d \n",mRefCnt-1); @@ -200,9 +172,7 @@ nsrefcnt nsTablePart::Release(void) return mRefCnt; } -/** - */ -int nsTablePart::GetMaxColumns () +PRInt32 nsTablePart::GetMaxColumns () { if (nsnull == mCellMap) { @@ -212,13 +182,13 @@ int nsTablePart::GetMaxColumns () } // XXX what do rows with no cells turn into? -/** - */ -int nsTablePart::GetRowCount () +PRInt32 nsTablePart::GetRowCount () { + // if we've already built the cellMap, ask it for the row count if (nsnull != mCellMap) return mCellMap->GetRowCount(); + // otherwise, we need to compute it by walking our children int rowCount = 0; int index = ChildCount (); while (0 < index) @@ -233,9 +203,8 @@ int nsTablePart::GetRowCount () return rowCount; } -/** counts columns in column groups - */ -int nsTablePart::GetSpecifiedColumnCount () +/* counts columns in column groups */ +PRInt32 nsTablePart::GetSpecifiedColumnCount () { if (mSpecifiedColCount < 0) { @@ -257,24 +226,22 @@ int nsTablePart::GetSpecifiedColumnCount () return mSpecifiedColCount; } - +// returns the actual cell map, not a copy, so don't mess with it! nsCellMap* nsTablePart::GetCellMap() const { return mCellMap; } -/** - */ +/* call when the cell structure has changed. mCellMap will be rebuilt on demand. */ void nsTablePart::ResetCellMap () { - if (mCellMap) + if (nsnull==mCellMap) delete mCellMap; mCellMap = nsnull; // for now, will rebuild when needed } -/** - */ +/* call when column structure has changed. */ void nsTablePart::ResetColumns () { mSpecifiedColCount = -1; @@ -361,6 +328,7 @@ void nsTablePart::NotifyContentComplete() */ PRBool nsTablePart::AppendChild (nsIContent * aContent) { + NS_PRECONDITION(nsnull!=aContent, "bad arg"); PRBool result = PR_FALSE; PRBool newCells = PR_FALSE; PRBool contentHandled = PR_FALSE; @@ -402,6 +370,7 @@ PRBool nsTablePart::AppendChild (nsIContent * aContent) { group = (nsTableRowGroup *)content; NS_ADDREF(group); // group: REFCNT++ + // SEC: this code might be a space leak for tables >1 row group } } NS_RELEASE(child); // child: REFCNT-- @@ -488,11 +457,12 @@ PRBool nsTablePart::AppendChild (nsIContent * aContent) return result; } -/** - */ - /* SEC: why can we only insertChildAt (captions or groups) ? */ -PRBool nsTablePart::InsertChildAt(nsIContent * aContent, int aIndex) +/* SEC: why can we only insertChildAt (captions or groups) ? */ +PRBool nsTablePart::InsertChildAt(nsIContent * aContent, PRInt32 aIndex) { + NS_PRECONDITION(nsnull!=aContent, "bad arg"); + // aIndex checked in nsHTMLContainer + PRBool result = PR_FALSE; nsTableContent *tableContent = (nsTableContent *)aContent; const int contentType = tableContent->GetType(); @@ -510,10 +480,13 @@ PRBool nsTablePart::InsertChildAt(nsIContent * aContent, int aIndex) return result; } -/** - */ -PRBool nsTablePart::ReplaceChildAt (nsIContent *aContent, int aIndex) +PRBool nsTablePart::ReplaceChildAt (nsIContent *aContent, PRInt32 aIndex) { + NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); + NS_PRECONDITION(0<=aIndex && aIndexGetType(); @@ -536,11 +509,15 @@ PRBool nsTablePart::ReplaceChildAt (nsIContent *aContent, int aIndex) } /** - * Remove a child at the given position. The method is ignored if + * Remove a child at the given position. The method is a no-op if * the index is invalid (too small or too large). */ -PRBool nsTablePart::RemoveChildAt (int aIndex) +PRBool nsTablePart::RemoveChildAt (PRInt32 aIndex) { + NS_PRECONDITION(0<=aIndex && aIndexGetRowSpan (); int rowCount = GetRowCount (); if (rowCount < (aRowIndex + rowSpan)) @@ -1063,6 +1042,9 @@ void nsTablePart::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) void nsTablePart::MapAttributesInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) { + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + float p2t; nsHTMLValue value; @@ -1094,6 +1076,10 @@ void nsTablePart::GetTableBorder(nsIHTMLContent* aContent, nsIPresContext* aPresContext, PRBool aForCell) { + NS_PRECONDITION(nsnull!=aContent, "bad content arg"); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + nsHTMLValue value; aContent->GetAttribute(nsHTMLAtoms::border, value); @@ -1103,10 +1089,10 @@ void nsTablePart::GetTableBorder(nsIHTMLContent* aContent, nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetData(kStyleSpacingSID); float p2t = aPresContext->GetPixelsToTwips(); - nscoord pixels = aForCell - ? nscoord(p2t * 1) - : nscoord(p2t * value.GetIntValue()); - nscoord two = nscoord(p2t * 2); + nscoord twips = aForCell + ? nscoord(NS_INT_PIXELS_TO_TWIPS(1, p2t)) + : nscoord(NS_INT_PIXELS_TO_TWIPS(value.GetIntValue(), p2t)); + nscoord two = nscoord(NS_INT_PIXELS_TO_TWIPS(2,p2t)); #if 0 // XXX do I need to do this or can I assert that it's zero? @@ -1116,25 +1102,25 @@ void nsTablePart::GetTableBorder(nsIHTMLContent* aContent, spacing->mBorderPadding.left -= spacing->mBorder.left; #endif - spacing->mBorder.top = pixels; - spacing->mBorder.right = pixels; - spacing->mBorder.bottom = pixels; - spacing->mBorder.left = pixels; + spacing->mBorder.top = twips; + spacing->mBorder.right = twips; + spacing->mBorder.bottom = twips; + spacing->mBorder.left = twips; spacing->mPadding.top = two; spacing->mPadding.right = two; spacing->mPadding.bottom = two; spacing->mPadding.left = two; - spacing->mBorderPadding.top += pixels + two; - spacing->mBorderPadding.right += pixels + two; - spacing->mBorderPadding.bottom += pixels + two; - spacing->mBorderPadding.left += pixels + two; + spacing->mBorderPadding.top += twips + two; + spacing->mBorderPadding.right += twips + two; + spacing->mBorderPadding.bottom += twips + two; + spacing->mBorderPadding.left += twips + two; - border->mSize.top = pixels; - border->mSize.right = pixels; - border->mSize.bottom = pixels; - border->mSize.left = pixels; + border->mSize.top = twips; + border->mSize.right = twips; + border->mSize.bottom = twips; + border->mSize.left = twips; if (border->mStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { border->mStyle[0] = NS_STYLE_BORDER_STYLE_SOLID; diff --git a/mozilla/layout/html/table/src/nsTablePart.h b/mozilla/layout/html/table/src/nsTablePart.h index 2e518175196..ebf4eb53cf6 100644 --- a/mozilla/layout/html/table/src/nsTablePart.h +++ b/mozilla/layout/html/table/src/nsTablePart.h @@ -87,7 +87,7 @@ public: * @param aTag the HTML tag that caused this content node to be instantiated * @param aColumnCount the number of columns in this table */ - nsTablePart(nsIAtom* aTag, int aColumnCount); + nsTablePart(nsIAtom* aTag, PRInt32 aColumnCount); // For debugging purposes only NS_IMETHOD_(nsrefcnt) AddRef(); @@ -123,18 +123,18 @@ public: * calls SetStartColumnIndex on each nsTableColumn
* sets mSpecifiedColCount.
*/ - virtual int GetSpecifiedColumnCount (); + virtual PRInt32 GetSpecifiedColumnCount (); /** returns the number of rows in this table. * if mCellMap has been created, it is asked for the number of rows.
* otherwise, the content is enumerated and the rows are counted. */ - virtual int GetRowCount(); + virtual PRInt32 GetRowCount(); /** returns the actual number of columns in this table.
* as a side effect, will call BuildCellMap to constuct mCellMap if needed. */ - virtual int GetMaxColumns(); + virtual PRInt32 GetMaxColumns(); /* overrides from nsHTMLContainer */ @@ -171,7 +171,7 @@ protected: * @return the row span, correcting for row spans that extend beyond the bottom * of the table. */ - virtual int GetEffectiveRowSpan(int aRowIndex, nsTableCell *aCell); + virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCell *aCell); /** build as much of the CellMap as possible from the info we have so far */ @@ -179,7 +179,7 @@ protected: /** called whenever the number of columns changes, to increase the storage in mCellMap */ - virtual void GrowCellMap(int aColCount); + virtual void GrowCellMap(PRInt32 aColCount); /** called every time we discover we have a new cell to add to the table. * This could be because we got actual cell content, because of rowspan/colspan attributes, etc. @@ -189,11 +189,11 @@ protected: * @param aRowIndex the row into which the cell is to be inserted * @param aColIndex the col into which the cell is to be inserted */ - virtual void BuildCellIntoMap (nsTableCell *aCell, int aRowIndex, int aColIndex); + virtual void BuildCellIntoMap (nsTableCell *aCell, PRInt32 aRowIndex, PRInt32 aColIndex); /** returns the index of the first child after aStartIndex that is a row group */ - virtual int NextRowGroup (int aStartIndex); + virtual PRInt32 NextRowGroup (PRInt32 aStartIndex); /** obsolete! */ virtual void ReorderChildren(); @@ -225,8 +225,8 @@ public: private: - int mColCount; - int mSpecifiedColCount; + PRInt32 mColCount; + PRInt32 mSpecifiedColCount; nsCellMap* mCellMap; static nsIAtom *kDefaultTag; }; diff --git a/mozilla/layout/html/table/src/nsTableRow.cpp b/mozilla/layout/html/table/src/nsTableRow.cpp index 5ee6119ed9b..9e215daed96 100644 --- a/mozilla/layout/html/table/src/nsTableRow.cpp +++ b/mozilla/layout/html/table/src/nsTableRow.cpp @@ -38,7 +38,7 @@ static const PRBool gsDebug = PR_FALSE; static const PRBool gsNoisyRefs = PR_FALSE; #endif - +// nsTableContent checks aTag nsTableRow::nsTableRow(nsIAtom* aTag) : nsTableContent(aTag), mRowGroup(0), @@ -46,6 +46,7 @@ nsTableRow::nsTableRow(nsIAtom* aTag) { } +// nsTableContent checks aTag nsTableRow::nsTableRow(nsIAtom* aTag, PRBool aImplicit) : nsTableContent(aTag), mRowGroup(0), @@ -79,6 +80,7 @@ void nsTableRow::SetRowGroup (nsTableRowGroup * aRowGroup) PRInt32 nsTableRow::GetRowIndex () { + NS_PRECONDITION(0<=mRowIndex, "bad mRowIndex"); return mRowIndex; } @@ -118,7 +120,6 @@ PRInt32 nsTableRow::GetMaxColumns() void nsTableRow::ResetCellMap () { - // SEC Assert.Assertion(nsnull!=mTable) if (nsnull != mRowGroup) { mRowGroup->ResetCellMap (); @@ -183,9 +184,10 @@ PRBool nsTableRow::InsertChildAt (nsIContent *aContent, int aIndex) PRBool nsTableRow::ReplaceChildAt (nsIContent *aContent, int aIndex) { PRBool result = PR_FALSE; - // SEC Assert.PreCondition (nsnull!=aContent); - // SEC Assert.PreCondition (aIndex in range); - if ((nsnull==aContent) || /*(aIndex not in range)*/PR_FALSE) + + NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); + NS_PRECONDITION(0<=aIndex && aIndexResetCellMap (); } PRBool nsTableRowGroup::AppendChild (nsIContent *aContent) { - //SEC Assert.PreCondition(nsnull!=aContent); + NS_PRECONDITION(nsnull!=aContent, "bad arg to AppendChild"); PRBool result = PR_TRUE; // is aContent a TableRow? @@ -175,7 +178,7 @@ PRBool nsTableRowGroup::AppendChild (nsIContent *aContent) PRBool nsTableRowGroup::InsertChildAt (nsIContent *aContent, int aIndex) { - //SEC Assert.PreCondition(nsnull!=aContent); + NS_PRECONDITION(nsnull!=aContent, "bad arg to InsertChildAt"); // is aContent a TableRow? PRBool isRow = IsRow(aContent); @@ -200,9 +203,9 @@ PRBool nsTableRowGroup::InsertChildAt (nsIContent *aContent, int aIndex) PRBool nsTableRowGroup::ReplaceChildAt (nsIContent *aContent, int aIndex) { - // SEC Assert.PreCondition (nsnull!=aContent); - // SEC Assert.PreCondition (aIndex in range); - if ((nsnull==aContent) || /*(aIndex not in range)*/PR_FALSE) + NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); + NS_PRECONDITION(0<=aIndex && aIndexmSize.left, myBorder->mSize.top, + myBorder->mSize.right, myBorder->mSize.bottom); + */ // for debug... if (nsIFrame::GetShowFrameBorders()) { diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index d8e5c25ddcd..2efa9daef97 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -39,7 +39,7 @@ #ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; +static PRBool gsDebug = PR_TRUE; static PRBool gsDebugCLD = PR_FALSE; static PRBool gsTiming = PR_FALSE; static PRBool gsDebugMBP = PR_FALSE; @@ -135,6 +135,26 @@ struct InnerTableReflowState { +/* ----------- SpanInfo ---------- */ + +struct SpanInfo +{ + PRInt32 span; + PRInt32 cellMinWidth; + PRInt32 cellDesiredWidth; + + SpanInfo(PRInt32 aSpan, PRInt32 aMinWidth, PRInt32 aDesiredWidth) + { + span = aSpan; + cellMinWidth = aMinWidth; + cellDesiredWidth = aDesiredWidth; + }; + + ~SpanInfo() {}; +}; + + + /* ----------- nsTableFrame ---------- */ @@ -1623,6 +1643,7 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, NS_ASSERTION(nsnull==mPrevInFlow, "never ever call me on a continuing frame!"); if (gsDebug==PR_TRUE) printf (" AssignFixedColumnWidths\n"); + nsVoidArray *spanList=nsnull; for (PRInt32 colIndex = 0; colIndexCount(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } + for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); @@ -1675,8 +1722,10 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, nsSize * cellMinSize = data->GetMaxElementSize(); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); if (gsDebug==PR_TRUE) - printf (" for cell %d min = %d,%d and des = %d,%d\n", cellIndex, cellMinSize->width, cellMinSize->height, + printf (" for cell %d with colspan=%d, min = %d,%d and des = %d,%d\n", + cellIndex, colSpan, cellMinSize->width, cellMinSize->height, cellDesiredSize->width, cellDesiredSize->height); PRBool haveCellWidth = PR_FALSE; @@ -1750,23 +1799,24 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, // regardless of the width specification, keep track of the // min/max column widths - /* TODO: must distribute COLSPAN'd cell widths between columns, - * either here or in the subsequent Balance***ColumnWidth - * routines - */ - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; + if (1AppendElement(spanInfo); + } if (gsDebug) { printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); } - /* take colspan into account? */ - /* - PRInt32 colSpan = col->GetColSpan(); - cellIndex += colSpan-1; - */ } #if 0 @@ -1797,6 +1847,8 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, printf (" after this col, minTableWidth = %d and maxTableWidth = %d\n", aMinTableWidth, aMaxTableWidth); } // end Step 1 for fixed-width columns + if (nsnull!=spanList) + delete spanList; return PR_TRUE; } @@ -1930,6 +1982,7 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, NS_ASSERTION(nsnull==mPrevInFlow, "never ever call me on a continuing frame!"); PRBool result = PR_TRUE; + nsVoidArray *spanList=nsnull; nsVoidArray *columnLayoutData = GetColumnLayoutData(); PRInt32 numCols = columnLayoutData->Count(); for (PRInt32 colIndex = 0; colIndexCount(); if (gsDebug==PR_TRUE) printf (" for col %d\n", colIndex); - /* TODO: must distribute COLSPAN'd cell widths between columns, either here - * or in the prior Balance***ColumnWidth routines - */ // XXX Need columnFrame to ask the style question nsStylePosition* colPosition = nsnull; if (PR_TRUE==IsProportionalWidth(colPosition)) { + // first, deal with any cells that span into this column from a pervious column + if (nsnull!=spanList) + { + PRInt32 spanCount = spanList->Count(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } + for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); NS_ASSERTION(nsnull != data, "bad data"); + + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); + // distribute a portion of the spanning cell's min and max width to this column nsSize * cellMinSize = data->GetMaxElementSize(); NS_ASSERTION(nsnull != cellMinSize, "bad cellMinSize"); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (PR_TRUE==gsDebug) + printf("factoring in cell %d with colSpan=%d\n factoring in min=%d and desired=%d\n", + cellIndex, colSpan, cellMinWidth, cellDesiredWidth); + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; if (gsDebug==PR_TRUE) printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); + if (1AppendElement(spanInfo); + } } if (gsDebug==PR_TRUE) @@ -2022,6 +2111,8 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, } } } + if (nsnull!=spanList) + delete spanList; return result; } @@ -2035,6 +2126,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext PRBool result = PR_TRUE; PRInt32 maxOfAllMinColWidths = 0; + nsVoidArray *spanList=nsnull; nsVoidArray *columnLayoutData = GetColumnLayoutData(); PRInt32 numCols = columnLayoutData->Count(); for (PRInt32 colIndex = 0; colIndexCount(); + // go through the list backwards so we can delete easily + for (PRInt32 spanIndex=spanCount-1; 0<=spanIndex; spanIndex--) + { + SpanInfo *spanInfo = (SpanInfo *)(spanList->ElementAt(spanIndex)); + if (minColWidth < spanInfo->cellMinWidth) + minColWidth = spanInfo->cellMinWidth; + if (maxColWidth < spanInfo->cellDesiredWidth) + maxColWidth = spanInfo->cellDesiredWidth; + spanInfo->span--; + if (gsDebug==PR_TRUE) + printf (" for spanning cell %d with remaining span=%d, min = %d and des = %d\n", + spanIndex, spanInfo->span, spanInfo->cellMinWidth, spanInfo->cellDesiredWidth); + if (0==spanInfo->span) + { + spanList->RemoveElementAt(spanIndex); + delete spanInfo; + } + } + } for (PRInt32 cellIndex = 0; cellIndexElementAt(cellIndex)); NS_ASSERTION(nsnull != data, "bad data"); + PRInt32 colSpan = data->GetCellFrame()->GetColSpan(); nsSize * cellMinSize = data->GetMaxElementSize(); NS_ASSERTION(nsnull != cellMinSize, "bad cellMinSize"); nsReflowMetrics * cellDesiredSize = data->GetDesiredSize(); NS_ASSERTION(nsnull != cellDesiredSize, "bad cellDesiredSize"); - if (minColWidth < cellMinSize->width) - minColWidth = cellMinSize->width; - if (maxColWidth < cellDesiredSize->width) - maxColWidth = cellDesiredSize->width; - /* + PRInt32 cellMinWidth = cellMinSize->width/colSpan; + PRInt32 cellDesiredWidth = cellDesiredSize->width/colSpan; + if (minColWidth < cellMinWidth) + minColWidth = cellMinWidth; + if (maxColWidth < cellDesiredWidth) + maxColWidth = cellDesiredWidth; + if (1AppendElement(spanInfo); + } if (gsDebug==PR_TRUE) printf (" after cell %d, minColWidth = %d and maxColWidth = %d\n", cellIndex, minColWidth, maxColWidth); - */ } if (gsDebug==PR_TRUE) @@ -2101,7 +2225,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext } else #endif - if (AutoColumnWidths()) + if (AutoColumnWidths()) { PRInt32 W = aMaxWidth - aMinTableWidth; PRInt32 D = aMaxTableWidth - aMinTableWidth; @@ -2149,6 +2273,9 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext mColumnWidths[colIndex] = maxOfAllMinColWidths; } + if (nsnull!=spanList) + delete spanList; + return result; } diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index c433909404e..9fc165ca65b 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -114,10 +114,12 @@ NS_METHOD nsTableRowFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect) { // for debug... + /* if (nsIFrame::GetShowFrameBorders()) { aRenderingContext.SetColor(NS_RGB(0,0,128)); aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } + */ PaintChildren(aPresContext, aRenderingContext, aDirtyRect); return NS_OK; diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index efc5c86d4af..3cbc1e206de 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -116,10 +116,12 @@ NS_METHOD nsTableRowGroupFrame::Paint(nsIPresContext& aPresContext, { // for debug... + /* if (nsIFrame::GetShowFrameBorders()) { aRenderingContext.SetColor(NS_RGB(128,0,0)); aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } + */ PaintChildren(aPresContext, aRenderingContext, aDirtyRect); return NS_OK;