fixed cellspacing and cellpadding handling

default cellspacing and cellpadding now comes from the table frame itself
other frames on longer look at the "tableStyle" struct for these values
This commit is contained in:
buster%netscape.com 1998-12-05 05:27:21 +00:00
Родитель 8173b65ac6
Коммит bee46015b7
10 изменённых файлов: 164 добавлений и 72 удалений

Просмотреть файл

@ -261,11 +261,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
maxColWidthArray = new PRInt32[mNumCols];
}
const nsStyleTable* tableStyle;
mTableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct*&)tableStyle);
nscoord cellPadding=0;
if (eStyleUnit_Coord==tableStyle->mCellPadding.GetUnit())
cellPadding=tableStyle->mCellPadding.GetCoordValue();
nscoord cellPadding=mTableFrame->GetCellPadding();
if (gsDebug) printf ("table cell padding = %d\n", cellPadding);
PRInt32 numRows = mTableFrame->GetRowCount();

Просмотреть файл

@ -299,19 +299,28 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
printf(" content returned desired width %d given avail width %d\n",
kidSize.width, availSize.width);
}
// Nav4 hack for 0 width cells.
// Empty cells are assigned a width of 3px
// Nav4 hack for 0 dimensioned cells.
// Empty cells are assigned a width and height of 4px
// see testcase "cellHeights.html"
if (0==kidSize.width)
{
float p2t;
aPresContext.GetScaledPixelsToTwips(p2t);
kidSize.width=NSIntPixelsToTwips(3, p2t);
kidSize.width=NSIntPixelsToTwips(4, p2t);
if (nsnull!=aDesiredSize.maxElementSize && 0==pMaxElementSize->width)
pMaxElementSize->width=NSIntPixelsToTwips(3, p2t);
if (gsDebug) printf ("setting child width from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(1, p2t));
pMaxElementSize->width=NSIntPixelsToTwips(4, p2t);
if (gsDebug) printf ("setting child width from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(4, p2t));
}
// end Nav4 hack for 0 width cells
if (0==kidSize.height)
{
float p2t;
aPresContext.GetScaledPixelsToTwips(p2t);
kidSize.height=NSIntPixelsToTwips(4, p2t);
if (nsnull!=aDesiredSize.maxElementSize && 0==pMaxElementSize->width)
pMaxElementSize->height=NSIntPixelsToTwips(4, p2t);
if (gsDebug) printf ("setting child height from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(4, p2t));
}
// end Nav4 hack for 0 dimensioned cells
#endif
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
{
@ -345,9 +354,10 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
// next determine the cell's width
nscoord cellWidth = kidSize.width; // at this point, we've factored in the cell's style attributes
// NAV4 compatibility: only add insets if cell content was not 0 width
if (0!=cellWidth)
if (NS_UNCONSTRAINEDSIZE!=availSize.width) // only add in insets if we previously subtracted them out
{
cellWidth += leftInset + rightInset; // factor in insets
}
// set the cell's desired size and max element size
aDesiredSize.width = cellWidth;
@ -357,10 +367,8 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
if (nsnull!=aDesiredSize.maxElementSize)
{
*aDesiredSize.maxElementSize = *pMaxElementSize;
// NAV4 compatibility: only add insets if cell content was not 0 min height
if (0!=pMaxElementSize->height)
aDesiredSize.maxElementSize->height += topInset + bottomInset;
// NAV4 compatibility: only add insets if cell content was not 0 min width
if (0!=pMaxElementSize->width)
aDesiredSize.maxElementSize->width += leftInset + rightInset;
}
@ -529,16 +537,17 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
// padding information in the cell. If these attributes
// are not defined, the the cells attributes are used
nscoord padding = 0;
nscoord spacing = 0;
nscoord border = 1;
nsTableFrame* tableFrame;
nsTableFrame::GetTableFrame(this, tableFrame);
NS_ASSERTION(tableFrame,"Table must not be null");
if (!tableFrame)
return;
nscoord padding = tableFrame->GetCellPadding();
nscoord spacing = tableFrame->GetCellSpacing();
nscoord border = 1;
// get the table frame style context, and from it get cellpadding, cellspacing, and border info
const nsStyleTable* tableStyle;
tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
@ -546,19 +555,14 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
tableFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)tableSpacingStyle);
nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing);
// check to see if cellpadding or cellspacing is defined
if (tableStyle->mCellPadding.GetUnit() != eStyleUnit_Null ||
tableStyle->mCellSpacing.GetUnit() != eStyleUnit_Null)
{
spacingData->mMargin.SetTop(tableStyle->mCellSpacing);
spacingData->mMargin.SetLeft(tableStyle->mCellSpacing);
spacingData->mMargin.SetBottom(tableStyle->mCellSpacing);
spacingData->mMargin.SetRight(tableStyle->mCellSpacing);
spacingData->mPadding.SetTop(tableStyle->mCellPadding);
spacingData->mPadding.SetLeft(tableStyle->mCellPadding);
spacingData->mPadding.SetBottom(tableStyle->mCellPadding);
spacingData->mPadding.SetRight(tableStyle->mCellPadding);
}
spacingData->mMargin.SetTop(spacing);
spacingData->mMargin.SetLeft(spacing);
spacingData->mMargin.SetBottom(spacing);
spacingData->mMargin.SetRight(spacing);
spacingData->mPadding.SetTop(padding);
spacingData->mPadding.SetLeft(padding);
spacingData->mPadding.SetBottom(padding);
spacingData->mPadding.SetRight(padding);
// get border information from the table
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE)

