1998-04-30 17:57:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-30 17:57:09 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-30 17:57:09 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-30 17:57:09 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-30 17:57:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BasicTableLayoutStrategy_h__
|
|
|
|
#define BasicTableLayoutStrategy_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsITableLayoutStrategy.h"
|
1998-05-26 23:28:48 +00:00
|
|
|
#include "nsCoord.h"
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1998-07-11 00:00:31 +00:00
|
|
|
class nsVoidArray;
|
1998-04-30 17:57:09 +00:00
|
|
|
class nsTableFrame;
|
1998-05-26 22:03:16 +00:00
|
|
|
struct nsStylePosition;
|
1998-11-16 06:46:00 +00:00
|
|
|
struct nsStyleTable;
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1998-09-16 00:48:14 +00:00
|
|
|
static const PRInt32 kUninitialized=-1;
|
|
|
|
|
1998-04-30 17:57:09 +00:00
|
|
|
/* ---------- BasicTableLayoutStrategy ---------- */
|
|
|
|
|
1998-08-31 21:23:28 +00:00
|
|
|
/** Implementation of Nav4 compatible HTML browser table layout.
|
|
|
|
* The input to this class is the results from pass1 table layout.
|
|
|
|
* The output from this class is to set the column widths in
|
|
|
|
* mTableFrame.
|
|
|
|
*/
|
1998-04-30 17:57:09 +00:00
|
|
|
class BasicTableLayoutStrategy : public nsITableLayoutStrategy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1998-06-23 23:23:21 +00:00
|
|
|
/** Public constructor.
|
|
|
|
* @paran aFrame the table frame for which this delegate will do layout
|
|
|
|
*/
|
1999-05-26 22:22:23 +00:00
|
|
|
BasicTableLayoutStrategy(nsTableFrame *aFrame,
|
|
|
|
PRBool aIsNavQuirksMode = PR_TRUE);
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1998-08-31 21:23:28 +00:00
|
|
|
/** destructor */
|
|
|
|
virtual ~BasicTableLayoutStrategy();
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1999-01-07 02:16:10 +00:00
|
|
|
/** call every time any table thing changes that might effect the width of any column
|
|
|
|
* in the table (content, structure, or style)
|
1998-10-19 23:43:06 +00:00
|
|
|
* @param aMaxElementSize [OUT] if not null, the max element size is computed and returned in this param
|
|
|
|
* @param aNumCols the total number of columns in the table
|
|
|
|
*/
|
1999-10-04 05:19:32 +00:00
|
|
|
virtual PRBool Initialize(nsSize* aMaxElementSize,
|
|
|
|
PRInt32 aNumCols,
|
|
|
|
nscoord aMaxSize);
|
1998-07-16 23:23:31 +00:00
|
|
|
|
1999-01-07 02:16:10 +00:00
|
|
|
/** compute the max element size of the table.
|
|
|
|
* assumes that Initialize has been called
|
|
|
|
*/
|
1998-10-09 19:59:45 +00:00
|
|
|
virtual void SetMaxElementSize(nsSize* aMaxElementSize);
|
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
void SetMinAndMaxTableContentWidths();
|
|
|
|
|
1998-08-31 21:23:28 +00:00
|
|
|
/** Called during resize reflow to determine the new column widths
|
|
|
|
* @param aTableStyle - the resolved style for mTableFrame
|
1998-10-09 19:59:45 +00:00
|
|
|
* @param aReflowState - the reflow state for mTableFrame
|
|
|
|
* @param aMaxWidth - the computed max width for columns to fit into
|
|
|
|
*/
|
1999-07-28 08:09:02 +00:00
|
|
|
virtual PRBool BalanceColumnWidths(nsIStyleContext* aTableStyle,
|
1998-10-02 04:10:00 +00:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1999-07-28 08:09:02 +00:00
|
|
|
nscoord aMaxWidth);
|
1998-05-26 22:03:16 +00:00
|
|
|
|
1998-09-02 21:59:54 +00:00
|
|
|
// these accessors are mostly for debugging purposes
|
1999-07-28 08:09:02 +00:00
|
|
|
nscoord GetTableMinContentWidth() const;
|
|
|
|
nscoord GetTableMaxContentWidth() const;
|
1998-09-02 21:59:54 +00:00
|
|
|
nscoord GetCOLSAttribute() const;
|
|
|
|
nscoord GetNumCols() const;
|
1999-07-28 08:09:02 +00:00
|
|
|
void Dump(PRInt32 aIndent);
|
1998-08-31 21:23:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
1998-07-16 23:23:31 +00:00
|
|
|
/** assign widths for each column.
|
|
|
|
* if the column has a fixed coord width, use it.
|
|
|
|
* if the column includes col spanning cells,
|
|
|
|
* then distribute the fixed space between cells proportionately.
|
1998-04-30 17:57:09 +00:00
|
|
|
* Computes the minimum and maximum table widths.
|
1998-07-16 23:23:31 +00:00
|
|
|
* Set column width information in each column frame and in the table frame.
|
1998-04-30 17:57:09 +00:00
|
|
|
*
|
1999-06-03 02:42:33 +00:00
|
|
|
* @param aMaxWidth - the computed width of the table or
|
|
|
|
* UNCONSTRAINED_SIZE if an auto width table
|
1998-04-30 17:57:09 +00:00
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*
|
|
|
|
*/
|
1999-06-03 02:42:33 +00:00
|
|
|
virtual PRBool AssignPreliminaryColumnWidths(nscoord aComputedWidth);
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1999-11-05 22:36:59 +00:00
|
|
|
/**
|
|
|
|
* Calculate the adjusted widths (min, desired, fixed, or pct) for a cell
|
|
|
|
* spanning multiple columns.
|
|
|
|
* @param aWidthIndex - the width to calculate (see nsTableColFrame.h for enums)
|
|
|
|
* @param aCellFrame - the frame of the cell with a colspan
|
|
|
|
* @param aColIndex - the column index of the cell in the table
|
|
|
|
* @param aColSpan - the colspan of the cell
|
|
|
|
* @param aConsiderPct - if true, consider columns that have pct widths and are spanned by the cell
|
|
|
|
*/
|
|
|
|
void ComputeColspanWidths(PRInt32 aWidthIndex,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aColSpan,
|
|
|
|
PRBool aConsiderPct);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* main helper for above. For min width calculations, it can get called up to
|
|
|
|
* 3 times, 1st to let constrained (fix or pct) cols reach their limit, 2nd
|
|
|
|
* to let auto cols reach their limit and 3rd to spread any remainder among
|
|
|
|
* auto cols. If there are no auto cols then only constrained cols are considered.
|
|
|
|
* @param aCellWidth - the width of the cell
|
|
|
|
* @param aLimitType - value indicating which type of width is being targeted
|
|
|
|
* to reach a limit
|
|
|
|
* @return - true if the computation completed, false otherwise
|
|
|
|
*/
|
|
|
|
PRBool ComputeColspanWidths(PRInt32 aWidthIndex,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
|
|
|
nscoord aCellWidth,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aColSpan,
|
|
|
|
PRBool aConsiderPct,
|
|
|
|
PRInt32 aLimitType);
|
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
nscoord AssignPercentageColumnWidths(nscoord aBasis,
|
|
|
|
PRBool aTableIsAutoWidth);
|
1998-04-30 17:57:09 +00:00
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
void CalculateTotals(PRInt32& aCellSpacing,
|
|
|
|
PRInt32* aTotalCounts,
|
|
|
|
PRInt32* aTotalWidths,
|
1999-10-04 05:19:32 +00:00
|
|
|
PRInt32* aTotalAvailWidths,
|
1999-07-28 08:09:02 +00:00
|
|
|
PRInt32* aMinWidths,
|
|
|
|
PRInt32& a0ProportionalCount);
|
1998-07-11 00:00:31 +00:00
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
void AllocateFully(nscoord& aTotalAllocated,
|
|
|
|
PRInt32* aAllocTypes,
|
|
|
|
PRInt32 aWidthType,
|
|
|
|
PRBool aMarkAllocated = PR_TRUE);
|
1998-07-16 23:23:31 +00:00
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
void AllocateConstrained(PRInt32 aAvailWidth,
|
|
|
|
PRInt32 aWidthType,
|
|
|
|
PRBool aStartAtMin,
|
|
|
|
PRInt32* aAllocTypes);
|
1998-07-16 23:23:31 +00:00
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
void AllocateUnconstrained(PRInt32 aAllocAmount,
|
|
|
|
PRInt32* aAllocTypes,
|
|
|
|
PRBool aSkip0Proportional);
|
1998-07-11 00:00:31 +00:00
|
|
|
|
1998-05-29 22:08:19 +00:00
|
|
|
/** return true if the style indicates that the width is a specific width
|
|
|
|
* for the purposes of column width determination.
|
|
|
|
* return false if the width changes based on content, parent size, etc.
|
1998-05-26 22:03:16 +00:00
|
|
|
*/
|
1998-11-16 06:46:00 +00:00
|
|
|
static PRBool IsFixedWidth(const nsStylePosition* aStylePosition,
|
|
|
|
const nsStyleTable* aStyleTable);
|
1998-05-26 22:03:16 +00:00
|
|
|
|
1998-07-23 21:55:45 +00:00
|
|
|
/** return true if the colIndex is in the list of colIndexes */
|
|
|
|
virtual PRBool IsColumnInList(const PRInt32 colIndex,
|
|
|
|
PRInt32 *colIndexes,
|
|
|
|
PRInt32 aNumFixedColumns);
|
|
|
|
|
1998-08-14 16:16:43 +00:00
|
|
|
/** returns true if the column is specified to have its min width */
|
|
|
|
virtual PRBool ColIsSpecifiedAsMinimumWidth(PRInt32 aColIndex);
|
|
|
|
|
1998-10-02 20:34:11 +00:00
|
|
|
/** eturns a list and count of all columns that behave like they have width=auto
|
|
|
|
* this includes columns with no width specified (the normal definition of "auto"),
|
|
|
|
* columns explicitly set to auto width,
|
|
|
|
* and columns whose fixed width comes from a span (meaning the real width is indeterminate.)
|
|
|
|
*
|
|
|
|
* @param aOutNumColumns -- out param, the number of columns matching aType
|
|
|
|
* @param aOutColumnIndexes -- out param, the indexes of the columns matching aType
|
|
|
|
*
|
|
|
|
* @return aOutNumColumns set to the number of auto columns, may be 0
|
|
|
|
* allocates and fills aOutColumnIndexes
|
|
|
|
* caller must "delete [] aOutColumnIndexes" if it is not null
|
|
|
|
*/
|
|
|
|
void GetColumnsThatActLikeAutoWidth(PRInt32& aOutNumColumns,
|
|
|
|
PRInt32*& aOutColumnIndexes);
|
1999-07-28 08:09:02 +00:00
|
|
|
void ContinuingFrameCheck();
|
1998-05-26 22:03:16 +00:00
|
|
|
|
1999-08-19 19:52:37 +00:00
|
|
|
// see nsTableFrame::ColumnsCanBeInvalidatedBy
|
|
|
|
PRBool ColumnsCanBeInvalidatedBy(nsStyleCoord* aPrevStyleWidth,
|
1999-08-20 23:27:54 +00:00
|
|
|
const nsTableCellFrame& aCellFrame) const;
|
1999-08-19 19:52:37 +00:00
|
|
|
|
|
|
|
// see nsTableFrame::ColumnsCanBeInvalidatedBy
|
|
|
|
PRBool ColumnsCanBeInvalidatedBy(const nsTableCellFrame& aCellFrame,
|
|
|
|
PRBool aConsiderMinWidth = PR_FALSE) const;
|
|
|
|
|
|
|
|
// see nsTableFrame::ColumnsCanBeInvalidatedBy
|
|
|
|
PRBool ColumnsAreValidFor(const nsTableCellFrame& aCellFrame,
|
|
|
|
nscoord aPrevCellMin,
|
|
|
|
nscoord aPrevCellDes) const;
|
|
|
|
|
1999-10-04 05:19:32 +00:00
|
|
|
PRBool RecomputeAdjMinIfNecessary();
|
|
|
|
|
1999-10-02 00:02:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const {
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-04-30 17:57:09 +00:00
|
|
|
protected:
|
|
|
|
nsTableFrame * mTableFrame;
|
1998-06-23 23:23:21 +00:00
|
|
|
PRInt32 mCols;
|
|
|
|
PRInt32 mNumCols;
|
1998-07-16 23:23:31 +00:00
|
|
|
// cached data
|
1999-07-28 08:09:02 +00:00
|
|
|
nscoord mMinTableContentWidth; // the smallest size for the table (excluding border and padding)
|
|
|
|
nscoord mMaxTableContentWidth; // the "natural" size for the table, if unconstrained (excluding border and padding)
|
|
|
|
nscoord mCellSpacingTotal; // all of the cellspacing for all of the cols
|
|
|
|
float mMinToDesProportionRatio;
|
|
|
|
PRPackedBool mIsNavQuirksMode;
|
1998-04-30 17:57:09 +00:00
|
|
|
};
|
|
|
|
|
1998-09-02 21:59:54 +00:00
|
|
|
// these accessors are mostly for debugging purposes
|
1999-07-28 08:09:02 +00:00
|
|
|
inline nscoord BasicTableLayoutStrategy::GetTableMinContentWidth() const
|
|
|
|
{ return mMinTableContentWidth; };
|
1998-08-31 21:23:28 +00:00
|
|
|
|
1999-07-28 08:09:02 +00:00
|
|
|
inline nscoord BasicTableLayoutStrategy::GetTableMaxContentWidth() const
|
|
|
|
{ return mMaxTableContentWidth; };
|
1998-09-02 21:59:54 +00:00
|
|
|
|
|
|
|
inline nscoord BasicTableLayoutStrategy::GetCOLSAttribute() const
|
|
|
|
{ return mCols; };
|
|
|
|
|
|
|
|
inline nscoord BasicTableLayoutStrategy::GetNumCols() const
|
|
|
|
{ return mNumCols; };
|
|
|
|
|
|
|
|
|
1998-05-08 21:12:12 +00:00
|
|
|
#endif
|
|
|
|
|