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 "nsTableOuterFrame.h"
|
|
|
|
#include "nsTableFrame.h"
|
|
|
|
#include "nsBodyFrame.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentDelegate.h"
|
|
|
|
#include "nsCSSLayout.h"
|
|
|
|
#include "nsVoidArray.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-22 10:37:57 +04:00
|
|
|
#include "nsIPtr.h"
|
1998-07-02 21:40:56 +04:00
|
|
|
#include "prinrval.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRBool gsDebug = PR_FALSE;
|
1998-07-02 21:40:56 +04:00
|
|
|
static PRBool gsTiming = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
//#define NOISY
|
|
|
|
//#define NOISY_FLOW
|
1998-05-22 03:43:18 +04:00
|
|
|
#define NOISY_MARGINS
|
1998-04-14 00:24:54 +04:00
|
|
|
#else
|
|
|
|
static const PRBool gsDebug = PR_FALSE;
|
1998-07-02 21:40:56 +04:00
|
|
|
static const PRBool gsTiming = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
|
|
|
|
1998-04-22 10:37:57 +04:00
|
|
|
NS_DEF_PTR(nsIStyleContext);
|
|
|
|
NS_DEF_PTR(nsIContent);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
struct OuterTableReflowState {
|
|
|
|
|
1998-04-17 02:21:32 +04:00
|
|
|
// The presentation context
|
|
|
|
nsIPresContext *pc;
|
|
|
|
|
1998-05-30 00:36:05 +04:00
|
|
|
// Our reflow state
|
|
|
|
const nsReflowState& reflowState;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// The total available size (computed from the parent)
|
|
|
|
nsSize availSize;
|
|
|
|
// The available size for the inner table frame
|
|
|
|
nsSize innerTableMaxSize;
|
|
|
|
|
|
|
|
// Margin tracking information
|
|
|
|
nscoord prevMaxPosBottomMargin;
|
|
|
|
nscoord prevMaxNegBottomMargin;
|
|
|
|
|
|
|
|
// Flags for whether the max size is unconstrained
|
|
|
|
PRBool unconstrainedWidth;
|
|
|
|
PRBool unconstrainedHeight;
|
|
|
|
|
|
|
|
// Running y-offset
|
|
|
|
nscoord y;
|
|
|
|
|
1998-05-30 00:36:05 +04:00
|
|
|
OuterTableReflowState(nsIPresContext* aPresContext,
|
|
|
|
const nsReflowState& aReflowState)
|
|
|
|
: reflowState(aReflowState)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-17 02:21:32 +04:00
|
|
|
pc = aPresContext;
|
1998-05-30 00:36:05 +04:00
|
|
|
availSize.width = reflowState.maxSize.width;
|
|
|
|
availSize.height = reflowState.maxSize.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
prevMaxPosBottomMargin = 0;
|
|
|
|
prevMaxNegBottomMargin = 0;
|
|
|
|
y=0; // border/padding/margin???
|
1998-05-30 00:36:05 +04:00
|
|
|
unconstrainedWidth = PRBool(aReflowState.maxSize.width == NS_UNCONSTRAINEDSIZE);
|
|
|
|
unconstrainedHeight = PRBool(aReflowState.maxSize.height == NS_UNCONSTRAINEDSIZE);
|
1998-06-03 04:43:53 +04:00
|
|
|
innerTableMaxSize.width=0;
|
|
|
|
innerTableMaxSize.height=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~OuterTableReflowState() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------- nsTableOuterFrame ---------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
1998-05-06 03:56:50 +04:00
|
|
|
nsTableOuterFrame::nsTableOuterFrame(nsIContent* aContent, nsIFrame* aParentFrame)
|
|
|
|
: nsContainerFrame(aContent, aParentFrame),
|
1998-04-14 00:24:54 +04:00
|
|
|
mInnerTableFrame(nsnull),
|
1998-07-08 08:49:01 +04:00
|
|
|
mCaptionFrame(nsnull),
|
1998-04-14 00:24:54 +04:00
|
|
|
mMinCaptionWidth(0),
|
1998-05-25 21:31:49 +04:00
|
|
|
mDesiredSize(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-16 21:19:20 +04:00
|
|
|
NS_IMETHODIMP nsTableOuterFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
mFirstChild = aChildList;
|
|
|
|
mChildCount = LengthOf(mFirstChild);
|
1998-09-17 08:07:58 +04:00
|
|
|
NS_ASSERTION(mChildCount > 0, "bad child list");
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Set our internal member data
|
|
|
|
if (1 == mChildCount) {
|
|
|
|
mInnerTableFrame = (nsTableFrame*)mFirstChild;
|
|
|
|
} else {
|
|
|
|
mCaptionFrame = mFirstChild;
|
|
|
|
|
|
|
|
nsIFrame* f;
|
|
|
|
mFirstChild->GetNextSibling(f);
|
|
|
|
mInnerTableFrame = (nsTableFrame*)f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsTableOuterFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// for debug...
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsTableOuterFrame::NeedsReflow(const nsSize& aMaxSize)
|
|
|
|
{
|
|
|
|
PRBool result=PR_TRUE;
|
|
|
|
if (nsnull!=mInnerTableFrame)
|
|
|
|
result = mInnerTableFrame->NeedsReflow(aMaxSize);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-06-19 04:34:12 +04:00
|
|
|
// Recover the reflow state to what it should be if aKidFrame is about
|
|
|
|
// to be reflowed
|
|
|
|
nsresult nsTableOuterFrame::RecoverState(OuterTableReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame)
|
|
|
|
{
|
1998-06-22 09:34:17 +04:00
|
|
|
// Get aKidFrame's previous sibling
|
1998-06-19 04:34:12 +04:00
|
|
|
nsIFrame* prevKidFrame = nsnull;
|
|
|
|
for (nsIFrame* frame = mFirstChild; frame != aKidFrame;) {
|
|
|
|
prevKidFrame = frame;
|
|
|
|
frame->GetNextSibling(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != prevKidFrame) {
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
// Set our running y-offset
|
|
|
|
prevKidFrame->GetRect(rect);
|
|
|
|
aState.y = rect.YMost();
|
|
|
|
|
|
|
|
// Adjust the available space
|
|
|
|
if (PR_FALSE == aState.unconstrainedHeight) {
|
|
|
|
aState.availSize.height -= aState.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the previous frame's bottom margin
|
|
|
|
const nsStyleSpacing* kidSpacing;
|
|
|
|
prevKidFrame->GetStyleData(eStyleStruct_Spacing, (nsStyleStruct *&)kidSpacing);
|
|
|
|
nsMargin margin;
|
|
|
|
kidSpacing->CalcMarginFor(prevKidFrame, margin);
|
|
|
|
if (margin.bottom < 0) {
|
|
|
|
aState.prevMaxNegBottomMargin = -margin.bottom;
|
|
|
|
} else {
|
|
|
|
aState.prevMaxPosBottomMargin = margin.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the inner table max size
|
|
|
|
nsSize innerTableSize(0,0);
|
|
|
|
|
|
|
|
mInnerTableFrame->GetSize(innerTableSize);
|
|
|
|
aState.innerTableMaxSize.width = innerTableSize.width;
|
|
|
|
aState.innerTableMaxSize.height = aState.reflowState.maxSize.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-19 09:21:45 +04:00
|
|
|
nsresult nsTableOuterFrame::AdjustSiblingsAfterReflow(nsIPresContext* aPresContext,
|
|
|
|
OuterTableReflowState& aState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
nscoord aDeltaY)
|
|
|
|
{
|
|
|
|
nsIFrame* lastKidFrame = aKidFrame;
|
|
|
|
|
|
|
|
if (aDeltaY != 0) {
|
|
|
|
// Move the frames that follow aKidFrame by aDeltaY
|
|
|
|
nsIFrame* kidFrame;
|
|
|
|
|
|
|
|
aKidFrame->GetNextSibling(kidFrame);
|
|
|
|
while (nsnull != kidFrame) {
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
// XXX We can't just slide the child if it has a next-in-flow
|
|
|
|
kidFrame->GetOrigin(origin);
|
|
|
|
origin.y += aDeltaY;
|
|
|
|
|
|
|
|
// XXX We need to send move notifications to the frame...
|
1998-06-22 09:34:17 +04:00
|
|
|
kidFrame->WillReflow(*aPresContext);
|
1998-06-19 09:21:45 +04:00
|
|
|
kidFrame->MoveTo(origin.x, origin.y);
|
|
|
|
|
|
|
|
// Get the next frame
|
|
|
|
lastKidFrame = kidFrame;
|
|
|
|
kidFrame->GetNextSibling(kidFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Get the last frame
|
|
|
|
LastChild(lastKidFrame);
|
1998-06-22 09:34:17 +04:00
|
|
|
}
|
1998-06-19 09:21:45 +04:00
|
|
|
|
1998-06-22 09:34:17 +04:00
|
|
|
// Update our running y-offset to reflect the bottommost child
|
|
|
|
nsRect rect;
|
1998-06-19 09:21:45 +04:00
|
|
|
|
1998-06-22 09:34:17 +04:00
|
|
|
lastKidFrame->GetRect(rect);
|
|
|
|
aState.y = rect.YMost();
|
1998-06-19 09:21:45 +04:00
|
|
|
|
|
|
|
// Get the bottom margin for the last child frame
|
|
|
|
const nsStyleSpacing* kidSpacing;
|
|
|
|
lastKidFrame->GetStyleData(eStyleStruct_Spacing, (nsStyleStruct *&)kidSpacing);
|
|
|
|
nsMargin margin;
|
|
|
|
kidSpacing->CalcMarginFor(lastKidFrame, margin);
|
|
|
|
if (margin.bottom < 0) {
|
|
|
|
aState.prevMaxNegBottomMargin = -margin.bottom;
|
|
|
|
} else {
|
|
|
|
aState.prevMaxPosBottomMargin = margin.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-19 04:34:12 +04:00
|
|
|
nsresult nsTableOuterFrame::IncrementalReflow(nsIPresContext* aPresContext,
|
1998-06-19 09:21:45 +04:00
|
|
|
OuterTableReflowState& aState,
|
1998-06-19 04:34:12 +04:00
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// Get the next frame in the reflow chain
|
1998-06-19 09:21:45 +04:00
|
|
|
nsIFrame* kidFrame;
|
|
|
|
aReflowState.reflowCommand->GetNext(kidFrame);
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1998-06-19 09:21:45 +04:00
|
|
|
// Recover our reflow state
|
|
|
|
RecoverState(aState, kidFrame);
|
1998-06-19 04:34:12 +04:00
|
|
|
|
|
|
|
// Pass along the reflow command
|
|
|
|
// XXX Check if we're the target...
|
1998-06-19 09:21:45 +04:00
|
|
|
nsSize kidMaxElementSize(0,0);
|
|
|
|
nsSize* pKidMaxElementSize = (nsnull != aDesiredSize.maxElementSize) ?
|
|
|
|
&kidMaxElementSize : nsnull;
|
|
|
|
nsReflowMetrics kidSize(pKidMaxElementSize);
|
|
|
|
nsRect oldKidRect;
|
|
|
|
|
|
|
|
kidFrame->GetRect(oldKidRect);
|
|
|
|
|
|
|
|
// Get the top margin for the child
|
|
|
|
const nsStyleSpacing* kidSpacing;
|
|
|
|
kidFrame->GetStyleData(eStyleStruct_Spacing, (nsStyleStruct *&)kidSpacing);
|
|
|
|
nsMargin kidMargin;
|
|
|
|
kidSpacing->CalcMarginFor(kidFrame, kidMargin);
|
1998-07-09 00:21:17 +04:00
|
|
|
nscoord topMargin = kidMargin.top;
|
1998-06-19 09:21:45 +04:00
|
|
|
nscoord bottomMargin = kidMargin.bottom;
|
|
|
|
|
|
|
|
// Figure out the amount of available size for the child (subtract
|
|
|
|
// off the top margin we are going to apply to it)
|
|
|
|
if (PR_FALSE == aState.unconstrainedHeight) {
|
|
|
|
aState.availSize.height -= topMargin;
|
|
|
|
}
|
|
|
|
// Subtract off for left and right margin
|
|
|
|
if (PR_FALSE == aState.unconstrainedWidth) {
|
|
|
|
aState.availSize.width -= kidMargin.left + kidMargin.right;
|
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1998-06-19 09:21:45 +04:00
|
|
|
// Now do the reflow
|
1998-06-19 04:34:12 +04:00
|
|
|
aState.y += topMargin;
|
1998-06-19 09:21:45 +04:00
|
|
|
kidFrame->WillReflow(*aPresContext);
|
|
|
|
kidFrame->MoveTo(kidMargin.left, aState.y);
|
1998-06-24 08:38:52 +04:00
|
|
|
nsReflowState kidReflowState(kidFrame, aState.reflowState, aState.availSize);
|
|
|
|
if (kidFrame != mInnerTableFrame) {
|
|
|
|
// Reflow captions to the width of the inner table
|
|
|
|
kidReflowState.maxSize.width = aState.innerTableMaxSize.width;
|
|
|
|
}
|
1998-06-23 09:43:27 +04:00
|
|
|
mInnerTableFrame->SetReflowPass(nsTableFrame::kPASS_INCREMENTAL);
|
1998-07-15 06:53:09 +04:00
|
|
|
kidFrame->Reflow(*aPresContext, kidSize, kidReflowState, aStatus);
|
1998-06-19 09:21:45 +04:00
|
|
|
|
|
|
|
// Place the child frame after taking into account its margin
|
|
|
|
nsRect kidRect (kidMargin.left, aState.y, kidSize.width, kidSize.height);
|
|
|
|
PlaceChild(aState, kidFrame, kidRect, aDesiredSize.maxElementSize, kidMaxElementSize);
|
1998-06-19 04:34:12 +04:00
|
|
|
if (bottomMargin < 0) {
|
|
|
|
aState.prevMaxNegBottomMargin = -bottomMargin;
|
|
|
|
} else {
|
|
|
|
aState.prevMaxPosBottomMargin = bottomMargin;
|
|
|
|
}
|
|
|
|
|
1998-06-23 09:43:27 +04:00
|
|
|
// XXX We're not correctly dealing with maxElementSize...
|
|
|
|
|
1998-06-19 04:34:12 +04:00
|
|
|
// Adjust the frames that follow
|
1998-06-19 09:21:45 +04:00
|
|
|
return AdjustSiblingsAfterReflow(aPresContext, aState, kidFrame,
|
|
|
|
kidRect.YMost() - oldKidRect.YMost());
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
1998-07-09 18:30:34 +04:00
|
|
|
* Called by the Reflow() member function to compute the table width
|
|
|
|
*/
|
|
|
|
nscoord nsTableOuterFrame::GetTableWidth(const nsReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nscoord maxWidth;
|
|
|
|
|
|
|
|
// Figure out the overall table width constraint. Default case, get 100% of
|
|
|
|
// available space
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.maxSize.width) {
|
|
|
|
maxWidth = aReflowState.maxSize.width;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const nsStylePosition* position =
|
|
|
|
(const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position);
|
|
|
|
|
|
|
|
switch (position->mWidth.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
maxWidth = position->mWidth.GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
maxWidth = aReflowState.maxSize.width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
maxWidth = (nscoord)((float)aReflowState.maxSize.width *
|
|
|
|
position->mWidth.GetPercentValue());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Proportional:
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
// XXX for now these fall through
|
|
|
|
|
|
|
|
default:
|
|
|
|
maxWidth = aReflowState.maxSize.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subtract out border and padding
|
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
|
|
|
|
maxWidth -= borderPadding.left + borderPadding.right;
|
|
|
|
if (maxWidth <= 0) {
|
|
|
|
// Nonsense style specification
|
|
|
|
maxWidth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflow is a multi-step process.
|
|
|
|
* 1. First we reflow the caption frame and get its maximum element size. We
|
|
|
|
* do this once during our initial reflow and whenever the caption changes
|
|
|
|
* incrementally
|
|
|
|
* 2. Next we reflow the inner table. This gives us the actual table width.
|
|
|
|
* The table must be at least as wide as the caption maximum element size
|
|
|
|
* 3. Now that we have the table width we reflow the caption and gets its
|
|
|
|
* desired height
|
|
|
|
* 4. Then we place the caption and the inner table
|
|
|
|
*
|
|
|
|
* If the table height is constrained, e.g. page mode, then it's possible the
|
|
|
|
* inner table no longer fits and has to be reflowed again this time with s
|
|
|
|
* smaller available height
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1998-07-15 06:53:09 +04:00
|
|
|
NS_METHOD nsTableOuterFrame::Reflow(nsIPresContext& aPresContext,
|
1998-05-25 21:31:49 +04:00
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-17 02:25:09 +04:00
|
|
|
if (PR_TRUE==gsDebug)
|
1998-06-24 03:23:21 +04:00
|
|
|
printf("%p: nsTableOuterFrame::Reflow : maxSize=%d,%d\n",
|
|
|
|
this, aReflowState.maxSize.width, aReflowState.maxSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-02 21:40:56 +04:00
|
|
|
PRIntervalTime startTime;
|
|
|
|
if (gsTiming) {
|
|
|
|
startTime = PR_IntervalNow();
|
|
|
|
}
|
|
|
|
|
1998-06-23 01:59:43 +04:00
|
|
|
// Initialize out parameters
|
1998-05-25 21:31:49 +04:00
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = 0;
|
|
|
|
aDesiredSize.maxElementSize->height = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-23 01:59:43 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-19 09:21:45 +04:00
|
|
|
// Initialize our local reflow state
|
1998-07-15 06:53:09 +04:00
|
|
|
OuterTableReflowState state(&aPresContext, aReflowState);
|
1998-06-19 04:34:12 +04:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
1998-07-15 06:53:09 +04:00
|
|
|
IncrementalReflow(&aPresContext, state, aDesiredSize, aReflowState, aStatus);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-09 18:30:34 +04:00
|
|
|
// Return our desired rect
|
|
|
|
aDesiredSize.width = state.innerTableMaxSize.width;
|
|
|
|
|
1998-06-19 04:34:12 +04:00
|
|
|
} else {
|
1998-06-23 01:59:43 +04:00
|
|
|
if (eReflowReason_Initial == aReflowState.reason) {
|
1998-08-04 21:16:56 +04:00
|
|
|
//KIPP/TROY: uncomment the following line for your own testing, do not check it in
|
|
|
|
// NS_ASSERTION(nsnull == mFirstChild, "unexpected reflow reason");
|
1998-08-04 03:29:35 +04:00
|
|
|
|
1998-06-23 01:59:43 +04:00
|
|
|
// Set up our kids. They're already present, on an overflow list,
|
|
|
|
// or there are none so we'll create them now
|
|
|
|
MoveOverflowToChildList();
|
1998-09-16 21:19:20 +04:00
|
|
|
// XXX CONSTRUCTION
|
|
|
|
#if 0
|
1998-07-09 00:21:17 +04:00
|
|
|
if (nsnull == mFirstChild) {
|
1998-07-15 06:53:09 +04:00
|
|
|
nsresult result = CreateChildFrames(&aPresContext);
|
1998-07-09 00:21:17 +04:00
|
|
|
if (NS_OK != result) {
|
|
|
|
return result;
|
|
|
|
}
|
1998-06-23 01:59:43 +04:00
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
#endif
|
1998-06-23 01:59:43 +04:00
|
|
|
|
1998-07-09 18:30:34 +04:00
|
|
|
// Lay out the caption and get its maximum element size
|
1998-07-09 00:21:17 +04:00
|
|
|
if (nsnull != mCaptionFrame) {
|
1998-07-09 18:30:34 +04:00
|
|
|
nsSize maxElementSize;
|
|
|
|
nsReflowMetrics captionSize(&maxElementSize);
|
|
|
|
nsReflowState captionReflowState(mCaptionFrame, aReflowState,
|
|
|
|
nsSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
|
|
|
|
eReflowReason_Initial);
|
1998-07-15 06:53:09 +04:00
|
|
|
mCaptionFrame->WillReflow(aPresContext);
|
1998-07-09 18:30:34 +04:00
|
|
|
mCaptionFrame->Reflow(aPresContext, captionSize, captionReflowState, aStatus);
|
|
|
|
mMinCaptionWidth = maxElementSize.width;
|
1998-07-09 00:21:17 +04:00
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
1998-06-23 01:59:43 +04:00
|
|
|
|
1998-07-09 00:21:17 +04:00
|
|
|
// At this point, we must have at least one child frame, and we must have an
|
|
|
|
// inner table frame
|
|
|
|
NS_ASSERTION(nsnull != mFirstChild, "no children");
|
|
|
|
NS_ASSERTION(nsnull != mInnerTableFrame, "no mInnerTableFrame");
|
1998-07-02 21:40:56 +04:00
|
|
|
|
1998-07-09 18:30:34 +04:00
|
|
|
// Compute the width to use for the table. In the case of an auto sizing
|
|
|
|
// table this represents the maximum available width
|
|
|
|
nscoord tableWidth = GetTableWidth(aReflowState);
|
|
|
|
|
|
|
|
// If the caption max element size is larger, then use it instead.
|
|
|
|
// Note: this implicitly forces the table width to be fixed...
|
|
|
|
if (mMinCaptionWidth > tableWidth) {
|
|
|
|
tableWidth = mMinCaptionWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First reflow the inner table
|
|
|
|
nsReflowState innerReflowState(mInnerTableFrame, aReflowState,
|
|
|
|
nsSize(tableWidth, aReflowState.maxSize.height));
|
|
|
|
nsReflowMetrics innerSize(aDesiredSize.maxElementSize);
|
1998-07-15 06:53:09 +04:00
|
|
|
mInnerTableFrame->WillReflow(aPresContext);
|
|
|
|
aStatus = ReflowChild(mInnerTableFrame, &aPresContext, innerSize,
|
1998-07-09 18:30:34 +04:00
|
|
|
innerReflowState);
|
|
|
|
|
|
|
|
// Table's max element size is the MAX of the caption's max element size
|
|
|
|
// and the inner table's max element size...
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
if (mMinCaptionWidth > aDesiredSize.maxElementSize->width) {
|
|
|
|
aDesiredSize.maxElementSize->width = mMinCaptionWidth;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
1998-07-09 18:30:34 +04:00
|
|
|
state.innerTableMaxSize.width = innerSize.width;
|
|
|
|
|
|
|
|
// Now that we know the table width we can reflow the caption, and
|
|
|
|
// place the caption and the inner table
|
|
|
|
if (nsnull != mCaptionFrame) {
|
|
|
|
// Get the caption's margin
|
|
|
|
nsMargin captionMargin;
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
|
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Spacing, (nsStyleStruct *&)spacing);
|
|
|
|
spacing->CalcMarginFor(mCaptionFrame, captionMargin);
|
|
|
|
|
|
|
|
// Compute the caption's y-origin
|
|
|
|
nscoord captionY = captionMargin.top;
|
|
|
|
if (mFirstChild == mInnerTableFrame) {
|
|
|
|
captionY += innerSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow the caption. Let it be as high as it wants
|
|
|
|
nsReflowState captionReflowState(mCaptionFrame, state.reflowState,
|
|
|
|
nsSize(innerSize.width, NS_UNCONSTRAINEDSIZE),
|
|
|
|
eReflowReason_Resize);
|
|
|
|
nsReflowMetrics captionSize(nsnull);
|
|
|
|
|
|
|
|
nsReflowStatus captionStatus;
|
1998-07-15 06:53:09 +04:00
|
|
|
mCaptionFrame->WillReflow(aPresContext);
|
1998-07-09 18:30:34 +04:00
|
|
|
mCaptionFrame->MoveTo(captionMargin.left, captionY);
|
|
|
|
mCaptionFrame->Reflow(aPresContext, captionSize, captionReflowState,
|
|
|
|
captionStatus);
|
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(captionStatus), "unexpected reflow status");
|
|
|
|
|
|
|
|
// XXX If the height is constrained then we need to check whether the inner
|
|
|
|
// table still fits...
|
|
|
|
|
|
|
|
// Place the caption
|
|
|
|
nsRect captionRect(captionMargin.left, captionY, captionSize.width, captionSize.height);
|
|
|
|
mCaptionFrame->SetRect(captionRect);
|
|
|
|
|
|
|
|
// Place the inner table
|
|
|
|
nscoord innerY;
|
|
|
|
if (mFirstChild == mCaptionFrame) {
|
|
|
|
// Inner table is below the caption
|
|
|
|
innerY = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
state.y = innerY + innerSize.height;
|
|
|
|
} else {
|
|
|
|
// Caption is below the inner table
|
|
|
|
innerY = 0;
|
|
|
|
state.y = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
}
|
|
|
|
nsRect innerRect(0, innerY, innerSize.width, innerSize.height);
|
|
|
|
mInnerTableFrame->SetRect(innerRect);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Place the inner table
|
|
|
|
nsRect innerRect(0, 0, innerSize.width, innerSize.height);
|
|
|
|
mInnerTableFrame->SetRect(innerRect);
|
|
|
|
state.y = innerSize.height;
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
1998-06-19 09:21:45 +04:00
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1998-06-19 09:21:45 +04:00
|
|
|
/* if we're incomplete, take up all the remaining height so we don't waste time
|
|
|
|
* trying to lay out in a slot that we know isn't tall enough to fit our minimum.
|
|
|
|
* otherwise, we're as tall as our kids want us to be */
|
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(aStatus))
|
|
|
|
aDesiredSize.height = aReflowState.maxSize.height;
|
|
|
|
else
|
|
|
|
aDesiredSize.height = state.y;
|
1998-07-09 18:30:34 +04:00
|
|
|
// Return our desired rect
|
|
|
|
aDesiredSize.width = state.innerTableMaxSize.width;
|
1998-07-03 01:24:56 +04:00
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
1998-06-19 09:21:45 +04:00
|
|
|
|
|
|
|
if (gsDebug==PR_TRUE)
|
|
|
|
{
|
|
|
|
if (nsnull!=aDesiredSize.maxElementSize)
|
1998-06-24 03:23:21 +04:00
|
|
|
printf("%p: Outer frame Reflow complete, returning %s with aDesiredSize = %d,%d and aMaxElementSize=%d,%d\n",
|
|
|
|
this, NS_FRAME_IS_COMPLETE(aStatus)? "Complete" : "Not Complete",
|
1998-06-19 09:21:45 +04:00
|
|
|
aDesiredSize.width, aDesiredSize.height,
|
|
|
|
aDesiredSize.maxElementSize->width, aDesiredSize.maxElementSize->height);
|
|
|
|
else
|
1998-06-24 03:23:21 +04:00
|
|
|
printf("%p: Outer frame Reflow complete, returning %s with aDesiredSize = %d,%d and NSNULL aMaxElementSize\n",
|
|
|
|
this, NS_FRAME_IS_COMPLETE(aStatus)? "Complete" : "Not Complete",
|
1998-06-19 09:21:45 +04:00
|
|
|
aDesiredSize.width, aDesiredSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-02 21:40:56 +04:00
|
|
|
if (gsTiming) {
|
|
|
|
PRIntervalTime endTime = PR_IntervalNow();
|
|
|
|
printf("Table reflow took %ld ticks for frame %d\n",
|
|
|
|
endTime-startTime, this);/* XXX need to use LL_* macros! */
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +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.
|
1998-04-17 02:21:32 +04:00
|
|
|
void nsTableOuterFrame::PlaceChild( OuterTableReflowState& aState,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
const nsRect& aKidRect,
|
|
|
|
nsSize* aMaxElementSize,
|
|
|
|
nsSize& aKidMaxElementSize)
|
|
|
|
{
|
1998-04-21 02:49:15 +04:00
|
|
|
if (PR_TRUE==gsDebug)
|
|
|
|
printf ("outer table place child: %p with aKidRect %d %d %d %d\n",
|
1998-04-14 00:24:54 +04:00
|
|
|
aKidFrame, aKidRect.x, aKidRect.y,
|
|
|
|
aKidRect.width, aKidRect.height);
|
|
|
|
// Place and size the child
|
|
|
|
aKidFrame->SetRect(aKidRect);
|
|
|
|
|
|
|
|
// Adjust the running y-offset
|
|
|
|
aState.y += aKidRect.height;
|
|
|
|
|
|
|
|
// If our height is constrained then update the available height
|
|
|
|
if (PR_FALSE == aState.unconstrainedHeight) {
|
|
|
|
aState.availSize.height -= aKidRect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the maximum element size, which is the sum of:
|
|
|
|
* the maxElementSize of our first row
|
|
|
|
* plus the maxElementSize of the top caption if we include it
|
|
|
|
* plus the maxElementSize of the bottom caption if we include it
|
|
|
|
*/
|
1998-07-09 18:30:34 +04:00
|
|
|
if (aKidFrame == mCaptionFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (nsnull != aMaxElementSize) {
|
|
|
|
aMaxElementSize->width = aKidMaxElementSize.width;
|
|
|
|
aMaxElementSize->height = aKidMaxElementSize.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-08 08:49:01 +04:00
|
|
|
nsresult nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-07-08 08:49:01 +04:00
|
|
|
// Create the inner table frame
|
1998-07-09 00:21:17 +04:00
|
|
|
nsresult result = CreateInnerTableFrame(aPresContext, mInnerTableFrame);
|
1998-07-08 08:49:01 +04:00
|
|
|
if (NS_OK != result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-07-09 00:21:17 +04:00
|
|
|
// Add it to the list of child frames
|
1998-04-14 00:24:54 +04:00
|
|
|
mFirstChild = mInnerTableFrame;
|
1998-07-08 08:49:01 +04:00
|
|
|
mChildCount++;
|
|
|
|
|
|
|
|
// Now create the caption frame, prepending a top caption and appending a
|
|
|
|
// bottom caption
|
|
|
|
//
|
|
|
|
// We only allow a single caption. If there are more than one caption, then
|
|
|
|
// ignore all but the first
|
|
|
|
for (PRInt32 kidIndex = 0; /* nada */ ; kidIndex++)
|
1998-06-17 20:38:24 +04:00
|
|
|
{
|
1998-08-30 00:20:38 +04:00
|
|
|
nsIContentPtr caption;
|
|
|
|
mContent->ChildAt(kidIndex, caption.AssignRef());
|
1998-06-17 20:38:24 +04:00
|
|
|
if (PR_TRUE==caption.IsNull()) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-07-08 08:49:01 +04:00
|
|
|
|
|
|
|
// Resolve style so we can tell if the content should be displayed
|
|
|
|
// as a caption
|
1998-06-17 20:38:24 +04:00
|
|
|
nsIStyleContextPtr captionSC =
|
|
|
|
aPresContext->ResolveStyleContextFor(caption, this);
|
|
|
|
NS_ASSERTION(captionSC.IsNotNull(), "bad style context for caption.");
|
|
|
|
nsStyleDisplay *childDisplay = (nsStyleDisplay*)captionSC->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CAPTION == childDisplay->mDisplay)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-07-08 08:49:01 +04:00
|
|
|
// Create the caption frame.
|
1998-09-15 21:58:24 +04:00
|
|
|
nsIContentDelegate* kidDel = nsnull;
|
|
|
|
kidDel = caption->GetDelegate(aPresContext);
|
|
|
|
nsresult rv = kidDel->CreateFrame(aPresContext, caption, this, captionSC,
|
|
|
|
mCaptionFrame);
|
|
|
|
NS_RELEASE(kidDel);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1998-07-08 08:49:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine if the caption is a top or bottom caption
|
1998-06-17 20:38:24 +04:00
|
|
|
const nsStyleText* captionTextStyle =
|
|
|
|
(const nsStyleText*)captionSC->GetStyleData(eStyleStruct_Text);
|
1998-05-22 04:05:22 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Link child frame into the list of children
|
1998-06-17 20:38:24 +04:00
|
|
|
if ((eStyleUnit_Enumerated == captionTextStyle->mVerticalAlign.GetUnit()) &&
|
|
|
|
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionTextStyle->mVerticalAlign.GetIntValue()))
|
1998-07-08 08:49:01 +04:00
|
|
|
{
|
|
|
|
// Bottom caption is added to the end of the child frame list
|
|
|
|
mInnerTableFrame->SetNextSibling(mCaptionFrame);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
else
|
1998-07-08 08:49:01 +04:00
|
|
|
{
|
|
|
|
// Top caption is added to the beginning of child frame list
|
|
|
|
mCaptionFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = mCaptionFrame;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-07-08 08:49:01 +04:00
|
|
|
mChildCount++;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-07-08 08:49:01 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-07 04:08:20 +04:00
|
|
|
NS_METHOD
|
1998-07-15 07:23:23 +04:00
|
|
|
nsTableOuterFrame::CreateContinuingFrame(nsIPresContext& aPresContext,
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-06 03:56:50 +04:00
|
|
|
nsTableOuterFrame* cf = new nsTableOuterFrame(mContent, aParent);
|
1998-05-07 04:08:20 +04:00
|
|
|
if (nsnull == cf) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
PrepareContinuingFrame(aPresContext, aParent, aStyleContext, cf);
|
1998-04-25 00:59:44 +04:00
|
|
|
if (PR_TRUE==gsDebug)
|
|
|
|
printf("nsTableOuterFrame::CCF parent = %p, this=%p, cf=%p\n", aParent, this, cf);
|
1998-04-17 05:41:24 +04:00
|
|
|
aContinuingFrame = cf;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-07 04:08:20 +04:00
|
|
|
void
|
1998-07-15 07:23:23 +04:00
|
|
|
nsTableOuterFrame::PrepareContinuingFrame(nsIPresContext& aPresContext,
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsTableOuterFrame* aContFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Append the continuing frame to the flow
|
|
|
|
aContFrame->AppendToFlow(this);
|
|
|
|
|
|
|
|
// Initialize it's content offsets. Note that we assume for now that
|
|
|
|
// the continuingFrame will map the remainder of the content and
|
|
|
|
// that therefore mLastContentIsComplete will be true.
|
|
|
|
PRInt32 nextOffset;
|
|
|
|
if (mChildCount > 0) {
|
|
|
|
nextOffset = mLastContentOffset;
|
|
|
|
if (mLastContentIsComplete) {
|
|
|
|
nextOffset++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextOffset = mFirstContentOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContFrame->SetFirstContentOffset(nextOffset);
|
|
|
|
aContFrame->SetLastContentOffset(nextOffset);
|
|
|
|
aContFrame->SetLastContentIsComplete(PR_TRUE);
|
1998-07-15 07:23:23 +04:00
|
|
|
aContFrame->SetStyleContext(&aPresContext, aStyleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsTableOuterFrame::VerifyTree() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
|
|
|
|
#endif
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 02:21:32 +04:00
|
|
|
/**
|
|
|
|
* Remove and delete aChild's next-in-flow(s). Updates the sibling and flow
|
|
|
|
* pointers.
|
|
|
|
*
|
|
|
|
* Updates the child count and content offsets of all containers that are
|
|
|
|
* affected
|
|
|
|
*
|
|
|
|
* Overloaded here because nsContainerFrame makes assumptions about pseudo-frames
|
|
|
|
* that are not true for tables.
|
|
|
|
*
|
|
|
|
* @param aChild child this child's next-in-flow
|
|
|
|
* @return PR_TRUE if successful and PR_FALSE otherwise
|
|
|
|
*/
|
1998-08-28 07:02:39 +04:00
|
|
|
PRBool nsTableOuterFrame::DeleteChildsNextInFlow(nsIPresContext& aPresContext, nsIFrame* aChild)
|
1998-04-17 02:21:32 +04:00
|
|
|
{
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_PRECONDITION(IsChild(aChild), "bad geometric parent");
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
|
|
|
|
aChild->GetNextInFlow(nextInFlow);
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != nextInFlow, "null next-in-flow");
|
|
|
|
nsTableOuterFrame* parent;
|
|
|
|
|
|
|
|
nextInFlow->GetGeometricParent((nsIFrame*&)parent);
|
1998-04-17 02:21:32 +04:00
|
|
|
|
|
|
|
// If the next-in-flow has a next-in-flow then delete it too (and
|
|
|
|
// delete it first).
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* nextNextInFlow;
|
|
|
|
|
|
|
|
nextInFlow->GetNextInFlow(nextNextInFlow);
|
|
|
|
if (nsnull != nextNextInFlow) {
|
1998-08-28 07:02:39 +04:00
|
|
|
parent->DeleteChildsNextInFlow(aPresContext, nextInFlow);
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
PRInt32 childCount;
|
|
|
|
nsIFrame* firstChild;
|
|
|
|
|
|
|
|
nextInFlow->ChildCount(childCount);
|
|
|
|
nextInFlow->FirstChild(firstChild);
|
|
|
|
|
|
|
|
NS_ASSERTION(childCount == 0, "deleting !empty next-in-flow");
|
|
|
|
|
|
|
|
NS_ASSERTION((0 == childCount) && (nsnull == firstChild), "deleting !empty next-in-flow");
|
|
|
|
#endif
|
1998-04-17 02:21:32 +04:00
|
|
|
|
|
|
|
// Disconnect the next-in-flow from the flow list
|
|
|
|
nextInFlow->BreakFromPrevFlow();
|
|
|
|
|
|
|
|
// Take the next-in-flow out of the parent's child list
|
|
|
|
if (parent->mFirstChild == nextInFlow) {
|
1998-04-17 05:41:24 +04:00
|
|
|
nextInFlow->GetNextSibling(parent->mFirstChild);
|
1998-04-17 02:21:32 +04:00
|
|
|
if (nsnull != parent->mFirstChild) {
|
1998-07-10 23:04:06 +04:00
|
|
|
PRInt32 contentIndex;
|
|
|
|
parent->mFirstChild->GetContentIndex(contentIndex);
|
|
|
|
parent->SetFirstContentOffset(contentIndex);
|
1998-04-17 02:21:32 +04:00
|
|
|
if (parent->IsPseudoFrame()) {
|
1998-07-01 00:22:44 +04:00
|
|
|
// Tell the parent's parent to update its content offsets
|
|
|
|
nsContainerFrame* pp = (nsContainerFrame*) parent->mGeometricParent;
|
|
|
|
pp->PropagateContentOffsets(parent, parent->mFirstContentOffset,
|
|
|
|
parent->mLastContentOffset,
|
|
|
|
parent->mLastContentIsComplete);
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When a parent loses it's last child and that last child is a
|
|
|
|
// pseudo-frame then the parent's content offsets are now wrong.
|
|
|
|
// However, we know that the parent will eventually be reflowed
|
|
|
|
// in one of two ways: it will either get a chance to pullup
|
|
|
|
// children or it will be deleted because it's prev-in-flow
|
|
|
|
// (e.g. this) is complete. In either case, the content offsets
|
|
|
|
// will be repaired.
|
|
|
|
|
|
|
|
} else {
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* nextSibling;
|
|
|
|
|
1998-04-17 02:21:32 +04:00
|
|
|
// Because the next-in-flow is not the first child of the parent
|
|
|
|
// we know that it shares a parent with aChild. Therefore, we need
|
|
|
|
// to capture the next-in-flow's next sibling (in case the
|
|
|
|
// next-in-flow is the last next-in-flow for aChild AND the
|
|
|
|
// next-in-flow is not the last child in parent)
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_ASSERTION(parent->IsChild(aChild), "screwy flow");
|
|
|
|
aChild->GetNextSibling(nextSibling);
|
|
|
|
NS_ASSERTION(nextSibling == nextInFlow, "unexpected sibling");
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
nextInFlow->GetNextSibling(nextSibling);
|
|
|
|
aChild->SetNextSibling(nextSibling);
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the next-in-flow frame and adjust it's parent's child count
|
1998-08-28 07:02:39 +04:00
|
|
|
nextInFlow->DeleteFrame(aPresContext);
|
1998-04-17 02:21:32 +04:00
|
|
|
parent->mChildCount--;
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
aChild->GetNextInFlow(nextInFlow);
|
|
|
|
NS_POSTCONDITION(nsnull == nextInFlow, "non null next-in-flow");
|
|
|
|
#endif
|
|
|
|
|
1998-04-17 02:21:32 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-09 00:21:17 +04:00
|
|
|
/**
|
|
|
|
* Called by member function CreareChildFrames() to create the inner table
|
|
|
|
* frame. Resolves and sets the frame's style context
|
|
|
|
*/
|
|
|
|
nsresult nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext,
|
|
|
|
nsTableFrame*& aTableFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Do we have a prev-in-flow?
|
|
|
|
if (nsnull == mPrevInFlow) {
|
1998-07-09 00:21:17 +04:00
|
|
|
// No, create the inner table frame
|
|
|
|
aTableFrame = new nsTableFrame(mContent, this);
|
|
|
|
if (nsnull == aTableFrame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-21 12:12:22 +04:00
|
|
|
// Resolve style and set the style context. Have the inner table use our
|
|
|
|
// style context
|
|
|
|
aTableFrame->SetStyleContext(aPresContext, mStyleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-09 00:21:17 +04:00
|
|
|
} else {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Create a continuing column
|
1998-07-09 00:21:17 +04:00
|
|
|
nsTableOuterFrame* prevOuterTable = (nsTableOuterFrame*)mPrevInFlow;
|
|
|
|
nsIFrame* prevInnerTable = prevOuterTable->mInnerTableFrame;
|
|
|
|
nsIStyleContextPtr kidSC;
|
|
|
|
|
|
|
|
prevInnerTable->GetStyleContext(aPresContext, kidSC.AssignRef());
|
1998-07-15 07:23:23 +04:00
|
|
|
prevInnerTable->CreateContinuingFrame(*aPresContext, this, kidSC,
|
1998-07-09 00:21:17 +04:00
|
|
|
(nsIFrame*&)aTableFrame);
|
|
|
|
if (nsnull == aTableFrame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1998-07-09 00:21:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
/* ----- global methods ----- */
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewTableOuterFrame( nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-15 21:58:24 +04:00
|
|
|
nsIFrame* it = new nsTableOuterFrame(aContent, aParentFrame);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-09-15 21:58:24 +04:00
|
|
|
aResult = it;
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-03 01:59:54 +04:00
|
|
|
|
|
|
|
/* ----- debugging methods ----- */
|
|
|
|
NS_METHOD nsTableOuterFrame::List(FILE* out, PRInt32 aIndent, nsIListFilter *aFilter) const
|
|
|
|
{
|
|
|
|
// if a filter is present, only output this frame if the filter says we should
|
|
|
|
// since this could be any "tag" with the right display type, we'll
|
|
|
|
// just pretend it's a tbody
|
|
|
|
if (nsnull==aFilter)
|
|
|
|
return nsContainerFrame::List(out, aIndent, aFilter);
|
|
|
|
|
|
|
|
nsAutoString tagString("tbody");
|
|
|
|
PRBool outputMe = aFilter->OutputTag(&tagString);
|
|
|
|
if (PR_TRUE==outputMe)
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
// Output the tag and rect
|
|
|
|
nsIAtom* tag;
|
|
|
|
mContent->GetTag(tag);
|
|
|
|
if (tag != nsnull) {
|
|
|
|
nsAutoString buf;
|
|
|
|
tag->ToString(buf);
|
|
|
|
fputs(buf, out);
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
}
|
|
|
|
PRInt32 contentIndex;
|
|
|
|
|
|
|
|
GetContentIndex(contentIndex);
|
|
|
|
fprintf(out, "(%d)", contentIndex);
|
|
|
|
out << mRect;
|
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
// Output the children
|
|
|
|
if (mChildCount > 0) {
|
|
|
|
if (PR_TRUE==outputMe)
|
|
|
|
{
|
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]\n", mState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (nsIFrame* child = mFirstChild; child; NextChild(child, child)) {
|
|
|
|
child->List(out, aIndent + 1, aFilter);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (PR_TRUE==outputMe)
|
|
|
|
{
|
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]\n", mState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|