mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
fixed a minor bug in colspan layout
the layout strategy can now query the outer frame for the caption min width, and use it to expand the table if necessary did some related cleanup while I was in there.
This commit is contained in:
parent
38310b7690
commit
85d7016988
@ -1009,7 +1009,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR
|
||||
nscoord spanCellMaxWidth;
|
||||
if (0!=spanInfo->effectiveMaxWidthOfSpannedCols)
|
||||
{
|
||||
spanCellMaxWidth = (spanInfo->cellDesiredWidth * colFrame->GetEffectiveMinColWidth()) /
|
||||
spanCellMaxWidth = (spanInfo->cellDesiredWidth * colFrame->GetEffectiveMaxColWidth()) /
|
||||
(spanInfo->effectiveMaxWidthOfSpannedCols);
|
||||
if (gsDebug==PR_TRUE)
|
||||
printf (" spanlist max: %d of %d\n", spanCellMaxWidth, spanInfo->effectiveMaxWidthOfSpannedCols);
|
||||
@ -1502,26 +1502,36 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR
|
||||
delete proportionalColumnsList;
|
||||
}
|
||||
|
||||
// next, if the specified width of the table is greater than the table's computed width, expand the
|
||||
// table's computed width to match the specified width, giving the extra space to proportionately-sized
|
||||
// columns if possible.
|
||||
if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) &&
|
||||
(gBigSpace!=aAvailWidth))
|
||||
// next, account for table width constraints
|
||||
// if the caption min width is wider than than the table, expand the table
|
||||
nscoord captionMinWidth=mTableFrame->GetMinCaptionWidth();
|
||||
if (captionMinWidth>tableWidth)
|
||||
{
|
||||
DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns);
|
||||
DistributeExcessSpace(captionMinWidth, tableWidth, widthOfFixedTableColumns);
|
||||
}
|
||||
// IFF the table is NOT (auto-width && all columns have fixed width)
|
||||
PRInt32 numFixedColumns=0;
|
||||
PRInt32 *fixedColumns=nsnull;
|
||||
mTableFrame->GetColumnsByType(eStyleUnit_Coord, numFixedColumns, fixedColumns);
|
||||
if (!((PR_TRUE==aTableIsAutoWidth) && (numFixedColumns==mNumCols)))
|
||||
{
|
||||
nscoord computedWidth=0;
|
||||
for (PRInt32 i=0; i<mNumCols; i++) {
|
||||
computedWidth += mTableFrame->GetColumnWidth(i) + colInset;
|
||||
else
|
||||
{ // else, if the caption min width is not an issue...
|
||||
/* if the specified width of the table is greater than the table's computed width, expand the
|
||||
* table's computed width to match the specified width, giving the extra space to proportionately-sized
|
||||
* columns if possible. */
|
||||
if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) &&
|
||||
(gBigSpace!=aAvailWidth))
|
||||
{
|
||||
DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns);
|
||||
}
|
||||
if (computedWidth>aMaxWidth) {
|
||||
AdjustTableThatIsTooWide(computedWidth, aMaxWidth, PR_FALSE);
|
||||
// IFF the table is NOT (auto-width && all columns have fixed width)
|
||||
PRInt32 numFixedColumns=0;
|
||||
PRInt32 *fixedColumns=nsnull;
|
||||
mTableFrame->GetColumnsByType(eStyleUnit_Coord, numFixedColumns, fixedColumns);
|
||||
if (!((PR_TRUE==aTableIsAutoWidth) && (numFixedColumns==mNumCols)))
|
||||
{
|
||||
nscoord computedWidth=0;
|
||||
for (PRInt32 i=0; i<mNumCols; i++) {
|
||||
computedWidth += mTableFrame->GetColumnWidth(i) + colInset;
|
||||
}
|
||||
if (computedWidth>aMaxWidth) {
|
||||
AdjustTableThatIsTooWide(computedWidth, aMaxWidth, PR_FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,11 @@
|
||||
#include "nsTableColGroupFrame.h"
|
||||
#include "nsTableRowFrame.h"
|
||||
#include "nsTableRowGroupFrame.h"
|
||||
#include "nsTableOuterFrame.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
|
||||
#include "BasicTableLayoutStrategy.h"
|
||||
// #include "FixedTableLayoutStrategy.h"
|
||||
#include "FixedTableLayoutStrategy.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
@ -1584,7 +1585,7 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext& aPresContext,
|
||||
// Constrain our reflow width to the computed table width
|
||||
nsReflowState reflowState(aReflowState);
|
||||
reflowState.maxSize.width = mRect.width;
|
||||
aStatus = ResizeReflowPass2(&aPresContext, aDesiredSize, reflowState, 0, 0);
|
||||
aStatus = ResizeReflowPass2(&aPresContext, aDesiredSize, reflowState);
|
||||
|
||||
mPass = kPASS_UNDEFINED;
|
||||
}
|
||||
@ -1721,9 +1722,7 @@ nsReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresContext,
|
||||
*/
|
||||
nsReflowStatus nsTableFrame::ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState,
|
||||
PRInt32 aMinCaptionWidth,
|
||||
PRInt32 mMaxCaptionWidth)
|
||||
const nsReflowState& aReflowState)
|
||||
{
|
||||
//DumpCellMap();
|
||||
NS_PRECONDITION(aReflowState.frame == this, "bad reflow state");
|
||||
@ -2249,28 +2248,11 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext,
|
||||
// need to figure out the overall table width constraint
|
||||
// default case, get 100% of available space
|
||||
|
||||
PRInt32 maxWidth;
|
||||
PRInt32 maxWidth = aMaxSize.width;
|
||||
const nsStylePosition* position =
|
||||
(const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position);
|
||||
switch (position->mWidth.GetUnit()) {
|
||||
case eStyleUnit_Coord:
|
||||
if (eStyleUnit_Coord==position->mWidth.GetUnit())
|
||||
maxWidth = position->mWidth.GetCoordValue();
|
||||
break;
|
||||
|
||||
case eStyleUnit_Auto:
|
||||
maxWidth = aMaxSize.width;
|
||||
break;
|
||||
|
||||
case eStyleUnit_Percent:
|
||||
case eStyleUnit_Proportional:
|
||||
case eStyleUnit_Inherit:
|
||||
// XXX for now these fall through
|
||||
|
||||
default:
|
||||
maxWidth = aMaxSize.width;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (0>maxWidth) // nonsense style specification
|
||||
maxWidth = 0;
|
||||
@ -2284,11 +2266,9 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext,
|
||||
{
|
||||
nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle);
|
||||
#if XXX
|
||||
if (NS_STYLE_TABLE_LAYOUT_FIXED==tableStyle->mLayoutStrategy)
|
||||
mTableLayoutStrategy = new FixedTableLayoutStrategy(this, numCols);
|
||||
else
|
||||
#endif
|
||||
mTableLayoutStrategy = new BasicTableLayoutStrategy(this, numCols);
|
||||
mTableLayoutStrategy->Initialize(aMaxElementSize);
|
||||
}
|
||||
@ -3259,6 +3239,14 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
|
||||
return result;
|
||||
}
|
||||
|
||||
nscoord nsTableFrame::GetMinCaptionWidth()
|
||||
{
|
||||
nsIFrame *outerTableFrame=nsnull;
|
||||
GetContentParent(outerTableFrame);
|
||||
return (((nsTableOuterFrame *)outerTableFrame)->GetMinCaptionWidth());
|
||||
}
|
||||
|
||||
|
||||
/* ----- debugging methods ----- */
|
||||
NS_METHOD nsTableFrame::List(FILE* out, PRInt32 aIndent, nsIListFilter *aFilter) const
|
||||
{
|
||||
|
@ -267,17 +267,13 @@ protected:
|
||||
* Pass 2 is executed every time the table needs to resize. An optimization is included
|
||||
* so that if the table doesn't need to actually be resized, no work is done (see NeedsReflow).
|
||||
*
|
||||
* @param aMinCaptionWidth - the max of all the minimum caption widths. 0 if no captions.
|
||||
* @param aMaxCaptionWidth - the max of all the desired caption widths. 0 if no captions.
|
||||
*
|
||||
* @see Reflow
|
||||
* @see NeedsReflow
|
||||
*/
|
||||
virtual nsReflowStatus ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState,
|
||||
PRInt32 aMinCaptionWidth,
|
||||
PRInt32 mMaxCaptionWidth);
|
||||
virtual nsReflowStatus ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState);
|
||||
|
||||
nsresult AdjustSiblingsAfterReflow(nsIPresContext* aPresContext,
|
||||
InnerTableReflowState& aState,
|
||||
@ -475,6 +471,9 @@ public: /* ----- Cell Map public methods ----- */
|
||||
*/
|
||||
PRBool ColHasSpanningCells(PRInt32 aColIndex);
|
||||
|
||||
/** return the minimum width of the table caption. Return 0 if there is no caption. */
|
||||
nscoord GetMinCaptionWidth();
|
||||
|
||||
private:
|
||||
void DebugPrintCount() const; // Debugging routine
|
||||
|
||||
@ -495,4 +494,5 @@ private:
|
||||
nsCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -68,6 +68,9 @@ public:
|
||||
nsIStyleContext* aStyleContext,
|
||||
nsIFrame*& aContinuingFrame);
|
||||
|
||||
/** return the min width of the caption. Return 0 if there is no caption. */
|
||||
nscoord GetMinCaptionWidth();
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0, nsIListFilter *aFilter = nsnull) const;
|
||||
|
||||
protected:
|
||||
@ -155,6 +158,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
inline nscoord nsTableOuterFrame::GetMinCaptionWidth()
|
||||
{ return mMinCaptionWidth; }
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1009,7 +1009,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR
|
||||
nscoord spanCellMaxWidth;
|
||||
if (0!=spanInfo->effectiveMaxWidthOfSpannedCols)
|
||||
{
|
||||
spanCellMaxWidth = (spanInfo->cellDesiredWidth * colFrame->GetEffectiveMinColWidth()) /
|
||||
spanCellMaxWidth = (spanInfo->cellDesiredWidth * colFrame->GetEffectiveMaxColWidth()) /
|
||||
(spanInfo->effectiveMaxWidthOfSpannedCols);
|
||||
if (gsDebug==PR_TRUE)
|
||||
printf (" spanlist max: %d of %d\n", spanCellMaxWidth, spanInfo->effectiveMaxWidthOfSpannedCols);
|
||||
@ -1502,26 +1502,36 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR
|
||||
delete proportionalColumnsList;
|
||||
}
|
||||
|
||||
// next, if the specified width of the table is greater than the table's computed width, expand the
|
||||
// table's computed width to match the specified width, giving the extra space to proportionately-sized
|
||||
// columns if possible.
|
||||
if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) &&
|
||||
(gBigSpace!=aAvailWidth))
|
||||
// next, account for table width constraints
|
||||
// if the caption min width is wider than than the table, expand the table
|
||||
nscoord captionMinWidth=mTableFrame->GetMinCaptionWidth();
|
||||
if (captionMinWidth>tableWidth)
|
||||
{
|
||||
DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns);
|
||||
DistributeExcessSpace(captionMinWidth, tableWidth, widthOfFixedTableColumns);
|
||||
}
|
||||
// IFF the table is NOT (auto-width && all columns have fixed width)
|
||||
PRInt32 numFixedColumns=0;
|
||||
PRInt32 *fixedColumns=nsnull;
|
||||
mTableFrame->GetColumnsByType(eStyleUnit_Coord, numFixedColumns, fixedColumns);
|
||||
if (!((PR_TRUE==aTableIsAutoWidth) && (numFixedColumns==mNumCols)))
|
||||
{
|
||||
nscoord computedWidth=0;
|
||||
for (PRInt32 i=0; i<mNumCols; i++) {
|
||||
computedWidth += mTableFrame->GetColumnWidth(i) + colInset;
|
||||
else
|
||||
{ // else, if the caption min width is not an issue...
|
||||
/* if the specified width of the table is greater than the table's computed width, expand the
|
||||
* table's computed width to match the specified width, giving the extra space to proportionately-sized
|
||||
* columns if possible. */
|
||||
if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) &&
|
||||
(gBigSpace!=aAvailWidth))
|
||||
{
|
||||
DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns);
|
||||
}
|
||||
if (computedWidth>aMaxWidth) {
|
||||
AdjustTableThatIsTooWide(computedWidth, aMaxWidth, PR_FALSE);
|
||||
// IFF the table is NOT (auto-width && all columns have fixed width)
|
||||
PRInt32 numFixedColumns=0;
|
||||
PRInt32 *fixedColumns=nsnull;
|
||||
mTableFrame->GetColumnsByType(eStyleUnit_Coord, numFixedColumns, fixedColumns);
|
||||
if (!((PR_TRUE==aTableIsAutoWidth) && (numFixedColumns==mNumCols)))
|
||||
{
|
||||
nscoord computedWidth=0;
|
||||
for (PRInt32 i=0; i<mNumCols; i++) {
|
||||
computedWidth += mTableFrame->GetColumnWidth(i) + colInset;
|
||||
}
|
||||
if (computedWidth>aMaxWidth) {
|
||||
AdjustTableThatIsTooWide(computedWidth, aMaxWidth, PR_FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,11 @@
|
||||
#include "nsTableColGroupFrame.h"
|
||||
#include "nsTableRowFrame.h"
|
||||
#include "nsTableRowGroupFrame.h"
|
||||
#include "nsTableOuterFrame.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
|
||||
#include "BasicTableLayoutStrategy.h"
|
||||
// #include "FixedTableLayoutStrategy.h"
|
||||
#include "FixedTableLayoutStrategy.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
@ -1584,7 +1585,7 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext& aPresContext,
|
||||
// Constrain our reflow width to the computed table width
|
||||
nsReflowState reflowState(aReflowState);
|
||||
reflowState.maxSize.width = mRect.width;
|
||||
aStatus = ResizeReflowPass2(&aPresContext, aDesiredSize, reflowState, 0, 0);
|
||||
aStatus = ResizeReflowPass2(&aPresContext, aDesiredSize, reflowState);
|
||||
|
||||
mPass = kPASS_UNDEFINED;
|
||||
}
|
||||
@ -1721,9 +1722,7 @@ nsReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresContext,
|
||||
*/
|
||||
nsReflowStatus nsTableFrame::ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState,
|
||||
PRInt32 aMinCaptionWidth,
|
||||
PRInt32 mMaxCaptionWidth)
|
||||
const nsReflowState& aReflowState)
|
||||
{
|
||||
//DumpCellMap();
|
||||
NS_PRECONDITION(aReflowState.frame == this, "bad reflow state");
|
||||
@ -2249,28 +2248,11 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext,
|
||||
// need to figure out the overall table width constraint
|
||||
// default case, get 100% of available space
|
||||
|
||||
PRInt32 maxWidth;
|
||||
PRInt32 maxWidth = aMaxSize.width;
|
||||
const nsStylePosition* position =
|
||||
(const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position);
|
||||
switch (position->mWidth.GetUnit()) {
|
||||
case eStyleUnit_Coord:
|
||||
if (eStyleUnit_Coord==position->mWidth.GetUnit())
|
||||
maxWidth = position->mWidth.GetCoordValue();
|
||||
break;
|
||||
|
||||
case eStyleUnit_Auto:
|
||||
maxWidth = aMaxSize.width;
|
||||
break;
|
||||
|
||||
case eStyleUnit_Percent:
|
||||
case eStyleUnit_Proportional:
|
||||
case eStyleUnit_Inherit:
|
||||
// XXX for now these fall through
|
||||
|
||||
default:
|
||||
maxWidth = aMaxSize.width;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (0>maxWidth) // nonsense style specification
|
||||
maxWidth = 0;
|
||||
@ -2284,11 +2266,9 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext,
|
||||
{
|
||||
nsStyleTable* tableStyle;
|
||||
GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle);
|
||||
#if XXX
|
||||
if (NS_STYLE_TABLE_LAYOUT_FIXED==tableStyle->mLayoutStrategy)
|
||||
mTableLayoutStrategy = new FixedTableLayoutStrategy(this, numCols);
|
||||
else
|
||||
#endif
|
||||
mTableLayoutStrategy = new BasicTableLayoutStrategy(this, numCols);
|
||||
mTableLayoutStrategy->Initialize(aMaxElementSize);
|
||||
}
|
||||
@ -3259,6 +3239,14 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame,
|
||||
return result;
|
||||
}
|
||||
|
||||
nscoord nsTableFrame::GetMinCaptionWidth()
|
||||
{
|
||||
nsIFrame *outerTableFrame=nsnull;
|
||||
GetContentParent(outerTableFrame);
|
||||
return (((nsTableOuterFrame *)outerTableFrame)->GetMinCaptionWidth());
|
||||
}
|
||||
|
||||
|
||||
/* ----- debugging methods ----- */
|
||||
NS_METHOD nsTableFrame::List(FILE* out, PRInt32 aIndent, nsIListFilter *aFilter) const
|
||||
{
|
||||
|
@ -267,17 +267,13 @@ protected:
|
||||
* Pass 2 is executed every time the table needs to resize. An optimization is included
|
||||
* so that if the table doesn't need to actually be resized, no work is done (see NeedsReflow).
|
||||
*
|
||||
* @param aMinCaptionWidth - the max of all the minimum caption widths. 0 if no captions.
|
||||
* @param aMaxCaptionWidth - the max of all the desired caption widths. 0 if no captions.
|
||||
*
|
||||
* @see Reflow
|
||||
* @see NeedsReflow
|
||||
*/
|
||||
virtual nsReflowStatus ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState,
|
||||
PRInt32 aMinCaptionWidth,
|
||||
PRInt32 mMaxCaptionWidth);
|
||||
virtual nsReflowStatus ResizeReflowPass2(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsReflowState& aReflowState);
|
||||
|
||||
nsresult AdjustSiblingsAfterReflow(nsIPresContext* aPresContext,
|
||||
InnerTableReflowState& aState,
|
||||
@ -475,6 +471,9 @@ public: /* ----- Cell Map public methods ----- */
|
||||
*/
|
||||
PRBool ColHasSpanningCells(PRInt32 aColIndex);
|
||||
|
||||
/** return the minimum width of the table caption. Return 0 if there is no caption. */
|
||||
nscoord GetMinCaptionWidth();
|
||||
|
||||
private:
|
||||
void DebugPrintCount() const; // Debugging routine
|
||||
|
||||
@ -495,4 +494,5 @@ private:
|
||||
nsCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -68,6 +68,9 @@ public:
|
||||
nsIStyleContext* aStyleContext,
|
||||
nsIFrame*& aContinuingFrame);
|
||||
|
||||
/** return the min width of the caption. Return 0 if there is no caption. */
|
||||
nscoord GetMinCaptionWidth();
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0, nsIListFilter *aFilter = nsnull) const;
|
||||
|
||||
protected:
|
||||
@ -155,6 +158,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
inline nscoord nsTableOuterFrame::GetMinCaptionWidth()
|
||||
{ return mMinCaptionWidth; }
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user