1998-04-14 00:24:54 +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 "nsTableRowFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentDelegate.h"
|
|
|
|
#include "nsTableFrame.h"
|
1998-06-05 06:36:25 +04:00
|
|
|
#include "nsTableColFrame.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
#include "nsCellLayoutData.h"
|
1998-06-05 06:36:25 +04:00
|
|
|
#include "nsColLayoutData.h"
|
1998-04-15 01:49:29 +04:00
|
|
|
#include "nsIView.h"
|
1998-06-03 04:43:53 +04:00
|
|
|
#include "nsIPtr.h"
|
1998-06-23 09:43:27 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-06-03 04:43:53 +04:00
|
|
|
|
|
|
|
NS_DEF_PTR(nsIStyleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRBool gsDebug1 = PR_FALSE;
|
|
|
|
static PRBool gsDebug2 = PR_FALSE;
|
|
|
|
//#define NOISY
|
|
|
|
#else
|
|
|
|
static const PRBool gsDebug1 = PR_FALSE;
|
|
|
|
static const PRBool gsDebug2 = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
/* ----------- RowReflowState ---------- */
|
|
|
|
|
|
|
|
struct RowReflowState {
|
1998-05-30 00:36:05 +04:00
|
|
|
// Our reflow state
|
|
|
|
const nsReflowState& reflowState;
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// The body's available size (computed from the body's parent)
|
|
|
|
nsSize availSize;
|
|
|
|
|
|
|
|
// Flags for whether the max size is unconstrained
|
|
|
|
PRBool unconstrainedWidth;
|
|
|
|
PRBool unconstrainedHeight;
|
|
|
|
|
|
|
|
// Running x-offset
|
|
|
|
nscoord x;
|
|
|
|
|
1998-07-01 08:55:15 +04:00
|
|
|
// Height of tallest cell (excluding cells with rowspan > 1)
|
|
|
|
nscoord maxCellHeight; // just the height of the cell frame
|
|
|
|
nscoord maxCellVertSpace; // the maximum MAX(cellheight + topMargin + bottomMargin)
|
1998-04-23 21:29:07 +04:00
|
|
|
|
|
|
|
nsTableFrame *tableFrame;
|
|
|
|
|
|
|
|
|
1998-05-30 00:36:05 +04:00
|
|
|
RowReflowState( nsIPresContext* aPresContext,
|
|
|
|
const nsReflowState& aReflowState)
|
|
|
|
: reflowState(aReflowState)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
1998-05-30 00:36:05 +04:00
|
|
|
availSize.width = reflowState.maxSize.width;
|
|
|
|
availSize.height = reflowState.maxSize.height;
|
1998-04-23 21:29:07 +04:00
|
|
|
x=0;
|
1998-05-30 00:36:05 +04:00
|
|
|
unconstrainedWidth = PRBool(reflowState.maxSize.width == NS_UNCONSTRAINEDSIZE);
|
|
|
|
unconstrainedHeight = PRBool(reflowState.maxSize.height == NS_UNCONSTRAINEDSIZE);
|
1998-07-01 08:55:15 +04:00
|
|
|
maxCellHeight = 0;
|
|
|
|
maxCellVertSpace = 0;
|
1998-04-23 21:29:07 +04:00
|
|
|
tableFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
~RowReflowState() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------- nsTableRowpFrame ---------- */
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsTableRowFrame::nsTableRowFrame(nsIContent* aContent,
|
1998-04-23 21:29:07 +04:00
|
|
|
nsIFrame* aParentFrame)
|
1998-05-06 03:56:50 +04:00
|
|
|
: nsContainerFrame(aContent, aParentFrame),
|
1998-05-22 03:43:18 +04:00
|
|
|
mTallestCell(0),
|
|
|
|
mCellMaxTopMargin(0),
|
1998-06-24 23:13:19 +04:00
|
|
|
mCellMaxBottomMargin(0),
|
|
|
|
mMinRowSpan(1)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTableRowFrame::~nsTableRowFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-07-03 00:35:23 +04:00
|
|
|
/**
|
|
|
|
* Post-reflow hook. This is where the table row does its post-processing
|
|
|
|
*/
|
|
|
|
NS_METHOD
|
|
|
|
nsTableRowFrame::DidReflow(nsIPresContext& aPresContext,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
|
|
|
|
// Resize and re-align the cell frames based on our row height
|
|
|
|
nscoord cellHeight = mRect.height - mCellMaxTopMargin - mCellMaxBottomMargin;
|
|
|
|
nsTableCellFrame *cellFrame = (nsTableCellFrame*)mFirstChild;
|
|
|
|
nsTableFrame* tableFrame;
|
|
|
|
mContentParent->GetContentParent((nsIFrame*&)tableFrame);
|
|
|
|
while (nsnull != cellFrame)
|
|
|
|
{
|
|
|
|
PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(mRowIndex, cellFrame);
|
|
|
|
if (1==rowSpan)
|
|
|
|
{
|
1998-07-10 09:23:05 +04:00
|
|
|
// Resize the cell's height
|
1998-07-03 00:35:23 +04:00
|
|
|
nsSize cellFrameSize;
|
|
|
|
cellFrame->GetSize(cellFrameSize);
|
|
|
|
cellFrame->SizeTo(cellFrameSize.width, cellHeight);
|
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// Realign cell content based on the new height
|
1998-07-03 00:35:23 +04:00
|
|
|
cellFrame->VerticallyAlignChild(&aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next cell
|
|
|
|
cellFrame->GetNextSibling((nsIFrame*&)cellFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let our base class do the usual work
|
|
|
|
return nsContainerFrame::DidReflow(aPresContext, aStatus);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void nsTableRowFrame::ResetMaxChildHeight()
|
|
|
|
{
|
|
|
|
mTallestCell=0;
|
1998-05-22 03:43:18 +04:00
|
|
|
mCellMaxTopMargin=0;
|
|
|
|
mCellMaxBottomMargin=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
void nsTableRowFrame::SetMaxChildHeight(nscoord aChildHeight, nscoord aTopMargin, nscoord aBottomMargin)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (mTallestCell<aChildHeight)
|
|
|
|
mTallestCell = aChildHeight;
|
1998-05-22 03:43:18 +04:00
|
|
|
|
|
|
|
if (mCellMaxTopMargin<aTopMargin)
|
|
|
|
mCellMaxTopMargin = aTopMargin;
|
|
|
|
|
|
|
|
if (mCellMaxBottomMargin<aBottomMargin)
|
|
|
|
mCellMaxBottomMargin = aBottomMargin;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsTableRowFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// for debug...
|
1998-04-30 04:27:59 +04:00
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,128));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
1998-04-30 04:27:59 +04:00
|
|
|
*/
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// aDirtyRect is in our coordinate system
|
|
|
|
// child rect's are also in our coordinate system
|
|
|
|
/** overloaded method from nsContainerFrame. The difference is that
|
|
|
|
* we don't want to clip our children, so a cell can do a rowspan
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::PaintChildren(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = mFirstChild;
|
|
|
|
while (nsnull != kid) {
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIView *pView;
|
|
|
|
|
|
|
|
kid->GetView(pView);
|
1998-04-15 01:49:29 +04:00
|
|
|
if (nsnull == pView) {
|
|
|
|
nsRect kidRect;
|
|
|
|
kid->GetRect(kidRect);
|
1998-06-14 04:45:21 +04:00
|
|
|
nsRect damageArea;
|
|
|
|
PRBool overlap = damageArea.IntersectRect(aDirtyRect, kidRect);
|
|
|
|
if (overlap) {
|
|
|
|
// Translate damage area into kid's coordinate system
|
|
|
|
nsRect kidDamageArea(damageArea.x - kidRect.x,
|
|
|
|
damageArea.y - kidRect.y,
|
|
|
|
damageArea.width, damageArea.height);
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(kidRect.x, kidRect.y);
|
|
|
|
kid->Paint(aPresContext, aRenderingContext, kidDamageArea);
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, kidRect.width, kidRect.height);
|
|
|
|
}
|
|
|
|
aRenderingContext.PopState();
|
1998-04-15 01:49:29 +04:00
|
|
|
}
|
1998-04-17 05:41:24 +04:00
|
|
|
} else {
|
1998-04-15 01:49:29 +04:00
|
|
|
NS_RELEASE(pView);
|
1998-04-17 05:41:24 +04:00
|
|
|
}
|
|
|
|
kid->GetNextSibling(kid);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-17 20:38:24 +04:00
|
|
|
void nsTableRowFrame::SetRowIndex (int aRowIndex)
|
|
|
|
{
|
|
|
|
mRowIndex = aRowIndex;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
/** returns the height of the tallest child in this row (ignoring any cell with rowspans) */
|
|
|
|
nscoord nsTableRowFrame::GetTallestChild() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
return mTallestCell;
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
nscoord nsTableRowFrame::GetChildMaxTopMargin() const
|
|
|
|
{
|
|
|
|
return mCellMaxTopMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord nsTableRowFrame::GetChildMaxBottomMargin() const
|
|
|
|
{
|
|
|
|
return mCellMaxBottomMargin;
|
|
|
|
}
|
|
|
|
|
1998-06-17 20:38:24 +04:00
|
|
|
PRInt32 nsTableRowFrame::GetMaxColumns() const
|
|
|
|
{
|
|
|
|
int sum = 0;
|
1998-06-26 04:48:44 +04:00
|
|
|
nsTableCellFrame *cell=(nsTableCellFrame *)mFirstChild;
|
1998-06-17 20:38:24 +04:00
|
|
|
while (nsnull!=cell) {
|
|
|
|
sum += cell->GetColSpan();
|
|
|
|
cell->GetNextSibling((nsIFrame *&)cell);
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
1998-06-24 23:13:19 +04:00
|
|
|
/* GetMinRowSpan is needed for deviant cases where every cell in a row has a rowspan > 1.
|
|
|
|
* It sets mMinRowSpan, which is used in FixMinCellHeight and PlaceChild
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::GetMinRowSpan()
|
|
|
|
{
|
|
|
|
PRInt32 minRowSpan=-1;
|
|
|
|
nsIFrame *frame=mFirstChild;
|
|
|
|
while (nsnull!=frame)
|
|
|
|
{
|
|
|
|
PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan();
|
|
|
|
if (-1==minRowSpan)
|
|
|
|
minRowSpan = rowSpan;
|
|
|
|
else if (minRowSpan>rowSpan)
|
|
|
|
minRowSpan = rowSpan;
|
|
|
|
frame->GetNextSibling(frame);
|
|
|
|
}
|
|
|
|
mMinRowSpan = minRowSpan;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTableRowFrame::FixMinCellHeight()
|
|
|
|
{
|
|
|
|
nsIFrame *frame=mFirstChild;
|
|
|
|
while (nsnull!=frame)
|
|
|
|
{
|
|
|
|
PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan();
|
|
|
|
if (mMinRowSpan==rowSpan)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
frame->GetRect(rect);
|
|
|
|
if (rect.height > mTallestCell)
|
|
|
|
mTallestCell = rect.height;
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Position and size aKidFrame and update our reflow state. The origin of
|
|
|
|
// aKidRect is relative to the upper-left origin of our frame, and includes
|
|
|
|
// any left/top margin.
|
|
|
|
void nsTableRowFrame::PlaceChild(nsIPresContext* aPresContext,
|
|
|
|
RowReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
const nsRect& aKidRect,
|
|
|
|
nsSize* aMaxElementSize,
|
1998-07-02 21:40:56 +04:00
|
|
|
nsSize* aKidMaxElementSize)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
|
|
|
if (PR_TRUE==gsDebug1)
|
|
|
|
printf ("row: placing cell at %d, %d, %d, %d\n",
|
|
|
|
aKidRect.x, aKidRect.y, aKidRect.width, aKidRect.height);
|
|
|
|
|
|
|
|
// Place and size the child
|
|
|
|
aKidFrame->SetRect(aKidRect);
|
|
|
|
|
1998-06-03 04:43:53 +04:00
|
|
|
// update the running total for the row width
|
|
|
|
aState.x += aKidRect.width;
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Update the maximum element size
|
|
|
|
PRInt32 rowSpan = ((nsTableCellFrame*)aKidFrame)->GetRowSpan();
|
1998-05-22 03:43:18 +04:00
|
|
|
if (nsnull != aMaxElementSize)
|
|
|
|
{
|
1998-07-02 21:40:56 +04:00
|
|
|
aMaxElementSize->width += aKidMaxElementSize->width;
|
|
|
|
if ((mMinRowSpan==rowSpan) && (aKidMaxElementSize->height>aMaxElementSize->height))
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
1998-07-02 21:40:56 +04:00
|
|
|
aMaxElementSize->height = aKidMaxElementSize->height;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
}
|
1998-07-01 08:55:15 +04:00
|
|
|
|
|
|
|
if (mMinRowSpan == rowSpan)
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
1998-07-01 08:55:15 +04:00
|
|
|
// Update maxCellHeight
|
|
|
|
if (aKidRect.height > aState.maxCellHeight)
|
|
|
|
aState.maxCellHeight = aKidRect.height;
|
|
|
|
|
|
|
|
// Update maxCellVertSpace
|
|
|
|
nsMargin margin;
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-06-17 20:38:24 +04:00
|
|
|
if (aState.tableFrame->GetCellMarginData((nsTableCellFrame *)aKidFrame, margin) == NS_OK)
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
|
|
|
nscoord height = aKidRect.height + margin.top + margin.bottom;
|
|
|
|
|
|
|
|
if (height > aState.maxCellVertSpace)
|
|
|
|
aState.maxCellVertSpace = height;
|
|
|
|
}
|
|
|
|
}
|
1998-04-23 21:29:07 +04: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
|
1998-07-10 09:23:05 +04:00
|
|
|
* otherwise
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
|
|
|
PRBool nsTableRowFrame::ReflowMappedChildren(nsIPresContext* aPresContext,
|
|
|
|
RowReflowState& aState,
|
|
|
|
nsSize* aMaxElementSize)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-23 21:29:07 +04:00
|
|
|
#ifdef NOISY
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": reflow mapped (childCount=%d) [%d,%d,%c]\n",
|
|
|
|
mChildCount,
|
|
|
|
mFirstContentOffset, mLastContentOffset,
|
|
|
|
(mLastContentIsComplete ? 'T' : 'F'));
|
|
|
|
#endif
|
|
|
|
NS_PRECONDITION(nsnull != mFirstChild, "no children");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
nsSize kidMaxElementSize;
|
|
|
|
nsSize* pKidMaxElementSize = (nsnull != aMaxElementSize) ? &kidMaxElementSize : nsnull;
|
|
|
|
PRBool result = PR_TRUE;
|
|
|
|
nscoord maxCellTopMargin = 0;
|
|
|
|
nscoord maxCellBottomMargin = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Reflow each of our existing child frames
|
1998-04-23 21:29:07 +04:00
|
|
|
for (nsIFrame* kidFrame = mFirstChild; nsnull != kidFrame; ) {
|
1998-07-10 08:00:38 +04:00
|
|
|
// Get the frame's margins and compare the top and bottom margin
|
|
|
|
// against our current max values
|
1998-07-02 09:39:10 +04:00
|
|
|
nsMargin kidMargin;
|
1998-06-17 20:38:24 +04:00
|
|
|
aState.tableFrame->GetCellMarginData((nsTableCellFrame *)kidFrame,kidMargin);
|
1998-05-22 03:43:18 +04:00
|
|
|
if (kidMargin.top > maxCellTopMargin)
|
|
|
|
maxCellTopMargin = kidMargin.top;
|
|
|
|
if (kidMargin.bottom > maxCellBottomMargin)
|
|
|
|
maxCellBottomMargin = kidMargin.bottom;
|
|
|
|
|
1998-07-07 01:00:11 +04:00
|
|
|
// left and right margins already taken into account by table layout strategy
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Compute the x-origin for the child
|
|
|
|
//
|
|
|
|
// XXX Having to re-compute the value each time from scratch is very inefficent...
|
|
|
|
nscoord x = ComputeCellXOffset(aState, kidFrame, kidMargin);
|
1998-06-24 22:09:47 +04:00
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// Compute the cell available width from the column widths
|
1998-07-10 08:00:38 +04:00
|
|
|
nscoord availWidth = ComputeCellAvailWidth(aState, kidFrame);
|
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// If the available width is the same as last time we reflowed the cell,
|
1998-07-10 08:00:38 +04:00
|
|
|
// then just use the previous desired size
|
|
|
|
//
|
1998-07-10 09:23:05 +04:00
|
|
|
// XXX Wouldn't it be cleaner (but slightly less efficient) for the row to
|
|
|
|
// just reflow the cell, and have the cell decide whether it could use the
|
|
|
|
// cached value rather than having the row make that determination?
|
1998-07-10 08:00:38 +04:00
|
|
|
nsReflowMetrics desiredSize(pKidMaxElementSize);
|
|
|
|
nsReflowStatus status;
|
1998-07-02 21:40:56 +04:00
|
|
|
if (availWidth != ((nsTableCellFrame *)kidFrame)->GetPriorAvailWidth())
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
1998-07-10 09:23:05 +04:00
|
|
|
// Always let the cell be as high as it wants. We ignore the height that's passed
|
|
|
|
// in and always place the entire row. Let the row group decide whether we fit or
|
|
|
|
// wehther the entire row is pushed
|
|
|
|
nsSize kidAvailSize(availWidth, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
1998-07-02 21:40:56 +04:00
|
|
|
// Reflow the child
|
|
|
|
kidFrame->WillReflow(*aPresContext);
|
|
|
|
kidFrame->MoveTo(x, kidMargin.top);
|
1998-07-10 08:00:38 +04:00
|
|
|
kidAvailSize.width = availWidth;
|
1998-07-02 21:40:56 +04:00
|
|
|
nsReflowState kidReflowState(kidFrame, aState.reflowState, kidAvailSize,
|
|
|
|
eReflowReason_Resize);
|
|
|
|
status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
|
1998-07-10 09:23:05 +04:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(status), "unexpected reflow status");
|
1998-07-02 21:40:56 +04:00
|
|
|
|
|
|
|
if (gsDebug1)
|
|
|
|
{
|
|
|
|
if (nsnull!=pKidMaxElementSize)
|
|
|
|
printf("reflow of cell returned result = %s with desired=%d,%d, min = %d,%d\n",
|
|
|
|
NS_FRAME_IS_COMPLETE(status)?"complete":"NOT complete",
|
|
|
|
desiredSize.width, desiredSize.height,
|
|
|
|
pKidMaxElementSize->width, pKidMaxElementSize->height);
|
|
|
|
else
|
|
|
|
printf("reflow of cell returned result = %s with desired=%d,%d, min = nsnull\n",
|
|
|
|
NS_FRAME_IS_COMPLETE(status)?"complete":"NOT complete",
|
|
|
|
desiredSize.width, desiredSize.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-07-07 05:06:51 +04:00
|
|
|
nsSize priorSize = ((nsTableCellFrame *)kidFrame)->GetPriorDesiredSize();
|
|
|
|
desiredSize.width = priorSize.width;
|
|
|
|
desiredSize.height = priorSize.height;
|
1998-07-10 09:23:05 +04:00
|
|
|
status = NS_FRAME_COMPLETE;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Place the child after taking into account its margin and attributes
|
1998-06-03 04:43:53 +04:00
|
|
|
nscoord specifiedHeight = 0;
|
|
|
|
nscoord cellHeight = desiredSize.height;
|
|
|
|
nsIStyleContextPtr kidSC;
|
|
|
|
kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef());
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStylePosition* kidPosition = (const nsStylePosition*)
|
|
|
|
kidSC->GetStyleData(eStyleStruct_Position);
|
1998-06-03 04:43:53 +04:00
|
|
|
switch (kidPosition->mHeight.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
specifiedHeight = kidPosition->mHeight.GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
1998-06-05 06:36:25 +04:00
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
// XXX for now, do nothing
|
1998-06-03 04:43:53 +04:00
|
|
|
default:
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (specifiedHeight>cellHeight)
|
|
|
|
cellHeight = specifiedHeight;
|
1998-06-24 03:23:21 +04:00
|
|
|
|
|
|
|
nscoord cellWidth = desiredSize.width;
|
|
|
|
// begin special Nav4 compatibility code
|
|
|
|
if (0==cellWidth)
|
|
|
|
{
|
1998-07-10 08:00:38 +04:00
|
|
|
PRInt32 cellColIndex = ((nsTableCellFrame *)kidFrame)->GetColIndex();
|
1998-06-24 03:23:21 +04:00
|
|
|
cellWidth = aState.tableFrame->GetColumnWidth(cellColIndex);
|
|
|
|
}
|
|
|
|
// end special Nav4 compatibility code
|
|
|
|
|
1998-06-24 22:09:47 +04:00
|
|
|
// Adjust the running x-offset
|
|
|
|
aState.x = x;
|
|
|
|
|
|
|
|
// Place the child
|
|
|
|
nsRect kidRect (x, kidMargin.top, cellWidth, cellHeight);
|
1998-06-24 03:23:21 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
PlaceChild(aPresContext, aState, kidFrame, kidRect, aMaxElementSize,
|
1998-07-02 21:40:56 +04:00
|
|
|
pKidMaxElementSize);
|
1998-04-23 21:29:07 +04:00
|
|
|
|
|
|
|
// Get the next child
|
|
|
|
kidFrame->GetNextSibling(kidFrame);
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
SetMaxChildHeight(aState.maxCellHeight,maxCellTopMargin, maxCellBottomMargin); // remember height of tallest child who doesn't have a row span
|
1998-04-23 21:29:07 +04:00
|
|
|
|
|
|
|
#ifdef NOISY
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": reflow mapped %sok (childCount=%d) [%d,%d,%c]\n",
|
|
|
|
(result ? "" : "NOT "),
|
|
|
|
mChildCount,
|
|
|
|
mFirstContentOffset, mLastContentOffset,
|
|
|
|
(mLastContentIsComplete ? 'T' : 'F'));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Compute the x-origin for the child by summing up the width of each
|
|
|
|
// prior column. This correctly handles cells from prior rows with rowspans
|
|
|
|
// > 1
|
|
|
|
nscoord nsTableRowFrame::ComputeCellXOffset(const RowReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
const nsMargin& aKidMargin) const
|
|
|
|
{
|
|
|
|
nscoord x = aKidMargin.left;
|
|
|
|
PRInt32 cellColIndex = ((nsTableCellFrame *)aKidFrame)->GetColIndex();
|
|
|
|
|
|
|
|
for (PRInt32 colIndex = 0; colIndex < cellColIndex; colIndex++)
|
|
|
|
{
|
|
|
|
x += aState.tableFrame->GetColumnWidth(colIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Computes the avail width for the cell. Takes into account column
|
|
|
|
// spans
|
|
|
|
nscoord nsTableRowFrame::ComputeCellAvailWidth(const RowReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame) const
|
|
|
|
{
|
|
|
|
nscoord availWidth = 0;
|
|
|
|
nsCellLayoutData *cellData = aState.tableFrame->GetCellLayoutData((nsTableCellFrame *)aKidFrame);
|
|
|
|
PRInt32 cellStartingCol = ((nsTableCellFrame *)aKidFrame)->GetColIndex();
|
|
|
|
PRInt32 cellColSpan = ((nsTableCellFrame *)aKidFrame)->GetColSpan();
|
|
|
|
|
|
|
|
for (PRInt32 numColSpan = 0; numColSpan < cellColSpan; numColSpan++)
|
|
|
|
{
|
|
|
|
availWidth += aState.tableFrame->GetColumnWidth(cellStartingCol + numColSpan);
|
|
|
|
}
|
|
|
|
|
|
|
|
return availWidth;
|
|
|
|
}
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
/**
|
|
|
|
* Create new frames for content we haven't yet mapped
|
|
|
|
*
|
|
|
|
* @param aPresContext presentation context to use
|
|
|
|
* @param aState current inline state
|
1998-07-10 08:00:38 +04:00
|
|
|
* @return Always returns NS_FRAME_COMPLETE. Rows always map every cell in the
|
|
|
|
* row, and they are never continued
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
1998-05-12 08:17:56 +04:00
|
|
|
nsReflowStatus
|
1998-07-10 08:00:38 +04:00
|
|
|
nsTableRowFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext,
|
|
|
|
RowReflowState& aState,
|
|
|
|
nsSize* aMaxElementSize)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
|
|
|
// Place our children, one at a time, until we are out of children
|
1998-07-10 08:00:38 +04:00
|
|
|
nsSize kidMaxElementSize;
|
|
|
|
PRInt32 kidIndex = 0;
|
|
|
|
nsIFrame* prevKidFrame = nsnull;
|
1998-05-22 03:43:18 +04:00
|
|
|
nscoord maxTopMargin = 0;
|
|
|
|
nscoord maxBottomMargin = 0;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
1998-07-10 08:00:38 +04:00
|
|
|
// For our initial reflow we expect to be given an unconstrained width
|
|
|
|
NS_ASSERTION(NS_UNCONSTRAINEDSIZE == aState.availSize.width, "bad size");
|
1998-06-29 07:09:14 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Get the next content object
|
|
|
|
nsIContent* cell = mContent->ChildAt(kidIndex);
|
1998-04-21 02:49:15 +04:00
|
|
|
if (nsnull == cell) {
|
1998-07-10 08:00:38 +04:00
|
|
|
break; // no more content
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1998-06-05 06:36:25 +04:00
|
|
|
// Create a child frame -- always an nsTableCell frame
|
1998-07-10 08:00:38 +04:00
|
|
|
nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(cell, this, PR_TRUE);
|
|
|
|
nsIContentDelegate* kidDel = cell->GetDelegate(aPresContext);
|
|
|
|
nsIFrame* kidFrame;
|
|
|
|
|
|
|
|
nsresult rv = kidDel->CreateFrame(aPresContext, cell, this, kidSC, kidFrame);
|
|
|
|
NS_RELEASE(kidDel);
|
|
|
|
NS_RELEASE(cell);
|
|
|
|
|
|
|
|
// Get the child's available space. Because we're not splittable always allow
|
|
|
|
// the child to be as high as it wants. The default avail width is also
|
|
|
|
// unconstrained so we can get the child's max width
|
|
|
|
nsSize kidAvailSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
|
|
|
// See if there's a width constraint that overrides
|
1998-06-30 00:38:22 +04:00
|
|
|
const nsStylePosition* cellPosition = (const nsStylePosition*)
|
1998-07-10 08:00:38 +04:00
|
|
|
kidSC->GetStyleData(eStyleStruct_Position);
|
|
|
|
if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit())
|
1998-06-30 00:38:22 +04:00
|
|
|
{
|
|
|
|
kidAvailSize.width = cellPosition->mWidth.GetCoordValue();
|
|
|
|
}
|
1998-07-10 08:00:38 +04:00
|
|
|
NS_RELEASE(kidSC);
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Get the child's margins
|
|
|
|
nsMargin margin;
|
1998-05-22 03:43:18 +04:00
|
|
|
nscoord topMargin = 0;
|
|
|
|
|
1998-06-17 20:38:24 +04:00
|
|
|
if (aState.tableFrame->GetCellMarginData((nsTableCellFrame *)kidFrame, margin) == NS_OK)
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
|
|
|
topMargin = margin.top;
|
|
|
|
}
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
maxTopMargin = PR_MAX(margin.top, maxTopMargin);
|
|
|
|
maxBottomMargin = PR_MAX(margin.bottom, maxBottomMargin);
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-06-24 20:35:21 +04:00
|
|
|
// Link child frame into the list of children
|
|
|
|
if (nsnull != prevKidFrame) {
|
|
|
|
prevKidFrame->SetNextSibling(kidFrame);
|
|
|
|
} else {
|
|
|
|
mFirstChild = kidFrame; // our first child
|
1998-07-10 08:00:38 +04:00
|
|
|
SetFirstContentOffset(kidIndex);
|
1998-06-24 20:35:21 +04:00
|
|
|
}
|
|
|
|
mChildCount++;
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Reflow the child. We always want to know the max element size even if the
|
|
|
|
// caller doesn't want it, because we need it to compute column widths
|
|
|
|
nsReflowMetrics kidSize(&kidMaxElementSize);
|
|
|
|
nsReflowState kidReflowState(kidFrame, aState.reflowState, kidAvailSize,
|
|
|
|
eReflowReason_Initial);
|
|
|
|
nsReflowStatus status;
|
1998-06-24 20:35:21 +04:00
|
|
|
|
|
|
|
kidFrame->WillReflow(*aPresContext);
|
1998-07-10 08:00:38 +04:00
|
|
|
status = ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState);
|
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(status), "unexpected child reflow status");
|
|
|
|
|
|
|
|
// Allocate and set the cell layout data
|
|
|
|
nsCellLayoutData *kidLayoutData = new nsCellLayoutData((nsTableCellFrame *)kidFrame,
|
|
|
|
&kidSize, &kidMaxElementSize);
|
1998-06-29 07:09:14 +04:00
|
|
|
((nsTableCellFrame *)kidFrame)->SetCellLayoutData(kidLayoutData);
|
1998-07-10 08:00:38 +04:00
|
|
|
|
1998-07-02 21:40:56 +04:00
|
|
|
if (gsDebug1)
|
1998-04-17 02:21:32 +04:00
|
|
|
{
|
1998-07-02 21:40:56 +04:00
|
|
|
printf("reflow of cell returned result = %s with desired=%d,%d, min = %d,%d\n",
|
|
|
|
NS_FRAME_IS_COMPLETE(status)?"complete":"NOT complete",
|
1998-07-10 08:00:38 +04:00
|
|
|
kidSize.width, kidSize.height,
|
|
|
|
kidMaxElementSize.width, kidMaxElementSize.height);
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
1998-06-24 22:09:47 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Place the child
|
1998-07-10 08:00:38 +04:00
|
|
|
aState.x += margin.left;
|
|
|
|
nsRect kidRect (aState.x, topMargin, kidSize.width, kidSize.height);
|
|
|
|
PlaceChild(aPresContext, aState, kidFrame, kidRect, aMaxElementSize, &kidMaxElementSize);
|
|
|
|
aState.x += margin.right;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Move to the next content child
|
1998-04-14 00:24:54 +04:00
|
|
|
prevKidFrame = kidFrame;
|
|
|
|
kidIndex++;
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
SetMaxChildHeight(aState.maxCellHeight, maxTopMargin, maxBottomMargin); // remember height of tallest child who doesn't have a row span
|
1998-04-23 21:29:07 +04:00
|
|
|
|
|
|
|
// Update the content mapping
|
1998-07-10 08:00:38 +04:00
|
|
|
if (nsnull != prevKidFrame) {
|
|
|
|
SetLastContentOffset(kidIndex - 1);
|
1998-04-23 21:29:07 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-07-10 08:00:38 +04:00
|
|
|
NS_ASSERTION(IsLastChild(prevKidFrame), "bad last child");
|
|
|
|
PRInt32 prevKidIndex;
|
|
|
|
prevKidFrame->GetContentIndex(prevKidIndex);
|
|
|
|
NS_ASSERTION((kidIndex - 1) == prevKidIndex, "bad index");
|
|
|
|
PRInt32 len = LengthOf(mFirstChild);
|
|
|
|
NS_ASSERTION(len == mChildCount, "bad child count");
|
1998-04-23 21:29:07 +04:00
|
|
|
#endif
|
1998-07-10 08:00:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_FRAME_COMPLETE;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1998-07-01 07:03:32 +04:00
|
|
|
// Recover the reflow state to what it should be if aKidFrame is about
|
|
|
|
// to be reflowed
|
|
|
|
nsresult nsTableRowFrame::RecoverState(RowReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame)
|
|
|
|
{
|
1998-07-01 08:55:15 +04:00
|
|
|
// Walk the list of children looking for aKidFrame
|
1998-07-01 07:03:32 +04:00
|
|
|
nsIFrame* prevKidFrame = nsnull;
|
|
|
|
for (nsIFrame* frame = mFirstChild; frame != aKidFrame;) {
|
1998-07-01 08:55:15 +04:00
|
|
|
PRInt32 rowSpan = ((nsTableCellFrame*)frame)->GetRowSpan();
|
|
|
|
if (mMinRowSpan == rowSpan) {
|
1998-07-10 08:00:38 +04:00
|
|
|
// XXX This isn't quite right. We also need to check whether the cell
|
|
|
|
// has a height property that affects the cell...
|
|
|
|
nsSize desiredSize = ((nsTableCellFrame *)frame)->GetPriorDesiredSize();
|
|
|
|
|
1998-07-01 08:55:15 +04:00
|
|
|
// Update maxCellHeight
|
1998-07-10 08:00:38 +04:00
|
|
|
if (desiredSize.height > aState.maxCellHeight) {
|
|
|
|
aState.maxCellHeight = desiredSize.height;
|
1998-07-01 08:55:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update maxCellVertHeight
|
|
|
|
nsMargin margin;
|
|
|
|
|
|
|
|
if (aState.tableFrame->GetCellMarginData((nsTableCellFrame *)frame, margin) == NS_OK)
|
|
|
|
{
|
1998-07-10 08:00:38 +04:00
|
|
|
nscoord height = desiredSize.height + margin.top + margin.bottom;
|
1998-07-01 08:55:15 +04:00
|
|
|
if (height > aState.maxCellVertSpace) {
|
|
|
|
aState.maxCellVertSpace = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// XXX We also need to recover the max element size if requested by the
|
|
|
|
// caller...
|
|
|
|
//
|
|
|
|
// We should be using GetReflowMetrics() to get information from the
|
|
|
|
// table cell, and that will include the max element size...
|
1998-07-01 08:55:15 +04:00
|
|
|
|
|
|
|
// Remember the frame that precedes aKidFrame
|
1998-07-01 07:03:32 +04:00
|
|
|
prevKidFrame = frame;
|
|
|
|
frame->GetNextSibling(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != prevKidFrame) {
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
// Set our running x-offset
|
|
|
|
prevKidFrame->GetRect(rect);
|
|
|
|
aState.x = rect.XMost();
|
1998-07-02 09:39:10 +04:00
|
|
|
}
|
1998-07-01 07:03:32 +04:00
|
|
|
|
1998-07-02 09:39:10 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTableRowFrame::IncrementalReflow(nsIPresContext* aPresContext,
|
|
|
|
RowReflowState& aState,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsSize* aMaxElementSize)
|
|
|
|
{
|
|
|
|
nsresult status;
|
|
|
|
|
|
|
|
// XXX Deal with the case where the reflow command is targeted at us
|
|
|
|
nsIFrame* target;
|
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
|
|
|
if (this == target) {
|
|
|
|
NS_NOTYETIMPLEMENTED("unexpected reflow command");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next frame in the reflow chain
|
|
|
|
nsIFrame* kidFrame;
|
|
|
|
aReflowState.reflowCommand->GetNext(kidFrame);
|
|
|
|
|
|
|
|
// Recover our reflow state
|
|
|
|
RecoverState(aState, kidFrame);
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Get the frame's margins
|
1998-07-02 09:39:10 +04:00
|
|
|
nsMargin kidMargin;
|
|
|
|
aState.tableFrame->GetCellMarginData((nsTableCellFrame *)kidFrame,kidMargin);
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Figure out the amount of available space for the child
|
|
|
|
nsSize kidAvailSize(aState.availSize);
|
1998-07-02 09:39:10 +04:00
|
|
|
if (PR_FALSE == aState.unconstrainedHeight)
|
|
|
|
{
|
|
|
|
kidAvailSize.height -= kidMargin.top + kidMargin.bottom;
|
|
|
|
}
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Compute the x-origin for the child, taking into account straddlers (cells
|
|
|
|
// from prior rows with rowspans > 1)
|
|
|
|
nscoord x = ComputeCellXOffset(aState, kidFrame, kidMargin);
|
1998-07-02 09:39:10 +04:00
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Compute the cell avail width from the column widths
|
|
|
|
nscoord availWidth = ComputeCellAvailWidth(aState, kidFrame);
|
1998-07-02 09:39:10 +04:00
|
|
|
kidAvailSize.width = availWidth;
|
|
|
|
|
|
|
|
// Pass along the reflow command. Reflow the child with an unconstrained
|
|
|
|
// width and get its maxElementSize
|
|
|
|
nsSize kidMaxElementSize;
|
|
|
|
nsReflowMetrics desiredSize(&kidMaxElementSize);
|
|
|
|
nsReflowState kidReflowState(kidFrame, aReflowState, kidAvailSize);
|
|
|
|
kidFrame->WillReflow(*aPresContext);
|
|
|
|
kidFrame->MoveTo(x, kidMargin.top);
|
|
|
|
|
|
|
|
// XXX Unfortunately we need to reflow the child several times.
|
|
|
|
// The first time is for the incremental reflow command. We can't pass in
|
|
|
|
// a max width of NS_UNCONSTRAINEDSIZE, because the max width must match
|
|
|
|
// the width of the previous reflow...
|
|
|
|
status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
|
|
|
|
|
|
|
|
// Now do the regular pass 1 reflow and gather the max width and max element
|
|
|
|
// size.
|
|
|
|
// XXX It would be nice if we could skip this step and the next step if the
|
|
|
|
// column width isn't dependent on the max cell width...
|
|
|
|
kidReflowState.reason = eReflowReason_Resize;
|
|
|
|
kidReflowState.reflowCommand = nsnull;
|
|
|
|
kidReflowState.maxSize.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
|
|
|
|
|
|
|
|
// Update the cell layout data. Note that we need to do this for both
|
|
|
|
// the data the cell maintains AND the data the table maintains...
|
|
|
|
nsCellLayoutData *kidLayoutData = ((nsTableCellFrame *)kidFrame)->GetCellLayoutData();
|
|
|
|
|
|
|
|
kidLayoutData->SetDesiredSize(&desiredSize);
|
|
|
|
kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
|
|
|
|
|
|
|
|
kidLayoutData = aState.tableFrame->GetCellLayoutData((nsTableCellFrame*)kidFrame);
|
|
|
|
kidLayoutData->SetDesiredSize(&desiredSize);
|
|
|
|
kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
|
|
|
|
|
|
|
|
// Now reflow the cell again this time constraining the width
|
|
|
|
// XXX Ignore for now the possibility that the column width has changed...
|
|
|
|
kidReflowState.maxSize.width = availWidth;
|
|
|
|
status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
|
|
|
|
|
1998-07-10 08:00:38 +04:00
|
|
|
// Place the child after taking into account its margin and attributes
|
1998-07-02 09:39:10 +04:00
|
|
|
nscoord specifiedHeight = 0;
|
|
|
|
nscoord cellHeight = desiredSize.height;
|
|
|
|
nsIStyleContextPtr kidSC;
|
|
|
|
kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef());
|
|
|
|
const nsStylePosition* kidPosition = (const nsStylePosition*)
|
|
|
|
kidSC->GetStyleData(eStyleStruct_Position);
|
|
|
|
switch (kidPosition->mHeight.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
specifiedHeight = kidPosition->mHeight.GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
// XXX for now, do nothing
|
|
|
|
default:
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (specifiedHeight>cellHeight)
|
|
|
|
cellHeight = specifiedHeight;
|
|
|
|
|
|
|
|
nscoord cellWidth = desiredSize.width;
|
|
|
|
// begin special Nav4 compatibility code
|
|
|
|
if (0==cellWidth)
|
|
|
|
{
|
1998-07-10 08:00:38 +04:00
|
|
|
PRInt32 cellColIndex = ((nsTableCellFrame *)kidFrame)->GetColIndex();
|
1998-07-02 09:39:10 +04:00
|
|
|
cellWidth = aState.tableFrame->GetColumnWidth(cellColIndex);
|
|
|
|
}
|
|
|
|
// end special Nav4 compatibility code
|
|
|
|
|
|
|
|
// Adjust the running x-offset
|
|
|
|
aState.x = x;
|
|
|
|
|
|
|
|
// Now place the child
|
|
|
|
nsRect kidRect (x, kidMargin.top, cellWidth, cellHeight);
|
|
|
|
|
|
|
|
PlaceChild(aPresContext, aState, kidFrame, kidRect, aMaxElementSize,
|
1998-07-02 21:40:56 +04:00
|
|
|
&kidMaxElementSize);
|
1998-07-02 09:39:10 +04:00
|
|
|
|
|
|
|
// Now iterate over the remaining cells, and update our max cell
|
|
|
|
// height and our running x-offset
|
|
|
|
//
|
1998-07-10 08:00:38 +04:00
|
|
|
// We don't have to re-position the x-origin of any of the child frames
|
|
|
|
// that follow, because the column width hasn't changed...
|
1998-07-02 09:39:10 +04:00
|
|
|
nscoord maxCellTopMargin = 0;
|
|
|
|
nscoord maxCellBottomMargin = 0;
|
|
|
|
kidFrame->GetNextSibling((nsIFrame*&)kidFrame);
|
|
|
|
while (nsnull != kidFrame) {
|
|
|
|
PRInt32 rowSpan = ((nsTableCellFrame*)kidFrame)->GetRowSpan();
|
|
|
|
nsRect rect;
|
|
|
|
kidFrame->GetRect(rect);
|
|
|
|
if (mMinRowSpan == rowSpan) {
|
1998-07-10 08:00:38 +04:00
|
|
|
nsSize desiredSize = ((nsTableCellFrame *)kidFrame)->GetPriorDesiredSize();
|
|
|
|
|
1998-07-02 09:39:10 +04:00
|
|
|
// Update maxCellHeight
|
1998-07-10 08:00:38 +04:00
|
|
|
if (desiredSize.height > aState.maxCellHeight) {
|
|
|
|
aState.maxCellHeight = desiredSize.height;
|
1998-07-02 09:39:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update maxCellVertHeight
|
|
|
|
nsMargin margin;
|
|
|
|
|
|
|
|
if (aState.tableFrame->GetCellMarginData((nsTableCellFrame *)kidFrame, margin) == NS_OK)
|
|
|
|
{
|
1998-07-10 08:00:38 +04:00
|
|
|
nscoord height = desiredSize.height + margin.top + margin.bottom;
|
1998-07-02 09:39:10 +04:00
|
|
|
if (height > aState.maxCellVertSpace) {
|
|
|
|
aState.maxCellVertSpace = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Currently we assume cells have margins, but that isn't correct...
|
|
|
|
if (margin.top > maxCellTopMargin) {
|
|
|
|
maxCellTopMargin = margin.top;
|
|
|
|
}
|
|
|
|
if (margin.bottom > maxCellBottomMargin) {
|
|
|
|
maxCellBottomMargin = margin.bottom;
|
|
|
|
}
|
|
|
|
}
|
1998-07-01 07:03:32 +04:00
|
|
|
}
|
1998-07-02 09:39:10 +04:00
|
|
|
|
|
|
|
// Set our running x-offset
|
|
|
|
aState.x = rect.XMost();
|
|
|
|
|
|
|
|
// Get the next cell frame
|
|
|
|
kidFrame->GetNextSibling((nsIFrame*&)kidFrame);
|
1998-07-01 07:03:32 +04:00
|
|
|
}
|
|
|
|
|
1998-07-02 09:39:10 +04:00
|
|
|
SetMaxChildHeight(aState.maxCellHeight,maxCellTopMargin, maxCellBottomMargin);
|
|
|
|
return status;
|
1998-07-01 07:03:32 +04:00
|
|
|
}
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
/** Layout the entire row.
|
1998-07-02 09:39:10 +04:00
|
|
|
* This method stacks cells horizontally according to HTML 4.0 rules.
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
|
|
|
NS_METHOD
|
1998-05-25 21:31:49 +04:00
|
|
|
nsTableRowFrame::Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
|
|
|
if (gsDebug1==PR_TRUE)
|
1998-05-25 21:31:49 +04:00
|
|
|
printf("nsTableRowFrame::Reflow - aMaxSize = %d, %d\n",
|
|
|
|
aReflowState.maxSize.width, aReflowState.maxSize.height);
|
1998-04-23 21:29:07 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
PreReflowCheck();
|
1998-04-21 22:25:52 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-23 09:43:27 +04:00
|
|
|
RowReflowState state(aPresContext, aReflowState);
|
|
|
|
mContentParent->GetContentParent((nsIFrame*&)(state.tableFrame));
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-06-23 09:43:27 +04:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
1998-07-02 09:39:10 +04:00
|
|
|
aStatus = IncrementalReflow(aPresContext, state, aReflowState,
|
|
|
|
aDesiredSize.maxElementSize);
|
1998-06-23 09:43:27 +04:00
|
|
|
} else {
|
|
|
|
// Initialize out parameter
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = 0;
|
|
|
|
aDesiredSize.maxElementSize->height = 0;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
1998-06-23 09:43:27 +04:00
|
|
|
|
|
|
|
// Initialize our internal data
|
|
|
|
ResetMaxChildHeight();
|
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// We're never continued
|
1998-06-23 09:43:27 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// We should never have an overflow list
|
|
|
|
NS_ASSERTION(nsnull == mOverflowList, "unexpected overflow list");
|
1998-06-23 09:43:27 +04:00
|
|
|
|
1998-07-10 09:23:05 +04:00
|
|
|
// If we have existing frames them reflow them; otherwise create some frames
|
|
|
|
if (nsnull == mFirstChild) {
|
|
|
|
NS_ASSERTION(eReflowReason_Initial == aReflowState.reason,
|
|
|
|
"unexpected reflow reason");
|
|
|
|
aStatus = ReflowUnmappedChildren(aPresContext, state,
|
|
|
|
aDesiredSize.maxElementSize);
|
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "unexpected reflow status");
|
|
|
|
GetMinRowSpan();
|
|
|
|
FixMinCellHeight();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PRBool reflowMappedOK = ReflowMappedChildren(aPresContext, state,
|
|
|
|
aDesiredSize.maxElementSize);
|
|
|
|
NS_ASSERTION(PR_TRUE == reflowMappedOK, "unexpected result");
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-02 09:39:10 +04:00
|
|
|
// Return our desired rect
|
|
|
|
aDesiredSize.width = state.x;
|
|
|
|
aDesiredSize.height = state.maxCellVertSpace;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-04-17 05:41:24 +04:00
|
|
|
PostReflowCheck(aStatus);
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
|
|
|
|
1998-04-15 01:45:28 +04:00
|
|
|
if (gsDebug1==PR_TRUE)
|
|
|
|
{
|
1998-05-25 21:31:49 +04:00
|
|
|
if (nsnull!=aDesiredSize.maxElementSize)
|
1998-04-15 01:45:28 +04:00
|
|
|
printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=%d,%d\n",
|
1998-05-12 08:17:56 +04:00
|
|
|
NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete",
|
1998-04-15 01:45:28 +04:00
|
|
|
aDesiredSize.width, aDesiredSize.height,
|
1998-05-25 21:31:49 +04:00
|
|
|
aDesiredSize.maxElementSize->width, aDesiredSize.maxElementSize->height);
|
1998-04-15 01:45:28 +04:00
|
|
|
else
|
|
|
|
printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=NSNULL\n",
|
1998-05-12 08:17:56 +04:00
|
|
|
NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete",
|
1998-04-15 01:45:28 +04:00
|
|
|
aDesiredSize.width, aDesiredSize.height);
|
|
|
|
}
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-07 04:08:20 +04:00
|
|
|
NS_METHOD
|
|
|
|
nsTableRowFrame::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-07-10 08:00:38 +04:00
|
|
|
// Because rows are always complete we should never be asked to create
|
1998-07-10 09:23:05 +04:00
|
|
|
// a continuing frame
|
1998-07-10 08:00:38 +04:00
|
|
|
NS_ERROR("Unexpected request");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTableRowFrame::NewFrame( nsIFrame** aInstancePtrResult,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-05-06 03:56:50 +04:00
|
|
|
nsIFrame* it = new nsTableRowFrame(aContent, aParent);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|