1998-04-30 21:57:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BasicTableLayoutStrategy.h"
|
|
|
|
#include "nsTableFrame.h"
|
1998-05-30 02:08:19 +04:00
|
|
|
#include "nsTableColFrame.h"
|
1998-04-30 21:57:09 +04:00
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-07-11 04:00:31 +04:00
|
|
|
#include "nsVoidArray.h"
|
1998-05-31 01:21:51 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
static const PRBool gsDebug = PR_FALSE;
|
1999-07-28 12:09:02 +04:00
|
|
|
#ifdef gsDebug
|
|
|
|
static PRInt32 debugCount = 0;
|
|
|
|
#endif
|
1998-05-30 02:08:19 +04:00
|
|
|
|
|
|
|
/* ---------- BasicTableLayoutStrategy ---------- */
|
|
|
|
|
1998-11-16 09:46:00 +03:00
|
|
|
/* return true if the style indicates that the width is fixed
|
1998-05-27 02:03:16 +04:00
|
|
|
* for the purposes of column width determination
|
|
|
|
*/
|
1998-11-16 09:46:00 +03:00
|
|
|
inline
|
|
|
|
PRBool BasicTableLayoutStrategy::IsFixedWidth(const nsStylePosition* aStylePosition,
|
1999-04-04 03:02:43 +04:00
|
|
|
const nsStyleTable* aStyleTable)
|
1998-05-27 02:03:16 +04:00
|
|
|
{
|
1998-11-16 09:46:00 +03:00
|
|
|
return PRBool ((eStyleUnit_Coord==aStylePosition->mWidth.GetUnit()) ||
|
|
|
|
(eStyleUnit_Coord==aStyleTable->mSpanWidth.GetUnit()));
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-27 02:22:23 +04:00
|
|
|
BasicTableLayoutStrategy::BasicTableLayoutStrategy(nsTableFrame *aFrame, PRBool aIsNavQuirks)
|
1998-04-30 21:57:09 +04:00
|
|
|
{
|
1999-04-04 03:02:43 +04:00
|
|
|
NS_ASSERTION(nsnull != aFrame, "bad frame arg");
|
1998-06-24 03:23:21 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
mTableFrame = aFrame;
|
|
|
|
mMinTableContentWidth = 0;
|
|
|
|
mMaxTableContentWidth = 0;
|
|
|
|
mCellSpacingTotal = 0;
|
|
|
|
mIsNavQuirksMode = aIsNavQuirks;
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicTableLayoutStrategy::~BasicTableLayoutStrategy()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-04-04 03:02:43 +04:00
|
|
|
PRBool BasicTableLayoutStrategy::Initialize(nsSize* aMaxElementSize,
|
1999-06-03 06:42:33 +04:00
|
|
|
PRInt32 aNumCols,
|
|
|
|
nscoord aMaxWidth)
|
1998-04-30 21:57:09 +04:00
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
ContinuingFrameCheck();
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1998-04-30 21:57:09 +04:00
|
|
|
PRBool result = PR_TRUE;
|
1998-05-27 02:03:16 +04:00
|
|
|
|
1998-07-22 22:22:12 +04:00
|
|
|
// re-init instance variables
|
1999-07-28 12:09:02 +04:00
|
|
|
mNumCols = aNumCols;
|
|
|
|
mMinTableContentWidth = 0;
|
|
|
|
mMaxTableContentWidth = 0;
|
|
|
|
mCellSpacingTotal = 0;
|
|
|
|
mCols = mTableFrame->GetEffectiveCOLSAttribute();
|
1998-07-22 22:22:12 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// assign the width of all fixed-width columns
|
1999-06-03 06:42:33 +04:00
|
|
|
AssignPreliminaryColumnWidths(aMaxWidth);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-07-17 03:23:31 +04:00
|
|
|
// set aMaxElementSize here because we compute mMinTableWidth in AssignPreliminaryColumnWidths
|
1999-04-04 03:02:43 +04:00
|
|
|
if (nsnull != aMaxElementSize) {
|
1998-10-09 23:59:45 +04:00
|
|
|
SetMaxElementSize(aMaxElementSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicTableLayoutStrategy::SetMaxElementSize(nsSize* aMaxElementSize)
|
|
|
|
{
|
1999-04-04 03:02:43 +04:00
|
|
|
if (nsnull != aMaxElementSize) {
|
1998-07-17 03:23:31 +04:00
|
|
|
aMaxElementSize->height = 0;
|
1998-08-07 06:11:51 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
const nsStylePosition* tablePosition;
|
|
|
|
const nsStyleSpacing* tableSpacing;
|
1998-11-20 12:29:58 +03:00
|
|
|
mTableFrame->GetStyleData(eStyleStruct_Position, ((const nsStyleStruct *&)tablePosition));
|
|
|
|
mTableFrame->GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing));
|
1998-12-23 18:47:43 +03:00
|
|
|
mTableFrame->GetTableBorder(borderPadding);
|
|
|
|
nsMargin padding;
|
|
|
|
tableSpacing->GetPadding(padding);
|
|
|
|
borderPadding += padding;
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord horBorderPadding = borderPadding.left + borderPadding.right;
|
1999-04-04 03:02:43 +04:00
|
|
|
if (tablePosition->mWidth.GetUnit() == eStyleUnit_Coord) {
|
1998-08-04 00:27:59 +04:00
|
|
|
aMaxElementSize->width = tablePosition->mWidth.GetCoordValue();
|
1999-07-28 12:09:02 +04:00
|
|
|
if (mMinTableContentWidth + horBorderPadding > aMaxElementSize->width) {
|
|
|
|
aMaxElementSize->width = mMinTableContentWidth + horBorderPadding;
|
|
|
|
}
|
1998-08-04 04:56:57 +04:00
|
|
|
}
|
1999-04-04 03:02:43 +04:00
|
|
|
else {
|
1999-07-28 12:09:02 +04:00
|
|
|
aMaxElementSize->width = mMinTableContentWidth + horBorderPadding;
|
1998-08-07 06:11:51 +04:00
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
void BasicTableLayoutStrategy::ContinuingFrameCheck()
|
1998-04-30 21:57:09 +04:00
|
|
|
{
|
1998-09-23 03:36:06 +04:00
|
|
|
#ifdef NS_DEBUG
|
1999-07-28 12:09:02 +04:00
|
|
|
nsIFrame* tablePIF = nsnull;
|
1999-02-24 07:48:08 +03:00
|
|
|
mTableFrame->GetPrevInFlow(&tablePIF);
|
1999-07-28 12:09:02 +04:00
|
|
|
NS_ASSERTION(!tablePIF, "never ever call me on a continuing frame!");
|
1998-04-30 21:57:09 +04:00
|
|
|
#endif
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
PRBool BCW_Wrapup(BasicTableLayoutStrategy* aStrategy,
|
|
|
|
nsTableFrame* aTableFrame,
|
|
|
|
PRInt32* aAllocTypes)
|
|
|
|
{
|
|
|
|
delete [] aAllocTypes;
|
|
|
|
//aStrategy->Dump(0);
|
|
|
|
//aTableFrame->Dump(PR_TRUE, PR_FALSE);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
PRBool
|
|
|
|
BasicTableLayoutStrategy::BalanceColumnWidths(nsIStyleContext* aTableStyle,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aMaxWidthIn)
|
|
|
|
{
|
|
|
|
//mTableFrame->Dump(PR_TRUE, PR_TRUE);
|
|
|
|
ContinuingFrameCheck();
|
|
|
|
if (!aTableStyle) {
|
|
|
|
NS_ASSERTION(aTableStyle, "bad style arg");
|
1998-07-17 03:23:31 +04:00
|
|
|
return PR_FALSE;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// determine if the table is auto/fixed and get the fixed width if available
|
|
|
|
nscoord maxWidth = aMaxWidthIn;
|
|
|
|
nscoord specifiedTableWidth = 0;
|
|
|
|
PRBool tableIsAutoWidth =
|
|
|
|
nsTableFrame::TableIsAutoWidth(mTableFrame, aTableStyle, aReflowState, specifiedTableWidth);
|
|
|
|
// a specifiedTableWidth of <= 0 indicates percentage based
|
|
|
|
if (!tableIsAutoWidth && (specifiedTableWidth > 0)) {
|
|
|
|
maxWidth = PR_MIN(specifiedTableWidth, aMaxWidthIn); // specifiedWidth usually == aMaxWidthIn for fixed table
|
|
|
|
}
|
|
|
|
// reduce the maxWidth by border and padding in some cases, since we will be dealing with content width
|
|
|
|
if (!tableIsAutoWidth && (maxWidth != NS_UNCONSTRAINEDSIZE)) {
|
|
|
|
const nsStylePosition* position;
|
|
|
|
mTableFrame->GetStyleData(eStyleStruct_Position, ((const nsStyleStruct *&)position));
|
|
|
|
if (eStyleUnit_Percent != position->mWidth.GetUnit()) {
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
mTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
|
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(mTableFrame, borderPadding);
|
|
|
|
maxWidth -= borderPadding.left + borderPadding.right;
|
|
|
|
maxWidth = PR_MAX(0, maxWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set the table's columns to the min width
|
|
|
|
// initialize the col percent and cell percent values to 0.
|
|
|
|
PRInt32 colX;
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord colMinWidth = colFrame->GetMinWidth();
|
|
|
|
mTableFrame->SetColumnWidth(colX, colMinWidth);
|
|
|
|
colFrame->SetWidth(PCT, WIDTH_NOT_SET);
|
|
|
|
colFrame->SetWidth(PCT_ADJ, WIDTH_NOT_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the max width available is less than the min content width for fixed table, we're done
|
|
|
|
if (!tableIsAutoWidth && (maxWidth < mMinTableContentWidth)) {
|
|
|
|
return PR_FALSE;
|
1998-07-18 01:02:28 +04:00
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// set PCT and PCT_ADJ widths on col frames and for an auto table return
|
|
|
|
// a new table width based on percent cells/cols if they exist
|
|
|
|
nscoord perAdjTableWidth = (maxWidth != NS_UNCONSTRAINEDSIZE)
|
|
|
|
? AssignPercentageColumnWidths(maxWidth - mCellSpacingTotal, tableIsAutoWidth) : 0;
|
|
|
|
|
|
|
|
// if the max width available is less than the min content width for auto table
|
|
|
|
// that had no % cells/cols, we're done
|
|
|
|
if (tableIsAutoWidth && (maxWidth < mMinTableContentWidth) & (0 == perAdjTableWidth)) {
|
|
|
|
return PR_TRUE;
|
1998-07-27 06:15:37 +04:00
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 cellSpacingTotal;
|
|
|
|
// the following are of size NUM_WIDTHS, but only MIN_CON, DES_CON, FIX, PCT
|
|
|
|
// are used and they account for colspan ADJusted values
|
|
|
|
PRInt32 totalWidths[NUM_WIDTHS]; // sum of col widths of a particular type
|
|
|
|
PRInt32 totalCounts[NUM_WIDTHS]; // num of cols of a particular type
|
|
|
|
PRInt32 minWidths[NUM_WIDTHS];
|
|
|
|
PRInt32 num0Proportional;
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
CalculateTotals(cellSpacingTotal, totalCounts, totalWidths, minWidths, num0Proportional);
|
|
|
|
// auto width table's adjusted width needs cell spacing
|
|
|
|
if (tableIsAutoWidth && perAdjTableWidth > 0) {
|
|
|
|
perAdjTableWidth = PR_MIN(perAdjTableWidth + cellSpacingTotal, maxWidth);
|
|
|
|
}
|
|
|
|
nscoord totalAllocated = totalWidths[MIN_CON] + cellSpacingTotal;
|
|
|
|
|
|
|
|
// allocate and initialize arrays indicating what col gets set
|
|
|
|
PRInt32* allocTypes = new PRInt32[mNumCols];
|
|
|
|
if (!allocTypes) return PR_FALSE;
|
|
|
|
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
allocTypes[colX] = -1;
|
|
|
|
}
|
1999-05-18 09:18:16 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// allocate percentage cols
|
|
|
|
if (totalCounts[PCT] > 0) {
|
|
|
|
if (totalAllocated + totalWidths[PCT] - minWidths[PCT] <= maxWidth) {
|
|
|
|
AllocateFully(totalAllocated, allocTypes, PCT);
|
|
|
|
NS_ASSERTION(totalAllocated <= maxWidth, "over allocated");
|
1999-05-18 09:18:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
else {
|
|
|
|
AllocateConstrained(maxWidth - totalAllocated, PCT, totalCounts[PCT],
|
|
|
|
totalWidths[PCT], PR_FALSE, allocTypes);
|
|
|
|
return BCW_Wrapup(this, mTableFrame, allocTypes);
|
1999-05-18 09:18:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
// allocate fixed cols
|
|
|
|
if (totalAllocated < maxWidth && totalCounts[FIX] > 0) {
|
|
|
|
if (totalAllocated + totalWidths[FIX] - minWidths[FIX] <= maxWidth) {
|
|
|
|
AllocateFully(totalAllocated, allocTypes, FIX);
|
|
|
|
NS_ASSERTION(totalAllocated <= maxWidth, "over allocated");
|
1999-05-18 09:18:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
else {
|
|
|
|
AllocateConstrained(maxWidth - totalAllocated, FIX, totalCounts[FIX],
|
|
|
|
totalWidths[FIX], PR_TRUE, allocTypes);
|
|
|
|
return BCW_Wrapup(this, mTableFrame, allocTypes);
|
1999-05-18 09:18:16 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
// allocate proportional cols up to their min proportional value
|
|
|
|
if (totalAllocated < maxWidth && totalCounts[MIN_PRO] > 0) {
|
|
|
|
if (totalAllocated + totalWidths[MIN_PRO] - minWidths[MIN_PRO] <= maxWidth) {
|
|
|
|
AllocateFully(totalAllocated, allocTypes, MIN_PRO, PR_FALSE);
|
|
|
|
NS_ASSERTION(totalAllocated <= maxWidth, "over allocated");
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-07-28 12:09:02 +04:00
|
|
|
AllocateConstrained(maxWidth - totalAllocated, MIN_PRO, totalCounts[MIN_PRO],
|
|
|
|
totalWidths[MIN_PRO], PR_FALSE, allocTypes);
|
|
|
|
return BCW_Wrapup(this, mTableFrame, allocTypes);
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// allocate auto cols, considering even those that are proportional
|
|
|
|
if (totalAllocated < maxWidth && totalCounts[DES_CON] > 0) {
|
|
|
|
if (totalAllocated + totalWidths[DES_CON] - minWidths[DES_CON]<= maxWidth) {
|
|
|
|
AllocateFully(totalAllocated, allocTypes, DES_CON);
|
|
|
|
NS_ASSERTION(totalAllocated <= maxWidth, "over allocated");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
AllocateConstrained(maxWidth - totalAllocated, DES_CON, totalCounts[DES_CON],
|
|
|
|
totalWidths[DES_CON], PR_FALSE, allocTypes);
|
|
|
|
return BCW_Wrapup(this, mTableFrame, allocTypes);
|
1998-06-24 03:23:21 +04:00
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
}
|
1998-06-24 03:23:21 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// if this is a nested table and pass1 reflow, we are done
|
|
|
|
if (maxWidth == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-11-30 22:06:33 +03:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// allocate the rest unconstrained
|
|
|
|
PRBool skip0Proportional = totalCounts[DES_CON] > num0Proportional;
|
|
|
|
if ( (tableIsAutoWidth && (perAdjTableWidth - totalAllocated > 0)) ||
|
|
|
|
(!tableIsAutoWidth && (totalAllocated < maxWidth)) ) {
|
|
|
|
if (totalCounts[PCT] != mNumCols) {
|
|
|
|
PRBool onlyAuto = (totalCounts[DES_CON] > 0) && !mIsNavQuirksMode;
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (PCT == allocTypes[colX]) {
|
|
|
|
allocTypes[colX] = -1;
|
|
|
|
}
|
|
|
|
else if ((FIX == allocTypes[colX]) && onlyAuto) {
|
|
|
|
allocTypes[colX] = -1;
|
1998-07-22 07:53:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (tableIsAutoWidth) {
|
|
|
|
AllocateUnconstrained(perAdjTableWidth - totalAllocated, allocTypes, skip0Proportional);
|
1998-07-13 22:11:12 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
else {
|
|
|
|
AllocateUnconstrained(maxWidth - totalAllocated, allocTypes, skip0Proportional);
|
1998-08-01 06:31:55 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
// give the proportional cols the rest up to the max width in quirks mode
|
|
|
|
else if (tableIsAutoWidth && mIsNavQuirksMode && (totalCounts[MIN_PRO] > 0)) {
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (DES_CON != allocTypes[colX]) {
|
|
|
|
allocTypes[colX] = -1;
|
1998-07-28 04:23:01 +04:00
|
|
|
}
|
1998-07-11 04:00:31 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
AllocateUnconstrained(maxWidth - totalAllocated, allocTypes, skip0Proportional);
|
1998-07-11 04:00:31 +04:00
|
|
|
}
|
|
|
|
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
return BCW_Wrapup(this, mTableFrame, allocTypes);
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// Allocate aWidthType values to all cols available in aIsAllocated
|
|
|
|
void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
|
|
|
|
PRInt32* aAllocTypes,
|
|
|
|
PRInt32 aWidthType,
|
|
|
|
PRBool aMarkAllocated)
|
1998-04-30 21:57:09 +04:00
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
for (PRInt32 colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (-1 != aAllocTypes[colX]) {
|
|
|
|
continue;
|
1998-07-18 01:02:28 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord oldWidth = mTableFrame->GetColumnWidth(colX);
|
|
|
|
nscoord newWidth = colFrame->GetWidth(aWidthType);
|
|
|
|
// account for col span overrides with DES_CON and FIX
|
|
|
|
if (DES_CON == aWidthType) {
|
|
|
|
newWidth = PR_MAX(newWidth, colFrame->GetWidth(DES_ADJ));
|
|
|
|
}
|
|
|
|
else if (FIX == aWidthType) {
|
|
|
|
newWidth = PR_MAX(newWidth, colFrame->GetWidth(FIX_ADJ));
|
|
|
|
}
|
|
|
|
else if (PCT == aWidthType) {
|
|
|
|
newWidth = PR_MAX(newWidth, colFrame->GetWidth(PCT_ADJ));
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (WIDTH_NOT_SET == newWidth) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (newWidth > oldWidth) {
|
|
|
|
mTableFrame->SetColumnWidth(colX, newWidth);
|
|
|
|
aTotalAllocated += newWidth - oldWidth;
|
|
|
|
}
|
|
|
|
if (aMarkAllocated) {
|
|
|
|
aAllocTypes[colX] = aWidthType;
|
1998-07-11 04:00:31 +04:00
|
|
|
}
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicTableLayoutStrategy::AllocateUnconstrained(PRInt32 aAllocAmount,
|
|
|
|
PRInt32* aAllocTypes,
|
|
|
|
PRBool aSkip0Proportional)
|
|
|
|
{
|
|
|
|
nscoord divisor = 0;
|
|
|
|
PRInt32 numAvail = 0;
|
|
|
|
PRInt32 colX;
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (-1 != aAllocTypes[colX]) {
|
|
|
|
divisor += mTableFrame->GetColumnWidth(colX);
|
|
|
|
numAvail++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (-1 != aAllocTypes[colX]) {
|
|
|
|
if (aSkip0Proportional) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
if (e0ProportionConstraint == colFrame->GetConstraint()) {
|
|
|
|
continue;
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord oldWidth = mTableFrame->GetColumnWidth(colX);
|
|
|
|
float percent = (divisor == 0)
|
|
|
|
? (1.0f / ((float)numAvail))
|
|
|
|
: ((float)oldWidth) / ((float)divisor);
|
|
|
|
nscoord addition = NSToCoordRound(((float)aAllocAmount) * percent);
|
|
|
|
mTableFrame->SetColumnWidth(colX, oldWidth + addition);
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine min, desired, fixed, and proportional sizes for the cols and
|
|
|
|
// and calculate min/max table width
|
|
|
|
PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aMaxWidth)
|
|
|
|
{
|
|
|
|
PRBool rv = PR_FALSE;
|
|
|
|
PRInt32 numRows = mTableFrame->GetRowCount();
|
|
|
|
nscoord spacingX = mTableFrame->GetCellSpacingX();
|
|
|
|
PRInt32 colX, rowX;
|
|
|
|
PRUint32 widthX;
|
|
|
|
mCellSpacingTotal = 0;
|
|
|
|
|
|
|
|
PRInt32 propTotal = 0; // total of numbers of the type 1*, 2*, etc
|
|
|
|
PRInt32 propTotalMin = 0;
|
|
|
|
PRInt32 numColsForColsAttr = 0; // Nav Quirks cols attribute for equal width cols
|
|
|
|
if (NS_STYLE_TABLE_COLS_NONE != mCols) {
|
|
|
|
numColsForColsAttr = (NS_STYLE_TABLE_COLS_ALL == mCols) ? mNumCols : mCols;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For every column, determine it's min and desired width based on cell style
|
|
|
|
// base on cells which do not span cols. Also, determine mCellSpacingTotal
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nscoord minWidth = 0;
|
|
|
|
nscoord desWidth = 0;
|
|
|
|
nscoord fixWidth = WIDTH_NOT_SET;
|
|
|
|
|
|
|
|
// Get column information
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
NS_ASSERTION(nsnull != colFrame, "bad col frame");
|
|
|
|
colFrame->SetConstraint(eNoConstraint);
|
|
|
|
|
|
|
|
if (mTableFrame->GetNumCellsOriginatingIn(colX) > 0) {
|
|
|
|
mCellSpacingTotal += spacingX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan the cells in the col that have colspan = 1 and find the maximum
|
|
|
|
// min, desired, and fixed cells.
|
|
|
|
for (rowX = 0; rowX < numRows; rowX++) {
|
|
|
|
nsTableCellFrame* cellFrame;
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
mTableFrame->GetCellInfoAt(rowX, colX, cellFrame, originates, colSpan);
|
|
|
|
// skip cells that don't originate at (rowX, colX); colspans are handled in the
|
|
|
|
// next pass, row spans don't need to be handled
|
|
|
|
if (!cellFrame || !originates || (colSpan > 1)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// these values include borders and padding
|
|
|
|
minWidth = PR_MAX(minWidth, cellFrame->GetPass1MaxElementSize().width);
|
|
|
|
desWidth = PR_MAX(desWidth, cellFrame->GetPass1DesiredSize().width);
|
|
|
|
// see if the cell has a style width specified
|
|
|
|
const nsStylePosition* cellPosition;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)cellPosition);
|
|
|
|
if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit()) {
|
|
|
|
nscoord coordValue = cellPosition->mWidth.GetCoordValue();
|
|
|
|
if (coordValue > 0) { // ignore if width == 0
|
|
|
|
// need to add padding into fixed width
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
|
|
|
nsMargin paddingMargin;
|
|
|
|
spacing->CalcPaddingFor(cellFrame, paddingMargin);
|
|
|
|
nscoord padding = paddingMargin.left + paddingMargin.right;
|
|
|
|
fixWidth = PR_MAX(fixWidth, coordValue + padding);
|
|
|
|
fixWidth = PR_MAX(fixWidth, minWidth);
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
desWidth = PR_MAX(desWidth, minWidth);
|
|
|
|
|
|
|
|
// cache the computed column info
|
|
|
|
colFrame->SetWidth(MIN_CON, minWidth);
|
|
|
|
colFrame->SetWidth(DES_CON, desWidth);
|
|
|
|
if (fixWidth > 0) {
|
|
|
|
colFrame->SetWidth(FIX, PR_MAX(fixWidth, minWidth));
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine if there is a proportional column either from html4
|
|
|
|
// proportional width on a col or Nav Quirks cols attr
|
|
|
|
if (fixWidth <= 0) {
|
|
|
|
nscoord proportion = WIDTH_NOT_SET;
|
|
|
|
const nsStylePosition* colPosition;
|
|
|
|
colFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)colPosition);
|
|
|
|
if (eStyleUnit_Proportional == colPosition->mWidth.GetUnit()) {
|
|
|
|
proportion = colPosition->mWidth.GetIntValue();
|
|
|
|
}
|
|
|
|
else if (colX < numColsForColsAttr) {
|
|
|
|
proportion = 1;
|
|
|
|
if ((eStyleUnit_Percent == colPosition->mWidth.GetUnit()) &&
|
|
|
|
(colPosition->mWidth.GetPercentValue() > 0.0f)) {
|
|
|
|
proportion = WIDTH_NOT_SET;
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (proportion >= 0) {
|
|
|
|
colFrame->SetWidth(MIN_PRO, proportion);
|
|
|
|
if (proportion > 0) {
|
|
|
|
propTotal += proportion;
|
|
|
|
colFrame->SetConstraint(eProportionConstraint);
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
1999-04-04 03:02:43 +04:00
|
|
|
else {
|
1999-07-28 12:09:02 +04:00
|
|
|
colFrame->SetConstraint(e0ProportionConstraint);
|
|
|
|
// override the desired, proportional widths
|
|
|
|
nscoord minWidth = colFrame->GetWidth(MIN_CON);
|
|
|
|
colFrame->SetWidth(DES_CON, minWidth);
|
|
|
|
colFrame->SetWidth(MIN_PRO, minWidth);
|
1998-08-11 22:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (mCellSpacingTotal > 0) {
|
|
|
|
mCellSpacingTotal += spacingX; // add last cell spacing on right
|
|
|
|
}
|
1998-08-11 22:42:10 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// figure the proportional width for porportional cols
|
|
|
|
if (propTotal > 0) {
|
|
|
|
nscoord minPropTotal = 0;
|
|
|
|
nscoord desPropTotal = 0;
|
|
|
|
// figure the totals of all proportional cols which support every min and desired width
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord colProp = colFrame->GetWidth(MIN_PRO);
|
|
|
|
if (colProp > 0) {
|
|
|
|
nscoord minWidth = colFrame->GetWidth(MIN_CON);
|
|
|
|
nscoord desWidth = colFrame->GetWidth(DES_CON);
|
|
|
|
minPropTotal = PR_MAX(minPropTotal, NSToCoordRound(((float)propTotal * minWidth) / (float)colProp));
|
|
|
|
desPropTotal = PR_MAX(desPropTotal, NSToCoordRound(((float)propTotal * desWidth) / (float)colProp));
|
1998-06-24 03:23:21 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
// store a ratio to allow going from a min to a desired proportional width
|
|
|
|
if (minPropTotal > 0) {
|
|
|
|
mMinToDesProportionRatio = ((float)desPropTotal) / ((float)minPropTotal);
|
|
|
|
}
|
|
|
|
// figure the cols proportional min width based on the new totals
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord colProp = colFrame->GetWidth(MIN_PRO);
|
|
|
|
if (colProp > 0) {
|
|
|
|
nscoord minWidth = colFrame->GetWidth(MIN_CON);
|
|
|
|
nscoord minProp = NSToCoordRound(((float)colProp * minPropTotal) / (float)propTotal);
|
|
|
|
colFrame->SetWidth(MIN_PRO, minProp);
|
|
|
|
colFrame->SetWidth(DES_CON, NSToCoordRound(((float)minProp) * mMinToDesProportionRatio));
|
1998-06-24 03:23:21 +04:00
|
|
|
}
|
1998-05-30 02:08:19 +04:00
|
|
|
}
|
|
|
|
}
|
1998-05-27 02:03:16 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// For each col, consider the cells originating in it with colspans > 1.
|
|
|
|
// Adjust the cols that each cell spans if necessary. Iterate backwards
|
|
|
|
// so that nested and/or overlaping col spans handle the inner ones first,
|
|
|
|
// ensuring more accurated calculations.
|
|
|
|
for (colX = mNumCols - 1; colX >= 0; colX--) {
|
|
|
|
for (rowX = 0; rowX < numRows; rowX++) {
|
|
|
|
nsTableCellFrame* cellFrame;
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
mTableFrame->GetCellInfoAt(rowX, colX, cellFrame, originates, colSpan);
|
|
|
|
if (!originates || (1 == colSpan)) {
|
|
|
|
continue;
|
1998-09-30 03:15:01 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord cellWidths[NUM_WIDTHS];
|
|
|
|
cellWidths[MIN_CON] = cellFrame->GetPass1MaxElementSize().width;
|
|
|
|
cellWidths[DES_CON] = cellFrame->GetPass1DesiredSize().width;
|
|
|
|
cellWidths[FIX] = WIDTH_NOT_SET;
|
|
|
|
// see if the cell has a style width specified
|
|
|
|
const nsStylePosition* cellPosition;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)cellPosition);
|
|
|
|
if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit()) {
|
|
|
|
// need to add padding into fixed width
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
|
|
|
nsMargin paddingMargin;
|
|
|
|
spacing->CalcPaddingFor(cellFrame, paddingMargin);
|
|
|
|
nscoord padding = paddingMargin.left + paddingMargin.right;
|
|
|
|
cellWidths[FIX] = cellPosition->mWidth.GetCoordValue() + padding;
|
|
|
|
cellWidths[FIX] = PR_MAX(cellWidths[FIX], cellWidths[MIN_CON]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set MIN_ADJ, DES_ADJ
|
|
|
|
nscoord spanCellSpacing = 0;
|
|
|
|
for (widthX = 0; widthX < NUM_MAJOR_WIDTHS; widthX++) {
|
|
|
|
// skip des if there is a fix
|
|
|
|
if ((DES_CON == widthX) && (cellWidths[FIX] > 0))
|
|
|
|
continue;
|
|
|
|
nscoord spanTotal = 0;
|
|
|
|
nscoord divisor = 0;
|
1999-07-28 12:56:12 +04:00
|
|
|
PRInt32 spanX;
|
|
|
|
for (spanX = 0; spanX < colSpan; spanX++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX + spanX);
|
|
|
|
nscoord colWidth = colFrame->GetWidth(widthX);
|
|
|
|
// need to get a contribution for every cell
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetMinWidth());
|
|
|
|
spanTotal += colWidth;
|
|
|
|
// accumulate divisor
|
|
|
|
if (widthX == FIX) {
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth());
|
|
|
|
}
|
|
|
|
else if (widthX == DES_CON) {
|
|
|
|
nscoord fixWidth = colFrame->GetFixWidth();
|
|
|
|
if (fixWidth > 0) {
|
|
|
|
colWidth = fixWidth;
|
|
|
|
}
|
|
|
|
//colWidth = PR_MAX(colWidth, colFrame->GetFixWidth());
|
|
|
|
}
|
|
|
|
else if (widthX == MIN_CON) {
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetFixWidth());
|
|
|
|
}
|
|
|
|
divisor += colWidth;
|
|
|
|
if ((0 == widthX) && (spanX > 0) && (mTableFrame->GetNumCellsOriginatingIn(colX + spanX) > 0)) {
|
|
|
|
spanCellSpacing += spacingX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spanTotal -= spanCellSpacing;
|
|
|
|
nscoord cellWidth = cellWidths[widthX] - spanCellSpacing;
|
|
|
|
if ((cellWidth > 0) && !((widthX == MIN_CON) && (cellWidth <= spanTotal))) {
|
1999-07-28 13:13:44 +04:00
|
|
|
for (PRInt32 spanX = 0; spanX < colSpan; spanX++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX + spanX);
|
|
|
|
nscoord colWidth = colFrame->GetWidth(widthX);
|
|
|
|
nscoord minWidth = colFrame->GetMinWidth();
|
|
|
|
// accumulate numerator similarly to divisor
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetMinWidth());
|
|
|
|
if (widthX == FIX) {
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth());
|
|
|
|
}
|
|
|
|
else if (widthX == DES_CON) {
|
|
|
|
nscoord fixWidth = colFrame->GetFixWidth();
|
|
|
|
if (fixWidth > 0) {
|
|
|
|
colWidth = fixWidth;
|
|
|
|
}
|
|
|
|
//colWidth = PR_MAX(colWidth, colFrame->GetFixWidth());
|
|
|
|
}
|
|
|
|
else if (widthX == MIN_CON) {
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetFixWidth());
|
|
|
|
}
|
|
|
|
nscoord colAdjWidth = colFrame->GetWidth(widthX + NUM_MAJOR_WIDTHS);
|
|
|
|
nscoord newColAdjWidth = (0 >= spanTotal)
|
|
|
|
? NSToCoordRound( ((float)cellWidth) / ((float)colSpan) )
|
|
|
|
: NSToCoordRound( (((float)colWidth) / ((float)divisor)) * cellWidth);
|
|
|
|
if ((newColAdjWidth > colAdjWidth) && (newColAdjWidth > 0)) {
|
|
|
|
newColAdjWidth = PR_MAX(newColAdjWidth, minWidth);
|
|
|
|
if (FIX != widthX)
|
|
|
|
colFrame->SetWidth(widthX + NUM_MAJOR_WIDTHS, newColAdjWidth);
|
|
|
|
// the following ensures that a spanned cell will reach its full desired width
|
|
|
|
// in an auto table, since allocations are done on fixed cols before auto cols
|
|
|
|
if (DES_CON == widthX) {
|
|
|
|
nscoord fixWidth = colFrame->GetFixWidth();
|
|
|
|
if ((fixWidth > 0) && (newColAdjWidth > fixWidth) && (newColAdjWidth > 0)) {
|
|
|
|
colFrame->SetWidth(FIX_ADJ, newColAdjWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FIX == widthX) {
|
|
|
|
nscoord desWidth = colFrame->GetDesWidth();
|
|
|
|
if ((newColAdjWidth > desWidth) && (newColAdjWidth > 0)) {
|
|
|
|
colFrame->SetWidth(DES_ADJ, newColAdjWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-30 03:15:01 +04:00
|
|
|
}
|
1998-08-02 00:31:40 +04:00
|
|
|
}
|
1998-07-24 01:55:45 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord desAdjWidth = colFrame->GetWidth(DES_ADJ);
|
|
|
|
nscoord fixWidth = colFrame->GetWidth(FIX);
|
|
|
|
if ((fixWidth >= 0) && (desAdjWidth > fixWidth)) {
|
|
|
|
colFrame->SetWidth(FIX, WIDTH_NOT_SET);
|
|
|
|
}
|
1998-07-18 01:02:28 +04:00
|
|
|
}
|
1998-06-30 04:37:03 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// Set the col's fixed width if present
|
|
|
|
// Set the table col width for each col to the content min.
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord fixColWidth = colFrame->GetWidth(FIX);
|
|
|
|
// use the style width of a col only if the col hasn't gotten a fixed width from any cell
|
|
|
|
if (fixColWidth <= 0) {
|
|
|
|
const nsStylePosition* colPosition;
|
|
|
|
colFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)colPosition);
|
|
|
|
if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) {
|
|
|
|
fixColWidth = colPosition->mWidth.GetCoordValue();
|
|
|
|
if (fixColWidth > 0) {
|
|
|
|
colFrame->SetWidth(FIX, fixColWidth);
|
|
|
|
}
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord minWidth = colFrame->GetMinWidth();
|
|
|
|
mTableFrame->SetColumnWidth(colX, minWidth);
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
SetMinAndMaxTableContentWidths();
|
|
|
|
|
|
|
|
return rv;
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// Determine percentage col widths for each col frame
|
|
|
|
nscoord BasicTableLayoutStrategy::AssignPercentageColumnWidths(nscoord aBasisIn,
|
|
|
|
PRBool aTableIsAutoWidth)
|
|
|
|
{
|
1998-07-11 04:00:31 +04:00
|
|
|
PRInt32 numRows = mTableFrame->GetRowCount();
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord spacingX = mTableFrame->GetCellSpacingX();
|
|
|
|
PRInt32 colX, rowX;
|
|
|
|
nscoord basis = aBasisIn;
|
|
|
|
// For an auto table, determine the potentially new percent adjusted width based
|
|
|
|
// on percent cells/cols.
|
|
|
|
if (aTableIsAutoWidth) {
|
|
|
|
nscoord fixWidthTotal = 0;
|
|
|
|
basis = 0;
|
|
|
|
PRInt32 numPerCols = 0;
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord colBasis = -1;
|
|
|
|
// Scan the cells in the col
|
|
|
|
for (rowX = 0; rowX < numRows; rowX++) {
|
|
|
|
nsTableCellFrame* cellFrame;
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
mTableFrame->GetCellInfoAt(rowX, colX, cellFrame, originates, colSpan);
|
|
|
|
if (!originates) { // skip cells that don't originate in the col
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// see if the cell has a style percent width specified
|
|
|
|
const nsStylePosition* cellPosition;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)cellPosition);
|
|
|
|
if (eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) {
|
|
|
|
float percent = cellPosition->mWidth.GetPercentValue();
|
|
|
|
colBasis = 0;
|
|
|
|
if (percent > 0.0f) {
|
|
|
|
nscoord desWidth = colFrame->GetDesWidth();
|
|
|
|
if (colSpan > 1) { // sum up the DES_ADJ widths of the spanned cols
|
|
|
|
for (PRInt32 spanX = 1; spanX < colSpan; spanX++) {
|
|
|
|
nsTableColFrame* spanFrame = mTableFrame->GetColFrame(colX + spanX);
|
|
|
|
desWidth += spanFrame->GetWidth(DES_ADJ);
|
1998-08-01 06:31:55 +04:00
|
|
|
}
|
1998-07-27 09:32:50 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
colBasis = NSToCoordRound((float)desWidth / percent);
|
1998-07-22 07:53:43 +04:00
|
|
|
}
|
1998-07-18 01:02:28 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
if (-1 == colBasis) {
|
|
|
|
// see if the col has a style percent width specified
|
|
|
|
const nsStylePosition* colPosition;
|
|
|
|
colFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)colPosition);
|
|
|
|
if (eStyleUnit_Percent == colPosition->mWidth.GetUnit()) {
|
|
|
|
float percent = colPosition->mWidth.GetPercentValue();
|
|
|
|
colBasis = 0;
|
|
|
|
if (percent > 0.0f) {
|
|
|
|
nscoord desWidth = colFrame->GetDesWidth();
|
|
|
|
colBasis = NSToCoordRound((float)desWidth / percent);
|
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
basis = PR_MAX(basis, colBasis);
|
|
|
|
if (colBasis >= 0) {
|
|
|
|
numPerCols++;
|
|
|
|
}
|
|
|
|
fixWidthTotal += colFrame->GetFixWidth();
|
|
|
|
} // end for (colX ..
|
|
|
|
// If there is only one col and it is % based, it won't affect anything
|
|
|
|
if ((1 == mNumCols) && (mNumCols == numPerCols)) {
|
|
|
|
return 0;
|
1998-07-18 01:02:28 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
basis = PR_MAX(basis, fixWidthTotal);
|
|
|
|
basis = PR_MIN(basis, aBasisIn);
|
|
|
|
}
|
1998-07-18 01:02:28 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord colPctTotal = 0;
|
|
|
|
nscoord* colPcts = new nscoord[mNumCols];
|
|
|
|
if (!colPcts) return 0;
|
|
|
|
|
|
|
|
// Determine the percentage contribution for cols and for cells with colspan = 1
|
|
|
|
// Iterate backwards, similarly to the reasoning in AssignPreliminaryColumnWidths
|
|
|
|
for (colX = mNumCols - 1; colX >= 0; colX--) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord maxColPctWidth = WIDTH_NOT_SET;
|
|
|
|
float maxColPct = 0.0f;
|
|
|
|
colPcts[colX] = 0;
|
|
|
|
|
|
|
|
// Scan the cells in the col that have colspan = 1; assign PER widths
|
|
|
|
for (rowX = 0; rowX < numRows; rowX++) {
|
|
|
|
nsTableCellFrame* cellFrame;
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
mTableFrame->GetCellInfoAt(rowX, colX, cellFrame, originates, colSpan);
|
|
|
|
// skip cells that don't originate at (rowX, colX); colspans are handled in the
|
|
|
|
// next pass, row spans don't need to be handled
|
|
|
|
if (!cellFrame || !originates || (colSpan > 1)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// see if the cell has a style percent width specified
|
|
|
|
const nsStylePosition* cellPosition;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)cellPosition);
|
|
|
|
if (eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) {
|
|
|
|
float percent = cellPosition->mWidth.GetPercentValue();
|
|
|
|
if (percent > maxColPct) {
|
|
|
|
maxColPct = percent;
|
|
|
|
maxColPctWidth = NSToCoordRound( ((float)basis) * maxColPct );
|
|
|
|
if (!mIsNavQuirksMode) {
|
|
|
|
// need to add padding
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
|
|
|
nsMargin paddingMargin;
|
|
|
|
spacing->CalcPaddingFor(cellFrame, paddingMargin);
|
|
|
|
maxColPctWidth += paddingMargin.left + paddingMargin.right;
|
1998-06-06 02:50:03 +04:00
|
|
|
}
|
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
if (WIDTH_NOT_SET == maxColPctWidth) {
|
|
|
|
// see if the col has a style percent width specified
|
|
|
|
const nsStylePosition* colPosition;
|
|
|
|
colFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)colPosition);
|
|
|
|
if (eStyleUnit_Percent == colPosition->mWidth.GetUnit()) {
|
|
|
|
maxColPct = colPosition->mWidth.GetPercentValue();
|
|
|
|
maxColPctWidth = NSToCoordRound( ((float)basis) * maxColPct );
|
1998-05-30 02:08:19 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
// conflicting pct/fixed widths are recorded. Nav 4.x may be changing the
|
|
|
|
// fixed width value if it exceeds the pct value and not recording the pct
|
|
|
|
// value. This is not being done and IE5 doesn't do it either.
|
|
|
|
if (maxColPctWidth > 0) {
|
|
|
|
nscoord minWidth = colFrame->GetMinWidth();
|
|
|
|
if (minWidth > maxColPctWidth) {
|
|
|
|
maxColPctWidth = minWidth;
|
|
|
|
colPcts[colX] = NSToCoordRound( 100.0f * ((float)maxColPctWidth) / ((float)basis) );
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
else {
|
|
|
|
colPcts[colX] = NSToCoordRound(maxColPct * 100.0f);
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
colFrame->SetWidth(PCT, maxColPctWidth);
|
|
|
|
colPctTotal += colPcts[colX];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each col, consider the cells originating in it with colspans > 1.
|
|
|
|
// Adjust the cols that each cell spans if necessary.
|
|
|
|
for (colX = 0; colX < mNumCols; colX++) {
|
|
|
|
for (rowX = 0; rowX < numRows; rowX++) {
|
|
|
|
nsTableCellFrame* cellFrame;
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
mTableFrame->GetCellInfoAt(rowX, colX, cellFrame, originates, colSpan);
|
|
|
|
if (!originates || (1 == colSpan)) {
|
|
|
|
continue;
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord cellPctWidth = WIDTH_NOT_SET;
|
|
|
|
// see if the cell has a style percentage width specified
|
|
|
|
const nsStylePosition* cellPosition;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)cellPosition);
|
|
|
|
float cellPct = 0.0f;
|
|
|
|
if (eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) {
|
|
|
|
cellPct = cellPosition->mWidth.GetPercentValue();
|
|
|
|
cellPctWidth = NSToCoordRound( ((float)basis) * cellPct );
|
|
|
|
if (!mIsNavQuirksMode) {
|
|
|
|
// need to add padding
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
cellFrame->GetStyleData(eStyleStruct_Spacing,(const nsStyleStruct *&)spacing);
|
|
|
|
nsMargin paddingMargin;
|
|
|
|
spacing->CalcPaddingFor(cellFrame, paddingMargin);
|
|
|
|
cellPctWidth += paddingMargin.left + paddingMargin.right;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-05-30 02:08:19 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (cellPctWidth > 0) {
|
|
|
|
nscoord spanCellSpacing = 0;
|
|
|
|
nscoord spanTotal = 0;
|
|
|
|
nscoord colPctWidthTotal = 0;
|
|
|
|
// accumulate the spanTotal as the max of MIN, DES, FIX, PCT
|
|
|
|
for (PRInt32 spanX = 0; spanX < colSpan; spanX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX + spanX);
|
|
|
|
nscoord colPctWidth = colFrame->GetWidth(PCT);
|
|
|
|
if (colPctWidth > 0) { // skip pct cols
|
|
|
|
colPctWidthTotal += colPctWidth;
|
|
|
|
continue;
|
1998-06-06 02:50:03 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord colWidth = PR_MAX(colFrame->GetMinWidth(), colFrame->GetFixWidth());
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth());
|
|
|
|
//colWidth = PR_MAX(colWidth, colFrame->GetPctWidth());
|
|
|
|
spanTotal += colWidth;
|
|
|
|
if ((spanX > 0) && (mTableFrame->GetNumCellsOriginatingIn(colX + spanX) > 0)) {
|
|
|
|
spanCellSpacing += spacingX;
|
1998-06-06 02:50:03 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
cellPctWidth += spanCellSpacing; // add it back in since it was subtracted from aBasisIn
|
|
|
|
if (cellPctWidth <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (colPctWidthTotal < cellPctWidth) {
|
|
|
|
// record the percent contributions for the spanned cols
|
1999-07-28 13:13:44 +04:00
|
|
|
for (PRInt32 spanX = 0; spanX < colSpan; spanX++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX + spanX);
|
|
|
|
if (colFrame->GetWidth(PCT) > 0) { // skip pct cols
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nscoord minWidth = colFrame->GetMinWidth();
|
|
|
|
nscoord colWidth = PR_MAX(minWidth, colFrame->GetFixWidth());
|
|
|
|
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth());
|
|
|
|
float colPctAdj = (0 == spanTotal)
|
|
|
|
? cellPctWidth / ((float) colSpan)
|
|
|
|
: cellPct * ((float)colWidth) / (float)spanTotal;
|
|
|
|
if (colPctAdj > 0) {
|
|
|
|
nscoord colPctAdjWidth = colFrame->GetWidth(PCT_ADJ);
|
|
|
|
nscoord newColPctAdjWidth = NSToCoordRound(colPctAdj * (float)basis);
|
|
|
|
if (newColPctAdjWidth > colPctAdjWidth) {
|
|
|
|
if (colPctAdjWidth > 0) { // remove its contribution
|
|
|
|
colPctTotal -= colPcts[colX + spanX];
|
|
|
|
}
|
|
|
|
if (minWidth > newColPctAdjWidth) {
|
|
|
|
newColPctAdjWidth = minWidth;
|
|
|
|
colPcts[colX + spanX] = NSToCoordRound( 100.0f * ((float)newColPctAdjWidth) / ((float)basis) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
colPcts[colX + spanX] = NSToCoordRound( 100.0f * colPctAdj );
|
|
|
|
}
|
|
|
|
colFrame->SetWidth(PCT_ADJ, newColPctAdjWidth);
|
|
|
|
colPctTotal += colPcts[colX + spanX];
|
|
|
|
}
|
1998-06-06 02:50:03 +04:00
|
|
|
}
|
1998-05-30 02:08:19 +04:00
|
|
|
}
|
1998-05-27 02:03:16 +04:00
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
} // end for (rowX ..
|
|
|
|
} // end for (colX ..
|
|
|
|
|
|
|
|
// if the percent total went over 100%, adjustments need to be made to right most cols
|
|
|
|
if (colPctTotal > 100) {
|
|
|
|
for (colX = mNumCols - 1; colX >= 0; colX--) {
|
|
|
|
if (colPcts[colX] > 0) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
nscoord fixWidth = colFrame->GetFixWidth();
|
|
|
|
nscoord pctWidth = colFrame->GetWidth(PCT);
|
|
|
|
nscoord pctAdjWidth = colFrame->GetWidth(PCT_ADJ);
|
|
|
|
nscoord newPct = colPcts[colX] - (colPctTotal - 100);
|
|
|
|
if (newPct > 0) { // this col has enough percent alloc to handle it
|
|
|
|
nscoord newPctWidth = NSToCoordRound( ((float)basis) * ((float)newPct) / 100.0f );
|
|
|
|
newPctWidth = PR_MAX(newPctWidth, colFrame->GetMinWidth());
|
|
|
|
// since we don't care which one contributed, set both
|
|
|
|
colFrame->SetWidth(PCT, newPctWidth);
|
|
|
|
colFrame->SetWidth(PCT_ADJ, newPctWidth);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else { // this col cannot handle all the reduction, reduce it down to zero
|
|
|
|
colFrame->SetWidth(PCT, WIDTH_NOT_SET);
|
|
|
|
colFrame->SetWidth(PCT_ADJ, WIDTH_NOT_SET);
|
|
|
|
colPctTotal -= colPcts[colX];
|
|
|
|
if (colPctTotal <= 100) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
1998-11-04 22:33:27 +03:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
delete [] colPcts;
|
|
|
|
return basis;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicTableLayoutStrategy::SetMinAndMaxTableContentWidths()
|
|
|
|
{
|
|
|
|
mMinTableContentWidth = 0;
|
|
|
|
mMaxTableContentWidth = 0;
|
|
|
|
|
|
|
|
nscoord spacingX = mTableFrame->GetCellSpacingX();
|
|
|
|
for (PRInt32 colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
mMinTableContentWidth += colFrame->GetMinWidth();
|
|
|
|
mMaxTableContentWidth += colFrame->GetDesWidth();
|
|
|
|
if (mTableFrame->GetNumCellsOriginatingIn(colX) > 0) {
|
|
|
|
mMaxTableContentWidth += spacingX;
|
|
|
|
mMinTableContentWidth += spacingX;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-11-04 22:33:27 +03:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
// if it is not a degenerate table, add the last spacing on the right
|
|
|
|
if (mMinTableContentWidth > 0) {
|
|
|
|
mMinTableContentWidth += spacingX;
|
|
|
|
mMaxTableContentWidth += spacingX;
|
1998-07-17 03:23:31 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// calculate totals by width type. A width type of a higher precedence will
|
|
|
|
// preclude one of a lower precedence for all types except MIN_CON
|
|
|
|
void BasicTableLayoutStrategy::CalculateTotals(PRInt32& aCellSpacing,
|
|
|
|
PRInt32* aTotalCounts,
|
|
|
|
PRInt32* aTotalWidths,
|
|
|
|
PRInt32* aMinWidths,
|
|
|
|
PRInt32& a0ProportionalCount)
|
|
|
|
{
|
|
|
|
//mTableFrame->Dump(PR_TRUE, PR_FALSE);
|
|
|
|
aCellSpacing = 0;
|
|
|
|
for (PRInt32 widthX = 0; widthX < NUM_WIDTHS; widthX++) {
|
|
|
|
aTotalCounts[widthX] = 0;
|
|
|
|
aTotalWidths[widthX] = 0;
|
|
|
|
aMinWidths[widthX] = 0;
|
|
|
|
}
|
|
|
|
a0ProportionalCount = 0;
|
|
|
|
|
|
|
|
nscoord spacingX = mTableFrame->GetCellSpacingX();
|
|
|
|
for (PRInt32 colX = 0; colX < mNumCols; colX++) {
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
if (mTableFrame->GetNumCellsOriginatingIn(colX) > 0) {
|
|
|
|
aCellSpacing += spacingX;
|
|
|
|
}
|
|
|
|
nscoord minCol = colFrame->GetMinWidth();
|
|
|
|
aTotalCounts[MIN_CON]++;
|
|
|
|
aTotalWidths[MIN_CON] += minCol;
|
|
|
|
|
|
|
|
if (e0ProportionConstraint == colFrame->GetConstraint()) {
|
|
|
|
a0ProportionalCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord pctCol = colFrame->GetPctWidth();
|
|
|
|
nscoord fixCol = colFrame->GetFixWidth();
|
|
|
|
// pct wins in conflict with fix
|
|
|
|
if (pctCol > 0) {
|
|
|
|
aTotalCounts[PCT]++;
|
|
|
|
aTotalWidths[PCT] += pctCol;
|
|
|
|
aMinWidths[PCT] += minCol;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (fixCol > 0) {
|
|
|
|
aTotalCounts[FIX]++;
|
|
|
|
aTotalWidths[FIX] += fixCol;
|
|
|
|
aMinWidths[FIX] += minCol;
|
|
|
|
continue;
|
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
if (eProportionConstraint == colFrame->GetConstraint()) {
|
|
|
|
nscoord minProp = colFrame->GetWidth(MIN_PRO);
|
|
|
|
aTotalCounts[MIN_PRO]++;
|
|
|
|
aTotalWidths[MIN_PRO] += minProp;
|
|
|
|
aTotalCounts[DES_CON]++;
|
|
|
|
aTotalWidths[DES_CON] += NSToCoordRound(((float)minProp) * mMinToDesProportionRatio);
|
|
|
|
aMinWidths[MIN_PRO] += minCol;
|
|
|
|
aMinWidths[DES_CON] += minProp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord desCol = colFrame->GetDesWidth();
|
|
|
|
aTotalCounts[DES_CON]++;
|
|
|
|
aTotalWidths[DES_CON] += desCol;
|
|
|
|
aMinWidths[DES_CON] += minCol;
|
1998-05-30 02:08:19 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
// if it is not a degenerate table, add the last spacing on the right
|
|
|
|
if (mNumCols > 0) {
|
|
|
|
aCellSpacing += spacingX;
|
1998-07-13 22:11:12 +04:00
|
|
|
}
|
1998-04-30 21:57:09 +04:00
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-05-10 23:23:09 +04:00
|
|
|
struct nsColInfo {
|
1999-05-27 02:22:23 +04:00
|
|
|
nsColInfo(nsTableColFrame* aFrame,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
PRInt32 aMinWidth,
|
|
|
|
PRInt32 aWidth,
|
|
|
|
PRInt32 aMaxWidth)
|
|
|
|
: mFrame(aFrame), mIndex(aIndex), mMinWidth(aMinWidth),
|
1999-07-28 12:09:02 +04:00
|
|
|
mWidth(aWidth), mMaxWidth(aMaxWidth), mWeight(0)
|
1999-05-27 02:22:23 +04:00
|
|
|
{}
|
|
|
|
nsTableColFrame* mFrame;
|
|
|
|
PRInt32 mIndex;
|
|
|
|
PRInt32 mMinWidth;
|
|
|
|
PRInt32 mWidth;
|
|
|
|
PRInt32 mMaxWidth;
|
|
|
|
float mWeight;
|
1999-05-10 23:23:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Wrapup(nsTableFrame* aTableFrame,
|
1999-07-28 23:43:37 +04:00
|
|
|
PRInt32 aNumItems,
|
|
|
|
nsColInfo** aColInfo,
|
|
|
|
PRBool aAbort = PR_FALSE)
|
1999-05-10 23:23:09 +04:00
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
if (aColInfo) {
|
|
|
|
for (PRInt32 i = 0; i < aNumItems; i++) {
|
|
|
|
if (aColInfo[i]) {
|
|
|
|
if (!aAbort) {
|
|
|
|
aTableFrame->SetColumnWidth(aColInfo[i]->mIndex, aColInfo[i]->mWidth);
|
|
|
|
}
|
|
|
|
delete aColInfo[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] aColInfo;
|
1999-05-27 02:22:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Increase(PRInt32 aNumAutoCols,
|
1999-05-27 02:22:23 +04:00
|
|
|
nsColInfo** aColInfo,
|
|
|
|
PRInt32 aDivisor,
|
|
|
|
PRInt32& aAvailWidth)
|
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
|
|
|
|
if ((aAvailWidth <= 0) || (aDivisor <= 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
|
|
|
|
aDivisor -= aColInfo[i]->mMaxWidth;
|
|
|
|
nscoord addition = PR_MIN(aAvailWidth, NSToCoordRound(((float)(aAvailWidth)) * percent));
|
1999-07-28 12:09:02 +04:00
|
|
|
addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
|
1999-05-27 02:22:23 +04:00
|
|
|
// don't let the total additions exceed what is available
|
|
|
|
if (i == aNumAutoCols - 1) {
|
|
|
|
addition = PR_MIN(addition, aAvailWidth);
|
|
|
|
}
|
|
|
|
aColInfo[i]->mWidth += addition;
|
|
|
|
aAvailWidth -= addition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Decrease(PRInt32 aNumAutoCols,
|
1999-05-27 02:22:23 +04:00
|
|
|
nsColInfo** aColInfo,
|
|
|
|
PRInt32 aDivisor,
|
|
|
|
PRInt32& aExcess)
|
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
|
|
|
|
if ((aExcess <= 0) || (aDivisor <= 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
|
|
|
|
aDivisor -= aColInfo[i]->mMaxWidth;
|
|
|
|
nscoord reduction = PR_MIN(aExcess, NSToCoordRound(((float)(aExcess)) * percent));
|
|
|
|
// don't go over the col min
|
|
|
|
reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
|
|
|
|
// don't let the total reductions exceed what is available
|
|
|
|
if (i == aNumAutoCols - 1) {
|
|
|
|
reduction = PR_MIN(reduction, aExcess);
|
|
|
|
}
|
|
|
|
aColInfo[i]->mWidth -= reduction;
|
|
|
|
aExcess -= reduction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Sort(nsColInfo** aColInfo, PRInt32 aNumCols)
|
1999-05-27 02:22:23 +04:00
|
|
|
{
|
|
|
|
// sort the cols based on the Weight
|
|
|
|
for (PRInt32 j = aNumCols - 1; j > 0; j--) {
|
|
|
|
for (PRInt32 i = 0; i < j; i++) {
|
|
|
|
if (aColInfo[i]->mWeight < aColInfo[i+1]->mWeight) { // swap them
|
|
|
|
nsColInfo* save = aColInfo[i];
|
|
|
|
aColInfo[i] = aColInfo[i+1];
|
|
|
|
aColInfo[i+1] = save;
|
|
|
|
}
|
|
|
|
}
|
1999-05-10 23:23:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// this assumes that the table has set the width for each col to be its min
|
|
|
|
void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
|
|
|
|
PRInt32 aWidthType,
|
|
|
|
PRInt32 aNumConstrainedCols,
|
|
|
|
PRInt32 aSumMaxConstraints,
|
|
|
|
PRBool aStartAtMin,
|
|
|
|
PRInt32* aAllocTypes)
|
1999-05-27 02:22:23 +04:00
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
if ((0 == aAvailWidth) || (aWidthType < 0) || (aWidthType >= NUM_WIDTHS) ||
|
|
|
|
(aNumConstrainedCols <= 0) || (aSumMaxConstraints <= 0)) {
|
|
|
|
NS_ASSERTION(PR_TRUE, "invalid args to AllocateConstrained");
|
1999-05-27 02:22:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// allocate storage for the affected cols. Only they get adjusted.
|
|
|
|
nsColInfo** colInfo = new nsColInfo*[aNumConstrainedCols];
|
1999-07-28 23:43:37 +04:00
|
|
|
if (!colInfo) return;
|
1999-07-28 22:52:04 +04:00
|
|
|
memset(colInfo, 0, aNumConstrainedCols * sizeof(nsColInfo *));
|
1999-07-28 23:43:37 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 maxMinDiff = 0;
|
|
|
|
PRInt32 constrColX = 0;
|
|
|
|
// set the col info entries for each constrained col
|
|
|
|
for (PRInt32 colX = 0; colX < mNumCols; colX++) {
|
|
|
|
if (-1 != aAllocTypes[colX]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
|
|
|
|
//nscoord minWidth = colFrame->GetMinWidth();
|
|
|
|
nscoord minWidth = mTableFrame->GetColumnWidth(colX);
|
|
|
|
nscoord maxWidth = colFrame->GetWidth(aWidthType);
|
|
|
|
if (DES_CON == aWidthType) {
|
|
|
|
maxWidth = PR_MAX(maxWidth, colFrame->GetWidth(DES_ADJ));
|
|
|
|
}
|
|
|
|
else if (FIX == aWidthType) {
|
|
|
|
maxWidth = PR_MAX(maxWidth, colFrame->GetWidth(FIX_ADJ));
|
|
|
|
}
|
|
|
|
else if (PCT == aWidthType) {
|
|
|
|
maxWidth = PR_MAX(maxWidth, colFrame->GetWidth(PCT_ADJ));
|
|
|
|
}
|
|
|
|
if (maxWidth <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (constrColX >= aNumConstrainedCols) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "AllocateConstrained called incorrectly");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
maxWidth = PR_MAX(maxWidth, minWidth);
|
|
|
|
maxMinDiff += maxWidth - minWidth;
|
|
|
|
nscoord startWidth = (aStartAtMin) ? minWidth : maxWidth;
|
1999-07-28 23:43:37 +04:00
|
|
|
colInfo[constrColX] = new nsColInfo(colFrame, colX, minWidth, startWidth, maxWidth);
|
1999-07-28 12:09:02 +04:00
|
|
|
if (!colInfo[constrColX]) {
|
|
|
|
AC_Wrapup(mTableFrame, aNumConstrainedCols, colInfo, PR_TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aAllocTypes[colX] = aWidthType;
|
1999-07-28 23:43:37 +04:00
|
|
|
constrColX++;
|
1999-05-27 02:22:23 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (constrColX < aNumConstrainedCols) {
|
|
|
|
// some of the constrainted cols might have been 0 and skipped
|
|
|
|
aNumConstrainedCols = constrColX;
|
|
|
|
}
|
|
|
|
PRInt32 i;
|
|
|
|
if (aStartAtMin) { // allocate extra space
|
|
|
|
nscoord availWidth = aAvailWidth;
|
|
|
|
for (i = 0; i < aNumConstrainedCols; i++) {
|
|
|
|
// the weight here is a relative metric for determining when cols reach their max constraint.
|
1999-05-27 02:22:23 +04:00
|
|
|
// A col with a larger weight will reach its max before one with a smaller value.
|
|
|
|
nscoord delta = colInfo[i]->mMaxWidth - colInfo[i]->mWidth;
|
|
|
|
colInfo[i]->mWeight = (delta <= 0)
|
|
|
|
? 1000000 // cols which have already reached their max get a large value
|
|
|
|
: ((float)colInfo[i]->mMaxWidth) / ((float)delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort the cols based on the weight so that in one pass cols with higher
|
|
|
|
// weights will get their max earlier than ones with lower weights
|
|
|
|
// This is an innefficient bubble sort, but unless there are an unlikely
|
|
|
|
// large number of cols, it is not an issue.
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Sort(colInfo, aNumConstrainedCols);
|
1999-05-27 02:22:23 +04:00
|
|
|
|
|
|
|
// compute the proportion to be added to each column, don't go beyond the col's
|
|
|
|
// max. This algorithm assumes that the Weight works as stated above
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Increase(aNumConstrainedCols, colInfo, aSumMaxConstraints, availWidth);
|
1999-05-27 02:22:23 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
else { // reduce each col width
|
|
|
|
nscoord reduceWidth = maxMinDiff - aAvailWidth;
|
|
|
|
if (reduceWidth < 0) {
|
|
|
|
NS_ASSERTION(PR_TRUE, "AllocateConstrained called incorrectly");
|
1999-07-28 23:43:37 +04:00
|
|
|
AC_Wrapup(mTableFrame, aNumConstrainedCols, colInfo);
|
1999-07-28 12:09:02 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < aNumConstrainedCols; i++) {
|
1999-05-27 02:22:23 +04:00
|
|
|
// the weight here is a relative metric for determining when cols reach their min.
|
|
|
|
// A col with a larger weight will reach its min before one with a smaller value.
|
|
|
|
nscoord delta = colInfo[i]->mWidth - colInfo[i]->mMinWidth;
|
|
|
|
colInfo[i]->mWeight = (delta <= 0)
|
|
|
|
? 1000000 // cols which have already reached their min get a large value
|
|
|
|
: ((float)colInfo[i]->mWidth) / ((float)delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort the cols based on the Weight
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Sort(colInfo, aNumConstrainedCols);
|
1999-05-27 02:22:23 +04:00
|
|
|
|
|
|
|
// compute the proportion to be subtracted from each column, don't go beyond
|
|
|
|
// the col's min. This algorithm assumes that the Weight works as stated above
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Decrease(aNumConstrainedCols, colInfo, aSumMaxConstraints, reduceWidth);
|
1999-05-10 23:23:09 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
AC_Wrapup(mTableFrame, aNumConstrainedCols, colInfo);
|
1998-07-17 03:23:31 +04:00
|
|
|
}
|
|
|
|
|
1998-07-25 03:26:23 +04:00
|
|
|
|
1998-07-24 01:55:45 +04:00
|
|
|
PRBool BasicTableLayoutStrategy::IsColumnInList(const PRInt32 colIndex,
|
1999-04-04 03:02:43 +04:00
|
|
|
PRInt32* colIndexes,
|
|
|
|
PRInt32 aNumFixedColumns)
|
1998-07-24 01:55:45 +04:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
1999-04-04 03:02:43 +04:00
|
|
|
for (PRInt32 i = 0; i < aNumFixedColumns; i++) {
|
|
|
|
if (colIndex == colIndexes[i]) {
|
1998-07-24 01:55:45 +04:00
|
|
|
result = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1999-04-04 03:02:43 +04:00
|
|
|
else if (colIndex<colIndexes[i]) {
|
1998-07-24 01:55:45 +04:00
|
|
|
break;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-07-24 01:55:45 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1998-08-14 20:16:43 +04:00
|
|
|
PRBool BasicTableLayoutStrategy::ColIsSpecifiedAsMinimumWidth(PRInt32 aColIndex)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
nsTableColFrame* colFrame;
|
|
|
|
mTableFrame->GetColumnFrame(aColIndex, colFrame);
|
|
|
|
const nsStylePosition* colPosition;
|
1998-11-20 12:29:58 +03:00
|
|
|
colFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)colPosition);
|
1999-04-04 03:02:43 +04:00
|
|
|
switch (colPosition->mWidth.GetUnit()) {
|
1998-08-14 20:16:43 +04:00
|
|
|
case eStyleUnit_Coord:
|
1999-04-04 03:02:43 +04:00
|
|
|
if (0 == colPosition->mWidth.GetCoordValue()) {
|
1998-08-14 20:16:43 +04:00
|
|
|
result = PR_TRUE;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-08-14 20:16:43 +04:00
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
{
|
|
|
|
// total hack for now for 0% and 1% specifications
|
|
|
|
// should compare percent to available parent width and see that it is below minimum
|
|
|
|
// for this column
|
|
|
|
float percent = colPosition->mWidth.GetPercentValue();
|
1999-04-04 03:02:43 +04:00
|
|
|
if (0.0f == percent || 0.01f == percent) {
|
1998-08-14 20:16:43 +04:00
|
|
|
result = PR_TRUE;
|
1999-04-04 03:02:43 +04:00
|
|
|
}
|
1998-08-14 20:16:43 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleUnit_Proportional:
|
1999-04-04 03:02:43 +04:00
|
|
|
if (0 == colPosition->mWidth.GetIntValue()) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1998-08-14 20:16:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
void BasicTableLayoutStrategy::Dump(PRInt32 aIndent)
|
1998-10-03 00:34:11 +04:00
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
char* indent = new char[aIndent + 1];
|
|
|
|
for (PRInt32 i = 0; i < aIndent + 1; i++) {
|
|
|
|
indent[i] = ' ';
|
|
|
|
}
|
|
|
|
indent[aIndent] = 0;
|
|
|
|
|
|
|
|
printf("%s**START BASIC STRATEGY DUMP** table=%X cols=%d numCols=%d",
|
|
|
|
indent, mTableFrame, mCols, mNumCols);
|
|
|
|
printf("\n%s minConWidth=%d maxConWidth=%d cellSpacing=%d propRatio=%.2f navQuirks=%d",
|
|
|
|
indent, mMinTableContentWidth, mMaxTableContentWidth, mCellSpacingTotal, mMinToDesProportionRatio, mIsNavQuirksMode);
|
|
|
|
printf(" **END BASIC STRATEGY DUMP** \n");
|
|
|
|
delete [] indent;
|
1998-10-03 00:34:11 +04:00
|
|
|
}
|
1998-08-14 20:16:43 +04:00
|
|
|
|