handle baseline for empty table cells closer to the new description in CSS2.1, bug 291060 r/sr=dbaron

This commit is contained in:
bmlk%gmx.de 2005-10-04 15:47:21 +00:00
parent ce191154d3
commit 8d2cb2369f
6 changed files with 95 additions and 6 deletions

View File

@ -704,7 +704,13 @@ nsBlockFrame::Reflow(nsPresContext* aPresContext,
// Just return our current size as our desired size.
aMetrics.width = mRect.width;
aMetrics.height = mRect.height;
aMetrics.ascent = mAscent;
// XXXbernd this should be revised when inline-blocks are implemented
if (GetFirstChild(nsnull))
aMetrics.ascent = mAscent;
else
aMetrics.ascent = aMetrics.height;
aMetrics.descent = aMetrics.height - aMetrics.ascent;
// Whether or not we're complete hasn't changed
@ -1415,7 +1421,11 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState,
aMetrics.height = autoHeight;
}
aMetrics.ascent = mAscent;
// XXXbernd this should be revised when inline-blocks are implemented
if (GetFirstChild(nsnull))
aMetrics.ascent = mAscent;
else
aMetrics.ascent = aMetrics.height;
aMetrics.descent = aMetrics.height - aMetrics.ascent;
if (aState.GetFlag(BRS_COMPUTEMAXELEMENTWIDTH)) {

View File

@ -4036,6 +4036,26 @@ nscoord nsTableFrame::GetCellSpacingY()
return GetStyleTableBorder()->mBorderSpacingY.GetCoordValue();
}
nscoord nsTableFrame::GetAscent()
{
nscoord ascent = 0;
nsAutoVoidArray orderedRowGroups;
PRUint32 numRowGroups;
OrderRowGroups(orderedRowGroups, numRowGroups);
nsTableRowFrame* firstRow = nsnull;
for (PRUint32 rgIndex = 0; rgIndex < numRowGroups; rgIndex++) {
nsTableRowGroupFrame* rgFrame = GetRowGroupFrame((nsIFrame*)orderedRowGroups.ElementAt(rgIndex));
if (rgFrame->GetRowCount()) {
firstRow = rgFrame->GetFirstRow();
ascent = rgFrame->GetRect().y + firstRow->GetRect().y + firstRow->GetAscent();
break;
}
}
if (!firstRow)
ascent = GetRect().height;
return ascent;
}
/* ----- global methods ----- */
nsresult

View File

@ -405,6 +405,7 @@ public:
/** helper to get the cell spacing Y style value */
virtual nscoord GetCellSpacingY();
nscoord GetAscent();
/** return the row span of a cell, taking into account row span magic at the bottom
* of a table. The row span equals the number of rows spanned by aCell starting at
* aStartRowIndex, and can be smaller if aStartRowIndex is greater than the row

View File

@ -2015,8 +2015,14 @@ NS_METHOD nsTableOuterFrame::Reflow(nsPresContext* aPresContext,
}
// Return our desired rect
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
if (mInnerTableFrame) {
aDesiredSize.ascent = mInnerTableFrame->GetAscent();
aDesiredSize.descent = aDesiredSize.height - aDesiredSize.ascent;
}
else {
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
}
// compute max element size and maximum width if it hasn't already been
if (needUpdateMetrics) {

View File

@ -406,6 +406,43 @@ nscoord nsTableRowFrame::GetMaxCellAscent() const
return mMaxCellAscent;
}
nscoord nsTableRowFrame::GetAscent()
{
if(mMaxCellAscent)
return mMaxCellAscent;
// If we don't have a baseline on any of the cells we go for the lowest
// content edge of the inner block frames.
// Every table cell has a cell frame with its border and padding. Inside
// the cell is a block frame. The cell is as high as the tallest cell in
// the parent row. As a consequence the block frame might not touch both
// the top and the bottom padding of it parent cell frame at the same time.
//
// bbbbbbbbbbbbbbbbbb cell border: b
// bppppppppppppppppb cell padding: p
// bpxxxxxxxxxxxxxxpb inner block: x
// bpx xpb
// bpx xpb
// bpx xpb
// bpxxxxxxxxxxxxxxpb base line
// bp pb
// bp pb
// bppppppppppppppppb
// bbbbbbbbbbbbbbbbbb
nsTableIterator iter(*this, eTableDIR);
nsIFrame* childFrame = iter.First();
nscoord ascent = 0;
while (childFrame) {
if (IS_TABLE_CELL(childFrame->GetType())) {
nsIFrame* firstKid = childFrame->GetFirstChild(nsnull);
ascent = PR_MAX(ascent, firstKid->GetRect().YMost());
}
// Get the next child
childFrame = iter.Next();
}
return ascent;
}
nscoord
nsTableRowFrame::GetHeight(nscoord aPctBasis) const
{
@ -506,7 +543,11 @@ nsTableRowFrame::CalcHeight(const nsHTMLReflowState& aReflowState)
CalculateCellActualSize(kidFrame, desSize.width, desSize.height, availWidth);
}
// height may have changed, adjust descent to absorb any excess difference
nscoord ascent = ((nsTableCellFrame *)kidFrame)->GetDesiredAscent();
nscoord ascent;
if (!kidFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
ascent = desSize.height;
else
ascent = ((nsTableCellFrame *)kidFrame)->GetDesiredAscent();
nscoord descent = desSize.height - ascent;
UpdateHeight(desSize.height, ascent, descent, tableFrame, (nsTableCellFrame*)kidFrame);
}
@ -1003,7 +1044,11 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext,
desiredSize.height, availCellWidth);
}
// height may have changed, adjust descent to absorb any excess difference
nscoord ascent = cellFrame->GetDesiredAscent();
nscoord ascent;
if (!kidFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
ascent = desiredSize.height;
else
ascent = ((nsTableCellFrame *)kidFrame)->GetDesiredAscent();
nscoord descent = desiredSize.height - ascent;
UpdateHeight(desiredSize.height, ascent, descent, &aTableFrame, cellFrame);
}
@ -1227,6 +1272,8 @@ nsTableRowFrame::IR_TargetIsChild(nsPresContext* aPresContext,
CalculateCellActualSize(aNextFrame, cellMet.width, cellMet.height, cellAvailWidth);
// height may have changed, adjust descent to absorb any excess difference
if (!aNextFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
cellMet.ascent = cellMet.height;
cellMet.descent = cellMet.height - cellMet.ascent;
// if the cell got shorter and it may have been the tallest, recalc the tallest cell
@ -1513,6 +1560,7 @@ nsTableRowFrame::GetNextRow() const
nsIFrame* childFrame = GetNextSibling();
while (childFrame) {
if (nsLayoutAtoms::tableRowFrame == childFrame->GetType()) {
NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW == childFrame->GetStyleDisplay()->mDisplay, "wrong display type on rowframe");
return (nsTableRowFrame*)childFrame;
}
childFrame = childFrame->GetNextSibling();

View File

@ -160,6 +160,10 @@ public:
* returns 0 if we don't have any cell with 'vertical-align: baseline'
*/
nscoord GetMaxCellAscent() const;
/* return the row ascent
*/
nscoord GetAscent();
/** returns the ordinal position of this row in its table */
virtual PRInt32 GetRowIndex() const;