Просмотреть файл

@ -286,12 +286,28 @@ nsTableFrame::nsTableFrame()
nsCRT::memset (mColumnWidths, 0, mColumnWidthsLength*sizeof(PRInt32));
mCellMap = new nsCellMap(0, 0);
mColGroups=nsnull;
mDefaultCellSpacing=0;
mDefaultCellPadding=0;
// XXX for now these are a memory leak
if (nsnull == gColGroupAtom) {
gColGroupAtom = NS_NewAtom("ColGroup-list");
}
}
NS_IMETHODIMP
nsTableFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext)
{
float p2t = aPresContext.GetPixelsToTwips();
mDefaultCellSpacing = NSIntPixelsToTwips(2, p2t);
mDefaultCellPadding = NSIntPixelsToTwips(1, p2t);
return nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext);
}
nsTableFrame::~nsTableFrame()
{
if (nsnull!=mCellMap)
@ -3583,17 +3599,39 @@ NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin&
return result;
}
// XXX: could cache this. But be sure to check style changes if you do!
nscoord nsTableFrame::GetCellSpacing()
{
nsTableFrame* tableFrame = this;
const nsStyleTable* tableStyle;
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
nscoord cellSpacing = 0;
if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord)
if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord) {
cellSpacing = tableStyle->mCellSpacing.GetCoordValue();
}
else {
cellSpacing = mDefaultCellSpacing;
}
return cellSpacing;
}
// XXX: could cache this. But be sure to check style changes if you do!
nscoord nsTableFrame::GetCellPadding()
{
nsTableFrame* tableFrame = this;
const nsStyleTable* tableStyle;
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
nscoord cellPadding = 0;
if (tableStyle->mCellPadding.GetUnit() == eStyleUnit_Coord) {
cellPadding = tableStyle->mCellPadding.GetCoordValue();
}
else {
cellPadding = mDefaultCellPadding;
}
return cellPadding;
}
void nsTableFrame::GetColumnsByType(const nsStyleUnit aType,
PRInt32& aOutNumColumns,
PRInt32 *& aOutColumnIndexes)

Просмотреть файл

