ElementAt(colIndex);
- if (nsnull==data)
- {
- result = colIndex;
- break;
- }
- result++;
- }
+ if ((aRow >= 0) && (aRow < mRowCount)) {
+ if (mIsCollapsedRows) {
+ return mIsCollapsedRows[aRow];
}
}
- return result;
+ return PR_FALSE;
}
+void nsCellMap::SetRowCollapsedAt(PRInt32 aRow, PRBool aValue)
+{
+ if ((aRow >= 0) && (aRow < mRowCount)) {
+ if (nsnull == mIsCollapsedRows) {
+ mIsCollapsedRows = new PRPackedBool[mRowCount];
+ for (PRInt32 i = 0; i < mRowCount; i++) {
+ mIsCollapsedRows[i] = PR_FALSE;
+ }
+ }
+ if (mIsCollapsedRows[aRow] != aValue) {
+ if (PR_TRUE == aValue) {
+ mNumCollapsedRows++;
+ } else {
+ mNumCollapsedRows--;
+ }
+ mIsCollapsedRows[aRow] = aValue;
+ }
+ }
+}
+
+PRInt32 nsCellMap::GetNumCollapsedCols()
+{
+ return mNumCollapsedCols;
+}
+
+PRBool nsCellMap::IsColCollapsedAt(PRInt32 aCol)
+{
+ PRInt32 colCount = mNumCellsInCol.Count();
+ if ((aCol >= 0) && (aCol < colCount)) {
+ if (mIsCollapsedCols) {
+ return mIsCollapsedCols[aCol];
+ }
+ }
+ return PR_FALSE;
+}
+
+void nsCellMap::SetColCollapsedAt(PRInt32 aCol, PRBool aValue)
+{
+ PRInt32 colCount = mNumCellsInCol.Count();
+ if ((aCol >= 0) && (aCol < colCount)) {
+ if (nsnull == mIsCollapsedCols) {
+ mIsCollapsedCols = new PRPackedBool[colCount];
+ for (PRInt32 i = 0; i < colCount; i++) {
+ mIsCollapsedCols[i] = PR_FALSE;
+ }
+ }
+ if (mIsCollapsedCols[aCol] != aValue) {
+ if (PR_TRUE == aValue) {
+ mNumCollapsedCols++;
+ } else {
+ mNumCollapsedCols--;
+ }
+ mIsCollapsedCols[aCol] = aValue;
+ }
+ }
+}
+
+// The following are not used and may not work. They have been removed from
+// nsTableFrame and nsCellMap headers but retained here if needed in the future.
+#if 0
/** returns PR_TRUE if the row at aRowIndex has any cells that are the result
* of a row-spanning cell above it. So, given this table:
*
@@ -259,22 +462,18 @@ PRInt32 nsCellMap::GetNextAvailColIndex(PRInt32 aRowIndex, PRInt32 aColIndex) co
// whenever a row|col|cell is added/deleted, or a span attribute is changed.
PRBool nsCellMap::RowIsSpannedInto(PRInt32 aRowIndex)
{
- NS_PRECONDITION (0<=aRowIndex && aRowIndexmCell)
- { // the cell at (aRowIndex, colIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
- NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
+ for (PRInt32 colIndex = 0; colIndex < colCount; colIndex++) {
+ CellData* cd = GetCellAt(aRowIndex, colIndex);
+ if (cd) { // there's really a cell at (aRowIndex, colIndex)
+ if (!cd->mOrigCell) { // the cell at (aRowIndex, colIndex) is the result of a span
+ nsTableCellFrame* cell = cd->mSpanData->mOrigCell;
+ NS_ASSERTION(cell, "bad cell map state, missing real cell");
PRInt32 realRowIndex;
cell->GetRowIndex (realRowIndex);
- if (realRowIndex!=aRowIndex)
- { // the span is caused by a rowspan
+ if (realRowIndex != aRowIndex) { // the span is caused by a rowspan
result = PR_TRUE;
break;
}
@@ -299,31 +498,24 @@ PRBool nsCellMap::RowIsSpannedInto(PRInt32 aRowIndex)
*/
PRBool nsCellMap::RowHasSpanningCells(PRInt32 aRowIndex)
{
- NS_PRECONDITION (0<=aRowIndex && aRowIndexmCell)
- { // the cell at (nextRowIndex, colIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
- NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
+ PRInt32 colCount = mTableColToMapCol.Count();
+ if (aRowIndex != mRowCount - 1) {
+ // aRowIndex is not the last row, so we check the next row after aRowIndex for spanners
+ for (PRInt32 colIndex = 0; colIndex < colCount; colIndex++) {
+ PRInt32 nextRowIndex = aRowIndex + 1;
+ CellData* cd = GetCellAt(nextRowIndex, colIndex);
+ if (cd) { // there's really a cell at (nextRowIndex, colIndex)
+ if (!cd->mOrigCell) { // the cell at (nextRowIndex, colIndex) is the result of a span
+ nsTableCellFrame* cell = cd->mSpanData->mOrigCell;
+ NS_ASSERTION(cell, "bad cell map state, missing real cell");
PRInt32 realRowIndex;
cell->GetRowIndex (realRowIndex);
- if (realRowIndex!=nextRowIndex)
- { // the span is caused by a rowspan
- CellData *spanningCell = GetCellAt(aRowIndex, colIndex);
- if (nsnull!=spanningCell)
- { // there's really a cell at (aRowIndex, colIndex)
- if (nsnull!=spanningCell->mCell)
- { // aRowIndex is where the rowspan originated
+ if (realRowIndex != nextRowIndex) { // the span is caused by a rowspan
+ CellData* spanningCell = GetCellAt(aRowIndex, colIndex);
+ if (spanningCell) { // there's really a cell at (aRowIndex, colIndex)
+ if (spanningCell->mOrigCell) { // aRowIndex is where the rowspan originated
result = PR_TRUE;
break;
}
@@ -336,7 +528,6 @@ PRBool nsCellMap::RowHasSpanningCells(PRInt32 aRowIndex)
return result;
}
-
/** returns PR_TRUE if the col at aColIndex has any cells that are the result
* of a col-spanning cell. So, given this table:
*
@@ -352,23 +543,18 @@ PRBool nsCellMap::RowHasSpanningCells(PRInt32 aRowIndex)
*/
PRBool nsCellMap::ColIsSpannedInto(PRInt32 aColIndex)
{
- PRInt32 colCount = GetColCount();
- NS_PRECONDITION (0<=aColIndex && aColIndexmCell)
- { // the cell at (rowIndex, aColIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
- NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
+ for (PRInt32 rowIndex = 0; rowIndex < mRowCount; rowIndex++) {
+ CellData* cd = GetCellAt(rowIndex, aColIndex);
+ if (cd) { // there's really a cell at (aRowIndex, aColIndex)
+ if (!cd->mOrigCell) { // the cell at (rowIndex, aColIndex) is the result of a span
+ nsTableCellFrame* cell = cd->mSpanData->mOrigCell;
+ NS_ASSERTION(cell, "bad cell map state, missing real cell");
PRInt32 realColIndex;
- cell->GetColIndex (realColIndex);
- if (realColIndex!=aColIndex)
- { // the span is caused by a colspan
+ cell->GetColIndex(realColIndex);
+ if (realColIndex != aColIndex) { // the span is caused by a colspan
result = PR_TRUE;
break;
}
@@ -392,29 +578,22 @@ PRBool nsCellMap::ColIsSpannedInto(PRInt32 aColIndex)
PRBool nsCellMap::ColHasSpanningCells(PRInt32 aColIndex)
{
PRBool result = PR_FALSE;
- const PRInt32 colCount = GetColCount();
- if (aColIndexmCell)
- { // the cell at (rowIndex, nextColIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
- NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
+ CellData* cd = GetCellAt(rowIndex, nextColIndex);
+ if (cd) { // there's really a cell at (rowIndex, nextColIndex)
+ if (!cd->mOrigCell) { // the cell at (rowIndex, nextColIndex) is the result of a span
+ nsTableCellFrame* cell = cd->mSpanData->mOrigCell;
+ NS_ASSERTION(cell, "bad cell map state, missing real cell");
PRInt32 realColIndex;
- cell->GetColIndex (realColIndex);
- if (realColIndex!=nextColIndex)
- { // the span is caused by a colspan
- CellData *spanningCell =GetCellAt(rowIndex, aColIndex);
- if (nsnull!=spanningCell)
- { // there's really a cell at (rowIndex, aColIndex)
- if (nsnull!=spanningCell->mCell)
- { // aCowIndex is where the cowspan originated
+ cell->GetColIndex(realColIndex);
+ if (realColIndex != nextColIndex) { // the span is caused by a colspan
+ CellData* spanningCell = GetCellAtInternal(rowIndex, aColIndex);
+ if (spanningCell) { // there's really a cell at (rowIndex, aColIndex)
+ if (spanningCell->mOrigCell) { // aCowIndex is where the cowspan originated
result = PR_TRUE;
break;
}
@@ -427,73 +606,6 @@ PRBool nsCellMap::ColHasSpanningCells(PRInt32 aColIndex)
return result;
}
-PRInt32 nsCellMap::GetNumCollapsedRows()
-{
- return mNumCollapsedRows;
-}
+#endif
-PRBool nsCellMap::IsRowCollapsedAt(PRInt32 aRow)
-{
- if ((aRow >= 0) && (aRow < mTotalRowCount)) {
- if (mIsCollapsedRows) {
- return mIsCollapsedRows[aRow];
- }
- }
- return PR_FALSE;
-}
-
-void nsCellMap::SetRowCollapsedAt(PRInt32 aRow, PRBool aValue)
-{
- if ((aRow >= 0) && (aRow < mRowCount)) {
- if (nsnull == mIsCollapsedRows) {
- mIsCollapsedRows = new PRBool[mRowCount];
- for (PRInt32 i = 0; i < mRowCount; i++) {
- mIsCollapsedRows[i] = PR_FALSE;
- }
- }
- if (mIsCollapsedRows[aRow] != aValue) {
- if (PR_TRUE == aValue) {
- mNumCollapsedRows++;
- } else {
- mNumCollapsedRows--;
- }
- mIsCollapsedRows[aRow] = aValue;
- }
- }
-}
-
-PRInt32 nsCellMap::GetNumCollapsedCols()
-{
- return mNumCollapsedCols;
-}
-
-PRBool nsCellMap::IsColCollapsedAt(PRInt32 aCol)
-{
- if ((aCol >= 0) && (aCol < mColCount)) {
- if (mIsCollapsedCols) {
- return mIsCollapsedCols[aCol];
- }
- }
- return PR_FALSE;
-}
-
-void nsCellMap::SetColCollapsedAt(PRInt32 aCol, PRBool aValue)
-{
- if ((aCol >= 0) && (aCol < mColCount)) {
- if (nsnull == mIsCollapsedCols) {
- mIsCollapsedCols = new PRBool[mColCount];
- for (PRInt32 i = 0; i < mColCount; i++) {
- mIsCollapsedCols[i] = PR_FALSE;
- }
- }
- if (mIsCollapsedCols[aCol] != aValue) {
- if (PR_TRUE == aValue) {
- mNumCollapsedCols++;
- } else {
- mNumCollapsedCols--;
- }
- mIsCollapsedCols[aCol] = aValue;
- }
- }
-}
diff --git a/mozilla/layout/html/table/src/nsCellMap.h b/mozilla/layout/html/table/src/nsCellMap.h
index aa3f208ef8a..4fbb71d053c 100644
--- a/mozilla/layout/html/table/src/nsCellMap.h
+++ b/mozilla/layout/html/table/src/nsCellMap.h
@@ -40,73 +40,52 @@ class nsTableCellFrame;
*/
class nsCellMap
{
-protected:
- /** storage for rows */
- nsVoidArray *mRows;
-
- /** storage for min col span info, just an int that gives the smallest
- * colspan for all cells originating in each column. If allocated,
- * each entry must be >= 1.
- */
- PRInt32 *mMinColSpans;
-
- /** a cache of the column frames, by col index */
- nsVoidArray * mColFrames;
-
- /** the number of rows. mRows[0] - mRows[mRowCount-1] are non-null. */
- PRInt32 mRowCount;
-
- /** the number of rows allocated (due to cells having rowspans extending beyond the end of the table */
- PRInt32 mTotalRowCount;
-
- /** the number of columns (the max of all row lengths) */
- PRInt32 mColCount;
-
- // an array of booleans where the ith element indicates if the ith row is collapsed
- PRBool* mIsCollapsedRows;
- PRInt32 mNumCollapsedRows;
-
- // an array of booleans where the ith element indicates if the ith col is collapsed
- PRBool* mIsCollapsedCols;
- PRInt32 mNumCollapsedCols;
-
public:
/** constructor
- * @param aRows - initial number of rows
- * @param aColumns - initial number of columns
+ * @param aNumRows - initial number of rows
+ * @param aNumColumns - initial number of columns
*/
- nsCellMap(PRInt32 aRows, PRInt32 aColumns);
+ nsCellMap(PRInt32 aNumRows,
+ PRInt32 aNumCols);
/** destructor
* NOT VIRTUAL BECAUSE THIS CLASS SHOULD **NEVER** BE SUBCLASSED
- */
+ */
~nsCellMap();
- /** set the CellMap to (aRows x aColumns) */
- void Reset(PRInt32 aRows, PRInt32 aColumns);
+ /** return the CellData for the cell at (aTableRowIndex, aTableColIndex) */
+ CellData* GetCellAt(PRInt32 aRowIndex,
+ PRInt32 aColIndex) const;
- /** return the CellData for the cell at (aRowIndex,aColIndex) */
- CellData * GetCellAt(PRInt32 aRowIndex, PRInt32 aColIndex) const;
+ /** return the nsTableCellFrame for the cell at (aTableRowIndex, aTableColIndex) */
+ nsTableCellFrame* GetCellFrameAt(PRInt32 aRowIndex,
+ PRInt32 aColIndex) const;
- /** return the nsTableCellFrame for the cell at (aRowIndex, aColIndex) */
- nsTableCellFrame * GetCellFrameAt(PRInt32 aRowIndex, PRInt32 aColIndex) const;
+ /** append the cellFrame at the end of the row at aRowIndex and return the col index
+ */
+ PRInt32 AppendCell(nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex);
- /** assign aCellData to the cell at (aRow,aColumn) */
- void SetCellAt(CellData *aCellData, PRInt32 aRow, PRInt32 aColumn);
+ void RemoveCell(nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex);
+
+ PRInt32 GetNextAvailRowIndex();
+
+ PRInt32 GetEffectiveColSpan(PRInt32 aColIndex,
+ nsTableCellFrame* aCell);
+
+ PRInt32 GetNumCellsIn(PRInt32 aColIndex);
+ PRInt32 GetNumCellsOriginatingIn(PRInt32 aColIndex);
PRInt32 GetNumCollapsedRows();
- PRBool IsRowCollapsedAt(PRInt32 aRow);
- void SetRowCollapsedAt(PRInt32 aRow, PRBool aValue);
+ PRBool IsRowCollapsedAt(PRInt32 aRowIndex);
+ void SetRowCollapsedAt(PRInt32 aRowIndex,
+ PRBool aValue);
PRInt32 GetNumCollapsedCols();
- PRBool IsColCollapsedAt(PRInt32 aCol);
- void SetColCollapsedAt(PRInt32 aCol, PRBool aValue);
-
- /** expand the CellMap to have aRowCount rows. The number of columns remains the same */
- void GrowToRow(PRInt32 aRowCount);
-
- /** expand the CellMap to have aColCount columns. The number of rows remains the same */
- void GrowToCol(PRInt32 aColCount);
+ PRBool IsColCollapsedAt(PRInt32 aColIndex);
+ void SetColCollapsedAt(PRInt32 aColIndex,
+ PRBool aValue);
/** return the total number of columns in the table represented by this CellMap */
PRInt32 GetColCount() const;
@@ -115,20 +94,7 @@ public:
PRInt32 GetRowCount() const;
/** return the column frame associated with aColIndex */
- nsTableColFrame * GetColumnFrame(PRInt32 aColIndex) const;
-
- /** return the index of the next column in aRowIndex after aColIndex
- * that does not have a cell assigned to it.
- * If aColIndex is past the end of the row, it is returned.
- * If the row is not initialized in the cell map, 0 is returned.
- */
- PRInt32 GetNextAvailColIndex(PRInt32 aRowIndex, PRInt32 aColIndex) const;
-
- /** cache the min col span for all cells in aColIndex */
- void SetMinColSpan(PRInt32 aColIndex, PRBool aColSpan);
-
- /** get the cached min col span for aColIndex */
- PRInt32 GetMinColSpan(PRInt32 aColIndex) const;
+ nsTableColFrame* GetColumnFrame(PRInt32 aColIndex) const;
/** add a column frame to the list of column frames
* column frames must be added in order
@@ -138,102 +104,105 @@ public:
/** empty the column frame cache */
void ClearColumnCache();
- /** returns PR_TRUE if the row at aRowIndex has any cells that are the result
- * of a row-spanning cell above it. So, given this table:
- *
- * TABLE
- * TR
- * TD ROWSPAN=2
- * TD
- * TR
- * TD
- *
- * RowIsSpannedInto(0) returns PR_FALSE, and RowIsSpannedInto(1) returns PR_TRUE.
- * @see RowHasSpanningCells
- */
- PRBool RowIsSpannedInto(PRInt32 aRowIndex);
-
- /** returns PR_TRUE if the row at aRowIndex has any cells that have a rowspan>1
- * So, given this table:
- *
- * TABLE
- * TR
- * TD ROWSPAN=2
- * TD
- * TR
- * TD
- *
- * RowHasSpanningCells(0) returns PR_TRUE, and RowHasSpanningCells(1) returns PR_FALSE.
- * @see RowIsSpannedInto
- */
- PRBool RowHasSpanningCells(PRInt32 aRowIndex);
-
- /** returns PR_TRUE if the col at aColIndex has any cells that are the result
- * of a col-spanning cell. So, given this table:
- *
- * TABLE
- * TR
- * TD COLSPAN=2
- * TD
- * TD
- *
- * ColIsSpannedInto(0) returns PR_FALSE, ColIsSpannedInto(1) returns PR_TRUE,
- * and ColIsSpannedInto(2) returns PR_FALSE.
- * @see ColHasSpanningCells
- */
- PRBool ColIsSpannedInto(PRInt32 aColIndex);
-
- /** returns PR_TRUE if the row at aColIndex has any cells that have a colspan>1
- * So, given this table:
- *
- * TABLE
- * TR
- * TD COLSPAN=2
- * TD
- *
- * ColHasSpanningCells(0) returns PR_TRUE, and ColHasSpanningCells(1) returns PR_FALSE.
- * @see ColIsSpannedInto
- */
- PRBool ColHasSpanningCells(PRInt32 aColIndex);
+ void GetCellInfoAt(PRInt32 aRowX,
+ PRInt32 aColX,
+ nsTableCellFrame*& aCellFrame,
+ PRBool& aOriginates,
+ PRInt32& aColSpan);
+ void AddColsAtEnd(PRUint32 aNumCols);
/** dump a representation of the cell map to stdout for debugging */
- void DumpCellMap() const;
+#ifdef NS_DEBUG
+ void Dump() const;
+#endif
+protected:
+ /** set the CellMap to (aNumRows x aNumColumns) */
+ void Grow(PRInt32 aNumMapRows,
+ PRInt32 aNumCols);
+
+ /** assign aCellData to the cell at (aRow,aColumn) */
+ void SetMapCellAt(CellData& aCellData,
+ PRInt32 aMapRowIndex,
+ PRInt32 aColIndex);
+
+ CellData* GetMapCellAt(PRInt32 aMapRowIndex,
+ PRInt32 aColIndex) const;
+
+ PRInt32 GetNumCellsIn(PRInt32 aColIndex, PRBool aOriginating);
+
+ /** an array containing col array. It can be larger than mRowCount due to
+ * row spans extending beyond the table */
+ nsVoidArray mRows;
+
+ /** an array of col frames. It is as large as mRowCount */
+ nsVoidArray mColFrames;
+
+ /** an array of PRInt32[2] indexed by col and giving the number of cells originating
+ * and occupying each col. */
+ nsVoidArray mNumCellsInCol;
+
+ // an array of booleans where the ith element indicates if the ith row is collapsed
+ PRPackedBool* mIsCollapsedRows;
+ PRInt32 mNumCollapsedRows;
+
+ // an array of booleans where the ith element indicates if the ith col is collapsed
+ PRPackedBool* mIsCollapsedCols;
+ PRInt32 mNumCollapsedCols;
+
+ /** the number of rows in the table which is <= the number of rows in the cell map
+ * due to row spans extending beyond the end of the table (dead rows) */
+ PRInt32 mRowCount;
+
+ PRInt32 mNextAvailRowIndex;
};
/* ----- inline methods ----- */
-
-inline CellData * nsCellMap::GetCellAt(PRInt32 aRowIndex, PRInt32 aColIndex) const
+inline CellData* nsCellMap::GetCellAt(PRInt32 aRowIndex,
+ PRInt32 aColIndex) const
{
- NS_PRECONDITION(0<=aRowIndex, "bad aRowIndex arg");
- NS_PRECONDITION(0<=aColIndex, "bad aColIndex arg");
- // don't check index vs. count for row or col, because it's ok to ask for a cell that doesn't yet exist
- NS_PRECONDITION(nsnull!=mRows, "bad mRows");
-
- CellData *result = nsnull;
- nsVoidArray *row = (nsVoidArray *)(mRows->ElementAt(aRowIndex));
- if (nsnull!=row)
+ NS_PRECONDITION((0 <= aRowIndex) && (aRowIndex < mRowCount), "GetCellAt: bad row index");
+ PRInt32 colCount = mNumCellsInCol.Count();
+ NS_PRECONDITION((0 <= aColIndex) && (aColIndex < colCount), "GetCellAt: bad col index");
+
+ CellData* result = nsnull;
+ nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aRowIndex));
+ if (row)
result = (CellData *)(row->ElementAt(aColIndex));
return result;
}
-inline nsTableCellFrame * nsCellMap::GetCellFrameAt(PRInt32 aRowIndex, PRInt32 aColIndex) const
+inline CellData* nsCellMap::GetMapCellAt(PRInt32 aMapRowIndex,
+ PRInt32 aColIndex) const
{
- NS_PRECONDITION(0<=aRowIndex, "bad aRowIndex arg");
- // don't check aRowIndex vs. mRowCount, because it's ok to ask for a cell in a row that doesn't yet exist
- NS_PRECONDITION(0<=aColIndex && aColIndex < mColCount, "bad aColIndex arg");
+ NS_PRECONDITION((0 <= aMapRowIndex) && (aMapRowIndex < mRows.Count()), "GetMapCellAt: bad row index");
+ NS_PRECONDITION((0 <= aColIndex) && (aColIndex < mNumCellsInCol.Count()), "GetMapCellAt: bad col index");
- nsTableCellFrame *result = nsnull;
- CellData * cellData = GetCellAt(aRowIndex, aColIndex);
- if (nsnull!=cellData)
- result = cellData->mCell;
+ CellData* result = nsnull;
+ nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aMapRowIndex));
+ if (row)
+ result = (CellData *)(row->ElementAt(aColIndex));
+ return result;
+}
+
+inline nsTableCellFrame* nsCellMap::GetCellFrameAt(PRInt32 aRowIndex,
+ PRInt32 aColIndex) const
+{
+ NS_PRECONDITION((0 <= aRowIndex) && (aRowIndex < mRowCount), "GetCellFrameAt: bad row index");
+ PRInt32 colCount = mNumCellsInCol.Count();
+ NS_PRECONDITION((0 <= aColIndex) && (aColIndex < colCount), "GetCellFrameAt: bad col index");
+
+ nsTableCellFrame* result = nsnull;
+ CellData* cellData = GetCellAt(aRowIndex, aColIndex);
+ if (cellData)
+ result = cellData->mOrigCell;
return result;
}
inline PRInt32 nsCellMap::GetColCount() const
{
- return mColCount;
+ return mNumCellsInCol.Count();
}
inline PRInt32 nsCellMap::GetRowCount() const
@@ -243,13 +212,12 @@ inline PRInt32 nsCellMap::GetRowCount() const
inline void nsCellMap::AppendColumnFrame(nsTableColFrame *aColFrame)
{
- mColFrames->AppendElement(aColFrame);
+ mColFrames.AppendElement(aColFrame);
}
inline void nsCellMap::ClearColumnCache()
{
- if (nsnull!=mColFrames)
- mColFrames->Clear();
+ mColFrames.Clear();
}
diff --git a/mozilla/layout/html/table/src/nsITableLayoutStrategy.h b/mozilla/layout/html/table/src/nsITableLayoutStrategy.h
index 4221ccd187b..7630fe3468f 100644
--- a/mozilla/layout/html/table/src/nsITableLayoutStrategy.h
+++ b/mozilla/layout/html/table/src/nsITableLayoutStrategy.h
@@ -48,9 +48,9 @@ public:
* @param aMaxWidth the width constraint
*/
- virtual PRBool BalanceColumnWidths(nsIStyleContext *aTableStyle,
+ virtual PRBool BalanceColumnWidths(nsIStyleContext* aTableStyle,
const nsHTMLReflowState& aReflowState,
- nscoord aMaxWidth)=0;
+ nscoord aMaxWidth)=0;
/** return the computed max "natural" size of the table.
* this is the sum of the desired size of the content taking into account table
@@ -58,7 +58,7 @@ public:
* the actual table width in a given situation will depend on the available size
* provided by the parent (especially for percent-width tables.)
*/
- virtual nscoord GetTableMaxWidth() const = 0;
+ virtual nscoord GetTableMaxContentWidth() const = 0;
/** return the computed minimum possible size of the table.
* this is the sum of the minimum sizes of the content taking into account table
@@ -66,13 +66,7 @@ public:
* the actual table width in a given situation will depend on the available size
* provided by the parent (especially for percent-width tables.)
*/
- virtual nscoord GetTableMinWidth() const = 0;
-
- /** return the portion of the table width that is specified as "fixed" aka
- * the amount of table width that does not vary with available width or other
- * inputs to the table balancing algorithm.
- */
- virtual nscoord GetTableFixedWidth() const = 0;
+ virtual nscoord GetTableMinContentWidth() const = 0;
/** return the value of the COLS attribute, used for balancing column widths */
virtual nscoord GetCOLSAttribute() const = 0;
diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp
index bf038a1fb7a..cf7b1d657ab 100644
--- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp
@@ -36,9 +36,11 @@
#include "nsIView.h"
#include "nsStyleUtil.h"
#include "nsLayoutAtoms.h"
+#include "nsCOMPtr.h"
+#include "nsIHTMLTableCellElement.h"
NS_DEF_PTR(nsIStyleContext);
-
+static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
#ifdef NS_DEBUG
static PRBool gsDebug = PR_FALSE;
@@ -78,7 +80,7 @@ nsTableCellFrame::Init(nsIPresContext& aPresContext,
void nsTableCellFrame::InitCellFrame(PRInt32 aColIndex)
{
NS_PRECONDITION(0<=aColIndex, "bad col index arg");
- mColIndex = aColIndex;
+ SetColIndex(aColIndex); // this also sets the contents col index
mBorderEdges.mOutsideEdge=PR_FALSE;
nsTableFrame* tableFrame=nsnull; // I should be checking my own style context, but border-collapse isn't inheriting correctly
nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
@@ -110,6 +112,33 @@ void nsTableCellFrame::InitCellFrame(PRInt32 aColIndex)
}
}
+nsresult nsTableCellFrame::SetColIndex(PRInt32 aColIndex)
+{
+ mColIndex = aColIndex;
+ // for style context optimization, set the content's column index if possible.
+ // this can only be done if we really have an nsTableCell.
+ // other tags mapped to table cell display won't benefit from this optimization
+ // see nsHTMLStyleSheet::RulesMatching
+
+ //nsIContent* cell;
+ //kidFrame->GetContent(&cell);
+ nsCOMPtr cell;
+ nsresult rv = GetContent(getter_AddRefs(cell));
+ if (NS_FAILED(rv) || !cell)
+ return rv;
+
+ nsIHTMLTableCellElement* cellContent = nsnull;
+ rv = cell->QueryInterface(kIHTMLTableCellElementIID,
+ (void **)&cellContent); // cellContent: REFCNT++
+ if (cellContent && NS_SUCCEEDED(rv)) { // it's a table cell
+ cellContent->SetColIndex(aColIndex);
+ if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, cellContent, aColIndex);
+ NS_RELEASE(cellContent);
+ }
+ return rv;
+}
+
+
void nsTableCellFrame::SetBorderEdgeLength(PRUint8 aSide,
PRInt32 aIndex,
nscoord aLength)
@@ -325,52 +354,49 @@ void nsTableCellFrame::VerticallyAlignChild()
/* XXX: remove tableFrame when border-collapse inherits */
nsTableFrame* tableFrame=nsnull;
nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
- if (NS_SUCCEEDED(rv) && tableFrame)
- {
- nsMargin borderPadding;
- GetCellBorder (borderPadding, tableFrame);
- nsMargin padding;
- spacing->GetPadding(padding);
- borderPadding += padding;
+ nsMargin borderPadding;
+ GetCellBorder (borderPadding, tableFrame);
+ nsMargin padding;
+ spacing->GetPadding(padding);
+ borderPadding += padding;
- nscoord topInset = borderPadding.top;
- nscoord bottomInset = borderPadding.bottom;
- PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
- if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
- verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
- }
- nscoord height = mRect.height;
- nsRect kidRect;
- nsIFrame* firstKid = mFrames.FirstChild();
- firstKid->GetRect(kidRect);
- nscoord childHeight = kidRect.height;
-
-
- // Vertically align the child
- nscoord kidYTop = 0;
- switch (verticalAlignFlags)
- {
- case NS_STYLE_VERTICAL_ALIGN_BASELINE:
- // Align the child's baseline at the max baseline
- //kidYTop = aMaxAscent - kidAscent;
- break;
-
- case NS_STYLE_VERTICAL_ALIGN_TOP:
- // Align the top of the child frame with the top of the box,
- // minus the top padding
- kidYTop = topInset;
- break;
-
- case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
- kidYTop = height - childHeight - bottomInset;
- break;
-
- default:
- case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
- kidYTop = height/2 - childHeight/2;
- }
- firstKid->MoveTo(kidRect.x, kidYTop);
+ nscoord topInset = borderPadding.top;
+ nscoord bottomInset = borderPadding.bottom;
+ PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
+ if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
+ verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
}
+ nscoord height = mRect.height;
+ nsRect kidRect;
+ nsIFrame* firstKid = mFrames.FirstChild();
+ firstKid->GetRect(kidRect);
+ nscoord childHeight = kidRect.height;
+
+
+ // Vertically align the child
+ nscoord kidYTop = 0;
+ switch (verticalAlignFlags)
+ {
+ case NS_STYLE_VERTICAL_ALIGN_BASELINE:
+ // Align the child's baseline at the max baseline
+ //kidYTop = aMaxAscent - kidAscent;
+ break;
+
+ case NS_STYLE_VERTICAL_ALIGN_TOP:
+ // Align the top of the child frame with the top of the box,
+ // minus the top padding
+ kidYTop = topInset;
+ break;
+
+ case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
+ kidYTop = height - childHeight - bottomInset;
+ break;
+
+ default:
+ case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
+ kidYTop = height/2 - childHeight/2;
+ }
+ firstKid->MoveTo(kidRect.x, kidYTop);
}
PRInt32 nsTableCellFrame::GetRowSpan()
@@ -486,7 +512,6 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
/* XXX: remove tableFrame when border-collapse inherits */
nsTableFrame* tableFrame=nsnull;
rv = nsTableFrame::GetTableFrame(this, tableFrame);
- if (NS_FAILED(rv)) { return rv; }
nsMargin borderPadding;
spacing->GetPadding(borderPadding);
nsMargin border;
@@ -527,7 +552,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
aReflowState.reflowCommand->GetType(type);
if (nsIReflowCommand::StyleChanged==type)
{
- rv = IR_StyleChanged(aPresContext, aDesiredSize, aReflowState, aStatus);
+ nsresult rv = IR_StyleChanged(aPresContext, aDesiredSize, aReflowState, aStatus);
aStatus = NS_FRAME_COMPLETE;
return rv;
}
@@ -674,7 +699,12 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
// So here all we have to do is tell the table to rebalance.
if (eReflowReason_Incremental == aReflowState.reason)
{
- tableFrame->InvalidateColumnWidths();
+ nsTableFrame* tableFrame=nsnull;
+ rv = nsTableFrame::GetTableFrame(this, tableFrame);
+ if ((NS_SUCCEEDED(rv)) && (nsnull!=tableFrame))
+ {
+ tableFrame->InvalidateColumnWidths();
+ }
}
@@ -1082,7 +1112,7 @@ PRUint8 nsTableCellFrame::GetOpposingEdge(PRUint8 aEdge)
nscoord nsTableCellFrame::FindLargestMargin(nsVoidArray* aList,PRUint8 aEdge)
{
nscoord result = 0;
- PRInt32 theIndex = 0;
+ PRInt32 index = 0;
PRInt32 count = 0;
@@ -1093,9 +1123,9 @@ nscoord nsTableCellFrame::FindLargestMargin(nsVoidArray* aList,PRUint8 aEdge)
nsIFrame* frame;
nscoord value = 0;
- while (theIndex < count)
+ while (index < count)
{
- frame = (nsIFrame*)(aList->ElementAt(theIndex++));
+ frame = (nsIFrame*)(aList->ElementAt(index++));
value = GetMargin(frame, aEdge);
if (value > result)
result = value;
diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h
index 5489878638c..c068d4c6aef 100644
--- a/mozilla/layout/html/table/src/nsTableCellFrame.h
+++ b/mozilla/layout/html/table/src/nsTableCellFrame.h
@@ -124,6 +124,7 @@ public:
/** return the cell's column index (starting at 0 for the first column) */
virtual nsresult GetColIndex(PRInt32 &aColIndex);
+ virtual nsresult SetColIndex(PRInt32 aColIndex);
/** return the available width given to this frame during its last reflow */
virtual nscoord GetPriorAvailWidth();
diff --git a/mozilla/layout/html/table/src/nsTableColFrame.cpp b/mozilla/layout/html/table/src/nsTableColFrame.cpp
index 5178a9c5747..98ee10562b1 100644
--- a/mozilla/layout/html/table/src/nsTableColFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableColFrame.cpp
@@ -32,10 +32,16 @@ static const PRBool gsDebug = PR_FALSE;
#endif
nsTableColFrame::nsTableColFrame()
- : nsFrame()
+ : nsFrame(), mIsAnonymous(PR_FALSE), mProportion(WIDTH_NOT_SET)
{
// note that all fields are initialized to 0 by nsFrame::operator new
- mWidthSource = eWIDTH_SOURCE_NONE;
+ for (PRInt32 widthX = 0; widthX < NUM_WIDTHS; widthX++) {
+ mWidths[widthX] = WIDTH_NOT_SET;
+ }
+}
+
+nsTableColFrame::~nsTableColFrame()
+{
}
NS_METHOD nsTableColFrame::Paint(nsIPresContext& aPresContext,
@@ -89,14 +95,63 @@ PRInt32 nsTableColFrame::GetSpan()
return tableStyle->mSpan;
}
-nscoord nsTableColFrame::GetColWidthForComputation()
+nscoord nsTableColFrame::GetWidth(PRUint32 aWidthType)
{
- const nsStylePosition* position;
- GetStyleData(eStyleStruct_Position, ((const nsStyleStruct *&)position));
- if (eStyleUnit_Coord==position->mWidth.GetUnit())
- return position->mWidth.GetCoordValue();
- else
- return GetEffectiveMaxColWidth();
+ NS_ASSERTION(aWidthType < NUM_WIDTHS, "GetWidth: bad width type");
+ return mWidths[aWidthType];
+}
+
+void nsTableColFrame::SetWidth(PRUint32 aWidthType,
+ nscoord aWidth)
+{
+ NS_ASSERTION(aWidthType < NUM_WIDTHS, "SetWidth: bad width type");
+ mWidths[aWidthType] = aWidth;
+#ifdef MY_DEBUG
+ if (aWidth > 0) {
+ nscoord minWidth = GetMinWidth();
+ if ((MIN_CON != aWidthType) && (aWidth < minWidth)) {
+ printf("non min width set to lower than min \n");
+ }
+ }
+#endif
+}
+
+nscoord nsTableColFrame::GetMinWidth()
+{
+ return PR_MAX(mWidths[MIN_CON], mWidths[MIN_ADJ]);
+}
+
+nscoord nsTableColFrame::GetDesWidth()
+{
+ return PR_MAX(mWidths[DES_CON], mWidths[DES_ADJ]);
+}
+
+nscoord nsTableColFrame::GetFixWidth()
+{
+ return PR_MAX(mWidths[FIX], mWidths[FIX_ADJ]);
+}
+
+nscoord nsTableColFrame::GetPctWidth()
+{
+ return PR_MAX(mWidths[PCT], mWidths[PCT_ADJ]);
+}
+
+void nsTableColFrame::Dump(PRInt32 aIndent)
+{
+ char* indent = new char[aIndent + 1];
+ for (PRInt32 i = 0; i < aIndent + 1; i++) {
+ indent[i] = ' ';
+ }
+ indent[aIndent] = 0;
+
+ printf("%s**START COL DUMP** colIndex=%d isAnonymous=%d constraint=%d",
+ indent, mColIndex, mIsAnonymous, mConstraint);
+ printf("\n%s widths=", indent);
+ for (PRInt32 widthX = 0; widthX < NUM_WIDTHS; widthX++) {
+ printf("%d ", mWidths[widthX]);
+ }
+ printf(" **END COL DUMP** ");
+ delete [] indent;
}
/* ----- global methods ----- */
diff --git a/mozilla/layout/html/table/src/nsTableColFrame.h b/mozilla/layout/html/table/src/nsTableColFrame.h
index 876b321160d..3bb204d4fb1 100644
--- a/mozilla/layout/html/table/src/nsTableColFrame.h
+++ b/mozilla/layout/html/table/src/nsTableColFrame.h
@@ -20,9 +20,36 @@
#include "nscore.h"
#include "nsContainerFrame.h"
+#include "nsTableFrame.h"
class nsVoidArray;
+// this is used to index arrays of widths in nsColFrame and to group important widths
+// for calculations. It is important that the order: min, desired, fixed be maintained
+// for each category (con, adj).
+// XXX MIN_ADJ, DES_ADJ, PCT_ADJ, DES_PRO can probably go away and be replaced
+// by MIN_CON, DES_CON, PCT_CON, DES_CON saving 16 bytes per col frame
+#define WIDTH_NOT_SET -1
+#define NUM_WIDTHS 9
+#define NUM_MAJOR_WIDTHS 3 // MIN, DES, FIX
+#define MIN_CON 0 // minimum width required of the content + padding
+#define DES_CON 1 // desired width of the content + padding
+#define FIX 2 // fixed width either from the content or cell, col, etc. + padding
+#define MIN_ADJ 3 // minimum width + padding due to col spans
+#define DES_ADJ 4 // desired width + padding due to col spans
+#define FIX_ADJ 5 // fixed width + padding due to col spans
+#define PCT 6 // percent width of cell or col
+#define PCT_ADJ 7 // percent width of cell or col from percent colspan
+#define MIN_PRO 8 // desired width due to proportional s or cols attribute
+
+enum nsColConstraint {
+ eNoConstraint = 0,
+ ePixelConstraint = 1, // pixel width
+ ePercentConstraint = 2, // percent width
+ eProportionConstraint = 3, // 1*, 2*, etc. cols attribute assigns 1*
+ e0ProportionConstraint = 4 // 0*, means to force to min width
+};
+
class nsTableColFrame : public nsFrame {
public:
@@ -67,57 +94,48 @@ public:
/** convenience method, calls into cellmap */
nsVoidArray * GetCells();
- nscoord GetMaxColWidth();
- void SetMaxColWidth(nscoord aMaxColWidth);
-
- nscoord GetMinColWidth();
- void SetMinColWidth(nscoord aMinColWidth);
-
- nscoord GetEffectiveMaxColWidth();
- void SetEffectiveMaxColWidth(nscoord aMaxColWidth);
-
- nscoord GetEffectiveMinColWidth();
- void SetEffectiveMinColWidth(nscoord aMinColWidth);
-
// return the min width for this column after provisions for col spans have
// been included. The adj min width is >= the min width.
nscoord GetAdjustedMinColWidth();
void SetAdjustedMinColWidth(nscoord aMinColWidth);
- // Return true if the column has a width either from HTML width attribute,
- // from a style rule on the column, from a width attr/style on a cell
- // that has colspan==1.
- PRBool HasConstrainedWidth();
- void SetHasConstrainedWidth(PRBool aIsConstrained);
+ nscoord GetWidth(PRUint32 aWidthType);
+ void GetWidths(nscoord* aWidths);
+ void SetWidth(PRUint32 aWidthType,
+ nscoord aWidth);
+ nscoord GetMinWidth();
+ nscoord GetDesWidth();
+ nscoord GetFixWidth();
+ nscoord GetPctWidth();
- PRInt32 GetWidthSource();
- void SetWidthSource(PRInt32 aMinColWidth);
-
- nscoord GetColWidthForComputation();
+ void SetConstraint(nsColConstraint aConstraint);
+ nsColConstraint GetConstraint() const;
/** convenience method, calls into cellmap */
PRInt32 Count() const;
+ /** Return true if this col was constructed implicitly due to cells needing a col.
+ * Return false if this col was constructed due to content having display type of table-col
+ */
+ PRBool IsAnonymous();
+ void SetIsAnonymous(PRBool aValue);
+
+ void Dump(PRInt32 aIndent);
+
protected:
nsTableColFrame();
+ ~nsTableColFrame();
/** the starting index of the column (starting at 0) that this col object represents */
PRInt32 mColIndex;
+ PRBool mIsAnonymous;
- nscoord mMaxColWidth;
- nscoord mMinColWidth;
-
- nscoord mMaxEffectiveColWidth;
- nscoord mMinEffectiveColWidth;
-
- nscoord mMinAdjustedColWidth;
-
- PRBool mHasConstrainedWidth;
-
- PRInt32 mWidthSource;
-
+ // Widths including MIN_CON, DES_CON, FIX_CON, MIN_ADJ, DES_ADJ, FIX_ADJ
+ nscoord mWidths[NUM_WIDTHS];
+ nscoord mProportion; // proportion for porportional width col
+ nsColConstraint mConstraint;
};
@@ -133,46 +151,17 @@ inline PRInt32 nsTableColFrame::GetColumnIndex()
inline void nsTableColFrame::SetColumnIndex (int aColIndex)
{ mColIndex = aColIndex;}
-inline nscoord nsTableColFrame::GetMaxColWidth()
-{ return mMaxColWidth; }
+inline nsColConstraint nsTableColFrame::GetConstraint() const
+{ return mConstraint; }
-inline void nsTableColFrame::SetMaxColWidth(nscoord aMaxColWidth)
-{ mMaxColWidth = aMaxColWidth; }
+inline void nsTableColFrame::SetConstraint(nsColConstraint aConstraint)
+{ mConstraint = aConstraint;}
-inline nscoord nsTableColFrame::GetMinColWidth()
-{ return mMinColWidth; }
+inline PRBool nsTableColFrame::IsAnonymous()
+{ return mIsAnonymous; }
-inline void nsTableColFrame::SetMinColWidth(nscoord aMinColWidth)
-{ mMinColWidth = aMinColWidth; }
+inline void nsTableColFrame::SetIsAnonymous(PRBool aIsAnonymous)
+{ mIsAnonymous = aIsAnonymous; }
-inline nscoord nsTableColFrame::GetEffectiveMaxColWidth()
-{ return mMaxEffectiveColWidth; }
-
-inline void nsTableColFrame::SetEffectiveMaxColWidth(nscoord aMaxColWidth)
-{ mMaxEffectiveColWidth = aMaxColWidth; }
-
-inline nscoord nsTableColFrame::GetEffectiveMinColWidth()
-{ return mMinEffectiveColWidth; }
-
-inline void nsTableColFrame::SetEffectiveMinColWidth(nscoord aMinEffectiveColWidth)
-{ mMinEffectiveColWidth = aMinEffectiveColWidth; }
-
-inline nscoord nsTableColFrame::GetAdjustedMinColWidth()
-{ return mMinAdjustedColWidth; }
-
-inline PRBool nsTableColFrame::HasConstrainedWidth()
-{ return mHasConstrainedWidth; }
-
-inline void nsTableColFrame::SetHasConstrainedWidth(PRBool aIsConstrained)
-{ mHasConstrainedWidth = aIsConstrained; }
-
-inline void nsTableColFrame::SetAdjustedMinColWidth(nscoord aMinAdjustedColWidth)
-{ mMinAdjustedColWidth = aMinAdjustedColWidth; }
-
-inline PRInt32 nsTableColFrame::GetWidthSource()
-{ return mWidthSource; }
-
-inline void nsTableColFrame::SetWidthSource(PRInt32 aWidthSource)
-{ mWidthSource = aWidthSource; }
#endif
diff --git a/mozilla/layout/html/table/src/nsTableColGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableColGroupFrame.cpp
index bc427d65155..23558781024 100644
--- a/mozilla/layout/html/table/src/nsTableColGroupFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableColGroupFrame.cpp
@@ -712,6 +712,11 @@ PRInt32 nsTableColGroupFrame::SetStartColumnIndex (int aIndex)
return result;
}
+void nsTableColGroupFrame::DeleteColFrame(nsIPresContext& aPresContext, nsTableColFrame* aColFrame)
+{
+ mFrames.DestroyFrame(aPresContext, aColFrame);
+}
+
/* ----- global methods ----- */
nsresult
diff --git a/mozilla/layout/html/table/src/nsTableColGroupFrame.h b/mozilla/layout/html/table/src/nsTableColGroupFrame.h
index 767c339c2df..cea8f0a8b3c 100644
--- a/mozilla/layout/html/table/src/nsTableColGroupFrame.h
+++ b/mozilla/layout/html/table/src/nsTableColGroupFrame.h
@@ -94,6 +94,8 @@ public:
*/
//PRBool IsManufactured();
+ void DeleteColFrame(nsIPresContext& aPresContext, nsTableColFrame* aColFrame);
+
protected:
/** implement abstract method on nsHTMLContainerFrame */
diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp
index 69698d5e2bf..3dd8a71ac09 100644
--- a/mozilla/layout/html/table/src/nsTableFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableFrame.cpp
@@ -75,9 +75,9 @@ static const PRInt32 kColumnWidthIncrement=100;
/* CellData is the info stored in the cell map */
CellData::CellData()
{
- mCell = nsnull;
- mRealCell = nsnull;
- mOverlap = nsnull;
+ mOrigCell = nsnull;
+ mSpanData = nsnull;
+ mSpanData2 = nsnull;
}
CellData::~CellData()
@@ -284,7 +284,6 @@ nsTableFrame::nsTableFrame()
mColCache(nsnull),
mTableLayoutStrategy(nsnull)
{
- mEffectiveColCount = -1; // -1 means uninitialized
mColumnWidthsSet=PR_FALSE;
mColumnWidthsLength = kColumnWidthIncrement;
mColumnWidths = new PRInt32[mColumnWidthsLength];
@@ -401,8 +400,10 @@ nsTableFrame::SetInitialChildList(nsIPresContext& aPresContext,
if (nsnull!=prevColGroupChild)
prevColGroupChild->SetNextSibling(nsnull);
- if (NS_SUCCEEDED(rv))
+ if (NS_SUCCEEDED(rv)) {
+ //mCellMap->Dump();
EnsureColumns(aPresContext);
+ }
return rv;
}
@@ -439,15 +440,14 @@ NS_IMETHODIMP nsTableFrame::DidAppendRowGroup(nsTableRowGroupFrame *aRowGroupFra
/* counts columns in column groups */
PRInt32 nsTableFrame::GetSpecifiedColumnCount ()
{
- mColCount=0;
+ PRInt32 colCount = 0;
nsIFrame * childFrame = mColGroups.FirstChild();
- while (nsnull!=childFrame)
- {
- mColCount += ((nsTableColGroupFrame *)childFrame)->GetColumnCount();
+ while (nsnull!=childFrame) {
+ colCount += ((nsTableColGroupFrame *)childFrame)->GetColumnCount();
childFrame->GetNextSibling(&childFrame);
}
- if (PR_TRUE==gsDebug) printf("TIF GetSpecifiedColumnCount: returning %d\n", mColCount);
- return mColCount;
+ if (PR_TRUE==gsDebug) printf("TIF GetSpecifiedColumnCount: returning %d\n", colCount);
+ return colCount;
}
PRInt32 nsTableFrame::GetRowCount () const
@@ -463,46 +463,14 @@ PRInt32 nsTableFrame::GetRowCount () const
/* return the effective col count */
PRInt32 nsTableFrame::GetColCount ()
{
- nsCellMap *cellMap = GetCellMap();
- NS_ASSERTION(nsnull!=cellMap, "GetColCount null cellmap");
-
- if (nsnull!=cellMap)
- {
- //if (-1==mEffectiveColCount)
- SetEffectiveColCount();
- }
- return mEffectiveColCount;
+ PRInt32 colCount = 0;
+ nsCellMap* cellMap = GetCellMap();
+ NS_ASSERTION(nsnull != cellMap, "GetColCount null cellmap");
+ if (nsnull != cellMap)
+ colCount = cellMap->GetColCount();
+ return colCount;
}
-void nsTableFrame::SetEffectiveColCount()
-{
- nsCellMap *cellMap = GetCellMap();
- NS_ASSERTION(nsnull!=cellMap, "SetEffectiveColCount null cellmap");
- if (nsnull!=cellMap)
- {
- PRInt32 colCount = cellMap->GetColCount();
- mEffectiveColCount = colCount;
- PRInt32 rowCount = cellMap->GetRowCount();
- for (PRInt32 colIndex=colCount-1; colIndex>0; colIndex--)
- {
- PRBool deleteCol=PR_TRUE;
- for (PRInt32 rowIndex=0; rowIndexGetCellAt(rowIndex, colIndex);
- if ((nsnull!=cell) && (cell->mCell != nsnull))
- { // found a real cell, so we're done
- deleteCol = PR_FALSE;
- break;
- }
- }
- if (PR_TRUE==deleteCol)
- mEffectiveColCount--;
- else
- break;
- }
- }
- if (PR_TRUE==gsDebug) printf("TIF SetEffectiveColumnCount: returning %d\n", mEffectiveColCount);
-}
nsTableColFrame * nsTableFrame::GetColFrame(PRInt32 aColIndex)
{
@@ -525,79 +493,14 @@ nsTableCellFrame * nsTableFrame::GetCellFrameAt(PRInt32 aRowIndex, PRInt32 aColI
CellData * cellData = cellMap->GetCellAt(aRowIndex, aColIndex);
if (nsnull!=cellData)
{
- result = cellData->mCell;
+ result = cellData->mOrigCell;
if (nsnull==result)
- result = cellData->mRealCell->mCell;
+ result = cellData->mSpanData->mOrigCell;
}
}
return result;
}
-/** returns PR_TRUE if the row at aRowIndex has any cells that are the result
- * of a row-spanning cell.
- * @see nsCellMap::RowIsSpannedInto
- */
-PRBool nsTableFrame::RowIsSpannedInto(PRInt32 aRowIndex)
-{
- NS_PRECONDITION (0<=aRowIndex && aRowIndexRowIsSpannedInto(aRowIndex);
- }
- return result;
-}
-
-/** returns PR_TRUE if the row at aRowIndex has any cells that have a rowspan>1
- * @see nsCellMap::RowHasSpanningCells
- */
-PRBool nsTableFrame::RowHasSpanningCells(PRInt32 aRowIndex)
-{
- NS_PRECONDITION (0<=aRowIndex && aRowIndexRowHasSpanningCells(aRowIndex);
- }
- return result;
-}
-
-
-/** returns PR_TRUE if the col at aColIndex has any cells that are the result
- * of a col-spanning cell.
- * @see nsCellMap::ColIsSpannedInto
- */
-PRBool nsTableFrame::ColIsSpannedInto(PRInt32 aColIndex)
-{
- PRBool result = PR_FALSE;
- nsCellMap * cellMap = GetCellMap();
- NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated.");
- if (nsnull!=cellMap)
- {
- result = cellMap->ColIsSpannedInto(aColIndex);
- }
- return result;
-}
-
-/** returns PR_TRUE if the row at aColIndex has any cells that have a colspan>1
- * @see nsCellMap::ColHasSpanningCells
- */
-PRBool nsTableFrame::ColHasSpanningCells(PRInt32 aColIndex)
-{
- PRBool result = PR_FALSE;
- nsCellMap * cellMap = GetCellMap();
- NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated.");
- if (nsnull!=cellMap)
- {
- result = cellMap->ColHasSpanningCells(aColIndex);
- }
- return result;
-}
-
// return the number of rows spanned by aCell starting at aRowIndex
// note that this is different from just the rowspan of aCell
// (that would be GetEffectiveRowSpan (indexOfRowThatContains_aCell, aCell)
@@ -642,54 +545,38 @@ PRInt32 nsTableFrame::GetEffectiveRowSpan (PRInt32 aRowIndex, nsTableCellFrame *
#endif
}
-// return the number of cols spanned by aCell starting at aColIndex
-// note that this is different from just the colspan of aCell
-// (that would be GetEffectiveColSpan (indexOfColThatContains_aCell, aCell)
+PRInt32 nsTableFrame::GetEffectiveRowSpan(nsTableCellFrame *aCell)
+{
+ PRInt32 startRow;
+ aCell->GetRowIndex(startRow);
+ return GetEffectiveRowSpan(startRow, aCell);
+}
+
+
+// Return the number of cols spanned by aCell starting at aColIndex
+// This is different from the colspan of aCell. If the cell spans no
+// dead cells then the colSpan of the cell would be
+// GetEffectiveColSpan (indexOfColThatContains_aCell, aCell)
//
// XXX Should be moved to colgroup, as GetEffectiveRowSpan should be moved to rowgroup?
-PRInt32 nsTableFrame::GetEffectiveColSpan (PRInt32 aColIndex, nsTableCellFrame *aCell)
+PRInt32 nsTableFrame::GetEffectiveColSpan(PRInt32 aColIndex, nsTableCellFrame* aCell)
{
- NS_PRECONDITION (nsnull!=aCell, "bad cell arg");
- nsCellMap *cellMap = GetCellMap();
- NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated.");
- PRInt32 colCount = GetColCount();
- NS_PRECONDITION (0<=aColIndex && aColIndexGetRowCount()==1)
- return 1;
- */
- PRInt32 colSpan = aCell->GetColSpan();
- if (colCount < (aColIndex + colSpan))
- result = colCount - aColIndex;
- else
- {
- result = colSpan;
- // check for case where all cells in a column have a colspan
- PRInt32 initialColIndex;
- aCell->GetColIndex(initialColIndex);
- PRInt32 minColSpanForCol = cellMap->GetMinColSpan(initialColIndex);
- result -= (minColSpanForCol - 1); // minColSpanForCol is always at least 1
- // and we want to treat default as 0 (no effect)
- }
-#ifdef NS_DEBUG
- if (0>=result)
- {
- printf("ERROR!\n");
- DumpCellMap();
- PRInt32 initialColIndex;
- aCell->GetColIndex(initialColIndex);
- printf("aColIndex=%d, cell->colIndex=%d\n", aColIndex, initialColIndex);
- printf("aCell->colSpan=%d\n", aCell->GetColSpan());
- printf("colCount=%d\n", mCellMap->GetColCount());
- }
-#endif
-NS_ASSERTION(0GetEffectiveColSpan(aColIndex, aCell);
+}
+
+PRInt32 nsTableFrame::GetEffectiveColSpan(nsTableCellFrame* aCell)
+{
+ NS_PRECONDITION (nsnull != aCell, "bad cell arg");
+ nsCellMap* cellMap = GetCellMap();
+ NS_PRECONDITION (nsnull != cellMap, "bad call, cellMap not yet allocated.");
+
+ PRInt32 initialColIndex;
+ aCell->GetColIndex(initialColIndex);
+ return cellMap->GetEffectiveColSpan(initialColIndex, aCell);
}
PRInt32 nsTableFrame::GetEffectiveCOLSAttribute()
@@ -714,9 +601,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
{
if (PR_TRUE==gsDebug) printf("TIF EnsureColumns\n");
NS_PRECONDITION(nsnull!=mCellMap, "bad state: null cellmap");
- // XXX sec should only be called on firstInFlow
- SetMinColSpanForTable();
- if (nsnull==mCellMap)
+ if (nsnull == mCellMap)
return; // no info yet, so nothing useful to do
// make sure we've accounted for the COLS attribute
@@ -726,8 +611,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
PRInt32 actualColumns = 0;
nsTableColGroupFrame *lastColGroupFrame = nsnull;
nsIFrame* childFrame = mColGroups.FirstChild();
- while (nsnull!=childFrame)
- {
+ while (nsnull!=childFrame) {
((nsTableColGroupFrame*)childFrame)->SetStartColumnIndex(actualColumns);
PRInt32 numCols = ((nsTableColGroupFrame*)childFrame)->GetColumnCount();
actualColumns += numCols;
@@ -739,20 +623,17 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
// if we have fewer column frames than we need, create some implicit column frames
PRInt32 colCount = mCellMap->GetColCount();
if (PR_TRUE==gsDebug) printf("EC: actual = %d, colCount=%d\n", actualColumns, colCount);
- if (actualColumns < colCount)
- {
+ if (actualColumns < colCount) {
if (PR_TRUE==gsDebug) printf("TIF EnsureColumns: actual %d < colCount %d\n", actualColumns, colCount);
nsIContent *lastColGroupElement = nsnull;
- if (nsnull==lastColGroupFrame)
- { // there are no col groups, so create an implicit colgroup frame
+ if (nsnull==lastColGroupFrame) { // there are no col groups, so create an implicit colgroup frame
if (PR_TRUE==gsDebug) printf("EnsureColumns:creating colgroup frame\n");
// Resolve style for the colgroup frame
// first, need to get the nearest containing content object
GetContent(&lastColGroupElement); // ADDREF a: lastColGroupElement++ (either here or in the loop below)
nsIFrame *parentFrame;
GetParent(&parentFrame);
- while (nsnull==lastColGroupElement)
- {
+ while (nsnull==lastColGroupElement) {
parentFrame->GetContent(&lastColGroupElement);
if (nsnull==lastColGroupElement)
parentFrame->GetParent(&parentFrame);
@@ -775,8 +656,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
// hook lastColGroupFrame into child list
mColGroups.SetFrames(lastColGroupFrame);
}
- else
- {
+ else {
lastColGroupFrame->GetContent(&lastColGroupElement); // ADDREF b: lastColGroupElement++
}
@@ -789,8 +669,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
nsIFrame* lastNewColFrame = nsnull;
nsIStyleContextPtr lastColGroupStyle;
lastColGroupFrame->GetStyleContext(lastColGroupStyle.AssignPtr());
- for ( ; excessColumns > 0; excessColumns--)
- {
+ for ( ; excessColumns > 0; excessColumns--) {
// Create a new col frame
nsIFrame* colFrame;
// note we pass in PR_TRUE here to force unique style contexts.
@@ -805,6 +684,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
colStyleContext, nsnull);
NS_RELEASE(colStyleContext);
colFrame->SetInitialChildList(aPresContext, nsnull, nsnull);
+ ((nsTableColFrame *)colFrame)->SetIsAnonymous(PR_TRUE);
// Add it to our list
if (nsnull == lastNewColFrame) {
@@ -817,6 +697,13 @@ void nsTableFrame::EnsureColumns(nsIPresContext& aPresContext)
lastColGroupFrame->SetInitialChildList(aPresContext, nsnull, firstNewColFrame);
NS_RELEASE(lastColGroupElement); // ADDREF: lastColGroupElement--
}
+ else if (actualColumns > colCount) { // the cell map needs to grow to accomodate extra cols
+ nsCellMap* cellMap = GetCellMap();
+ if (cellMap) {
+ cellMap->AddColsAtEnd(actualColumns - colCount);
+ }
+ }
+
}
@@ -838,26 +725,12 @@ PRInt32 nsTableFrame::GetNextAvailRowIndex() const
PRInt32 result=0;
nsCellMap *cellMap = GetCellMap();
NS_PRECONDITION (nsnull!=cellMap, "null cellMap.");
- if (nsnull!=cellMap)
- {
- result = cellMap->GetRowCount(); // the next index is the current count
- cellMap->GrowToRow(result+1); // expand the cell map to include this new row
+ if (nsnull!=cellMap) {
+ result = cellMap->GetNextAvailRowIndex();
}
return result;
}
-/** return the index of the next column in aRowIndex that does not have a cell assigned to it */
-PRInt32 nsTableFrame::GetNextAvailColIndex(PRInt32 aRowIndex, PRInt32 aColIndex) const
-{
- PRInt32 result=0;
- nsCellMap *cellMap = GetCellMap();
- NS_PRECONDITION (nsnull!=cellMap, "null cellMap.");
- if (nsnull!=cellMap)
- result = cellMap->GetNextAvailColIndex(aRowIndex, aColIndex);
- if (gsDebug==PR_TRUE) printf("TIF: GetNextAvailColIndex returning %d\n", result);
- return result;
-}
-
/** Get the cell map for this table frame. It is not always mCellMap.
* Only the firstInFlow has a legit cell map
*/
@@ -871,89 +744,34 @@ nsCellMap * nsTableFrame::GetCellMap() const
return mCellMap;
}
-void nsTableFrame::SetMinColSpanForTable()
-{ // XXX: must be called ONLY on first-in-flow
- // set the minColSpan for each column
- PRInt32 rowCount = mCellMap->GetRowCount();
- PRInt32 colCount = mCellMap->GetColCount();
- for (PRInt32 colIndex=0; colIndexGetCellFrameAt(rowIndex, colIndex);
- if (nsnull!=cellFrame)
- {
- PRInt32 colSpan = cellFrame->GetColSpan();
- if (0==minColSpan)
- minColSpan = colSpan;
- else
- minColSpan = PR_MIN(minColSpan, colSpan);
- }
- }
- if (1SetMinColSpan(colIndex, minColSpan);
-#ifdef NS_DEBUG
- if (gsDebug==PR_TRUE)
- {
- printf("minColSpan for col %d set to %d\n", colIndex, minColSpan);
- DumpCellMap();
- }
-#endif
- }
- }
-}
-
-void nsTableFrame::AddCellToTable (nsTableRowFrame *aRowFrame,
- nsTableCellFrame *aCellFrame,
- PRBool aAddRow)
+PRInt32 nsTableFrame::AddCellToTable(nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex)
{
- NS_ASSERTION(nsnull!=aRowFrame, "bad aRowFrame arg");
- NS_ASSERTION(nsnull!=aCellFrame, "bad aCellFrame arg");
- NS_PRECONDITION(nsnull!=mCellMap, "bad cellMap");
+ NS_ASSERTION(nsnull != aCellFrame, "bad aCellFrame arg");
+ NS_ASSERTION(nsnull != mCellMap, "bad cellMap");
// XXX: must be called only on first-in-flow!
if (gsDebug==PR_TRUE) printf("TIF AddCellToTable: frame %p\n", aCellFrame);
- // Make an educated guess as to how many columns we have. It's
- // only a guess because we can't know exactly until we have
- // processed the last row.
- if (0 == mColCount)
- mColCount = GetSpecifiedColumnCount();
- if (0 == mColCount) // no column parts
- {
- mColCount = aRowFrame->GetMaxColumns();
- }
+ return mCellMap->AppendCell(aCellFrame, aRowIndex);
+}
- PRInt32 rowIndex;
- // also determine the index of aRowFrame and set it if necessary
- if (0==mCellMap->GetRowCount())
- { // this is the first time we've ever been called
- rowIndex = 0;
- if (gsDebug==PR_TRUE) printf("rowFrame %p set to index %d\n", aRowFrame, rowIndex);
+void nsTableFrame::RemoveCellFromTable(nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex)
+{
+ nsCellMap* cellMap = GetCellMap();
+ PRInt32 numCols = cellMap->GetColCount();
+ cellMap->RemoveCell(aCellFrame, aRowIndex);
+ if (numCols != cellMap->GetColCount()) {
+ // XXX need to remove the anonymous col frames at the end
+ //nsTableColFrame* colFrame = nsnull;
+ //GetColumnFrame(colIndex, colFrame);
+ //if (colFrame && colFrame->IsAnonymous()) {
+ // nsTableColGroupFrame* colGroupFrame = nsnull;
+ //colFrame->GetParent((nsIFrame **)&colGroupFrame);
+ //if (colGroupFrame) {
+ // colGroupFrame->DeleteColFrame(aPresContext, colFrame);
}
- else
- {
- rowIndex = mCellMap->GetRowCount() - 1; // rowIndex is 0-indexed, rowCount is 1-indexed
- }
-
- PRInt32 colIndex=0;
- while (PR_TRUE)
- {
- CellData *data = mCellMap->GetCellAt(rowIndex, colIndex);
- if (nsnull == data)
- {
- BuildCellIntoMap(aCellFrame, rowIndex, colIndex);
- break;
- }
- colIndex++;
- }
-
-#ifdef NS_DEBUG
- if (gsDebug==PR_TRUE)
- DumpCellMap ();
-#endif
}
static nsresult BuildCellMapForRowGroup(nsIFrame* rowGroupFrame)
@@ -997,166 +815,6 @@ NS_METHOD nsTableFrame::ReBuildCellMap()
return rv;
}
-#ifdef NS_DEBUG
-void nsTableFrame::DumpCellMap ()
-{
- printf("dumping CellMap:\n");
- if (nsnull != mCellMap) {
- PRInt32 colIndex;
- PRInt32 rowCount = mCellMap->GetRowCount();
- PRInt32 colCount = mCellMap->GetColCount();
- printf("rowCount=%d, colCount=%d\n", rowCount, colCount);
-
- for (PRInt32 rowIndex = 0; rowIndex < rowCount; rowIndex++) {
- printf("row %d : ", rowIndex);
- for (colIndex = 0; colIndex < colCount; colIndex++) {
- CellData* cd = mCellMap->GetCellAt(rowIndex, colIndex);
- if (cd != nsnull) {
- if (cd->mCell != nsnull) {
- printf("C%d,%d ", rowIndex, colIndex);
- } else {
- nsTableCellFrame* cell = cd->mRealCell->mCell;
- nsTableRowFrame* row;
- cell->GetParent((nsIFrame**)&row);
- int rr = row->GetRowIndex();
- int cc;
- cell->GetColIndex(cc);
- printf("S%d,%d ", rr, cc);
- if (cd->mOverlap != nsnull){
- cell = cd->mOverlap->mCell;
- nsTableRowFrame* row2;
- cell->GetParent((nsIFrame**)&row2);
- rr = row2->GetRowIndex();
- cell->GetColIndex(cc);
- printf("O%d,%c ", rr, cc);
- }
- }
- } else {
- printf("---- ");
- }
- }
- PRBool spanners = RowHasSpanningCells(rowIndex);
- PRBool spannedInto = RowIsSpannedInto(rowIndex);
- printf (" spanners=%s spannedInto=%s\n", spanners?"T":"F", spannedInto?"T":"F");
- }
-
- // output info mapping Ci,j to cell address
- PRInt32 cellCount = 0;
- for (PRInt32 rIndex = 0; rIndex < rowCount; rIndex++) {
- for (colIndex = 0; colIndex < colCount; colIndex++) {
- CellData* cd = mCellMap->GetCellAt(rIndex, colIndex);
- if (cd != nsnull) {
- if (cd->mCell != nsnull) {
- printf("C%d,%d=%p ", rIndex, colIndex, cd->mCell);
- cellCount++;
- }
- }
- if (0 == (cellCount % 4)) {
- printf("\n");
- }
- }
- }
-
- // output colspan info
- for (colIndex=0; colIndexGetColumnFrame(colIndex);
- printf ("col index %d has frame=%p\n", colIndex, colFrame);
- }
- } else {
- printf ("[nsnull]");
- }
-}
-#endif
-
-void nsTableFrame::BuildCellIntoMap (nsTableCellFrame *aCell, PRInt32 aRowIndex, PRInt32 aColIndex)
-{
- NS_PRECONDITION (nsnull!=aCell, "bad cell arg");
- NS_PRECONDITION (0 <= aColIndex, "bad column index arg");
- NS_PRECONDITION (0 <= aRowIndex, "bad row index arg");
-
- // Setup CellMap for this cell
- int rowSpan = aCell->GetRowSpan();
- int colSpan = aCell->GetColSpan();
- if (gsDebug==PR_TRUE) printf("BCIM: rowSpan = %d, colSpan = %d\n", rowSpan, colSpan);
-
- // Grow the mCellMap array if we will end up addressing
- // some new columns.
- if (mCellMap->GetColCount() < (aColIndex + colSpan))
- {
- if (gsDebug==PR_TRUE)
- printf("BCIM: calling GrowCellMap(%d)\n", aColIndex+colSpan);
- GrowCellMap (aColIndex + colSpan);
- }
-
- if (mCellMap->GetRowCount() < (aRowIndex+1))
- {
- printf("BCIM: calling GrowToRow(%d)\n", aRowIndex+1);
- mCellMap->GrowToRow(aRowIndex+1);
- }
-
- // Setup CellMap for this cell in the table
- CellData *data = new CellData ();
- data->mCell = aCell;
- data->mRealCell = data;
- if (gsDebug==PR_TRUE) printf("BCIM: calling mCellMap->SetCellAt(data, %d, %d)\n", aRowIndex, aColIndex);
- mCellMap->SetCellAt(data, aRowIndex, aColIndex);
-
- // Create CellData objects for the rows that this cell spans. Set
- // their mCell to nsnull and their mRealCell to point to data. If
- // there were no column overlaps then we could use the same
- // CellData object for each row that we span...
- if ((1 < rowSpan) || (1 < colSpan))
- {
- if (gsDebug==PR_TRUE) printf("BCIM: spans\n");
- for (int rowIndex = 0; rowIndex < rowSpan; rowIndex++)
- {
- if (gsDebug==PR_TRUE) printf("BCIM: rowIndex = %d\n", rowIndex);
- int workRow = aRowIndex + rowIndex;
- if (gsDebug==PR_TRUE) printf("BCIM: workRow = %d\n", workRow);
- for (int colIndex = 0; colIndex < colSpan; colIndex++)
- {
- if (gsDebug==PR_TRUE) printf("BCIM: colIndex = %d\n", colIndex);
- int workCol = aColIndex + colIndex;
- if (gsDebug==PR_TRUE) printf("BCIM: workCol = %d\n", workCol);
- CellData *testData = mCellMap->GetCellAt(workRow, workCol);
- if (nsnull == testData)
- {
- CellData *spanData = new CellData ();
- spanData->mRealCell = data;
- if (gsDebug==PR_TRUE) printf("BCIM: null GetCellFrameAt(%d, %d) so setting to spanData\n", workRow, workCol);
- mCellMap->SetCellAt(spanData, workRow, workCol);
- }
- else if ((0 < rowIndex) || (0 < colIndex))
- { // we overlap, replace existing data, it might be shared
- if (gsDebug==PR_TRUE) printf("BCIM: overlapping Cell from GetCellFrameAt(%d, %d) so setting to spanData\n", workRow, workCol);
- CellData *overlap = new CellData ();
- overlap->mCell = testData->mCell;
- overlap->mRealCell = testData->mRealCell;
- overlap->mOverlap = data;
- mCellMap->SetCellAt(overlap, workRow, workCol);
- }
- }
- }
- }
-}
-
-void nsTableFrame::GrowCellMap (PRInt32 aColCount)
-{
- if (nsnull!=mCellMap)
- {
- mCellMap->GrowToCol(aColCount);
- mColCount = aColCount;
- }
-}
-
-
/* ***** Column Layout Data methods ***** */
/*
@@ -1243,7 +901,7 @@ void nsTableFrame::DidComputeHorizontalCollapsingBorders(nsIPresContext& aPresCo
{
CellData *cellData = mCellMap->GetCellAt(0, 0);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
nsRect rowRect(0,0,0,0);
if (nsnull!=cellFrame)
@@ -1267,7 +925,7 @@ void nsTableFrame::DidComputeHorizontalCollapsingBorders(nsIPresContext& aPresCo
{
CellData *cellData = mCellMap->GetCellAt(lastRowIndex, 0);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
nsRect rowRect(0,0,0,0);
if (nsnull!=cellFrame)
@@ -1405,7 +1063,7 @@ void nsTableFrame::ComputeLeftBorderForEdgeAt(nsIPresContext& aPresContext,
{
CellData *cellData = mCellMap->GetCellAt(aRowIndex, aColIndex);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
nsRect rowRect(0,0,0,0);
if (nsnull!=cellFrame)
@@ -1481,21 +1139,21 @@ void nsTableFrame::ComputeRightBorderForEdgeAt(nsIPresContext& aPresContext,
CellData *cd = mCellMap->GetCellAt(aRowIndex, colIndex);
if (cd != nsnull)
{ // there's really a cell at (aRowIndex, colIndex)
- if (nsnull==cd->mCell)
+ if (nsnull==cd->mOrigCell)
{ // the cell at (aRowIndex, colIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
+ nsTableCellFrame *cell = cd->mSpanData->mOrigCell;
NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
PRInt32 realRowIndex;
cell->GetRowIndex (realRowIndex);
if (realRowIndex!=aRowIndex)
{ // the span is caused by a rowspan
- rightNeighborFrame = cd->mRealCell->mCell;
+ rightNeighborFrame = cd->mSpanData->mOrigCell;
break;
}
}
else
{
- rightNeighborFrame = cd->mCell;
+ rightNeighborFrame = cd->mOrigCell;
break;
}
}
@@ -1522,7 +1180,7 @@ void nsTableFrame::ComputeRightBorderForEdgeAt(nsIPresContext& aPresContext,
{
CellData *cellData = mCellMap->GetCellAt(aRowIndex, aColIndex);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
nsRect rowRect(0,0,0,0);
if (nsnull!=cellFrame)
@@ -1623,7 +1281,7 @@ void nsTableFrame::ComputeTopBorderForEdgeAt(nsIPresContext& aPresContext,
{
CellData *cellData = mCellMap->GetCellAt(aRowIndex, aColIndex);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
if (nsnull!=cellFrame)
{
@@ -1704,21 +1362,21 @@ void nsTableFrame::ComputeBottomBorderForEdgeAt(nsIPresContext& aPresContext,
CellData *cd = mCellMap->GetCellAt(rowIndex, aColIndex);
if (cd != nsnull)
{ // there's really a cell at (rowIndex, aColIndex)
- if (nsnull==cd->mCell)
+ if (nsnull==cd->mOrigCell)
{ // the cell at (rowIndex, aColIndex) is the result of a span
- nsTableCellFrame *cell = cd->mRealCell->mCell;
+ nsTableCellFrame *cell = cd->mSpanData->mOrigCell;
NS_ASSERTION(nsnull!=cell, "bad cell map state, missing real cell");
PRInt32 realColIndex;
cell->GetColIndex (realColIndex);
if (realColIndex!=aColIndex)
{ // the span is caused by a colspan
- bottomNeighborFrame = cd->mRealCell->mCell;
+ bottomNeighborFrame = cd->mSpanData->mOrigCell;
break;
}
}
else
{
- bottomNeighborFrame = cd->mCell;
+ bottomNeighborFrame = cd->mOrigCell;
break;
}
}
@@ -1746,7 +1404,7 @@ void nsTableFrame::ComputeBottomBorderForEdgeAt(nsIPresContext& aPresContext,
{
CellData *cellData = mCellMap->GetCellAt(aRowIndex, aColIndex);
if (nsnull!=cellData)
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
}
nsRect rowRect(0,0,0,0);
if (nsnull!=cellFrame)
@@ -2091,7 +1749,7 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
CellData* cellData = cellMap->GetCellAt(row,col);
if (cellData)
- cell = cellData->mCell;
+ cell = cellData->mOrigCell;
if (nsnull==cell)
continue;
@@ -2113,7 +1771,8 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
{
cellData = cellMap->GetCellAt(row-1,col);
if (nsnull != cellData)
- above = cellData->mRealCell->mCell;
+// XXX was above = cellData->mSpanData->mOrigCell;
+ above = (cellData->mOrigCell) ? cellData->mOrigCell : cellData->mSpanData->mOrigCell;
// Does the cell data point to the same cell?
// If it is, then continue
@@ -2128,7 +1787,8 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
{
cellData = cellMap->GetCellAt(row,col-1);
if (cellData != nsnull)
- left = cellData->mRealCell->mCell;
+// XXX was left = cellData->mSpanData->mOrigCell;
+left = (cellData->mOrigCell) ? cellData->mOrigCell : cellData->mSpanData->mOrigCell;
if ((nsnull != left) && (left == cell))
continue;
@@ -2158,9 +1818,9 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
if (c != col)
{
cellData = cellMap->GetCellAt(r1,c);
- if ((cellData != nsnull) && (cellData->mCell != above))
+ if ((cellData != nsnull) && (cellData->mOrigCell != above))
{
- above = cellData->mCell;
+ above = cellData->mOrigCell;
if (above != nsnull)
AppendLayoutData(boundaryCells[NS_SIDE_TOP],above);
}
@@ -2175,9 +1835,9 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
{
// Add bottom edge cells
cellData = cellMap->GetCellAt(r2,c);
- if ((cellData != nsnull) && cellData->mCell != below)
+ if ((cellData != nsnull) && cellData->mOrigCell != below)
{
- below = cellData->mCell;
+ below = cellData->mOrigCell;
if (below != nsnull)
AppendLayoutData(boundaryCells[NS_SIDE_BOTTOM],below);
}
@@ -2200,9 +1860,9 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
if (r != row)
{
cellData = cellMap->GetCellAt(r,c1);
- if ((cellData != nsnull) && (cellData->mCell != left))
+ if ((cellData != nsnull) && (cellData->mOrigCell != left))
{
- left = cellData->mCell;
+ left = cellData->mOrigCell;
if (left != nsnull)
AppendLayoutData(boundaryCells[NS_SIDE_LEFT],left);
}
@@ -2217,9 +1877,9 @@ void nsTableFrame::RecalcLayoutData(nsIPresContext& aPresContext)
{
// Add right edge cells
cellData = cellMap->GetCellAt(r,c2);
- if ((cellData != nsnull) && (cellData->mCell != right))
+ if ((cellData != nsnull) && (cellData->mOrigCell != right))
{
- right = cellData->mCell;
+ right = cellData->mOrigCell;
if (right != nsnull)
AppendLayoutData(boundaryCells[NS_SIDE_RIGHT],right);
}
@@ -2443,20 +2103,25 @@ void nsTableFrame::SetColumnDimensions(nscoord aHeight)
nsIFrame* colGroupFrame = mColGroups.FirstChild();
PRInt32 colX = 0;
nsPoint colGroupOrigin(borderPadding.left, borderPadding.top);
+ PRInt32 numCols = GetColCount();
while (nsnull != colGroupFrame) {
nscoord colGroupWidth = 0;
nsIFrame* colFrame = nsnull;
colGroupFrame->FirstChild(nsnull, &colFrame);
nsPoint colOrigin(0, 0);
while (nsnull != colFrame) {
- NS_ASSERTION(colX < mColCount, "invalid number of columns");
- nscoord colWidth = mColumnWidths[colX] + cellSpacingX;
- if (mColCount == 1) {
+ NS_ASSERTION(colX < numCols, "invalid number of columns");
+ nscoord colWidth = mColumnWidths[colX];
+ if (numCols == 1) {
+ colWidth += cellSpacingX + cellSpacingX;
+ }
+ else if ((0 == colX) || (numCols - 1 == colX)) {
+ colWidth += cellSpacingX + halfCellSpacingX;
+ }
+ else if (GetNumCellsOriginatingIn(colX) > 0) {
colWidth += cellSpacingX;
}
- else if ((0 == colX) || (mColCount - 1 == colX)) {
- colWidth += halfCellSpacingX;
- }
+
colGroupWidth += colWidth;
nsRect colRect(colOrigin.x, colOrigin.y, colWidth, colHeight);
colFrame->SetRect(colRect);
@@ -2523,8 +2188,7 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext& aPresContext,
#ifdef NS_DEBUG
if (PR_TRUE==gsDebugIR)
{
- DumpCellMap();
- printf("tableFrame thinks colCount is %d\n", mEffectiveColCount);
+ if (mCellMap) mCellMap->Dump();
}
#endif
needsRecalc=PR_TRUE;
@@ -2599,10 +2263,6 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext& aPresContext,
// set aDesiredSize and aMaxElementSize
}
- // DumpCellMap is useful for debugging the results of an incremental reflow. But it's noisy,
- // so this module should not be checked in with the call enabled.
- //DumpCellMap();
-
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
{
if (nsnull!=aDesiredSize.maxElementSize)
@@ -2939,6 +2599,7 @@ NS_METHOD nsTableFrame::ResizeReflowPass2(nsIPresContext& aPresContext,
NS_METHOD nsTableFrame::AdjustForCollapsingRowGroup(nsIFrame* aRowGroupFrame,
PRInt32& aRowX)
{
+ nsCellMap* cellMap = GetCellMap(); // XXX is this right
const nsStyleDisplay* groupDisplay;
aRowGroupFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)groupDisplay));
PRBool groupIsCollapsed = (NS_STYLE_VISIBILITY_COLLAPSE == groupDisplay->mVisible);
@@ -2950,7 +2611,7 @@ NS_METHOD nsTableFrame::AdjustForCollapsingRowGroup(nsIFrame* aRowGroupFrame,
rowFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)rowDisplay));
if (NS_STYLE_DISPLAY_TABLE_ROW == rowDisplay->mDisplay) {
if (groupIsCollapsed || (NS_STYLE_VISIBILITY_COLLAPSE == rowDisplay->mVisible)) {
- mCellMap->SetRowCollapsedAt(aRowX, PR_TRUE);
+ cellMap->SetRowCollapsedAt(aRowX, PR_TRUE);
}
aRowX++;
}
@@ -3009,9 +2670,9 @@ NS_METHOD nsTableFrame::CollapseRowGroup(nsIFrame* aRowGroupFrame,
nsTableCellFrame* lastCell = nsnull;
for (int colX = 0; colX < numCols; colX++) {
CellData* cellData = mCellMap->GetCellAt(aRowX, colX);
- if (cellData && !cellData->mCell) { // a cell above is spanning into here
+ if (cellData && !cellData->mOrigCell) { // a cell above is spanning into here
// adjust the real cell's rect only once
- nsTableCellFrame* realCell = cellData->mRealCell->mCell;
+ nsTableCellFrame* realCell = cellData->mSpanData->mOrigCell;
if (realCell != lastCell) {
nsRect realRect;
realCell->GetRect(realRect);
@@ -3147,7 +2808,7 @@ NS_METHOD nsTableFrame::AdjustForCollapsingCols(nsIPresContext& aPresContext,
CellData* cellData = mCellMap->GetCellAt(rowX, col2X);
nsRect cellRect;
if (cellData) {
- cellFrame = cellData->mCell;
+ cellFrame = cellData->mOrigCell;
if (cellFrame) { // the cell originates at (rowX, colX)
cellFrame->GetRect(cellRect);
if (collapseGroup || collapseCol) {
@@ -3161,7 +2822,7 @@ NS_METHOD nsTableFrame::AdjustForCollapsingCols(nsIPresContext& aPresContext,
cellFrame->SetRect(cellRect);
// if the cell does not originate at (rowX, colX), adjust the real cells width
} else if (collapseGroup || collapseCol) {
- cellFrame = cellData->mRealCell->mCell;
+ cellFrame = cellData->mSpanData->mOrigCell;
if ((cellFrame) && (lastCell != cellFrame)) {
cellFrame->GetRect(cellRect);
cellRect.width -= colWidth + cellSpacingX;
@@ -3674,7 +3335,7 @@ nscoord nsTableFrame::ComputeDesiredWidth(const nsHTMLReflowState& aReflowState)
nsTableFrame* table = (nsTableFrame*)GetFirstInFlow();
tableLayoutStrategy = table->mTableLayoutStrategy;
}
- desiredWidth = tableLayoutStrategy->GetTableMaxWidth();
+ desiredWidth = tableLayoutStrategy->GetTableMaxContentWidth();
}
return desiredWidth;
}
@@ -4112,6 +3773,7 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext& aPresContext,
}
mTableLayoutStrategy->BalanceColumnWidths(mStyleContext, aReflowState, maxWidth);
+ //Dump(PR_TRUE, PR_TRUE);
mColumnWidthsSet=PR_TRUE;
// if collapsing borders, compute the top and bottom edges now that we have column widths
@@ -4136,18 +3798,28 @@ void nsTableFrame::SetTableWidth(nsIPresContext& aPresContext)
nscoord cellSpacing = GetCellSpacingX();
if (gsDebug==PR_TRUE)
printf ("SetTableWidth with cellSpacing = %d ", cellSpacing);
- PRInt32 tableWidth = cellSpacing;
+ PRInt32 tableWidth = 0;
PRInt32 numCols = GetColCount();
- for (PRInt32 colIndex = 0; colIndex 0) { // skip degenerate cols
+ totalColWidth += cellSpacing; // add cell spacing to left of col
+ }
+ if (gsDebug == PR_TRUE) printf (" += %d ", totalColWidth);
tableWidth += totalColWidth;
}
+ if (numCols > 0) {
+ tableWidth += cellSpacing; // add last cellspacing
+ }
+ else if (0 == tableWidth) {
+ nsRect tableRect = mRect;
+ tableRect.width = 0;
+ SetRect(tableRect);
+ return;
+ }
+
// Compute the insets (sum of border and padding)
const nsStyleSpacing* spacing =
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
@@ -4402,6 +4074,8 @@ nscoord nsTableFrame::ComputeDesiredHeight(nsIPresContext& aPresContext,
void nsTableFrame::AdjustColumnsForCOLSAttribute()
{
+// XXX this is not right,
+#if 0
nsCellMap *cellMap = GetCellMap();
NS_ASSERTION(nsnull!=cellMap, "bad cell map");
@@ -4431,6 +4105,7 @@ void nsTableFrame::AdjustColumnsForCOLSAttribute()
}
}
}
+#endif
}
/*
@@ -4440,11 +4115,16 @@ void nsTableFrame::AdjustColumnsForCOLSAttribute()
because specified widths tell us what proportion of the span width to give to each column
(in their absence, we use the desired width of the cell.)
*/
+
+// XXX this is being phased out. cells with colspans will potentially overwrite
+// col info stored by cells that don't span just because they are a bigger value.
+// The fixed width column info should be gotten from nsTableColFrame::GetFixedWidth
NS_METHOD
nsTableFrame::SetColumnStyleFromCell(nsIPresContext & aPresContext,
nsTableCellFrame* aCellFrame,
nsTableRowFrame * aRowFrame)
{
+#if 0
// if the cell has a colspan, the width is used provisionally, divided equally among
// the spanned columns until the table layout strategy computes the real column width.
if (PR_TRUE==gsDebug) printf("TIF SetCSFromCell: cell %p in row %p\n", aCellFrame, aRowFrame);
@@ -4535,6 +4215,7 @@ nsTableFrame::SetColumnStyleFromCell(nsIPresContext & aPresContext,
}
}
}
+#endif
return NS_OK;
}
@@ -4703,7 +4384,7 @@ void nsTableFrame::CacheColFramesInCellMap()
PRInt32 repeat = colFrame->GetSpan();
for (PRInt32 i=0; iGetColumnFrame(colIndex+i);
+ nsTableColFrame *cachedColFrame = mCellMap->GetColumnFrame(colIndex+i);
if (nsnull==cachedColFrame)
{
if (gsDebug)
@@ -5392,12 +5073,10 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
const nsHTMLReflowState& aReflowState,
nscoord& aSpecifiedTableWidth)
{
- NS_ASSERTION(nsnull!=aTableStyle, "bad arg - aTableStyle");
+ NS_ASSERTION(nsnull != aTableStyle, "bad arg - aTableStyle");
PRBool result = PR_TRUE; // the default
- if (nsnull!=aTableStyle)
- {
+ if (aTableStyle) {
nsStylePosition* tablePosition = (nsStylePosition*)aTableStyle->GetStyleData(eStyleStruct_Position);
- nsMargin borderPadding;
const nsStyleSpacing* spacing;
switch (tablePosition->mWidth.GetUnit()) {
case eStyleUnit_Auto: // specified auto width
@@ -5413,12 +5092,8 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
{
nscoord coordWidth = tablePosition->mWidth.GetCoordValue();
// NAV4 compatibility. If coord width is 0, do nothing so we get same result as "auto"
- if (0!=coordWidth)
- {
+ if (0 != coordWidth) {
aSpecifiedTableWidth = coordWidth;
- aReflowState.frame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
- spacing->CalcBorderPaddingFor(aReflowState.frame, borderPadding); //XXX: COLLAPSE
- aSpecifiedTableWidth -= (borderPadding.right + borderPadding.left);
result = PR_FALSE;
}
}
@@ -5429,9 +5104,9 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
// set aSpecifiedTableWidth to be the given percent of the parent.
// first, get the effective parent width (parent width - insets)
nscoord parentWidth = nsTableFrame::GetTableContainerWidth(aReflowState);
- if (NS_UNCONSTRAINEDSIZE!=parentWidth)
- {
+ if (NS_UNCONSTRAINEDSIZE != parentWidth) {
aReflowState.frame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
+ nsMargin borderPadding;
spacing->CalcBorderPaddingFor(aReflowState.frame, borderPadding); //XXX: COLLAPSE
parentWidth -= (borderPadding.right + borderPadding.left);
@@ -5442,8 +5117,7 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
printf("%p: TableIsAutoWidth setting aSpecifiedTableWidth = %d with parentWidth = %d and percent = %f\n",
aTableFrame, aSpecifiedTableWidth, parentWidth, percent);
}
- else
- {
+ else {
aSpecifiedTableWidth=parentWidth;
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
printf("%p: TableIsAutoWidth setting aSpecifiedTableWidth = %d with parentWidth = %d\n",
@@ -5469,20 +5143,20 @@ nscoord nsTableFrame::GetMinCaptionWidth()
}
/** return the minimum width of the table. Return 0 if the min width is unknown. */
-nscoord nsTableFrame::GetMinTableWidth()
+nscoord nsTableFrame::GetMinTableContentWidth()
{
nscoord result = 0;
if (nsnull!=mTableLayoutStrategy)
- result = mTableLayoutStrategy->GetTableMinWidth();
+ result = mTableLayoutStrategy->GetTableMinContentWidth();
return result;
}
/** return the maximum width of the table. Return 0 if the max width is unknown. */
-nscoord nsTableFrame::GetMaxTableWidth()
+nscoord nsTableFrame::GetMaxTableContentWidth()
{
nscoord result = 0;
if (nsnull!=mTableLayoutStrategy)
- result = mTableLayoutStrategy->GetTableMaxWidth();
+ result = mTableLayoutStrategy->GetTableMaxContentWidth();
return result;
}
@@ -5533,6 +5207,29 @@ nsTableFrame::IsFinalPass(const nsReflowState& aState)
(NS_UNCONSTRAINEDSIZE != aState.availableHeight);
}
+void nsTableFrame::Dump(PRBool aDumpCols, PRBool aDumpCellMap)
+{
+ printf("***START TABLE DUMP***, \n colWidths=");
+ PRInt32 colX;
+ PRInt32 numCols = GetColCount();
+ for (colX = 0; colX < numCols; colX++) {
+ printf("%d ", mColumnWidths[colX]);
+ }
+ if (aDumpCols) {
+ for (colX = 0; colX < numCols; colX++) {
+ printf("\n");
+ nsTableColFrame* colFrame = GetColFrame(colX);
+ colFrame->Dump(1);
+ }
+ }
+ if (aDumpCellMap) {
+ printf("\n");
+ nsCellMap* cellMap = GetCellMap();
+ cellMap->Dump();
+ }
+ printf(" ***END TABLE DUMP*** \n");
+}
+
// nsTableIterator
nsTableIterator::nsTableIterator(nsIFrame& aSource,
nsTableIteration aType)
@@ -5632,4 +5329,86 @@ PRInt32 nsTableIterator::Count()
return mCount;
}
+void nsTableFrame::GetCellInfoAt(PRInt32 aRowX,
+ PRInt32 aColX,
+ nsTableCellFrame*& aCellFrame,
+ PRBool& aOriginates,
+ PRInt32& aColSpan)
+{
+ nsCellMap* cellMap = GetCellMap();
+ cellMap->GetCellInfoAt(aRowX, aColX, aCellFrame, aOriginates, aColSpan);
+}
+PRInt32 nsTableFrame::GetNumCellsOriginatingIn(PRInt32 aColIndex)
+{
+ nsCellMap* cellMap = GetCellMap();
+ return cellMap->GetNumCellsOriginatingIn(aColIndex);
+}
+
+// The following are not used anywhere, but have been retained here just in case.
+#if 0
+/** returns PR_TRUE if the row at aRowIndex has any cells that are the result
+ * of a row-spanning cell.
+ * @see nsCellMap::RowIsSpannedInto
+ */
+PRBool nsTableFrame::RowIsSpannedInto(PRInt32 aRowIndex)
+{
+ NS_PRECONDITION (0<=aRowIndex && aRowIndexRowIsSpannedInto(aRowIndex);
+ }
+ return result;
+}
+
+/** returns PR_TRUE if the row at aRowIndex has any cells that have a rowspan>1
+ * @see nsCellMap::RowHasSpanningCells
+ */
+PRBool nsTableFrame::RowHasSpanningCells(PRInt32 aRowIndex)
+{
+ NS_PRECONDITION (0<=aRowIndex && aRowIndexRowHasSpanningCells(aRowIndex);
+ }
+ return result;
+}
+
+
+/** returns PR_TRUE if the col at aColIndex has any cells that are the result
+ * of a col-spanning cell.
+ * @see nsCellMap::ColIsSpannedInto
+ */
+PRBool nsTableFrame::ColIsSpannedInto(PRInt32 aColIndex)
+{
+ PRBool result = PR_FALSE;
+ nsCellMap * cellMap = GetCellMap();
+ NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated.");
+ if (nsnull!=cellMap)
+ {
+ result = cellMap->ColIsSpannedInto(aColIndex);
+ }
+ return result;
+}
+
+/** returns PR_TRUE if the row at aColIndex has any cells that have a colspan>1
+ * @see nsCellMap::ColHasSpanningCells
+ */
+PRBool nsTableFrame::ColHasSpanningCells(PRInt32 aColIndex)
+{
+ PRBool result = PR_FALSE;
+ nsCellMap * cellMap = GetCellMap();
+ NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated.");
+ if (nsnull!=cellMap)
+ {
+ result = cellMap->ColHasSpanningCells(aColIndex);
+ }
+ return result;
+}
+#endif
diff --git a/mozilla/layout/html/table/src/nsTableFrame.h b/mozilla/layout/html/table/src/nsTableFrame.h
index c9f7184012e..328ec1a8e92 100644
--- a/mozilla/layout/html/table/src/nsTableFrame.h
+++ b/mozilla/layout/html/table/src/nsTableFrame.h
@@ -47,6 +47,7 @@ struct nsStyleSpacing;
#define NS_TABLE_FRAME_COLGROUP_LIST_INDEX 0
#define NS_TABLE_FRAME_LAST_LIST_INDEX NS_TABLE_FRAME_COLGROUP_LIST_INDEX
+
/* ============================================================================ */
/** nsTableFrame maps the inner portion of a table (everything except captions.)
@@ -91,14 +92,6 @@ public:
/** @see nsIFrame::Destroy */
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
- /** helper method for determining if this is a nested table or not
- * @param aReflowState The reflow state for this inner table frame
- * @param aPosition [OUT] The position style struct for the parent table, if nested.
- * If not nested, undefined.
- * @return PR_TRUE if this table is nested inside another table.
- */
- PRBool IsNested(const nsHTMLReflowState& aReflowState, const nsStylePosition *& aPosition) const;
-
/** helper method to find the table parent of any table frame object */
// TODO: today, this depends on display types. This should be changed to rely
// on stronger criteria, like an inner table frame atom
@@ -377,6 +370,7 @@ public:
* of the table.
*/
virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCellFrame *aCell);
+ virtual PRInt32 GetEffectiveRowSpan(nsTableCellFrame *aCell);
/** return the col span of a cell, taking into account col span magic at the edge
* of a table.
@@ -388,6 +382,7 @@ public:
* of the table.
*/
virtual PRInt32 GetEffectiveColSpan(PRInt32 aColIndex, nsTableCellFrame *aCell);
+ virtual PRInt32 GetEffectiveColSpan(nsTableCellFrame *aCell);
/** return the value of the COLS attribute, adjusted for the
* actual number of columns in the table
@@ -399,23 +394,24 @@ public:
*/
PRInt32 GetNextAvailRowIndex() const;
- /** return the index of the next column in aRowIndex after aColIndex
- * that does not have a cell assigned to it.
- * If aColIndex is past the end of the row, it is returned.
- * If the row is not initialized, 0 is returned.
- */
- PRInt32 GetNextAvailColIndex(PRInt32 aRowIndex, PRInt32 aColIndex) const;
-
/** build as much of the CellMap as possible from the info we have so far
*/
- virtual void AddCellToTable (nsTableRowFrame *aRowFrame,
- nsTableCellFrame *aCellFrame,
- PRBool aAddRow);
+ virtual PRInt32 AddCellToTable (nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex);
+ virtual void RemoveCellFromTable (nsTableCellFrame* aCellFrame,
+ PRInt32 aRowIndex);
virtual void AddColumnFrame (nsTableColFrame *aColFrame);
static PRBool IsFinalPass(const nsReflowState& aReflowState);
+ void GetCellInfoAt(PRInt32 aRowX,
+ PRInt32 aColX,
+ nsTableCellFrame*& aCellFrame,
+ PRBool& aOriginates,
+ PRInt32& aColSpan);
+ PRInt32 GetNumCellsOriginatingIn(PRInt32 aColIndex);
+
NS_METHOD GetBorderPlusMarginPadding(nsMargin& aResult);
protected:
@@ -433,6 +429,14 @@ protected:
virtual PRBool ParentDisablesSelection() const; //override default behavior
+ /** helper method for determining if this is a nested table or not
+ * @param aReflowState The reflow state for this inner table frame
+ * @param aPosition [OUT] The position style struct for the parent table, if nested.
+ * If not nested, undefined.
+ * @return PR_TRUE if this table is nested inside another table.
+ */
+ PRBool IsNested(const nsHTMLReflowState& aReflowState, const nsStylePosition *& aPosition) const;
+
public:
/** first pass of ResizeReflow.
* lays out all table content with aMaxSize(NS_UNCONSTRAINEDSIZE,NS_UNCONSTRAINEDSIZE) and
@@ -700,14 +704,15 @@ protected:
void MapHTMLBorderStyle(nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth);
PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult);
- /** called whenever the number of columns changes, to increase the storage in mCellMap
- */
- virtual void GrowCellMap(PRInt32 aColCount);
-
/** returns PR_TRUE if the cached pass 1 data is still valid */
virtual PRBool IsCellMapValid() const;
public:
+ /** Get the cell map for this table frame. It is not always mCellMap.
+ * Only the firstInFlow has a legit cell map
+ */
+ virtual nsCellMap *GetCellMap() const;
+
/** ResetCellMap is called when the cell structure of the table is changed.
* Call with caution, only when changing the structure of the table such as
* inserting or removing rows, changing the rowspan or colspan attribute of a cell, etc.
@@ -718,19 +723,9 @@ protected:
/** iterates all child frames and creates a new cell map */
NS_IMETHOD ReBuildCellMap();
- /** Get the cell map for this table frame. It is not always mCellMap.
- * Only the firstInFlow has a legit cell map
- */
- virtual nsCellMap *GetCellMap() const;
-
void SetColumnDimensions(nscoord aHeight);
#ifdef NS_DEBUG
- /** for debugging only
- * prints out information about the cell map
- */
- void DumpCellMap();
-
/** for debugging only
* prints out info about the table layout state, printing columns and their cells
*/
@@ -743,9 +738,6 @@ protected:
*/
virtual void EnsureColumns (nsIPresContext& aPresContext);
- /** Set the min col span for every column in the table. Scans the whole table. */
- virtual void SetMinColSpanForTable();
-
virtual void BuildColumnCache(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
@@ -756,16 +748,6 @@ protected:
virtual void CacheColFramesInCellMap();
- /** 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.
- * This method changes mCellMap as necessary to account for the new cell.
- *
- * @param aCell the content object created for the cell
- * @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 (nsTableCellFrame *aCell, PRInt32 aRowIndex, PRInt32 aColIndex);
-
/** return the number of columns as specified by the input.
* has 2 side effects:
* calls SetStartColumnIndex on each nsTableColumn
@@ -786,13 +768,9 @@ public: /* ----- Cell Map public methods ----- */
*/
virtual PRInt32 GetRowCount() const;
- /** returns the number of columns in this table. */
- virtual PRInt32 GetColCount();
-
- /** adjust the col count for screwy table attributes.
- * currently just handles excess colspan at end of table
+ /** returns the number of columns in this table after redundant columns have been removed
*/
- virtual void SetEffectiveColCount();
+ virtual PRInt32 GetColCount();
/** return the column frame at colIndex.
* returns nsnull if the col frame has not yet been allocated, or if aColIndex is out of range
@@ -805,37 +783,16 @@ public: /* ----- Cell Map public methods ----- */
*/
nsTableCellFrame * GetCellFrameAt(PRInt32 aRowIndex, PRInt32 aColIndex);
- /** returns PR_TRUE if the row at aRowIndex has any cells that are the result
- * of a row-spanning cell above it.
- * @see nsCellMap::RowIsSpannedInto
- */
- PRBool RowIsSpannedInto(PRInt32 aRowIndex);
-
- /** returns PR_TRUE if the row at aRowIndex has any cells that have a rowspan>1
- * that originate in aRowIndex.
- * @see nsCellMap::RowHasSpanningCells
- */
- PRBool RowHasSpanningCells(PRInt32 aRowIndex);
-
- /** returns PR_TRUE if the col at aColIndex has any cells that are the result
- * of a col-spanning cell.
- * @see nsCellMap::ColIsSpannedInto
- */
- PRBool ColIsSpannedInto(PRInt32 aColIndex);
-
- /** returns PR_TRUE if the row at aColIndex has any cells that have a colspan>1
- * @see nsCellMap::ColHasSpanningCells
- */
- PRBool ColHasSpanningCells(PRInt32 aColIndex);
-
/** return the minimum width of the table caption. Return 0 if there is no caption. */
nscoord GetMinCaptionWidth();
- /** return the minimum width of the table. Return 0 if the min width is unknown. */
- nscoord GetMinTableWidth();
+ /** return the minimum contend width of the table (excludes borders and padding).
+ Return 0 if the min width is unknown. */
+ nscoord GetMinTableContentWidth();
- /** return the maximum width of the table caption. Return 0 if the max width is unknown. */
- nscoord GetMaxTableWidth();
+ /** return the maximum content width of the table (excludes borders and padding).
+ Return 0 if the max width is unknown. */
+ nscoord GetMaxTableContentWidth();
/** compute the max-element-size for the table
* @param aMaxElementSize [OUT] width field set to the min legal width of the table
@@ -847,6 +804,7 @@ public: /* ----- Cell Map public methods ----- */
public:
static nsIAtom* gColGroupAtom;
+ void Dump(PRBool aDumpCols, PRBool aDumpCellMap);
protected:
void DebugPrintCount() const; // Debugging routine
@@ -862,7 +820,6 @@ protected:
PRBool mIsInvariantWidth; // PR_TRUE if table width cannot change
PRBool mHasScrollableRowGroup; // PR_TRUE if any section has overflow == "auto" or "scroll"
PRInt32 mColCount; // the number of columns in this table
- PRInt32 mEffectiveColCount; // the number of columns in this table adjusted for weird table attributes
nsCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
ColumnInfoCache *mColCache; // cached information about the table columns
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp
index 82ed2a40cbf..fccb0a19cee 100644
--- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp
@@ -17,6 +17,7 @@
*/
#include "nsTableRowFrame.h"
#include "nsIRenderingContext.h"
+#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
@@ -31,6 +32,10 @@
#include "nsCSSRendering.h"
#include "nsHTMLIIDs.h"
#include "nsLayoutAtoms.h"
+#include "nsHTMLParts.h"
+#include "nsTableColGroupFrame.h"
+#include "nsTableColFrame.h"
+#include "nsCOMPtr.h"
// the following header files are required for style optimizations that work only when the child content is really a cell
#include "nsIHTMLTableCellElement.h"
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
@@ -117,7 +122,7 @@ nsTableRowFrame::Init(nsIPresContext& aPresContext,
}
NS_IMETHODIMP
-nsTableRowFrame::InitChildren(PRInt32 aRowIndex)
+nsTableRowFrame::InitChildren()
{
if (gsDebug) printf("Row InitChildren: begin\n");
nsTableFrame* table = nsnull;
@@ -132,11 +137,7 @@ nsTableRowFrame::InitChildren(PRInt32 aRowIndex)
if ((NS_OK==result) && (table != nsnull))
{
mInitializedChildren=PR_TRUE;
- PRInt32 rowIndex;
- if (-1==aRowIndex)
- rowIndex = table->GetNextAvailRowIndex();
- else
- rowIndex = aRowIndex;
+ PRInt32 rowIndex = table->GetNextAvailRowIndex();
SetRowIndex(rowIndex);
if (gsDebug) printf("Row InitChildren: set row index to %d\n", rowIndex);
PRInt32 colIndex = 0;
@@ -146,33 +147,14 @@ nsTableRowFrame::InitChildren(PRInt32 aRowIndex)
kidFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
{
+ // add the cell frame to the table's cell map and get its col index
+ PRInt32 colIndex;
+ colIndex = table->AddCellToTable((nsTableCellFrame *)kidFrame, rowIndex);
// what column does this cell belong to?
- colIndex = table->GetNextAvailColIndex(mRowIndex, colIndex);
- if (gsDebug) printf("Row InitChildren: cell given colIndex %d\n", colIndex);
- /* for style context optimization, set the content's column index if possible.
- * this can only be done if we really have an nsTableCell.
- * other tags mapped to table cell display won't benefit from this optimization
- * see nsHTMLStyleSheet::RulesMatching
- */
- nsIContent* cell;
- kidFrame->GetContent(&cell);
- nsIHTMLTableCellElement *cellContent = nsnull;
- nsresult rv = cell->QueryInterface(kIHTMLTableCellElementIID,
- (void **)&cellContent); // cellContent: REFCNT++
- NS_RELEASE(cell);
- if (NS_SUCCEEDED(rv))
- { // we know it's a table cell
- cellContent->SetColIndex(colIndex);
- if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, cellContent, colIndex);
- NS_RELEASE(cellContent);
- }
-
+ if (gsDebug) printf("Row InitChildren: cell given colIndex %d\n", colIndex);
// this sets the frame's notion of it's column index
((nsTableCellFrame *)kidFrame)->InitCellFrame(colIndex);
- if (gsDebug) printf("%p : set cell frame %p to col index = %d\n", this, kidFrame, colIndex);
- // add the cell frame to the table's cell map
- if (gsDebug) printf("Row InitChildren: calling AddCellToTable...\n");
- table->AddCellToTable(this, (nsTableCellFrame *)kidFrame, kidFrame == mFrames.FirstChild());
+ if (gsDebug) printf("%p : set cell frame %p to col index = %d\n", this, kidFrame, colIndex);
}
}
}
@@ -515,17 +497,16 @@ void nsTableRowFrame::PlaceChild(nsIPresContext& aPresContext,
aReflowState.x += aKidRect.width;
// Update the maximum element size
- PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan(mRowIndex,
- ((nsTableCellFrame*)aKidFrame));
- if (nsnull != aMaxElementSize)
- {
+ PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan((nsTableCellFrame*)aKidFrame);
+ if (nsnull != aMaxElementSize) {
aMaxElementSize->width += aKidMaxElementSize->width;
- if ((mMinRowSpan==rowSpan) && (aKidMaxElementSize->height>aMaxElementSize->height))
- {
- aMaxElementSize->height = aKidMaxElementSize->height;
+ if (1 == rowSpan) {
+ aMaxElementSize->height = PR_MAX(aMaxElementSize->height, aKidMaxElementSize->height);
}
}
+// XXX this will be fixed when row spans deal with dead rows
+#if 0
// this accounts for cases where all cells in a row have a rowspan>1
// XXX "numColsInThisRow==numColsInTable" probably isn't the right metric to use here
// the point is to skip a cell who's span effects another row, maybe use cellmap?
@@ -548,6 +529,23 @@ void nsTableRowFrame::PlaceChild(nsIPresContext& aPresContext,
aReflowState.maxCellVertSpace = height;
}
}
+#else
+ if (1 == rowSpan) {
+ // Update maxCellHeight
+ if (aKidRect.height > aReflowState.maxCellHeight)
+ aReflowState.maxCellHeight = aKidRect.height;
+
+ // Update maxCellVertSpace
+ nsMargin margin;
+
+ if (aReflowState.tableFrame->GetCellMarginData((nsTableCellFrame *)aKidFrame, margin) == NS_OK) {
+ nscoord height = aKidRect.height + margin.top + margin.bottom;
+
+ if (height > aReflowState.maxCellVertSpace)
+ aReflowState.maxCellVertSpace = height;
+ }
+ }
+#endif
}
/**
@@ -615,7 +613,9 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext,
if (prevColIndex != (cellColIndex - 1)) {
for (PRInt32 colIndex = prevColIndex + 1; cellColIndex > colIndex; colIndex++) {
aReflowState.x += aReflowState.tableFrame->GetColumnWidth(colIndex);
- aReflowState.x += cellSpacingX;
+ if (aReflowState.tableFrame->GetNumCellsOriginatingIn(colIndex) > 0) {
+ aReflowState.x += cellSpacingX;
+ }
if (PR_TRUE==gsDebug)
printf(" Row: in loop, aReflowState.x set to %d from cellSpacing %d and col width %d\n",
aReflowState.x, cellSpacingX, aReflowState.tableFrame->GetColumnWidth(colIndex));
@@ -627,7 +627,9 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext,
PRInt32 lastCol = cellColIndex + cellColSpan - 1;
for (PRInt32 colIndex = prevColIndex - 1; colIndex > lastCol; colIndex--) {
aReflowState.x += aReflowState.tableFrame->GetColumnWidth(colIndex);
- aReflowState.x += cellSpacingX;
+ if (aReflowState.tableFrame->GetNumCellsOriginatingIn(colIndex) > 0) {
+ aReflowState.x += cellSpacingX;
+ }
if (PR_TRUE==gsDebug)
printf(" Row: in loop, aReflowState.x set to %d from cellSpacing %d and col width %d\n",
aReflowState.x, cellSpacingX, aReflowState.tableFrame->GetColumnWidth(colIndex));
@@ -641,16 +643,15 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext,
// at this point, we know the column widths.
// so we get the avail width from the known column widths
nscoord availWidth = 0;
- for (PRInt32 numColSpan=0; numColSpanGetColumnWidth(cellColIndex+numColSpan);
- if (numColSpan != 0)
- {
+ if ((numColSpan != 0) && (aReflowState.tableFrame->GetNumCellsOriginatingIn(cellColIndex + numColSpan) > 0)) {
availWidth += cellSpacingX;
}
- if (PR_TRUE==gsDebug)
+ if (PR_TRUE==gsDebug) {
printf(" Row: in loop, availWidth set to %d from colIndex %d width %d and cellSpacing\n",
availWidth, cellColIndex, aReflowState.tableFrame->GetColumnWidth(cellColIndex+numColSpan));
+ }
}
if (PR_TRUE==gsDebug) printf(" Row: availWidth for this cell is %d\n", availWidth);
// remember the rightmost (ltr) or leftmost (rtl) column this cell spans into
@@ -777,21 +778,21 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext,
// we were given by the row group frame
aDesiredSize.width = aReflowState.x;
aDesiredSize.height = aReflowState.maxCellVertSpace;
+#ifdef DEBUG
+ nscoord overAllocated = aDesiredSize.width - aReflowState.reflowState.availableWidth;
+ if (overAllocated > 0) {
+ float p2t;
+ aPresContext.GetScaledPixelsToTwips(&p2t);
+ if (overAllocated > p2t) {
+ printf("row over allocated by %d twips", overAllocated);
+ }
+ }
+#endif
if (gsDebug)
printf("Row: RR -- row %p width = %d from maxSize %d\n",
this, aDesiredSize.width, aReflowState.reflowState.availableWidth);
- if (aDesiredSize.width > aReflowState.reflowState.availableWidth)
- {
- if (gsDebug)
- {
- printf ("Row %p error case, desired width = %d, maxSize=%d\n",
- this, aDesiredSize.width, aReflowState.reflowState.availableWidth);
- fflush (stdout);
- }
- }
- NS_ASSERTION(aDesiredSize.width <= aReflowState.reflowState.availableWidth, "row calculated to be too wide.");
return rv;
}
@@ -1153,6 +1154,7 @@ NS_METHOD nsTableRowFrame::IR_CellInserted(nsIPresContext& aPresContext,
if (NS_FAILED(rv) || nsnull==tableFrame)
return rv;
+#if 0
// do a pass-1 layout of the cell
if (PR_TRUE==tableFrame->RequiresPass1Layout())
{
@@ -1161,6 +1163,7 @@ NS_METHOD nsTableRowFrame::IR_CellInserted(nsIPresContext& aPresContext,
if (NS_FAILED(rv))
return rv;
}
+#endif
// set row state
GetMinRowSpan(tableFrame);
@@ -1169,6 +1172,7 @@ NS_METHOD nsTableRowFrame::IR_CellInserted(nsIPresContext& aPresContext,
// set table state
tableFrame->InvalidateCellMap();
tableFrame->InvalidateColumnCache();
+ tableFrame->InvalidateColumnWidths();
return rv;
}
@@ -1184,7 +1188,7 @@ NS_METHOD nsTableRowFrame::IR_CellAppended(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowReflowState& aReflowState,
nsReflowStatus& aStatus,
- nsTableCellFrame * aAppendedFrame)
+ nsTableCellFrame* aAppendedFrame)
{
if (PR_TRUE==gsDebugIR) printf("\nTRF IR: IR_CellInserted\n");
@@ -1197,6 +1201,7 @@ NS_METHOD nsTableRowFrame::IR_CellAppended(nsIPresContext& aPresContext,
if (NS_FAILED(rv) || nsnull==tableFrame)
return rv;
+ tableFrame->AddCellToTable(aAppendedFrame, GetRowIndex());
// do a pass-1 layout of the cell
if (PR_TRUE==tableFrame->RequiresPass1Layout())
{
@@ -1260,9 +1265,33 @@ NS_METHOD nsTableRowFrame::IR_CellRemoved(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowReflowState& aReflowState,
nsReflowStatus& aStatus,
- nsTableCellFrame * aDeletedFrame)
+ nsTableCellFrame* aDeletedFrame)
{
if (PR_TRUE==gsDebugIR) printf("\nRow IR: IR_RowRemoved\n");
+
+ nsTableFrame* tableFrame=nsnull;
+ nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
+ if (NS_FAILED(rv) || nsnull == tableFrame)
+ return rv;
+
+ PRInt32 colIndex;
+ aDeletedFrame->GetColIndex(colIndex);
+ tableFrame->RemoveCellFromTable(aDeletedFrame, GetRowIndex());
+ rv = mFrames.DestroyFrame(aPresContext, (nsIFrame*)aDeletedFrame);
+ if (NS_FAILED(rv))
+ return rv;
+
+ ResetMaxChildHeight();
+
+ // set row state
+ GetMinRowSpan(tableFrame);
+ FixMinCellHeight(tableFrame);
+
+ // set table state
+ tableFrame->InvalidateCellMap();
+ tableFrame->InvalidateColumnCache();
+
+#if 0
nsresult rv = mFrames.DestroyFrame(aPresContext, (nsIFrame*)aDeletedFrame);
if (NS_SUCCEEDED(rv))
{
@@ -1271,19 +1300,11 @@ NS_METHOD nsTableRowFrame::IR_CellRemoved(nsIPresContext& aPresContext,
rv = nsTableFrame::GetTableFrame(this, tableFrame);
if (NS_FAILED(rv) || nsnull==tableFrame)
return rv;
+#endif
- // set row state
- GetMinRowSpan(tableFrame);
- FixMinCellHeight(tableFrame);
-
- // set table state
- tableFrame->InvalidateCellMap();
- tableFrame->InvalidateColumnCache();
-
- // if any column widths have to change due to this, rebalance column widths
- //XXX need to calculate this, but for now just do it
- tableFrame->InvalidateColumnWidths();
- }
+ // if any column widths have to change due to this, rebalance column widths
+ //XXX need to calculate this, but for now just do it
+ tableFrame->InvalidateColumnWidths();
return rv;
}
diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.h b/mozilla/layout/html/table/src/nsTableRowFrame.h
index dbb1535c4b9..cddb6b6b175 100644
--- a/mozilla/layout/html/table/src/nsTableRowFrame.h
+++ b/mozilla/layout/html/table/src/nsTableRowFrame.h
@@ -45,7 +45,7 @@ public:
nsIFrame* aPrevInFlow);
/** Initialization of data */
- NS_IMETHOD InitChildren(PRInt32 aRowIndex=-1);
+ NS_IMETHOD InitChildren();
void ResetInitChildren();
diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp
index 6611c38338e..00394daff15 100644
--- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp
@@ -468,15 +468,13 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext& aPresC
kidRect.height);
PRInt32 colCount = aReflowState.tableFrame->GetColCount();
PRInt32 colIndex = 0;
- nsIFrame *cellFrame = aReflowState.tableFrame->GetCellFrameAt(rowIndex, colIndex);
- while (colIndexGetCellFrameAt(rowIndex, colIndex);
+ if (cellFrame) {
const nsStyleDisplay *cellDisplay;
cellFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)cellDisplay));
- if (NS_STYLE_DISPLAY_TABLE_CELL == cellDisplay->mDisplay)
- {
+ if (NS_STYLE_DISPLAY_TABLE_CELL == cellDisplay->mDisplay) {
((nsTableCellFrame *)(cellFrame))->SetBorderEdgeLength(NS_SIDE_LEFT,
rowIndex,
kidRect.height);
@@ -485,8 +483,6 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext& aPresC
kidRect.height);
}
}
- colIndex++;
- cellFrame = aReflowState.tableFrame->GetCellFrameAt(rowIndex, colIndex);
}
}
}
@@ -668,7 +664,6 @@ void nsTableRowGroupFrame::CalculateRowHeights(nsIPresContext& aPresContext,
// the avail height needs to reduce by top and bottom margins
nscoord availHeightOfRowsSpanned = heightOfRowsSpanned - cellSpacingY - cellSpacingY;
if (gsDebug) printf("TRGF CalcRowH: availHeightOfRowsSpanned=%d\n", availHeightOfRowsSpanned);
-
/* if the cell height fits in the rows, expand the spanning cell's height and slap it in */
nsSize cellFrameSize;
cellFrame->GetSize(cellFrameSize);
diff --git a/mozilla/layout/html/tests/table/bugs/bug1800.html b/mozilla/layout/html/tests/table/bugs/bug1800.html
index 72f4900a8a4..d9cdaaa7140 100644
--- a/mozilla/layout/html/tests/table/bugs/bug1800.html
+++ b/mozilla/layout/html/tests/table/bugs/bug1800.html
@@ -1,10 +1,49 @@
-|
-cell of outer table
- |
-|
-
- |
+
+ |
+ cell of outer table |
+
+
+
+
+ | cell of nested table |
+
+ |
+
+
+
+nested table width includes border
+
+
+nested table width includes border
+
+
+nested table width includes border
+
+
+nested table width includes border
+
diff --git a/mozilla/layout/html/tests/table/bugs/bug2763.html b/mozilla/layout/html/tests/table/bugs/bug2763.html
new file mode 100644
index 00000000000..774ca8b582e
--- /dev/null
+++ b/mozilla/layout/html/tests/table/bugs/bug2763.html
@@ -0,0 +1,10 @@
+two and words should be on the same line
+
+
+ | two words |
+ blah |
+
+
+ | blah |
+
+
diff --git a/mozilla/layout/html/tests/table/bugs/file_list.txt b/mozilla/layout/html/tests/table/bugs/file_list.txt
index 7439ad94e7a..a0b9b15ef48 100644
--- a/mozilla/layout/html/tests/table/bugs/file_list.txt
+++ b/mozilla/layout/html/tests/table/bugs/file_list.txt
@@ -31,6 +31,7 @@ file://s:/mozilla/layout/html/tests/table/bugs/bug2469.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2516.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2585.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2757.html
+file://s:/mozilla/layout/html/tests/table/bugs/bug2763.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2962.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2981-1.html
file://s:/mozilla/layout/html/tests/table/bugs/bug2981-2.html
diff --git a/mozilla/layout/html/tests/table/core/bloomberg.html b/mozilla/layout/html/tests/table/core/bloomberg.html
new file mode 100644
index 00000000000..1c982cb9262
--- /dev/null
+++ b/mozilla/layout/html/tests/table/core/bloomberg.html
@@ -0,0 +1,112 @@
+
+
+
+
+
+©1999 Bloomberg L.P. All rights reserved. Terms of Service, Privacy Policy and Trademarks.
+
+
+