support for css padding in table cells
git-svn-id: svn://10.0.0.236/trunk@32042 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1176,6 +1176,7 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
|
||||
}
|
||||
|
||||
// cellspacing (reuses tableStyle if already resolved)
|
||||
// ua.css sets cellspacing
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Pixel) {
|
||||
if (nsnull==tableStyle)
|
||||
@@ -1183,13 +1184,6 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
|
||||
tableStyle->mBorderSpacingX.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
||||
tableStyle->mBorderSpacingY.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
||||
}
|
||||
else
|
||||
{ // XXX: remove me as soon as we get this from the style sheet
|
||||
if (nsnull==tableStyle)
|
||||
tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);
|
||||
tableStyle->mBorderSpacingX.SetCoordValue(NSIntPixelsToTwips(2, p2t));
|
||||
tableStyle->mBorderSpacingY.SetCoordValue(NSIntPixelsToTwips(2, p2t));
|
||||
}
|
||||
|
||||
// cols
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::cols, value);
|
||||
|
||||
@@ -1176,6 +1176,7 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
|
||||
}
|
||||
|
||||
// cellspacing (reuses tableStyle if already resolved)
|
||||
// ua.css sets cellspacing
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Pixel) {
|
||||
if (nsnull==tableStyle)
|
||||
@@ -1183,13 +1184,6 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
|
||||
tableStyle->mBorderSpacingX.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
||||
tableStyle->mBorderSpacingY.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
||||
}
|
||||
else
|
||||
{ // XXX: remove me as soon as we get this from the style sheet
|
||||
if (nsnull==tableStyle)
|
||||
tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);
|
||||
tableStyle->mBorderSpacingX.SetCoordValue(NSIntPixelsToTwips(2, p2t));
|
||||
tableStyle->mBorderSpacingY.SetCoordValue(NSIntPixelsToTwips(2, p2t));
|
||||
}
|
||||
|
||||
// cols
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::cols, value);
|
||||
|
||||
@@ -131,12 +131,13 @@ table {
|
||||
display: table;
|
||||
/* border-style: outset; */
|
||||
border-color: #c0c0c0;
|
||||
cell-spacing: 2px;
|
||||
cell-padding: 2px;
|
||||
border-spacing: 2px;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* must never set padding in td, th */
|
||||
td, th {
|
||||
vertical-align: inherit;
|
||||
background-color: inherit;
|
||||
|
||||
@@ -345,6 +345,47 @@ PRBool BasicTableLayoutStrategy::BalanceColumnWidths(nsIStyleContext* aT
|
||||
return result;
|
||||
}
|
||||
|
||||
nscoord BasicTableLayoutStrategy::CalcHorizontalPadding(PRInt32 aColX)
|
||||
{
|
||||
nscoord maxLeftPadding = 0; // max left padding for cells starting in this col
|
||||
nscoord maxRightPadding = 0; // max right padding for cells ending in this col
|
||||
PRInt32 numRows = mTableFrame->GetRowCount();
|
||||
|
||||
for (PRInt32 rowX = 0; rowX < numRows; rowX++) {
|
||||
nsTableCellFrame* cellFrame = mTableFrame->GetCellFrameAt(rowX, aColX);
|
||||
if (nsnull == cellFrame) { // there is no cell in this row that corresponds to this column
|
||||
continue;
|
||||
}
|
||||
PRInt32 cellRowX;
|
||||
cellFrame->GetRowIndex(cellRowX);
|
||||
if (rowX != cellRowX) { // don't do anything except for 1st row this cell is in
|
||||
continue;
|
||||
}
|
||||
const nsStyleSpacing* spacing;
|
||||
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
||||
nsMargin marg;
|
||||
spacing->CalcPaddingFor(cellFrame, marg);
|
||||
maxLeftPadding = PR_MAX(maxLeftPadding, marg.left);
|
||||
|
||||
PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(aColX, cellFrame);
|
||||
|
||||
nsStyleCoord coord;
|
||||
PRInt32 cellColX;
|
||||
cellFrame->GetColIndex(cellColX);
|
||||
if (aColX != cellColX) { // the cell does not originate in this col
|
||||
if (-1 == aColX - cellColX - colSpan) { // the cell ends in this col
|
||||
spacing->mPadding.GetLeft(coord);
|
||||
maxRightPadding = PR_MAX(maxLeftPadding, marg.right);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (1 == colSpan) { // the cell ends in this col
|
||||
maxRightPadding = PR_MAX(maxLeftPadding, marg.right);
|
||||
}
|
||||
}
|
||||
return maxLeftPadding + maxRightPadding;
|
||||
}
|
||||
|
||||
// Step 1 - assign the width of all fixed-width columns, all other columns get there max,
|
||||
// and calculate min/max table width
|
||||
PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
@@ -362,11 +403,9 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
maxColWidthArray = new PRInt32[mNumCols];
|
||||
}
|
||||
|
||||
nscoord cellPadding = mTableFrame->GetCellPadding();
|
||||
TDBG_SD("table cell padding = %d\n", cellPadding);
|
||||
|
||||
PRInt32 numRows = mTableFrame->GetRowCount();
|
||||
PRInt32 colIndex, rowIndex;
|
||||
PRInt32* horPadding = new PRInt32[mNumCols];
|
||||
|
||||
// for every column, determine it's min and max width, and keep track of the table width
|
||||
for (colIndex = 0; colIndex < mNumCols; colIndex++) {
|
||||
@@ -380,7 +419,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
PRBool haveColWidth = PR_FALSE; // if true, the column has a width either from HTML width attribute,
|
||||
// from a style rule on the column,
|
||||
// or from a width attr/style on a cell that has colspan==1
|
||||
|
||||
horPadding[colIndex] = 0;
|
||||
// Get column information
|
||||
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colIndex);
|
||||
TDBG_SDD("BTLS::APCW - got colFrame %p for colIndex %d\n", colFrame, colIndex);
|
||||
@@ -396,7 +435,8 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) {
|
||||
haveColWidth = PR_TRUE;
|
||||
specifiedFixedColWidth = colPosition->mWidth.GetCoordValue();
|
||||
specifiedFixedColWidth += (cellPadding*2);
|
||||
horPadding[colIndex] = CalcHorizontalPadding(colIndex);
|
||||
specifiedFixedColWidth += horPadding[colIndex];
|
||||
TDBG_SD("BTLS::APCW - got specified col width = %d\n", specifiedFixedColWidth);
|
||||
}
|
||||
|
||||
@@ -421,8 +461,10 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
NS_ASSERTION(1 != cellFrame->GetRowSpan(), "row index does not match row span"); // sanity check
|
||||
continue;
|
||||
}
|
||||
|
||||
PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame);
|
||||
maxColSpan = PR_MAX(maxColSpan,colSpan);
|
||||
|
||||
PRInt32 cellColIndex;
|
||||
cellFrame->GetColIndex(cellColIndex);
|
||||
if (colIndex != cellColIndex) {
|
||||
@@ -437,12 +479,8 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
nscoord cellMinWidth = cellMinSize.width;
|
||||
|
||||
if (1 == colSpan) {
|
||||
if (0 == minColContentWidth) {
|
||||
minColContentWidth = cellMinWidth;
|
||||
}
|
||||
else {
|
||||
minColContentWidth = PR_MAX(minColContentWidth, cellMinWidth);
|
||||
}
|
||||
minColContentWidth = (0 == minColContentWidth)
|
||||
? cellMinWidth : PR_MAX(minColContentWidth, cellMinWidth);
|
||||
}
|
||||
else {
|
||||
minColContentWidth = PR_MAX(minColContentWidth, cellMinWidth/colSpan); // no need to divide this proportionately
|
||||
@@ -556,7 +594,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
} // end for (rowIndex = 0; rowIndex < numRows; rowIndex++)
|
||||
|
||||
// adjust the "fixed" width for content that is too wide
|
||||
if (effectiveMinColumnWidth > specifiedFixedColWidth) {
|
||||
if (haveColWidth && (effectiveMinColumnWidth > specifiedFixedColWidth)) {
|
||||
specifiedFixedColWidth = effectiveMinColumnWidth;
|
||||
}
|
||||
// do all the global bookkeeping, factoring in margins
|
||||
@@ -707,7 +745,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) {
|
||||
if (nsTableColFrame::eWIDTH_SOURCE_CELL_WITH_SPAN!=colFrame->GetWidthSource()) {
|
||||
nscoord specifiedFixedColWidth = colPosition->mWidth.GetCoordValue();
|
||||
specifiedFixedColWidth += (cellPadding*2);
|
||||
specifiedFixedColWidth += horPadding[colIndex];
|
||||
if (specifiedFixedColWidth>=colFrame->GetEffectiveMinColWidth()) {
|
||||
mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth);
|
||||
colFrame->SetMaxColWidth(specifiedFixedColWidth);
|
||||
@@ -719,6 +757,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] horPadding;
|
||||
|
||||
// now set the min and max table widths
|
||||
SetMinAndMaxTableWidths();
|
||||
|
||||
@@ -277,6 +277,8 @@ protected:
|
||||
void GetColumnsThatActLikeAutoWidth(PRInt32& aOutNumColumns,
|
||||
PRInt32*& aOutColumnIndexes);
|
||||
|
||||
nscoord CalcHorizontalPadding(PRInt32 aColX);
|
||||
|
||||
|
||||
protected:
|
||||
nsTableFrame * mTableFrame;
|
||||
|
||||
@@ -678,8 +678,8 @@ NS_METHOD nsTableCellFrame::IR_StyleChanged(nsIPresContext& aPresContex
|
||||
*/
|
||||
void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsStyleSpacing& aSpacingStyle,
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame *aTableFrame)
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame* aTableFrame)
|
||||
{
|
||||
nsStyleCoord width;
|
||||
width.SetCoordValue(aBorderWidth);
|
||||
@@ -704,7 +704,7 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsIStyleContext* styleContext = nsnull;
|
||||
|
||||
tableFrame->GetStyleContext(&styleContext);
|
||||
|
||||
|
||||
const nsStyleColor* colorData =
|
||||
nsStyleUtil::FindNonTransparentBackground(styleContext);
|
||||
NS_IF_RELEASE(styleContext);
|
||||
@@ -754,7 +754,7 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
*/
|
||||
break;
|
||||
case NS_STYLE_TABLE_RULES_COLS:
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_NONE);
|
||||
break;
|
||||
|
||||
@@ -796,11 +796,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
||||
if (!tableFrame)
|
||||
return;
|
||||
|
||||
nscoord padding = tableFrame->GetCellPadding();
|
||||
nscoord spacingX = tableFrame->GetCellSpacingX();
|
||||
nscoord spacingY = tableFrame->GetCellSpacingY();
|
||||
nscoord border = 1;
|
||||
|
||||
|
||||
// get the table frame style context, and from it get cellpadding, cellspacing, and border info
|
||||
const nsStyleTable* tableStyle;
|
||||
@@ -809,23 +806,38 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
||||
tableFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)tableSpacingStyle);
|
||||
nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing);
|
||||
|
||||
// Cache the border-spacing into margin and wipe out any previous
|
||||
// margins, since CSS doesn't allow margins to be set on cells
|
||||
spacingData->mMargin.SetTop(spacingY);
|
||||
spacingData->mMargin.SetLeft(spacingX);
|
||||
spacingData->mMargin.SetBottom(spacingY);
|
||||
spacingData->mMargin.SetRight(spacingX);
|
||||
spacingData->mPadding.SetTop(padding);
|
||||
spacingData->mPadding.SetLeft(padding);
|
||||
spacingData->mPadding.SetBottom(padding);
|
||||
spacingData->mPadding.SetRight(padding);
|
||||
spacingData->mMargin.SetBottom(spacingY);
|
||||
spacingData->mMargin.SetLeft(spacingX);
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
// Get the table's cellpadding or use 2 pixels as the default if it is not set.
|
||||
// This assumes that ua.css does not set padding for the cell.
|
||||
nscoord defaultPadding = tableFrame->GetCellPadding();
|
||||
if (-1 == defaultPadding) { // not set in table
|
||||
defaultPadding = NSIntPixelsToTwips(1, p2t);
|
||||
}
|
||||
|
||||
// if the padding is not already set, set it to the table's cellpadding
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetTopUnit())
|
||||
spacingData->mPadding.SetTop(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetRightUnit())
|
||||
spacingData->mPadding.SetRight(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetBottomUnit())
|
||||
spacingData->mPadding.SetBottom(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetLeftUnit())
|
||||
spacingData->mPadding.SetLeft(defaultPadding);
|
||||
|
||||
// get border information from the table
|
||||
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE)
|
||||
{
|
||||
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE) {
|
||||
// XXX: need to get border width here
|
||||
// in HTML, cell borders are always 1 pixel by default
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
border = NSIntPixelsToTwips(1, p2t);
|
||||
nscoord border = NSIntPixelsToTwips(1, p2t);
|
||||
MapHTMLBorderStyle(aPresContext, *spacingData, border, tableFrame);
|
||||
}
|
||||
|
||||
|
||||
@@ -200,8 +200,8 @@ protected:
|
||||
|
||||
void MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsStyleSpacing& aSpacingStyle,
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame *aTableFrame);
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame* aTableFrame);
|
||||
|
||||
void MapVAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame);
|
||||
void MapHAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame);
|
||||
|
||||
@@ -290,9 +290,6 @@ nsTableFrame::nsTableFrame()
|
||||
mColumnWidths = new PRInt32[mColumnWidthsLength];
|
||||
nsCRT::memset (mColumnWidths, 0, mColumnWidthsLength*sizeof(PRInt32));
|
||||
mCellMap = new nsCellMap(0, 0);
|
||||
mDefaultCellSpacingX=0;
|
||||
mDefaultCellSpacingY=0;
|
||||
mDefaultCellPadding=0;
|
||||
mBorderEdges.mOutsideEdge=PR_TRUE;
|
||||
}
|
||||
|
||||
@@ -304,12 +301,6 @@ nsTableFrame::Init(nsIPresContext& aPresContext,
|
||||
nsIFrame* aPrevInFlow)
|
||||
{
|
||||
nsresult rv;
|
||||
float p2t;
|
||||
|
||||
aPresContext.GetPixelsToTwips(&p2t);
|
||||
mDefaultCellSpacingX = NSIntPixelsToTwips(2, p2t);
|
||||
mDefaultCellSpacingY = NSIntPixelsToTwips(2, p2t);
|
||||
mDefaultCellPadding = NSIntPixelsToTwips(1, p2t);
|
||||
|
||||
// Let the base class do its processing
|
||||
rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext,
|
||||
@@ -4850,50 +4841,38 @@ nscoord nsTableFrame::GetCellSpacingX()
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellSpacing = 0;
|
||||
PRUint8 borderCollapseStyle = GetBorderCollapseStyle();
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle)
|
||||
{
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle) {
|
||||
if (tableStyle->mBorderSpacingX.GetUnit() == eStyleUnit_Coord) {
|
||||
cellSpacing = tableStyle->mBorderSpacingX.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellSpacing = mDefaultCellSpacingX;
|
||||
}
|
||||
}
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
nscoord nsTableFrame::GetCellSpacingY()
|
||||
{
|
||||
const nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellSpacing = 0;
|
||||
PRUint8 borderCollapseStyle = GetBorderCollapseStyle();
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle)
|
||||
{
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle) {
|
||||
if (tableStyle->mBorderSpacingY.GetUnit() == eStyleUnit_Coord) {
|
||||
cellSpacing = tableStyle->mBorderSpacingY.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellSpacing = mDefaultCellSpacingY;
|
||||
}
|
||||
}
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
// Get the cellpadding defined on the table. Each cell can override this with style
|
||||
nscoord nsTableFrame::GetCellPadding()
|
||||
{
|
||||
const nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellPadding = 0;
|
||||
nscoord cellPadding = -1;
|
||||
if (tableStyle->mCellPadding.GetUnit() == eStyleUnit_Coord) {
|
||||
cellPadding = tableStyle->mCellPadding.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellPadding = mDefaultCellPadding;
|
||||
}
|
||||
return cellPadding;
|
||||
}
|
||||
|
||||
|
||||
@@ -828,9 +828,6 @@ protected:
|
||||
ColumnInfoCache *mColCache; // cached information about the table columns
|
||||
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
|
||||
nsFrameList mColGroups; // the list of colgroup frames
|
||||
nscoord mDefaultCellSpacingX;// the default cell spacing X for this table
|
||||
nscoord mDefaultCellSpacingY;// the default cell spacing X for this table
|
||||
nscoord mDefaultCellPadding; // the default cell padding for this table
|
||||
|
||||
nsBorderEdges mBorderEdges; // one list of border segments for each side of the table frame
|
||||
// used only for the collapsing border model
|
||||
|
||||
@@ -131,12 +131,13 @@ table {
|
||||
display: table;
|
||||
/* border-style: outset; */
|
||||
border-color: #c0c0c0;
|
||||
cell-spacing: 2px;
|
||||
cell-padding: 2px;
|
||||
border-spacing: 2px;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* must never set padding in td, th */
|
||||
td, th {
|
||||
vertical-align: inherit;
|
||||
background-color: inherit;
|
||||
|
||||
@@ -345,6 +345,47 @@ PRBool BasicTableLayoutStrategy::BalanceColumnWidths(nsIStyleContext* aT
|
||||
return result;
|
||||
}
|
||||
|
||||
nscoord BasicTableLayoutStrategy::CalcHorizontalPadding(PRInt32 aColX)
|
||||
{
|
||||
nscoord maxLeftPadding = 0; // max left padding for cells starting in this col
|
||||
nscoord maxRightPadding = 0; // max right padding for cells ending in this col
|
||||
PRInt32 numRows = mTableFrame->GetRowCount();
|
||||
|
||||
for (PRInt32 rowX = 0; rowX < numRows; rowX++) {
|
||||
nsTableCellFrame* cellFrame = mTableFrame->GetCellFrameAt(rowX, aColX);
|
||||
if (nsnull == cellFrame) { // there is no cell in this row that corresponds to this column
|
||||
continue;
|
||||
}
|
||||
PRInt32 cellRowX;
|
||||
cellFrame->GetRowIndex(cellRowX);
|
||||
if (rowX != cellRowX) { // don't do anything except for 1st row this cell is in
|
||||
continue;
|
||||
}
|
||||
const nsStyleSpacing* spacing;
|
||||
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
||||
nsMargin marg;
|
||||
spacing->CalcPaddingFor(cellFrame, marg);
|
||||
maxLeftPadding = PR_MAX(maxLeftPadding, marg.left);
|
||||
|
||||
PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(aColX, cellFrame);
|
||||
|
||||
nsStyleCoord coord;
|
||||
PRInt32 cellColX;
|
||||
cellFrame->GetColIndex(cellColX);
|
||||
if (aColX != cellColX) { // the cell does not originate in this col
|
||||
if (-1 == aColX - cellColX - colSpan) { // the cell ends in this col
|
||||
spacing->mPadding.GetLeft(coord);
|
||||
maxRightPadding = PR_MAX(maxLeftPadding, marg.right);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (1 == colSpan) { // the cell ends in this col
|
||||
maxRightPadding = PR_MAX(maxLeftPadding, marg.right);
|
||||
}
|
||||
}
|
||||
return maxLeftPadding + maxRightPadding;
|
||||
}
|
||||
|
||||
// Step 1 - assign the width of all fixed-width columns, all other columns get there max,
|
||||
// and calculate min/max table width
|
||||
PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
@@ -362,11 +403,9 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
maxColWidthArray = new PRInt32[mNumCols];
|
||||
}
|
||||
|
||||
nscoord cellPadding = mTableFrame->GetCellPadding();
|
||||
TDBG_SD("table cell padding = %d\n", cellPadding);
|
||||
|
||||
PRInt32 numRows = mTableFrame->GetRowCount();
|
||||
PRInt32 colIndex, rowIndex;
|
||||
PRInt32* horPadding = new PRInt32[mNumCols];
|
||||
|
||||
// for every column, determine it's min and max width, and keep track of the table width
|
||||
for (colIndex = 0; colIndex < mNumCols; colIndex++) {
|
||||
@@ -380,7 +419,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
PRBool haveColWidth = PR_FALSE; // if true, the column has a width either from HTML width attribute,
|
||||
// from a style rule on the column,
|
||||
// or from a width attr/style on a cell that has colspan==1
|
||||
|
||||
horPadding[colIndex] = 0;
|
||||
// Get column information
|
||||
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colIndex);
|
||||
TDBG_SDD("BTLS::APCW - got colFrame %p for colIndex %d\n", colFrame, colIndex);
|
||||
@@ -396,7 +435,8 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) {
|
||||
haveColWidth = PR_TRUE;
|
||||
specifiedFixedColWidth = colPosition->mWidth.GetCoordValue();
|
||||
specifiedFixedColWidth += (cellPadding*2);
|
||||
horPadding[colIndex] = CalcHorizontalPadding(colIndex);
|
||||
specifiedFixedColWidth += horPadding[colIndex];
|
||||
TDBG_SD("BTLS::APCW - got specified col width = %d\n", specifiedFixedColWidth);
|
||||
}
|
||||
|
||||
@@ -421,8 +461,10 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
NS_ASSERTION(1 != cellFrame->GetRowSpan(), "row index does not match row span"); // sanity check
|
||||
continue;
|
||||
}
|
||||
|
||||
PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame);
|
||||
maxColSpan = PR_MAX(maxColSpan,colSpan);
|
||||
|
||||
PRInt32 cellColIndex;
|
||||
cellFrame->GetColIndex(cellColIndex);
|
||||
if (colIndex != cellColIndex) {
|
||||
@@ -437,12 +479,8 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
nscoord cellMinWidth = cellMinSize.width;
|
||||
|
||||
if (1 == colSpan) {
|
||||
if (0 == minColContentWidth) {
|
||||
minColContentWidth = cellMinWidth;
|
||||
}
|
||||
else {
|
||||
minColContentWidth = PR_MAX(minColContentWidth, cellMinWidth);
|
||||
}
|
||||
minColContentWidth = (0 == minColContentWidth)
|
||||
? cellMinWidth : PR_MAX(minColContentWidth, cellMinWidth);
|
||||
}
|
||||
else {
|
||||
minColContentWidth = PR_MAX(minColContentWidth, cellMinWidth/colSpan); // no need to divide this proportionately
|
||||
@@ -556,7 +594,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
} // end for (rowIndex = 0; rowIndex < numRows; rowIndex++)
|
||||
|
||||
// adjust the "fixed" width for content that is too wide
|
||||
if (effectiveMinColumnWidth > specifiedFixedColWidth) {
|
||||
if (haveColWidth && (effectiveMinColumnWidth > specifiedFixedColWidth)) {
|
||||
specifiedFixedColWidth = effectiveMinColumnWidth;
|
||||
}
|
||||
// do all the global bookkeeping, factoring in margins
|
||||
@@ -707,7 +745,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) {
|
||||
if (nsTableColFrame::eWIDTH_SOURCE_CELL_WITH_SPAN!=colFrame->GetWidthSource()) {
|
||||
nscoord specifiedFixedColWidth = colPosition->mWidth.GetCoordValue();
|
||||
specifiedFixedColWidth += (cellPadding*2);
|
||||
specifiedFixedColWidth += horPadding[colIndex];
|
||||
if (specifiedFixedColWidth>=colFrame->GetEffectiveMinColWidth()) {
|
||||
mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth);
|
||||
colFrame->SetMaxColWidth(specifiedFixedColWidth);
|
||||
@@ -719,6 +757,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] horPadding;
|
||||
|
||||
// now set the min and max table widths
|
||||
SetMinAndMaxTableWidths();
|
||||
|
||||
@@ -277,6 +277,8 @@ protected:
|
||||
void GetColumnsThatActLikeAutoWidth(PRInt32& aOutNumColumns,
|
||||
PRInt32*& aOutColumnIndexes);
|
||||
|
||||
nscoord CalcHorizontalPadding(PRInt32 aColX);
|
||||
|
||||
|
||||
protected:
|
||||
nsTableFrame * mTableFrame;
|
||||
|
||||
@@ -678,8 +678,8 @@ NS_METHOD nsTableCellFrame::IR_StyleChanged(nsIPresContext& aPresContex
|
||||
*/
|
||||
void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsStyleSpacing& aSpacingStyle,
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame *aTableFrame)
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame* aTableFrame)
|
||||
{
|
||||
nsStyleCoord width;
|
||||
width.SetCoordValue(aBorderWidth);
|
||||
@@ -704,7 +704,7 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsIStyleContext* styleContext = nsnull;
|
||||
|
||||
tableFrame->GetStyleContext(&styleContext);
|
||||
|
||||
|
||||
const nsStyleColor* colorData =
|
||||
nsStyleUtil::FindNonTransparentBackground(styleContext);
|
||||
NS_IF_RELEASE(styleContext);
|
||||
@@ -754,7 +754,7 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
*/
|
||||
break;
|
||||
case NS_STYLE_TABLE_RULES_COLS:
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
|
||||
aSpacingStyle.SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_NONE);
|
||||
break;
|
||||
|
||||
@@ -796,11 +796,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
||||
if (!tableFrame)
|
||||
return;
|
||||
|
||||
nscoord padding = tableFrame->GetCellPadding();
|
||||
nscoord spacingX = tableFrame->GetCellSpacingX();
|
||||
nscoord spacingY = tableFrame->GetCellSpacingY();
|
||||
nscoord border = 1;
|
||||
|
||||
|
||||
// get the table frame style context, and from it get cellpadding, cellspacing, and border info
|
||||
const nsStyleTable* tableStyle;
|
||||
@@ -809,23 +806,38 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
||||
tableFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)tableSpacingStyle);
|
||||
nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing);
|
||||
|
||||
// Cache the border-spacing into margin and wipe out any previous
|
||||
// margins, since CSS doesn't allow margins to be set on cells
|
||||
spacingData->mMargin.SetTop(spacingY);
|
||||
spacingData->mMargin.SetLeft(spacingX);
|
||||
spacingData->mMargin.SetBottom(spacingY);
|
||||
spacingData->mMargin.SetRight(spacingX);
|
||||
spacingData->mPadding.SetTop(padding);
|
||||
spacingData->mPadding.SetLeft(padding);
|
||||
spacingData->mPadding.SetBottom(padding);
|
||||
spacingData->mPadding.SetRight(padding);
|
||||
spacingData->mMargin.SetBottom(spacingY);
|
||||
spacingData->mMargin.SetLeft(spacingX);
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
// Get the table's cellpadding or use 2 pixels as the default if it is not set.
|
||||
// This assumes that ua.css does not set padding for the cell.
|
||||
nscoord defaultPadding = tableFrame->GetCellPadding();
|
||||
if (-1 == defaultPadding) { // not set in table
|
||||
defaultPadding = NSIntPixelsToTwips(1, p2t);
|
||||
}
|
||||
|
||||
// if the padding is not already set, set it to the table's cellpadding
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetTopUnit())
|
||||
spacingData->mPadding.SetTop(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetRightUnit())
|
||||
spacingData->mPadding.SetRight(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetBottomUnit())
|
||||
spacingData->mPadding.SetBottom(defaultPadding);
|
||||
if (eHTMLUnit_Null == spacingData->mPadding.GetLeftUnit())
|
||||
spacingData->mPadding.SetLeft(defaultPadding);
|
||||
|
||||
// get border information from the table
|
||||
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE)
|
||||
{
|
||||
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE) {
|
||||
// XXX: need to get border width here
|
||||
// in HTML, cell borders are always 1 pixel by default
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
border = NSIntPixelsToTwips(1, p2t);
|
||||
nscoord border = NSIntPixelsToTwips(1, p2t);
|
||||
MapHTMLBorderStyle(aPresContext, *spacingData, border, tableFrame);
|
||||
}
|
||||
|
||||
|
||||
@@ -200,8 +200,8 @@ protected:
|
||||
|
||||
void MapHTMLBorderStyle(nsIPresContext* aPresContext,
|
||||
nsStyleSpacing& aSpacingStyle,
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame *aTableFrame);
|
||||
nscoord aBorderWidth,
|
||||
nsTableFrame* aTableFrame);
|
||||
|
||||
void MapVAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame);
|
||||
void MapHAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame);
|
||||
|
||||
@@ -290,9 +290,6 @@ nsTableFrame::nsTableFrame()
|
||||
mColumnWidths = new PRInt32[mColumnWidthsLength];
|
||||
nsCRT::memset (mColumnWidths, 0, mColumnWidthsLength*sizeof(PRInt32));
|
||||
mCellMap = new nsCellMap(0, 0);
|
||||
mDefaultCellSpacingX=0;
|
||||
mDefaultCellSpacingY=0;
|
||||
mDefaultCellPadding=0;
|
||||
mBorderEdges.mOutsideEdge=PR_TRUE;
|
||||
}
|
||||
|
||||
@@ -304,12 +301,6 @@ nsTableFrame::Init(nsIPresContext& aPresContext,
|
||||
nsIFrame* aPrevInFlow)
|
||||
{
|
||||
nsresult rv;
|
||||
float p2t;
|
||||
|
||||
aPresContext.GetPixelsToTwips(&p2t);
|
||||
mDefaultCellSpacingX = NSIntPixelsToTwips(2, p2t);
|
||||
mDefaultCellSpacingY = NSIntPixelsToTwips(2, p2t);
|
||||
mDefaultCellPadding = NSIntPixelsToTwips(1, p2t);
|
||||
|
||||
// Let the base class do its processing
|
||||
rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext,
|
||||
@@ -4850,50 +4841,38 @@ nscoord nsTableFrame::GetCellSpacingX()
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellSpacing = 0;
|
||||
PRUint8 borderCollapseStyle = GetBorderCollapseStyle();
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle)
|
||||
{
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle) {
|
||||
if (tableStyle->mBorderSpacingX.GetUnit() == eStyleUnit_Coord) {
|
||||
cellSpacing = tableStyle->mBorderSpacingX.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellSpacing = mDefaultCellSpacingX;
|
||||
}
|
||||
}
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
nscoord nsTableFrame::GetCellSpacingY()
|
||||
{
|
||||
const nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellSpacing = 0;
|
||||
PRUint8 borderCollapseStyle = GetBorderCollapseStyle();
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle)
|
||||
{
|
||||
if (NS_STYLE_BORDER_COLLAPSE!=borderCollapseStyle) {
|
||||
if (tableStyle->mBorderSpacingY.GetUnit() == eStyleUnit_Coord) {
|
||||
cellSpacing = tableStyle->mBorderSpacingY.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellSpacing = mDefaultCellSpacingY;
|
||||
}
|
||||
}
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
|
||||
// XXX: could cache this. But be sure to check style changes if you do!
|
||||
// Get the cellpadding defined on the table. Each cell can override this with style
|
||||
nscoord nsTableFrame::GetCellPadding()
|
||||
{
|
||||
const nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
||||
nscoord cellPadding = 0;
|
||||
nscoord cellPadding = -1;
|
||||
if (tableStyle->mCellPadding.GetUnit() == eStyleUnit_Coord) {
|
||||
cellPadding = tableStyle->mCellPadding.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
cellPadding = mDefaultCellPadding;
|
||||
}
|
||||
return cellPadding;
|
||||
}
|
||||
|
||||
|
||||
@@ -828,9 +828,6 @@ protected:
|
||||
ColumnInfoCache *mColCache; // cached information about the table columns
|
||||
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
|
||||
nsFrameList mColGroups; // the list of colgroup frames
|
||||
nscoord mDefaultCellSpacingX;// the default cell spacing X for this table
|
||||
nscoord mDefaultCellSpacingY;// the default cell spacing X for this table
|
||||
nscoord mDefaultCellPadding; // the default cell padding for this table
|
||||
|
||||
nsBorderEdges mBorderEdges; // one list of border segments for each side of the table frame
|
||||
// used only for the collapsing border model
|
||||
|
||||
Reference in New Issue
Block a user