1998-04-13 20:24:54 +00: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 nsTableFrame_h__
|
|
|
|
#define nsTableFrame_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsContainerFrame.h"
|
|
|
|
|
|
|
|
class nsCellLayoutData;
|
|
|
|
class nsTableCell;
|
|
|
|
class nsVoidArray;
|
|
|
|
class nsTableCellFrame;
|
|
|
|
class CellData;
|
1998-04-30 17:57:09 +00:00
|
|
|
class nsITableLayoutStrategy;
|
1998-04-13 20:24:54 +00:00
|
|
|
struct InnerTableReflowState;
|
1998-04-25 18:48:48 +00:00
|
|
|
struct nsStylePosition;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** nsTableFrame maps the inner portion of a table (everything except captions.)
|
|
|
|
* Used as a pseudo-frame within nsTableOuterFrame,
|
|
|
|
* it may also be used stand-alone as the top-level frame.
|
|
|
|
* The meaningful child frames of nsTableFrame map rowgroups.
|
|
|
|
*
|
|
|
|
* @author sclark
|
|
|
|
*
|
|
|
|
* TODO: make methods virtual so nsTableFrame can be used as a base class in the future.
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
|
|
|
class nsTableFrame : public nsContainerFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** nsTableOuterFrame has intimate knowledge of the inner table frame */
|
1998-04-13 20:24:54 +00:00
|
|
|
friend class nsTableOuterFrame;
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** instantiate a new instance of nsTableFrame.
|
|
|
|
* @param aInstancePtrResult the new object is returned in this out-param
|
|
|
|
* @param aContent the table object to map
|
|
|
|
* @param aParent the parent of the new frame
|
|
|
|
*
|
|
|
|
* @return NS_OK if the frame was properly allocated, otherwise an error code
|
|
|
|
*/
|
1998-04-13 20:24:54 +00:00
|
|
|
static nsresult NewFrame(nsIFrame** aInstancePtrResult,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** @see nsIFrame::Paint */
|
1998-04-17 01:41:24 +00:00
|
|
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** inner tables are reflowed in two steps.
|
|
|
|
* <pre>
|
|
|
|
* if mFirstPassValid is false, this is our first time through since content was last changed
|
|
|
|
* set pass to 1
|
|
|
|
* do pass 1
|
|
|
|
* get min/max info for all cells in an infinite space
|
|
|
|
* do column balancing
|
|
|
|
* set mFirstPassValid to true
|
|
|
|
* do pass 2
|
|
|
|
* use column widths to ResizeReflow cells
|
|
|
|
* shrinkWrap Cells in each row to tallest, realigning contents within the cell
|
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @see ResizeReflowPass1
|
|
|
|
* @see ResizeReflowPass2
|
|
|
|
* @see BalanceColumnWidths
|
|
|
|
* @see nsIFrame::ResizeReflow
|
|
|
|
*/
|
1998-04-17 01:41:24 +00:00
|
|
|
NS_IMETHOD ResizeReflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsSize* aMaxElementSize,
|
1998-05-12 04:17:56 +00:00
|
|
|
nsReflowStatus& aStatus);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** @see nsIFrame::IncrementalReflow */
|
1998-04-17 01:41:24 +00:00
|
|
|
NS_IMETHOD IncrementalReflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsReflowCommand& aReflowCommand,
|
1998-05-12 04:17:56 +00:00
|
|
|
nsReflowStatus& aStatus);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** @see nsContainerFrame::CreateContinuingFrame */
|
1998-05-07 00:08:20 +00:00
|
|
|
NS_IMETHOD CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
/** resize myself and my children according to the arcane rules of cell height magic.
|
|
|
|
* By default, the height of a cell is the max (height of cells in its row)
|
|
|
|
* In the case of a cell with rowspan>1 (lets call this C),
|
|
|
|
* if the sum of the height of the rows spanned (excluding C in the calculation)
|
|
|
|
* is greater than or equal to the height of C,
|
|
|
|
* the cells in the rows are sized normally and
|
|
|
|
* the height of C is set to the sum of the heights (taking into account borders, padding, and margins)
|
|
|
|
* else
|
|
|
|
* the height of each row is expanded by a percentage of the difference between
|
|
|
|
* the row's desired height and the height of C
|
|
|
|
*/
|
|
|
|
virtual void ShrinkWrapChildren(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
nsSize* aMaxElementSize);
|
|
|
|
|
|
|
|
/** return the column layout data for this inner table frame.
|
|
|
|
* if this is a continuing frame, return the first-in-flow's column layout data.
|
|
|
|
*/
|
|
|
|
virtual nsVoidArray *GetColumnLayoutData();
|
|
|
|
|
|
|
|
/** Associate aData with the cell at (aRow,aCol)
|
|
|
|
* @return PR_TRUE if the data was successfully associated with a Cell
|
|
|
|
* PR_FALSE if there was an error, such as aRow or aCol being invalid
|
|
|
|
*/
|
|
|
|
virtual PRBool SetCellLayoutData(nsCellLayoutData * aData, nsTableCell *aCell);
|
|
|
|
|
|
|
|
/** Get the layout data associated with the cell at (aRow,aCol)
|
|
|
|
* @return PR_NULL if there was an error, such as aRow or aCol being invalid
|
|
|
|
* otherwise, the data is returned.
|
|
|
|
*/
|
|
|
|
virtual nsCellLayoutData * GetCellLayoutData(nsTableCell *aCell);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** returns PR_TRUE if this table has proportional width
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
1998-04-25 18:48:48 +00:00
|
|
|
PRBool IsProportionalWidth(nsStylePosition* aStylePosition);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DEBUG METHOD
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void ListColumnLayoutData(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** return the width of the column at aColIndex */
|
1998-04-13 20:24:54 +00:00
|
|
|
PRInt32 GetColumnWidth(PRInt32 aColIndex);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** set the width of the column at aColIndex to aWidth */
|
1998-04-13 20:24:54 +00:00
|
|
|
void SetColumnWidth(PRInt32 aColIndex, PRInt32 aWidth);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate Layout Information
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsCellLayoutData* FindCellLayoutData(nsTableCell* aCell);
|
|
|
|
void AppendLayoutData(nsVoidArray* aList, nsTableCell* aTableCell);
|
1998-04-28 22:41:25 +00:00
|
|
|
void RecalcLayoutData();
|
1998-04-13 20:24:54 +00:00
|
|
|
void ResetCellLayoutData( nsTableCell* aCell,
|
|
|
|
nsTableCell* aAbove,
|
|
|
|
nsTableCell* aBelow,
|
|
|
|
nsTableCell* aLeft,
|
|
|
|
nsTableCell* aRight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** protected constructor.
|
|
|
|
* @see NewFrame
|
|
|
|
*/
|
1998-05-05 23:56:50 +00:00
|
|
|
nsTableFrame(nsIContent* aContent, nsIFrame* aParentFrame);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** destructor, responsible for mColumnLayoutData and mColumnWidths */
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual ~nsTableFrame();
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** helper method to delete contents of mColumnLayoutData
|
|
|
|
* should be called with care (ie, only by destructor)
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
|
|
|
virtual void DeleteColumnLayoutData();
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** first pass of ResizeReflow.
|
|
|
|
* lays out all table content with aMaxSize(NS_UNCONSTRAINEDSIZE,NS_UNCONSTRAINEDSIZE) and
|
|
|
|
* a non-null aMaxElementSize so we get all the metrics we need to do column balancing.
|
|
|
|
* Pass 1 only needs to be executed once no matter how many times the table is resized,
|
|
|
|
* as long as content and style don't change. This is managed in the member variable mFirstPassIsValid.
|
|
|
|
* The layout information for each cell is cached in mColumLayoutData.
|
|
|
|
*
|
|
|
|
* @see ResizeReflow
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
1998-05-12 04:17:56 +00:00
|
|
|
virtual nsReflowStatus ResizeReflowPass1(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsSize* aMaxElementSize);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** second pass of ResizeReflow.
|
|
|
|
* lays out all table content with aMaxSize(computed_table_width, given_table_height)
|
|
|
|
* Pass 2 is executed every time the table needs to resize. An optimization is included
|
|
|
|
* so that if the table doesn't need to actually be resized, no work is done (see NeedsReflow).
|
|
|
|
*
|
|
|
|
* @param aMinCaptionWidth - the max of all the minimum caption widths. 0 if no captions.
|
|
|
|
* @param aMaxCaptionWidth - the max of all the desired caption widths. 0 if no captions.
|
|
|
|
*
|
|
|
|
* @see ResizeReflow
|
|
|
|
* @see NeedsReflow
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
1998-05-12 04:17:56 +00:00
|
|
|
virtual nsReflowStatus ResizeReflowPass2(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsSize* aMaxElementSize,
|
|
|
|
PRInt32 aMinCaptionWidth,
|
|
|
|
PRInt32 mMaxCaptionWidth);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nscoord GetTopMarginFor(nsIPresContext* aCX,
|
|
|
|
InnerTableReflowState& aState,
|
1998-05-12 22:28:01 +00:00
|
|
|
const nsMargin& aKidMargin);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
void PlaceChild(nsIPresContext* aPresContext,
|
|
|
|
InnerTableReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
const nsRect& aKidRect,
|
|
|
|
nsSize* aMaxElementSize,
|
|
|
|
nsSize& aKidMaxElementSize);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/**
|
|
|
|
* Reflow the frames we've already created
|
|
|
|
*
|
|
|
|
* @param aPresContext presentation context to use
|
|
|
|
* @param aState current inline state
|
|
|
|
* @return true if we successfully reflowed all the mapped children and false
|
|
|
|
* otherwise, e.g. we pushed children to the next in flow
|
|
|
|
*/
|
1998-04-13 20:24:54 +00:00
|
|
|
PRBool ReflowMappedChildren(nsIPresContext* aPresContext,
|
|
|
|
InnerTableReflowState& aState,
|
|
|
|
nsSize* aMaxElementSize);
|
1998-04-14 21:45:28 +00:00
|
|
|
/**
|
|
|
|
* Try and pull-up frames from our next-in-flow
|
|
|
|
*
|
|
|
|
* @param aPresContext presentation context to use
|
|
|
|
* @param aState current inline state
|
|
|
|
* @return true if we successfully pulled-up all the children and false
|
|
|
|
* otherwise, e.g. child didn't fit
|
|
|
|
*/
|
1998-04-13 20:24:54 +00:00
|
|
|
PRBool PullUpChildren(nsIPresContext* aPresContext,
|
|
|
|
InnerTableReflowState& aState,
|
|
|
|
nsSize* aMaxElementSize);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/**
|
|
|
|
* Create new frames for content we haven't yet mapped
|
|
|
|
*
|
|
|
|
* @param aPresContext presentation context to use
|
|
|
|
* @param aState current inline state
|
|
|
|
* @return frComplete if all content has been mapped and frNotComplete
|
|
|
|
* if we should be continued
|
|
|
|
*/
|
1998-05-12 04:17:56 +00:00
|
|
|
nsReflowStatus ReflowUnmappedChildren(nsIPresContext* aPresContext,
|
|
|
|
InnerTableReflowState& aState,
|
|
|
|
nsSize* aMaxElementSize);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** assign widths for each column, taking into account the table content, the effective style,
|
|
|
|
* the layout constraints, and the compatibility mode. Sets mColumnWidths as a side effect.
|
|
|
|
* @param aPresContext the presentation context
|
|
|
|
* @param aTableStyle the resolved style for the table
|
|
|
|
* @param aMaxSize the height and width constraints
|
|
|
|
* @param aMaxElementSize the min size of the largest indivisible object
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
|
|
|
virtual void BalanceColumnWidths(nsIPresContext* aPresContext,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsSize* aMaxElementSize);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** sets the width of the table according to the computed widths of each column. */
|
1998-04-25 18:48:48 +00:00
|
|
|
virtual void SetTableWidth(nsIPresContext* aPresContext);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
virtual void VerticallyAlignChildren(nsIPresContext* aPresContext,
|
|
|
|
nscoord* aAscents,
|
|
|
|
nscoord aMaxAscent,
|
|
|
|
nscoord aMaxHeight);
|
|
|
|
|
|
|
|
/** given the new parent size, do I really need to do a reflow? */
|
|
|
|
virtual PRBool NeedsReflow(const nsSize& aMaxSize);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** what stage of reflow is currently in process? */
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual PRInt32 GetReflowPass() const;
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** sets the reflow pass flag. use with caution! */
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual void SetReflowPass(PRInt32 aReflowPass);
|
|
|
|
|
1998-04-14 21:45:28 +00:00
|
|
|
/** returns PR_TRUE if the cached pass 1 data is still valid */
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual PRBool IsFirstPassValid() const;
|
|
|
|
|
1998-05-01 20:44:55 +00:00
|
|
|
/** do post processing to setting up style information for the frame */
|
|
|
|
virtual NS_METHOD DidSetStyleContext(nsIPresContext* aPresContext);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
private:
|
|
|
|
void nsTableFrame::DebugPrintCount() const; // Debugging routine
|
|
|
|
|
|
|
|
|
|
|
|
/** table reflow is a multi-pass operation. Use these constants to keep track of
|
|
|
|
* which pass is currently being executed.
|
|
|
|
*/
|
|
|
|
enum {kPASS_UNDEFINED=0, kPASS_FIRST=1, kPASS_SECOND=2, kPASS_THIRD=3};
|
|
|
|
|
|
|
|
nsVoidArray *mColumnLayoutData; // array of array of cellLayoutData's
|
|
|
|
PRInt32 *mColumnWidths; // widths of each column
|
|
|
|
PRBool mFirstPassValid; // PR_TRUE if first pass data is still legit
|
|
|
|
PRInt32 mPass; // which Reflow pass are we currently in?
|
|
|
|
PRBool mIsInvariantWidth; // PR_TRUE if table width cannot change
|
1998-04-30 17:57:09 +00:00
|
|
|
nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|