@ -77,6 +77,12 @@ public:
friend nsresult
NS_NewTableFrame(nsIFrame*& aResult);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext);
// nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
@ -189,6 +195,9 @@ public:
/** helper to get the cell spacing style value */
virtual nscoord GetCellSpacing();
/** helper to get the cell spacing style value */
virtual nscoord GetCellPadding();
/**
* Calculate Layout Information
@ -623,6 +632,8 @@ private:
ColumnInfoCache *mColCache; // cached information about the table columns
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
nsIFrame* mColGroups; // the list of colgroup frames
nscoord mDefaultCellSpacing; // the default cell spacing for this table
nscoord mDefaultCellPadding; // the default cell padding for this table
};

Просмотреть файл

@ -768,9 +768,6 @@ nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext,
kidSize.width = kidMaxElementSize.width;
if (kidMaxElementSize.height>kidSize.height)
kidSize.height = kidMaxElementSize.height;
kidSize.width += borderPadding.left+borderPadding.right;
kidSize.height += borderPadding.top+borderPadding.bottom;
kidMaxElementSize.SizeBy(borderPadding.left+borderPadding.right, borderPadding.top+borderPadding.bottom);
((nsTableCellFrame *)kidFrame)->SetPass1DesiredSize(kidSize);
((nsTableCellFrame *)kidFrame)->SetPass1MaxElementSize(kidMaxElementSize);
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "unexpected child reflow status");

Просмотреть файл

@ -261,11 +261,7 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths()
maxColWidthArray = new PRInt32[mNumCols];
}
const nsStyleTable* tableStyle;
mTableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct*&)tableStyle);
nscoord cellPadding=0;
if (eStyleUnit_Coord==tableStyle->mCellPadding.GetUnit())
cellPadding=tableStyle->mCellPadding.GetCoordValue();
nscoord cellPadding=mTableFrame->GetCellPadding();
if (gsDebug) printf ("table cell padding = %d\n", cellPadding);
PRInt32 numRows = mTableFrame->GetRowCount();

Просмотреть файл

@ -299,19 +299,28 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
printf(" content returned desired width %d given avail width %d\n",
kidSize.width, availSize.width);
}
// Nav4 hack for 0 width cells.
// Empty cells are assigned a width of 3px
// Nav4 hack for 0 dimensioned cells.
// Empty cells are assigned a width and height of 4px
// see testcase "cellHeights.html"
if (0==kidSize.width)
{
float p2t;
aPresContext.GetScaledPixelsToTwips(p2t);
kidSize.width=NSIntPixelsToTwips(3, p2t);
kidSize.width=NSIntPixelsToTwips(4, p2t);
if (nsnull!=aDesiredSize.maxElementSize && 0==pMaxElementSize->width)
pMaxElementSize->width=NSIntPixelsToTwips(3, p2t);
if (gsDebug) printf ("setting child width from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(1, p2t));
pMaxElementSize->width=NSIntPixelsToTwips(4, p2t);
if (gsDebug) printf ("setting child width from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(4, p2t));
}
// end Nav4 hack for 0 width cells
if (0==kidSize.height)
{
float p2t;
aPresContext.GetScaledPixelsToTwips(p2t);
kidSize.height=NSIntPixelsToTwips(4, p2t);
if (nsnull!=aDesiredSize.maxElementSize && 0==pMaxElementSize->width)
pMaxElementSize->height=NSIntPixelsToTwips(4, p2t);
if (gsDebug) printf ("setting child height from 0 to %d for nav4 compatibility\n", NSIntPixelsToTwips(4, p2t));
}
// end Nav4 hack for 0 dimensioned cells
#endif
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
{
@ -345,9 +354,10 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
// next determine the cell's width
nscoord cellWidth = kidSize.width; // at this point, we've factored in the cell's style attributes
// NAV4 compatibility: only add insets if cell content was not 0 width
if (0!=cellWidth)
if (NS_UNCONSTRAINEDSIZE!=availSize.width) // only add in insets if we previously subtracted them out
{
cellWidth += leftInset + rightInset; // factor in insets
}
// set the cell's desired size and max element size
aDesiredSize.width = cellWidth;
@ -357,10 +367,8 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext,
if (nsnull!=aDesiredSize.maxElementSize)
{
*aDesiredSize.maxElementSize = *pMaxElementSize;
// NAV4 compatibility: only add insets if cell content was not 0 min height
if (0!=pMaxElementSize->height)
aDesiredSize.maxElementSize->height += topInset + bottomInset;
// NAV4 compatibility: only add insets if cell content was not 0 min width
if (0!=pMaxElementSize->width)
aDesiredSize.maxElementSize->width += leftInset + rightInset;
}
@ -529,16 +537,17 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
// padding information in the cell. If these attributes
// are not defined, the the cells attributes are used
nscoord padding = 0;
nscoord spacing = 0;
nscoord border = 1;
nsTableFrame* tableFrame;
nsTableFrame::GetTableFrame(this, tableFrame);
NS_ASSERTION(tableFrame,"Table must not be null");
if (!tableFrame)
return;
nscoord padding = tableFrame->GetCellPadding();
nscoord spacing = tableFrame->GetCellSpacing();
nscoord border = 1;
// get the table frame style context, and from it get cellpadding, cellspacing, and border info
const nsStyleTable* tableStyle;
tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
@ -546,19 +555,14 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
tableFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)tableSpacingStyle);
nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing);
// check to see if cellpadding or cellspacing is defined
if (tableStyle->mCellPadding.GetUnit() != eStyleUnit_Null ||
tableStyle->mCellSpacing.GetUnit() != eStyleUnit_Null)
{
spacingData->mMargin.SetTop(tableStyle->mCellSpacing);
spacingData->mMargin.SetLeft(tableStyle->mCellSpacing);
spacingData->mMargin.SetBottom(tableStyle->mCellSpacing);
spacingData->mMargin.SetRight(tableStyle->mCellSpacing);
spacingData->mPadding.SetTop(tableStyle->mCellPadding);
spacingData->mPadding.SetLeft(tableStyle->mCellPadding);
spacingData->mPadding.SetBottom(tableStyle->mCellPadding);
spacingData->mPadding.SetRight(tableStyle->mCellPadding);
}
spacingData->mMargin.SetTop(spacing);
spacingData->mMargin.SetLeft(spacing);
spacingData->mMargin.SetBottom(spacing);
spacingData->mMargin.SetRight(spacing);
spacingData->mPadding.SetTop(padding);
spacingData->mPadding.SetLeft(padding);
spacingData->mPadding.SetBottom(padding);
spacingData->mPadding.SetRight(padding);
// get border information from the table
if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE)

Просмотреть файл

@ -286,12 +286,28 @@ nsTableFrame::nsTableFrame()
nsCRT::memset (mColumnWidths, 0, mColumnWidthsLength*sizeof(PRInt32));
mCellMap = new nsCellMap(0, 0);
mColGroups=nsnull;
mDefaultCellSpacing=0;
mDefaultCellPadding=0;
// XXX for now these are a memory leak
if (nsnull == gColGroupAtom) {
gColGroupAtom = NS_NewAtom("ColGroup-list");
}
}
NS_IMETHODIMP
nsTableFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext)
{
float p2t = aPresContext.GetPixelsToTwips();
mDefaultCellSpacing = NSIntPixelsToTwips(2, p2t);
mDefaultCellPadding = NSIntPixelsToTwips(1, p2t);
return nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext);
}
nsTableFrame::~nsTableFrame()
{
if (nsnull!=mCellMap)
@ -3583,17 +3599,39 @@ NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin&
return result;
}
// XXX: could cache this. But be sure to check style changes if you do!
nscoord nsTableFrame::GetCellSpacing()
{
nsTableFrame* tableFrame = this;
const nsStyleTable* tableStyle;
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
nscoord cellSpacing = 0;
if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord)
if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord) {
cellSpacing = tableStyle->mCellSpacing.GetCoordValue();
}
else {
cellSpacing = mDefaultCellSpacing;
}
return cellSpacing;
}
// XXX: could cache this. But be sure to check style changes if you do!
nscoord nsTableFrame::GetCellPadding()
{
nsTableFrame* tableFrame = this;
const nsStyleTable* tableStyle;
GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
nscoord cellPadding = 0;
if (tableStyle->mCellPadding.GetUnit() == eStyleUnit_Coord) {
cellPadding = tableStyle->mCellPadding.GetCoordValue();
}
else {
cellPadding = mDefaultCellPadding;
}
return cellPadding;
}
void nsTableFrame::GetColumnsByType(const nsStyleUnit aType,
PRInt32& aOutNumColumns,
PRInt32 *& aOutColumnIndexes)

Просмотреть файл

@ -77,6 +77,12 @@ public:
friend nsresult
NS_NewTableFrame(nsIFrame*& aResult);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext);
// nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
@ -189,6 +195,9 @@ public:
/** helper to get the cell spacing style value */
virtual nscoord GetCellSpacing();
/** helper to get the cell spacing style value */
virtual nscoord GetCellPadding();
/**
* Calculate Layout Information
@ -623,6 +632,8 @@ private:
ColumnInfoCache *mColCache; // cached information about the table columns
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
nsIFrame* mColGroups; // the list of colgroup frames
nscoord mDefaultCellSpacing; // the default cell spacing for this table
nscoord mDefaultCellPadding; // the default cell padding for this table
};

Просмотреть файл

@ -768,9 +768,6 @@ nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext,
kidSize.width = kidMaxElementSize.width;
if (kidMaxElementSize.height>kidSize.height)
kidSize.height = kidMaxElementSize.height;
kidSize.width += borderPadding.left+borderPadding.right;
kidSize.height += borderPadding.top+borderPadding.bottom;
kidMaxElementSize.SizeBy(borderPadding.left+borderPadding.right, borderPadding.top+borderPadding.bottom);
((nsTableCellFrame *)kidFrame)->SetPass1DesiredSize(kidSize);
((nsTableCellFrame *)kidFrame)->SetPass1MaxElementSize(kidMaxElementSize);
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "unexpected child reflow status");