2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-30 21:57:09 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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 21:57:09 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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 21:57:09 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2001-07-16 23:15:01 +04:00
|
|
|
* buster@netscape.com
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-30 21:57:09 +04:00
|
|
|
|
|
|
|
#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
|
|
|
|
1998-09-16 04:48:14 +04:00
|
|
|
static const PRInt32 kUninitialized=-1;
|
|
|
|
|
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.
|
2001-07-16 23:15:01 +04:00
|
|
|
* @paran aFrame - the table frame for which this delegate will do layout
|
|
|
|
* @param aIsNavQuirksMode - honor NN4x table quirks
|
1998-06-24 03:23:21 +04:00
|
|
|
*/
|
1999-05-27 02:22:23 +04:00
|
|
|
BasicTableLayoutStrategy(nsTableFrame *aFrame,
|
|
|
|
PRBool aIsNavQuirksMode = PR_TRUE);
|
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
|
|
|
|
1999-01-07 05:16:10 +03:00
|
|
|
/** call every time any table thing changes that might effect the width of any column
|
|
|
|
* in the table (content, structure, or style)
|
2001-07-16 23:15:01 +04:00
|
|
|
* @param aPresContext - the presentation context
|
|
|
|
* @param aReflowState - the reflow state for mTableFrame
|
1998-10-20 03:43:06 +04:00
|
|
|
*/
|
2000-02-12 04:55:40 +03:00
|
|
|
virtual PRBool Initialize(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** Called during resize reflow to determine the new column widths
|
2001-07-16 23:15:01 +04:00
|
|
|
* @param aPresContext - the presentation context
|
|
|
|
* @param aReflowState - the reflow state for mTableFrame
|
|
|
|
*/
|
2000-01-22 04:16:50 +03:00
|
|
|
virtual PRBool BalanceColumnWidths(nsIPresContext* aPresContext,
|
2001-03-13 09:38:59 +03:00
|
|
|
const nsHTMLReflowState& aReflowState);
|
2001-07-16 23:15:01 +04:00
|
|
|
|
2001-08-06 17:58:46 +04:00
|
|
|
/**
|
|
|
|
* Calculate the basis for percent width calculations of the table elements
|
|
|
|
* @param aReflowState - the reflow state of the table
|
|
|
|
* @param aAvailWidth - the available width for the table
|
|
|
|
* @param aPixelToTwips - the number of twips in a pixel.
|
|
|
|
* @return - the basis for percent calculations
|
|
|
|
*/
|
2002-02-19 18:48:28 +03:00
|
|
|
virtual nscoord CalcPctAdjTableWidth(nsIPresContext& aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2001-08-06 17:58:46 +04:00
|
|
|
nscoord aAvailWidth,
|
|
|
|
float aPixelToTwips);
|
1999-07-28 12:09:02 +04:00
|
|
|
void Dump(PRInt32 aIndent);
|
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
|
|
|
*
|
1999-06-03 06:42:33 +04:00
|
|
|
* @param aMaxWidth - the computed width of the table or
|
|
|
|
* UNCONSTRAINED_SIZE if an auto width table
|
2001-07-16 23:15:01 +04:00
|
|
|
* @return PR_TRUE has a pct cell or col, PR_FALSE otherwise
|
1998-04-30 21:57:09 +04:00
|
|
|
*/
|
2000-09-09 05:46:44 +04:00
|
|
|
virtual PRBool AssignNonPctColumnWidths(nsIPresContext* aPresContext,
|
|
|
|
nscoord aComputedWidth,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
float aPixelToTwips);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
1999-11-06 01:36:59 +03:00
|
|
|
/**
|
|
|
|
* Calculate the adjusted widths (min, desired, fixed, or pct) for a cell
|
|
|
|
* spanning multiple columns.
|
2000-12-19 23:29:46 +03:00
|
|
|
* @param aReflowState - the reflow state of the table
|
1999-11-06 01:36:59 +03:00
|
|
|
* @param aConsiderPct - if true, consider columns that have pct widths and are spanned by the cell
|
2000-12-19 23:29:46 +03:00
|
|
|
* @param aPixelToTwips- the number of twips in a pixel.
|
2001-03-13 09:38:59 +03:00
|
|
|
* @param aHasPctCol - if not null, then set *aHasPctCol to true if there is a pct cell or col
|
1999-11-06 01:36:59 +03:00
|
|
|
*/
|
2000-09-09 05:46:44 +04:00
|
|
|
void ComputeNonPctColspanWidths(const nsHTMLReflowState& aReflowState,
|
|
|
|
PRBool aConsiderPct,
|
2001-03-13 09:38:59 +03:00
|
|
|
float aPixelToTwips,
|
|
|
|
PRBool* aHasPctCol);
|
1999-11-06 01:36:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* main helper for above. For min width calculations, it can get called up to
|
2000-12-19 23:29:46 +03:00
|
|
|
* 3 times, 1st to let constrained pct cols reach their limit, 2nd
|
|
|
|
* to let fix cols reach their limit and 3rd to spread any remainder among
|
1999-11-06 01:36:59 +03:00
|
|
|
* auto cols. If there are no auto cols then only constrained cols are considered.
|
2000-12-19 23:29:46 +03:00
|
|
|
* @param aWidthIndex - the width to calculate (see nsTableColFrame.h for enums)
|
|
|
|
* @param aCellFrame - the frame of the cell with a colspan
|
|
|
|
* @param aCellWidth - the width 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 aLimitType - the type of limit (ie. pct, fix, none).
|
|
|
|
* @param aPixelToTwips- the number of twips in a pixel.
|
|
|
|
* @return - true if all of aCellWidth was allocated, false otherwise
|
1999-11-06 01:36:59 +03:00
|
|
|
*/
|
2000-09-09 05:46:44 +04:00
|
|
|
PRBool ComputeNonPctColspanWidths(PRInt32 aWidthIndex,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
2000-12-19 23:29:46 +03:00
|
|
|
PRInt32 aCellWidth,
|
2000-09-09 05:46:44 +04:00
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aColSpan,
|
|
|
|
PRInt32& aLimitType,
|
|
|
|
float aPixelToTwips);
|
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Determine percentage col widths for each col frame
|
|
|
|
* @param aReflowState - the reflow state of the table
|
|
|
|
* @param aBasis - the basis for percent width as computed by CalcPctAdjTableWidth
|
|
|
|
* @param aTableIsAutoWidth - true if no width specification for the table is available
|
|
|
|
* @param aPixelToTwips - the number of twips in a pixel.
|
|
|
|
* @return - the adjusted basis including table border, padding and cell spacing
|
|
|
|
*/
|
2002-02-19 18:48:28 +03:00
|
|
|
nscoord AssignPctColumnWidths(nsIPresContext& aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2001-02-07 07:31:38 +03:00
|
|
|
nscoord aBasis,
|
|
|
|
PRBool aTableIsAutoWidth,
|
|
|
|
float aPixelToTwips);
|
2000-09-09 05:46:44 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Reduce the percent columns by the amount specified in aExcess as the percent width's
|
|
|
|
* can accumulate to be over 100%
|
|
|
|
* @param aExcess - reduction amount
|
|
|
|
*/
|
2000-09-09 05:46:44 +04:00
|
|
|
void ReduceOverSpecifiedPctCols(nscoord aExcess);
|
1998-04-30 21:57:09 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Sort rows by rising colspans, in order to treat the inner colspans first
|
|
|
|
* the result will be returned in the aRowIndices array.
|
|
|
|
* @param aRowIndices - array with indices of those rows which have colspans starting in the corresponding column
|
|
|
|
* @param aColSpans - array with the correspong colspan values
|
|
|
|
* @param aIndex - number of valid entries in the arrays
|
|
|
|
*/
|
|
|
|
void RowSort(PRInt32* aRowIndices,
|
|
|
|
PRInt32* aColSpans,
|
|
|
|
PRInt32 aIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calculate totals by width type. The logic here is kept in synch with
|
|
|
|
* that in CanAllocate
|
|
|
|
* @param aTotalCounts - array with counts for each width type that has determined the aTotalWidths sum
|
|
|
|
* @param aTotalWidths - array with accumulated widths for each width type
|
|
|
|
* @param aDupedWidths - (duplicatd) are widths that will be allocated in BalanceColumnWidths before aTotalsWidths
|
|
|
|
* @param a0ProportionalCount - number of columns with col="0*" constraint
|
|
|
|
*/
|
2001-03-13 09:38:59 +03:00
|
|
|
void CalculateTotals(PRInt32* aTotalCounts,
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32* aTotalWidths,
|
2001-07-16 23:15:01 +04:00
|
|
|
PRInt32* aDupedWidths,
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32& a0ProportionalCount);
|
1998-07-11 04:00:31 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Allocate aWidthType values to the corresponding columns
|
|
|
|
* @param aTotalAllocated - width that has been allocated in this routine
|
|
|
|
* @param aAllocTypes - width type that has determined col width
|
|
|
|
* @param aWidthType - width type selecting the columns for full width allocation
|
|
|
|
*/
|
1999-07-28 12:09:02 +04:00
|
|
|
void AllocateFully(nscoord& aTotalAllocated,
|
|
|
|
PRInt32* aAllocTypes,
|
2000-12-19 23:29:46 +03:00
|
|
|
PRInt32 aWidthType);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Allocate aWidthType values to the corresponding columns up to the aAvailWidth
|
|
|
|
* @param aAvailWidth - width that can distributed to the selected columns
|
|
|
|
* @param aWidthType - width type selecting the columns for width allocation
|
|
|
|
* @param aStartAtMin - allocation should start at min. content width
|
|
|
|
* @param aAllocTypes - width type that has determined col width
|
|
|
|
* @param aPixelToTwips - the number of twips in a pixel.
|
|
|
|
*/
|
1999-07-28 12:09:02 +04:00
|
|
|
void AllocateConstrained(PRInt32 aAvailWidth,
|
|
|
|
PRInt32 aWidthType,
|
|
|
|
PRBool aStartAtMin,
|
2000-09-01 05:29:50 +04:00
|
|
|
PRInt32* aAllocTypes,
|
|
|
|
float aPixelToTwips);
|
1998-07-17 03:23:31 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Give the remaining space and exclude the selected columns
|
|
|
|
* @param aAllocAmount - space that can be distributed
|
|
|
|
* @param aAllocTypes - width type that has determined col width
|
|
|
|
* @param aExcludePct - dont give space to percent columns
|
|
|
|
* @param aExcludeFix - dont give space to fixed width columns
|
|
|
|
* @param aExcludePro - dont give space to proportional columns
|
|
|
|
* @param aExclude0Pro - dont give space to proportional columns with 0*
|
|
|
|
* @param aPixelToTwips - the number of twips in a pixel.
|
|
|
|
*/
|
1999-07-28 12:09:02 +04:00
|
|
|
void AllocateUnconstrained(PRInt32 aAllocAmount,
|
|
|
|
PRInt32* aAllocTypes,
|
2000-12-19 23:29:46 +03:00
|
|
|
PRBool aExcludePct,
|
|
|
|
PRBool aExcludeFix,
|
|
|
|
PRBool aExcludePro,
|
|
|
|
PRBool aExclude0Pro,
|
2000-09-01 05:29:50 +04:00
|
|
|
float aPixelToTwips);
|
1998-07-11 04:00:31 +04:00
|
|
|
|
2001-07-16 23:15:01 +04:00
|
|
|
/**
|
|
|
|
* Check in debug mode whether the routine is called on a continuing frame
|
1998-10-03 00:34:11 +04:00
|
|
|
*/
|
1999-07-28 12:09:02 +04:00
|
|
|
void ContinuingFrameCheck();
|
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;
|
1998-07-17 03:23:31 +04:00
|
|
|
// cached data
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord mCellSpacingTotal; // all of the cellspacing for all of the cols
|
|
|
|
float mMinToDesProportionRatio;
|
|
|
|
PRPackedBool mIsNavQuirksMode;
|
1998-04-30 21:57:09 +04:00
|
|
|
};
|
1998-05-09 01:12:12 +04:00
|
|
|
#endif
|
|
|
|
|