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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BasicTableLayoutStrategy_h__
|
|
|
|
#define BasicTableLayoutStrategy_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsITableLayoutStrategy.h"
|
1998-05-27 03:28:48 +04:00
|
|
|
#include "nsCoord.h"
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
class nsVoidArray;
|
1998-04-30 21:57:09 +04:00
|
|
|
class nsTableFrame;
|
1998-05-27 02:03:16 +04:00
|
|
|
struct nsStylePosition;
|
1998-11-16 09:46:00 +03:00
|
|
|
struct nsStyleTable;
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
/* ----------- SpanInfo ---------- */
|
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** SpanInfo is a transient data structure that holds info about
|
|
|
|
* cells that have col spans. Used during column balancing.
|
|
|
|
*/
|
1998-04-30 21:57:09 +04:00
|
|
|
struct SpanInfo
|
|
|
|
{
|
1998-07-17 03:23:31 +04:00
|
|
|
PRInt32 span;
|
|
|
|
const PRInt32 initialColSpan;
|
1998-07-22 07:53:43 +04:00
|
|
|
const PRInt32 initialColIndex;
|
1998-06-06 02:50:03 +04:00
|
|
|
nscoord cellMinWidth;
|
|
|
|
nscoord cellDesiredWidth;
|
1998-07-22 07:53:43 +04:00
|
|
|
nscoord effectiveMinWidthOfSpannedCols;
|
|
|
|
nscoord effectiveMaxWidthOfSpannedCols;
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-07-22 07:53:43 +04:00
|
|
|
SpanInfo(PRInt32 aColIndex, PRInt32 aSpan, nscoord aMinWidth, nscoord aDesiredWidth);
|
1998-04-30 21:57:09 +04:00
|
|
|
~SpanInfo() {};
|
1998-09-16 04:48:14 +04:00
|
|
|
|
1998-04-30 21:57:09 +04:00
|
|
|
};
|
|
|
|
|
1998-09-16 04:48:14 +04:00
|
|
|
static const PRInt32 kUninitialized=-1;
|
|
|
|
|
1998-07-22 07:53:43 +04:00
|
|
|
inline SpanInfo::SpanInfo(PRInt32 aColIndex, PRInt32 aSpan,
|
|
|
|
nscoord aMinWidth, nscoord aDesiredWidth)
|
|
|
|
: initialColIndex(aColIndex),
|
|
|
|
initialColSpan(aSpan)
|
1998-07-17 03:23:31 +04:00
|
|
|
{
|
|
|
|
span = aSpan;
|
|
|
|
cellMinWidth = aMinWidth;
|
|
|
|
cellDesiredWidth = aDesiredWidth;
|
1998-09-16 04:48:14 +04:00
|
|
|
effectiveMinWidthOfSpannedCols=kUninitialized;
|
|
|
|
effectiveMaxWidthOfSpannedCols=kUninitialized;
|
1998-07-17 03:23:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
/* ---------- BasicTableLayoutStrategy ---------- */
|
|
|
|
|
1998-09-01 01:23:28 +04: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 21:57:09 +04:00
|
|
|
class BasicTableLayoutStrategy : public nsITableLayoutStrategy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
/** Public constructor.
|
|
|
|
* @paran aFrame the table frame for which this delegate will do layout
|
|
|
|
*/
|
1998-10-20 03:43:06 +04:00
|
|
|
BasicTableLayoutStrategy(nsTableFrame *aFrame);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** destructor */
|
|
|
|
virtual ~BasicTableLayoutStrategy();
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-10-20 03:43:06 +04:00
|
|
|
/** call once every time any table thing changes (content, structure, or style)
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
virtual PRBool Initialize(nsSize* aMaxElementSize, PRInt32 aNumCols);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1998-10-09 23:59:45 +04:00
|
|
|
virtual void SetMaxElementSize(nsSize* aMaxElementSize);
|
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** Called during resize reflow to determine the new column widths
|
|
|
|
* @param aTableStyle - the resolved style for mTableFrame
|
1998-10-09 23:59:45 +04:00
|
|
|
* @param aReflowState - the reflow state for mTableFrame
|
|
|
|
* @param aMaxWidth - the computed max width for columns to fit into
|
|
|
|
*/
|
1998-07-17 03:23:31 +04:00
|
|
|
virtual PRBool BalanceColumnWidths(nsIStyleContext * aTableStyle,
|
1998-10-02 08:10:00 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1998-07-17 03:23:31 +04:00
|
|
|
nscoord aMaxWidth);
|
1998-05-27 02:03:16 +04:00
|
|
|
|
1998-09-03 01:59:54 +04:00
|
|
|
// these accessors are mostly for debugging purposes
|
|
|
|
nscoord GetTableMinWidth() const;
|
1998-09-01 01:23:28 +04:00
|
|
|
nscoord GetTableMaxWidth() const;
|
1998-09-03 01:59:54 +04:00
|
|
|
nscoord GetTableFixedWidth() const;
|
|
|
|
nscoord GetCOLSAttribute() const;
|
|
|
|
nscoord GetNumCols() const;
|
1998-09-01 01:23:28 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
1998-07-17 03:23:31 +04: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 21:57:09 +04:00
|
|
|
* Computes the minimum and maximum table widths.
|
1998-07-17 03:23:31 +04:00
|
|
|
* Set column width information in each column frame and in the table frame.
|
1998-04-30 21:57:09 +04:00
|
|
|
*
|
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*
|
|
|
|
*/
|
1998-07-17 03:23:31 +04:00
|
|
|
virtual PRBool AssignPreliminaryColumnWidths();
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-08-01 06:31:55 +04:00
|
|
|
virtual void SetMinAndMaxTableWidths();
|
|
|
|
|
1998-04-30 21:57:09 +04:00
|
|
|
/** assign widths for each column that has proportional width inside a table that
|
|
|
|
* has auto width (width set by the content and available space.)
|
|
|
|
* Sets mColumnWidths as a side effect.
|
|
|
|
*
|
1998-07-17 03:23:31 +04:00
|
|
|
* @param aTableStyle the resolved style for the table
|
|
|
|
* @param aAvailWidth the remaining amount of horizontal space available
|
|
|
|
* @param aMaxWidth the total amount of horizontal space available
|
|
|
|
* @param aTableSpecifiedWidth the width of the table based on its attributes and its parent's width
|
|
|
|
* @param aTableIsAutoWidth PR_TRUE if the table is auto-width
|
1998-04-30 21:57:09 +04:00
|
|
|
*
|
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*
|
|
|
|
*/
|
1998-10-02 08:10:00 +04:00
|
|
|
virtual PRBool BalanceProportionalColumns(const nsHTMLReflowState& aReflowState,
|
1998-06-06 02:50:03 +04:00
|
|
|
nscoord aAvailWidth,
|
|
|
|
nscoord aMaxWidth,
|
1998-07-17 03:23:31 +04:00
|
|
|
nscoord aTableSpecifiedWidth,
|
1998-07-07 02:48:19 +04:00
|
|
|
PRBool aTableIsAutoWidth);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
/** assign the minimum allowed width for each column that has proportional width.
|
|
|
|
* Typically called when the min table width doesn't fit in the available space.
|
|
|
|
* Sets mColumnWidths as a side effect.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*/
|
1998-10-23 23:56:11 +04:00
|
|
|
virtual PRBool BalanceColumnsTableDoesNotFit();
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
/** assign the maximum allowed width for each column that has proportional width.
|
|
|
|
* Typically called when the desired max table width fits in the available space.
|
|
|
|
* Sets mColumnWidths as a side effect.
|
|
|
|
*
|
1998-07-17 03:23:31 +04:00
|
|
|
* @param aAvailWidth the remaining amount of horizontal space available
|
|
|
|
* @param aMaxWidth the total amount of horizontal space available
|
|
|
|
* @param aTableSpecifiedWidth the specified width of the table. If there is none,
|
|
|
|
* this param is 0
|
|
|
|
* @param aTableIsAutoWidth PR_TRUE if the table is auto-width
|
1998-05-27 02:03:16 +04:00
|
|
|
*
|
1998-04-30 21:57:09 +04:00
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*/
|
1998-10-02 08:10:00 +04:00
|
|
|
virtual PRBool BalanceColumnsTableFits(const nsHTMLReflowState& aReflowState,
|
1998-07-07 02:48:19 +04:00
|
|
|
nscoord aAvailWidth,
|
|
|
|
nscoord aMaxWidth,
|
1998-07-17 03:23:31 +04:00
|
|
|
nscoord aTableSpecifiedWidth,
|
1998-07-07 02:48:19 +04:00
|
|
|
PRBool aTableIsAutoWidth);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
/** assign widths for each column that has proportional width inside a table that
|
|
|
|
* has auto width (width set by the content and available space) according to the
|
|
|
|
* HTML 4 specification.
|
|
|
|
* Sets mColumnWidths as a side effect.
|
|
|
|
*
|
|
|
|
* @param aTableStyle the resolved style for the table
|
|
|
|
* @param aAvailWidth the remaining amount of horizontal space available
|
|
|
|
* @param aMaxWidth the total amount of horizontal space available
|
|
|
|
* @param aMinTableWidth the min possible table width
|
|
|
|
* @param aMaxTableWidth the max table width
|
|
|
|
*
|
|
|
|
* @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error
|
|
|
|
*
|
|
|
|
* TODO: rename this method to reflect that it is a Nav4 compatibility method
|
|
|
|
*/
|
1998-10-02 08:10:00 +04:00
|
|
|
virtual PRBool BalanceColumnsConstrained(const nsHTMLReflowState& aReflowState,
|
1998-06-06 02:50:03 +04:00
|
|
|
nscoord aAvailWidth,
|
1998-08-02 00:31:40 +04:00
|
|
|
nscoord aMaxWidth,
|
|
|
|
PRBool aTableIsAutoWidth);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
/** post-process to AssignFixedColumnWidths
|
|
|
|
*
|
|
|
|
* @param aColSpanList a list of fixed-width columns that have colspans
|
|
|
|
*
|
|
|
|
* NOTE: does not yet properly handle overlapping col spans
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
1998-07-17 03:23:31 +04:00
|
|
|
virtual void DistributeFixedSpace(nsVoidArray *aColSpanList);
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1998-06-30 04:37:03 +04:00
|
|
|
/** starting with a partially balanced table, compute the amount
|
|
|
|
* of space to pad each column by to completely balance the table.
|
|
|
|
* set the column widths in mTableFrame based on these computations.
|
|
|
|
*
|
1998-07-11 04:00:31 +04:00
|
|
|
* @param aAvailWidth the space still to be allocated within the table
|
|
|
|
* @param aTableWidth the sum of all columns widths
|
|
|
|
* @param aWidthOfFixedTableColumns the sum of the widths of fixed-width columns
|
|
|
|
* @param aColWidths the effective column widths (ignoring col span cells)
|
1998-06-30 04:37:03 +04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
1998-07-11 04:00:31 +04:00
|
|
|
virtual void DistributeExcessSpace(nscoord aAvailWidth,
|
|
|
|
nscoord aTableWidth,
|
1998-07-17 03:23:31 +04:00
|
|
|
nscoord aWidthOfFixedTableColumns);
|
1998-07-07 01:00:11 +04:00
|
|
|
|
|
|
|
/** starting with a partially balanced table, compute the amount
|
1998-10-01 22:39:31 +04:00
|
|
|
* of space to allocate to each column to completely balance the table.
|
1998-07-07 01:00:11 +04:00
|
|
|
* set the column widths in mTableFrame based on these computations.
|
1998-10-01 22:39:31 +04:00
|
|
|
* assumes auto-width columns have been set to their minimum width.
|
|
|
|
* must be called with a PRInt32 variable initialized to 0 for aRecursionControl.
|
1998-07-07 01:00:11 +04:00
|
|
|
*
|
|
|
|
* @param aTableFixedWidth the specified width of the table. If there is none,
|
|
|
|
* this param is 0
|
1998-10-01 22:39:31 +04:00
|
|
|
* @param aComputedTableWidth IN: the width of the table before this step.
|
|
|
|
* OUT:the width of the table after this step.
|
|
|
|
* @param aTableIsAutoWidth TRUE if the table style indicates it is autoWidth
|
|
|
|
* @param aRecursionControl IN: must be a PRInt32 set to 0
|
|
|
|
* OUT: the number of iterations. Not generally useful to the caller.
|
1998-07-07 01:00:11 +04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
virtual void DistributeRemainingSpace(nscoord aTableFixedWidth,
|
1998-10-01 22:39:31 +04:00
|
|
|
nscoord &aComputedTableWidth,
|
|
|
|
PRBool aTableIsAutoWidth,
|
|
|
|
PRInt32 &aRecursionControl);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
|
|
|
virtual void AdjustTableThatIsTooWide(nscoord aComputedWidth,
|
1998-07-24 01:55:45 +04:00
|
|
|
nscoord aTableWidth,
|
|
|
|
PRBool aShrinkFixedCols);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
|
|
|
virtual void AdjustTableThatIsTooNarrow(nscoord aComputedWidth,
|
|
|
|
nscoord aTableWidth);
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1998-05-30 02:08:19 +04: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-27 02:03:16 +04:00
|
|
|
*/
|
1998-11-16 09:46:00 +03:00
|
|
|
static PRBool IsFixedWidth(const nsStylePosition* aStylePosition,
|
|
|
|
const nsStyleTable* aStyleTable);
|
1998-05-27 02:03:16 +04:00
|
|
|
|
1998-07-24 01:55:45 +04: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 20:16:43 +04:00
|
|
|
/** returns true if the column is specified to have its min width */
|
|
|
|
virtual PRBool ColIsSpecifiedAsMinimumWidth(PRInt32 aColIndex);
|
|
|
|
|
1998-10-03 00:34:11 +04: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);
|
|
|
|
|
1998-05-27 02:03:16 +04:00
|
|
|
|
1998-04-30 21:57:09 +04:00
|
|
|
protected:
|
|
|
|
nsTableFrame * mTableFrame;
|
1998-06-24 03:23:21 +04:00
|
|
|
PRInt32 mCols;
|
|
|
|
PRInt32 mNumCols;
|
1998-07-17 03:23:31 +04:00
|
|
|
// cached data
|
1998-07-27 06:15:37 +04:00
|
|
|
nscoord mMinTableWidth; // the smallest size for the table
|
|
|
|
nscoord mMaxTableWidth; // the "natural" size for the table, if unconstrained
|
|
|
|
nscoord mFixedTableWidth; // the amount of space taken up by fixed-width columns
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
1998-09-03 01:59:54 +04:00
|
|
|
// these accessors are mostly for debugging purposes
|
|
|
|
inline nscoord BasicTableLayoutStrategy::GetTableMinWidth() const
|
|
|
|
{ return mMinTableWidth; };
|
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
inline nscoord BasicTableLayoutStrategy::GetTableMaxWidth() const
|
|
|
|
{ return mMaxTableWidth; };
|
|
|
|
|
1998-09-03 01:59:54 +04:00
|
|
|
inline nscoord BasicTableLayoutStrategy::GetTableFixedWidth() const
|
|
|
|
{ return mFixedTableWidth; };
|
|
|
|
|
|
|
|
inline nscoord BasicTableLayoutStrategy::GetCOLSAttribute() const
|
|
|
|
{ return mCols; };
|
|
|
|
|
|
|
|
inline nscoord BasicTableLayoutStrategy::GetNumCols() const
|
|
|
|
{ return mNumCols; };
|
|
|
|
|
|
|
|
|
1998-05-09 01:12:12 +04:00
|
|
|
#endif
|
|
|
|
|