1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
#include "nsTableOuterFrame.h"
|
|
|
|
#include "nsTableFrame.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 "nsVoidArray.h"
|
1998-04-22 10:37:57 +04:00
|
|
|
#include "nsIPtr.h"
|
1998-07-02 21:40:56 +04:00
|
|
|
#include "prinrval.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1999-02-24 08:54:31 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-08-10 07:52:15 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIPresShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-01-28 05:19:45 +03:00
|
|
|
#define NS_TABLE_FRAME_CAPTION_LIST_INDEX 0
|
|
|
|
|
|
|
|
// caption frame
|
|
|
|
nsTableCaptionFrame::nsTableCaptionFrame()
|
|
|
|
{
|
|
|
|
// shrink wrap
|
|
|
|
SetFlags(NS_BLOCK_SPACE_MGR|NS_BLOCK_WRAP_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableCaptionFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::tableCaptionFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewTableCaptionFrame(nsIPresShell* aPresShell,
|
|
|
|
nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsTableCaptionFrame* it = new (aPresShell) nsTableCaptionFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OuterTableReflowState
|
|
|
|
|
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
|
1998-10-02 08:10:00 +04:00
|
|
|
const nsHTMLReflowState& reflowState;
|
1998-05-30 00:36:05 +04:00
|
|
|
|
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;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
OuterTableReflowState(nsIPresContext* aPresContext,
|
1998-10-02 08:10:00 +04:00
|
|
|
const nsHTMLReflowState& aReflowState)
|
1998-05-30 00:36:05 +04:00
|
|
|
: reflowState(aReflowState)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
pc = aPresContext;
|
1999-01-06 02:31:18 +03:00
|
|
|
availSize.width = reflowState.availableWidth;
|
|
|
|
availSize.height = reflowState.availableHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
prevMaxPosBottomMargin = 0;
|
|
|
|
prevMaxNegBottomMargin = 0;
|
|
|
|
y=0; // border/padding/margin???
|
1999-01-06 02:31:18 +03:00
|
|
|
unconstrainedWidth = PRBool(aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE);
|
|
|
|
unconstrainedHeight = PRBool(aReflowState.availableHeight == 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 ---------- */
|
|
|
|
|
1999-08-01 22:26:45 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsTableOuterFrame, nsHTMLContainerFrame)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsTableOuterFrame, nsHTMLContainerFrame)
|
|
|
|
|
|
|
|
nsresult nsTableOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(nsITableLayout::GetIID()))
|
|
|
|
{ // note there is no addref here, frames are not addref'd
|
|
|
|
*aInstancePtr = (void*)(nsITableLayout*)this;
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-01-28 18:43:25 +03:00
|
|
|
// tables change 0 width into auto, trees override this and do nothing
|
2000-01-28 05:19:45 +03:00
|
|
|
NS_IMETHODIMP
|
2000-01-28 18:43:25 +03:00
|
|
|
nsTableOuterFrame::AdjustZeroWidth()
|
1998-09-16 21:19:20 +04:00
|
|
|
{
|
2000-01-28 05:19:45 +03:00
|
|
|
// a 0 width table becomes auto
|
|
|
|
PRBool makeAuto = PR_FALSE;
|
|
|
|
nsStylePosition* position = (nsStylePosition*)mStyleContext->GetMutableStyleData(eStyleStruct_Position);
|
|
|
|
if (position->mWidth.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
if (0 >= position->mWidth.GetCoordValue()) {
|
|
|
|
makeAuto= PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (position->mWidth.GetUnit() == eStyleUnit_Percent) {
|
|
|
|
if (0.0f >= position->mWidth.GetPercentValue()) {
|
|
|
|
makeAuto= PR_TRUE;
|
1999-01-20 10:27:06 +03:00
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
}
|
|
|
|
|
2000-01-28 05:19:45 +03:00
|
|
|
if (makeAuto) {
|
|
|
|
position->mWidth = nsStyleCoord(eStyleUnit_Auto);
|
|
|
|
}
|
2000-01-28 18:43:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::Init(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent,
|
|
|
|
aContext, aPrevInFlow);
|
|
|
|
if (NS_FAILED(rv) || !mStyleContext) return rv;
|
|
|
|
AdjustZeroWidth();
|
|
|
|
|
2000-01-28 05:19:45 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::FirstChild(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFirstChild, "null OUT parameter pointer");
|
|
|
|
*aFirstChild = (nsLayoutAtoms::captionList == aListName)
|
|
|
|
? mCaptionFrame : mFrames.FirstChild();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::GetAdditionalChildListName(PRInt32 aIndex,
|
|
|
|
nsIAtom** aListName) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
*aListName = nsnull;
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_TABLE_FRAME_CAPTION_LIST_INDEX:
|
|
|
|
*aListName = nsLayoutAtoms::captionList;
|
|
|
|
NS_ADDREF(*aListName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
if (nsLayoutAtoms::captionList == aListName) {
|
|
|
|
// the frame constructor already checked for table-caption display type
|
|
|
|
mCaptionFrame = aChildList;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFrames.SetFrames(aChildList);
|
|
|
|
mInnerTableFrame = aChildList;
|
|
|
|
}
|
|
|
|
|
1998-09-16 21:19:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-10 07:52:15 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsTableOuterFrame::AppendFrames(nsIPresContext* aPresContext,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2000-01-28 05:19:45 +03:00
|
|
|
nsresult rv;
|
1999-08-10 07:52:15 +04:00
|
|
|
|
|
|
|
// We only have two child frames: the inner table and one caption frame.
|
|
|
|
// The inner frame is provided when we're initialized, and it cannot change
|
2000-01-28 05:19:45 +03:00
|
|
|
if (nsLayoutAtoms::captionList == aListName) {
|
1999-08-10 07:52:15 +04:00
|
|
|
NS_PRECONDITION(!mCaptionFrame, "already have a caption frame");
|
|
|
|
// We only support having a single caption frame
|
|
|
|
if (mCaptionFrame || (LengthOf(aFrameList) > 1)) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
} else {
|
|
|
|
// Insert the caption frame into the child list
|
|
|
|
mCaptionFrame = aFrameList;
|
|
|
|
|
|
|
|
// Reflow the new caption frame. It's already marked dirty, so generate a reflow
|
|
|
|
// command that tells us to reflow our dirty child frames
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, nsIReflowCommand::ReflowDirty);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_PRECONDITION(PR_FALSE, "unexpected child frame type");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsTableOuterFrame::InsertFrames(nsIPresContext* aPresContext,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aPrevFrame, "invalid previous frame");
|
|
|
|
return AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsTableOuterFrame::RemoveFrame(nsIPresContext* aPresContext,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2000-01-28 05:19:45 +03:00
|
|
|
nsresult rv;
|
1999-08-10 07:52:15 +04:00
|
|
|
|
|
|
|
// We only have two child frames: the inner table and one caption frame.
|
|
|
|
// The inner frame can't be removed so this should be the caption
|
2000-01-28 05:19:45 +03:00
|
|
|
NS_PRECONDITION(nsLayoutAtoms::captionList == aListName, "can't remove inner frame");
|
|
|
|
NS_PRECONDITION(aOldFrame == mCaptionFrame, "invalid caption frame");
|
1999-08-10 07:52:15 +04:00
|
|
|
|
|
|
|
// See if the caption's minimum width impacted the inner table
|
|
|
|
if (mMinCaptionWidth > mRect.width) {
|
|
|
|
// The old caption width had an effect on the inner table width so
|
|
|
|
// we're going to need to reflow it. Mark it dirty
|
|
|
|
nsFrameState frameState;
|
|
|
|
mInnerTableFrame->GetFrameState(&frameState);
|
|
|
|
frameState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mInnerTableFrame->SetFrameState(frameState);
|
|
|
|
}
|
|
|
|
|
2000-01-28 05:19:45 +03:00
|
|
|
// Remove the caption frame and destroy it
|
|
|
|
if (mCaptionFrame && (mCaptionFrame == aOldFrame)) {
|
|
|
|
mCaptionFrame->Destroy(aPresContext);
|
|
|
|
mCaptionFrame = nsnull;
|
|
|
|
mMinCaptionWidth = 0;
|
|
|
|
}
|
1999-08-10 07:52:15 +04:00
|
|
|
|
|
|
|
// Generate a reflow command so we get reflowed
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, nsIReflowCommand::ReflowDirty);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_METHOD nsTableOuterFrame::Paint(nsIPresContext* aPresContext,
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1999-04-04 04:06:48 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-04-14 00:24:54 +04:00
|
|
|
// for debug...
|
1999-03-26 03:39:35 +03:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
1998-04-14 00:24:54 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-01-28 05:19:45 +03:00
|
|
|
// the remaining code was copied from nsContainerFrame::PaintChildren since
|
|
|
|
// it only paints the primary child list
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
// Child elements have the opportunity to override the visibility property
|
|
|
|
// of their parent and display even if the parent is hidden
|
|
|
|
PRBool clipState;
|
|
|
|
|
|
|
|
// If overflow is hidden then set the clip rect so that children
|
|
|
|
// don't leak out of us
|
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(nsRect(0, 0, mRect.width, mRect.height),
|
|
|
|
nsClipCombine_kIntersect, clipState);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCaptionFrame) {
|
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect, mCaptionFrame, aWhichLayer);
|
|
|
|
}
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
while (nsnull != kid) {
|
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect, kid, aWhichLayer);
|
|
|
|
kid->GetNextSibling(&kid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
NS_IMETHODIMP nsTableOuterFrame::SetSelected(nsIPresContext* aPresContext,
|
|
|
|
nsIDOMRange *aRange,
|
|
|
|
PRBool aSelected,
|
|
|
|
nsSpread aSpread)
|
1999-05-20 04:52:00 +04:00
|
|
|
{
|
1999-10-26 08:44:41 +04:00
|
|
|
nsresult result = nsFrame::SetSelected(aPresContext, aRange,aSelected, aSpread);
|
1999-05-20 04:52:00 +04:00
|
|
|
if (NS_SUCCEEDED(result) && mInnerTableFrame)
|
1999-10-26 08:44:41 +04:00
|
|
|
return mInnerTableFrame->SetSelected(aPresContext, aRange,aSelected, aSpread);
|
1999-05-20 04:52:00 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-19 07:51:25 +04:00
|
|
|
PRBool nsTableOuterFrame::NeedsReflow(const nsHTMLReflowState& aReflowState)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRBool result=PR_TRUE;
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsnull != mInnerTableFrame) {
|
1999-08-19 07:51:25 +04:00
|
|
|
result = ((nsTableFrame *)mInnerTableFrame)->NeedsReflow(aReflowState);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
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
|
1998-10-08 19:34:48 +04:00
|
|
|
nsresult nsTableOuterFrame::RecoverState(OuterTableReflowState& aReflowState,
|
1998-06-19 04:34:12 +04:00
|
|
|
nsIFrame* aKidFrame)
|
|
|
|
{
|
1998-10-08 19:34:48 +04:00
|
|
|
#if 0
|
1998-06-22 09:34:17 +04:00
|
|
|
// Get aKidFrame's previous sibling
|
1998-06-19 04:34:12 +04:00
|
|
|
nsIFrame* prevKidFrame = nsnull;
|
1999-01-16 01:52:05 +03:00
|
|
|
for (nsIFrame* frame = mFrames.FirstChild(); frame != aKidFrame;) {
|
1998-06-19 04:34:12 +04:00
|
|
|
prevKidFrame = frame;
|
|
|
|
frame->GetNextSibling(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != prevKidFrame) {
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
// Set our running y-offset
|
|
|
|
prevKidFrame->GetRect(rect);
|
1998-10-08 19:34:48 +04:00
|
|
|
aReflowState.y = rect.YMost();
|
1998-06-19 04:34:12 +04:00
|
|
|
|
|
|
|
// Adjust the available space
|
1998-10-08 19:34:48 +04:00
|
|
|
if (PR_FALSE == aReflowState.unconstrainedHeight) {
|
|
|
|
aReflowState.availSize.height -= aReflowState.y;
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the previous frame's bottom margin
|
|
|
|
const nsStyleSpacing* kidSpacing;
|
1998-12-02 19:45:20 +03:00
|
|
|
prevKidFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)kidSpacing);
|
1998-06-19 04:34:12 +04:00
|
|
|
nsMargin margin;
|
|
|
|
kidSpacing->CalcMarginFor(prevKidFrame, margin);
|
|
|
|
if (margin.bottom < 0) {
|
1998-10-08 19:34:48 +04:00
|
|
|
aReflowState.prevMaxNegBottomMargin = -margin.bottom;
|
1998-06-19 04:34:12 +04:00
|
|
|
} else {
|
1998-10-08 19:34:48 +04:00
|
|
|
aReflowState.prevMaxPosBottomMargin = margin.bottom;
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-08 19:34:48 +04:00
|
|
|
#endif
|
|
|
|
|
1999-04-04 04:06:48 +04:00
|
|
|
aReflowState.y = 0;
|
1998-06-19 04:34:12 +04:00
|
|
|
|
|
|
|
// Set the inner table max size
|
|
|
|
nsSize innerTableSize(0,0);
|
|
|
|
|
|
|
|
mInnerTableFrame->GetSize(innerTableSize);
|
1998-10-08 19:34:48 +04:00
|
|
|
aReflowState.innerTableMaxSize.width = innerTableSize.width;
|
1999-01-06 02:31:18 +03:00
|
|
|
aReflowState.innerTableMaxSize.height = aReflowState.reflowState.availableHeight;
|
1998-06-19 04:34:12 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IncrementalReflow(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-06-19 04:34:12 +04:00
|
|
|
{
|
1998-10-01 08:46:11 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1998-10-08 19:34:48 +04:00
|
|
|
// determine if this frame is the target or not
|
1999-04-04 04:06:48 +04:00
|
|
|
nsIFrame* target=nsnull;
|
1998-10-08 19:34:48 +04:00
|
|
|
rv = aReflowState.reflowState.reflowCommand->GetTarget(target);
|
1999-04-04 04:06:48 +04:00
|
|
|
if ((PR_TRUE == NS_SUCCEEDED(rv)) && (nsnull != target)) {
|
|
|
|
if (this == target) {
|
1998-10-08 19:34:48 +04:00
|
|
|
rv = IR_TargetIsMe(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-08 19:34:48 +04:00
|
|
|
// Get the next frame in the reflow chain
|
|
|
|
nsIFrame* nextFrame;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetNext(nextFrame);
|
2000-01-27 01:11:47 +03:00
|
|
|
NS_ASSERTION(nextFrame, "next frame in reflow command is null");
|
1998-10-08 19:34:48 +04:00
|
|
|
|
|
|
|
// Recover our reflow state
|
|
|
|
RecoverState(aReflowState, nextFrame);
|
|
|
|
rv = IR_TargetIsChild(aPresContext, aDesiredSize, aReflowState, aStatus, nextFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_TargetIsChild(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
1999-04-04 04:06:48 +04:00
|
|
|
nsIFrame* aNextFrame)
|
1998-10-08 19:34:48 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-28 05:19:45 +03:00
|
|
|
if (!aNextFrame) {
|
|
|
|
// this will force Reflow to return the height of the last reflow rather than 0
|
|
|
|
aReflowState.y = mRect.height;
|
1999-07-02 09:28:32 +04:00
|
|
|
return NS_OK;
|
2000-01-28 05:19:45 +03:00
|
|
|
}
|
1999-07-02 09:28:32 +04:00
|
|
|
|
1999-04-04 04:06:48 +04:00
|
|
|
if (aNextFrame == mInnerTableFrame) {
|
1998-10-08 19:34:48 +04:00
|
|
|
rv = IR_TargetIsInnerTableFrame(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else if (aNextFrame==mCaptionFrame) {
|
1998-10-08 19:34:48 +04:00
|
|
|
rv = IR_TargetIsCaptionFrame(aPresContext, aDesiredSize, aReflowState, aStatus);
|
2000-01-11 18:55:31 +03:00
|
|
|
|
|
|
|
// If we're supposed to update our maximum width, then just use the inner
|
|
|
|
// table's maximum width
|
|
|
|
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
aDesiredSize.mMaximumWidth = mInnerTableMaximumWidth;
|
|
|
|
}
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-22 02:29:00 +04:00
|
|
|
const nsStyleDisplay* nextDisplay;
|
|
|
|
aNextFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)nextDisplay);
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_HEADER_GROUP==nextDisplay->mDisplay ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP==nextDisplay->mDisplay ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_ROW_GROUP ==nextDisplay->mDisplay ||
|
1999-04-04 04:06:48 +04:00
|
|
|
NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP==nextDisplay->mDisplay) {
|
1998-10-22 02:29:00 +04:00
|
|
|
rv = IR_TargetIsInnerTableFrame(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-22 02:29:00 +04:00
|
|
|
NS_ASSERTION(PR_FALSE, "illegal next frame in incremental reflow.");
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-08 19:34:48 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_TargetIsInnerTableFrame(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = IR_InnerTableReflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
return rv;
|
|
|
|
}
|
1998-06-19 09:21:45 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_TargetIsCaptionFrame(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-04-04 04:06:48 +04:00
|
|
|
PRBool innerTableNeedsReflow = PR_FALSE;
|
1998-10-09 23:59:45 +04:00
|
|
|
// remember the old width and height
|
|
|
|
nsRect priorCaptionRect;
|
|
|
|
mCaptionFrame->GetRect(priorCaptionRect);
|
|
|
|
// if the reflow type is a style change, also remember the prior style
|
|
|
|
nsIReflowCommand::ReflowType reflowCommandType;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetType(reflowCommandType);
|
1999-09-02 04:07:14 +04:00
|
|
|
const nsStyleTable* priorCaptionTableStyle = nsnull;
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsIReflowCommand::StyleChanged == reflowCommandType) {
|
1999-09-02 04:07:14 +04:00
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Table, ((const nsStyleStruct *&)priorCaptionTableStyle));
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-09 23:59:45 +04:00
|
|
|
|
|
|
|
// pass along the reflow command to the caption
|
|
|
|
nsSize captionMES(0,0);
|
|
|
|
nsHTMLReflowMetrics captionSize(&captionMES);
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState captionReflowState(aPresContext, aReflowState.reflowState, mCaptionFrame,
|
|
|
|
nsSize(mRect.width, aReflowState.reflowState.availableHeight),
|
|
|
|
aReflowState.reflowState.reason);
|
|
|
|
captionReflowState.reflowCommand = aReflowState.reflowState.reflowCommand;
|
1999-11-19 18:33:29 +03:00
|
|
|
|
|
|
|
rv = ReflowChild(mCaptionFrame, aPresContext, captionSize, captionReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
mCaptionFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-04-04 04:06:48 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-10-09 23:59:45 +04:00
|
|
|
return rv;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
if (mMinCaptionWidth != captionMES.width) {
|
|
|
|
// set the new caption min width, and set state to reflow the inner table if necessary
|
1998-10-09 23:59:45 +04:00
|
|
|
mMinCaptionWidth = captionMES.width;
|
1999-04-04 04:06:48 +04:00
|
|
|
if (mMinCaptionWidth > mRect.width) {
|
1998-10-09 23:59:45 +04:00
|
|
|
innerTableNeedsReflow=PR_TRUE;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-09 23:59:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if the caption alignment changed axis
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsIReflowCommand::StyleChanged == reflowCommandType) {
|
1999-09-02 04:07:14 +04:00
|
|
|
const nsStyleTable* captionTableStyle;
|
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Table, ((const nsStyleStruct *&)captionTableStyle));
|
|
|
|
if (PR_TRUE == IR_CaptionChangedAxis(priorCaptionTableStyle, captionTableStyle)) {
|
1998-10-09 23:59:45 +04:00
|
|
|
innerTableNeedsReflow=PR_TRUE;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-09 23:59:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we've determined that the inner table needs to be reflowed, do it here
|
|
|
|
nsSize innerTableSize;
|
1999-04-04 04:06:48 +04:00
|
|
|
if (PR_TRUE == innerTableNeedsReflow) {
|
1998-10-09 23:59:45 +04:00
|
|
|
// Compute the width to use for the table. In the case of an auto sizing
|
|
|
|
// table this represents the maximum available width
|
2000-01-13 08:29:38 +03:00
|
|
|
nscoord tableWidth = ((nsTableFrame*)mInnerTableFrame)->CalcBorderBoxWidth(aReflowState.reflowState);
|
1998-10-09 23:59:45 +04:00
|
|
|
|
|
|
|
// If the caption max element size is larger, then use it instead.
|
|
|
|
// XXX: caption align = left|right ignored here!
|
|
|
|
if (mMinCaptionWidth > tableWidth) {
|
|
|
|
tableWidth = mMinCaptionWidth;
|
|
|
|
}
|
|
|
|
nsHTMLReflowMetrics innerSize(aDesiredSize.maxElementSize);
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState innerReflowState(aPresContext, aReflowState.reflowState, mInnerTableFrame,
|
|
|
|
nsSize(tableWidth, aReflowState.reflowState.availableHeight),
|
|
|
|
eReflowReason_Resize);
|
1999-11-19 18:33:29 +03:00
|
|
|
rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
mInnerTableFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-04-04 04:06:48 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-10-09 23:59:45 +04:00
|
|
|
return rv;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-09 23:59:45 +04:00
|
|
|
innerTableSize.SizeTo(innerSize.width, innerSize.height);
|
|
|
|
// set maxElementSize width if requested
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
1998-10-09 23:59:45 +04:00
|
|
|
((nsTableFrame *)mInnerTableFrame)->SetMaxElementSize(aDesiredSize.maxElementSize);
|
1999-04-04 04:06:48 +04:00
|
|
|
if (mMinCaptionWidth > aDesiredSize.maxElementSize->width) {
|
1998-10-09 23:59:45 +04:00
|
|
|
aDesiredSize.maxElementSize->width = mMinCaptionWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-04 04:06:48 +04:00
|
|
|
else {
|
1998-10-09 23:59:45 +04:00
|
|
|
nsRect innerTableRect;
|
|
|
|
mInnerTableFrame->GetRect(innerTableRect);
|
|
|
|
innerTableSize.SizeTo(innerTableRect.width, innerTableRect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// regardless of what we've done up to this point, place the caption and inner table
|
1999-11-24 09:03:41 +03:00
|
|
|
rv = SizeAndPlaceChildren(aPresContext, innerTableSize,
|
1998-10-09 23:59:45 +04:00
|
|
|
nsSize (captionSize.width, captionSize.height),
|
|
|
|
aReflowState);
|
|
|
|
|
1998-10-08 19:34:48 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-06-19 09:21:45 +04:00
|
|
|
|
1999-08-10 07:52:15 +04:00
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsTableOuterFrame::IR_ReflowDirty(nsIPresContext* aPresContext,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-10-08 19:34:48 +04:00
|
|
|
{
|
1999-08-10 07:52:15 +04:00
|
|
|
nsFrameState frameState;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// See if the caption frame is dirty. This would be because of a newly
|
|
|
|
// inserted caption
|
|
|
|
if (mCaptionFrame) {
|
|
|
|
mCaptionFrame->GetFrameState(&frameState);
|
|
|
|
if (frameState & NS_FRAME_IS_DIRTY) {
|
|
|
|
rv = IR_CaptionInserted(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
|
|
|
|
// Repaint our entire bounds
|
|
|
|
// XXX Improve this...
|
1999-11-24 09:03:41 +03:00
|
|
|
Invalidate(aPresContext, nsRect(0, 0, mRect.width, mRect.height));
|
1999-08-10 07:52:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the inner table frame is dirty
|
|
|
|
mInnerTableFrame->GetFrameState(&frameState);
|
|
|
|
if (frameState & NS_FRAME_IS_DIRTY) {
|
1999-08-02 02:01:37 +04:00
|
|
|
// Inner table is dirty so reflow it. Change the reflow state and set the
|
|
|
|
// reason to resize reflow.
|
|
|
|
((nsHTMLReflowState&)aReflowState.reflowState).reason = eReflowReason_Resize;
|
|
|
|
((nsHTMLReflowState&)aReflowState.reflowState).reflowCommand = nsnull;
|
|
|
|
|
|
|
|
// Get the inner table frame's current bounds. We'll use that when
|
|
|
|
// repainting it
|
|
|
|
// XXX It should really do the repainting, but because it think it's
|
|
|
|
// getting a resize reflow it won't know to...
|
|
|
|
nsRect dirtyRect;
|
|
|
|
mInnerTableFrame->GetRect(dirtyRect);
|
|
|
|
rv = IR_InnerTableReflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
|
|
|
|
// Repaint the inner table frame's entire visible area
|
|
|
|
dirtyRect.x = dirtyRect.y = 0;
|
1999-11-24 09:03:41 +03:00
|
|
|
Invalidate(aPresContext, dirtyRect);
|
1999-08-02 02:01:37 +04:00
|
|
|
|
1999-08-10 07:52:15 +04:00
|
|
|
} else if (!mCaptionFrame) {
|
|
|
|
// The inner table isn't dirty so we don't need to reflow it, but make
|
|
|
|
// sure it's placed correctly. It could be that we're dirty because the
|
|
|
|
// caption was removed
|
1999-11-24 09:03:41 +03:00
|
|
|
mInnerTableFrame->MoveTo(aPresContext, 0,0);
|
1999-08-10 07:52:15 +04:00
|
|
|
|
|
|
|
// Update our state so we calculate our desired size correctly
|
|
|
|
nsRect innerRect;
|
|
|
|
mInnerTableFrame->GetRect(innerRect);
|
|
|
|
aReflowState.innerTableMaxSize.width = innerRect.width;
|
|
|
|
aReflowState.y = innerRect.height;
|
|
|
|
|
|
|
|
// Repaint our entire bounds
|
|
|
|
// XXX Improve this...
|
1999-11-24 09:03:41 +03:00
|
|
|
Invalidate(aPresContext, nsRect(0, 0, mRect.width, mRect.height));
|
1998-06-19 09:21:45 +04:00
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1999-08-10 07:52:15 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-06-23 09:43:27 +04:00
|
|
|
|
1999-08-10 07:52:15 +04:00
|
|
|
// IR_TargetIsMe is free to foward the request to the inner table frame
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_TargetIsMe(nsIPresContext* aPresContext,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIReflowCommand::ReflowType type;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetType(type);
|
|
|
|
nsIFrame* objectFrame;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetChildFrame(objectFrame);
|
|
|
|
switch (type) {
|
|
|
|
case nsIReflowCommand::ReflowDirty:
|
1999-08-19 23:52:37 +04:00
|
|
|
rv = IR_ReflowDirty(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1998-10-08 19:34:48 +04:00
|
|
|
break;
|
1998-09-30 22:11:48 +04:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
case nsIReflowCommand::StyleChanged :
|
1998-10-30 10:57:44 +03:00
|
|
|
rv = IR_InnerTableReflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1998-10-08 19:34:48 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIReflowCommand::ContentChanged :
|
|
|
|
NS_ASSERTION(PR_FALSE, "illegal reflow type: ContentChanged");
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
break;
|
1998-10-01 08:46:11 +04:00
|
|
|
|
1999-03-05 07:19:09 +03:00
|
|
|
default:
|
1999-08-10 07:52:15 +04:00
|
|
|
NS_NOTYETIMPLEMENTED("unexpected reflow command type");
|
1998-10-08 19:34:48 +04:00
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_InnerTableReflow(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-09-02 04:07:14 +04:00
|
|
|
const nsStyleTable* captionTableStyle=nsnull;
|
1998-10-08 19:34:48 +04:00
|
|
|
nsMargin captionMargin;
|
|
|
|
// remember the old width and height
|
|
|
|
nsRect priorInnerTableRect;
|
|
|
|
mInnerTableFrame->GetRect(priorInnerTableRect);
|
|
|
|
// pass along the reflow command to the inner table
|
|
|
|
nsHTMLReflowMetrics innerSize(aDesiredSize.maxElementSize);
|
1999-01-06 02:31:18 +03:00
|
|
|
nscoord tableMaxWidth = PR_MAX(aReflowState.reflowState.availableWidth, mMinCaptionWidth);
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState innerReflowState(aPresContext, aReflowState.reflowState, mInnerTableFrame,
|
1999-01-06 02:31:18 +03:00
|
|
|
nsSize(tableMaxWidth, aReflowState.reflowState.availableHeight));
|
2000-01-10 06:04:05 +03:00
|
|
|
|
2000-01-11 22:49:04 +03:00
|
|
|
// When the above reflow state is constructed, mComputedWidth and mComputedHeight get set
|
|
|
|
// to the table's styled width and height. Flex from XUL boxes can make the styled #s
|
|
|
|
// inaccurate, which means that mComputedWidth and mComputedHeight from the parent
|
|
|
|
// reflow state should be used instead.
|
2000-01-10 06:04:05 +03:00
|
|
|
|
2000-01-11 22:49:04 +03:00
|
|
|
// The following function will patch the reflow state so that trees behave properly inside boxes.
|
|
|
|
// This might work for tables as well, but until regression tests can be run to make sure,
|
|
|
|
// I'm holding off on patching tables.
|
2000-01-10 06:04:05 +03:00
|
|
|
FixBadReflowState(aReflowState.reflowState, innerReflowState);
|
|
|
|
|
2000-01-11 18:55:31 +03:00
|
|
|
// If we're supposed to update our maximum width, then ask the child to
|
|
|
|
// as well
|
|
|
|
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
innerSize.mFlags |= NS_REFLOW_CALC_MAX_WIDTH;
|
|
|
|
}
|
1999-11-19 18:33:29 +03:00
|
|
|
rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
mInnerTableFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
2000-01-11 18:55:31 +03:00
|
|
|
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
aDesiredSize.mMaximumWidth = innerSize.mMaximumWidth;
|
|
|
|
|
|
|
|
// Update the cached value
|
|
|
|
mInnerTableMaximumWidth = innerSize.mMaximumWidth;
|
|
|
|
}
|
|
|
|
|
1998-10-08 19:34:48 +04:00
|
|
|
// if there is a caption and the width or height of the inner table changed from a successful reflow,
|
|
|
|
// then reflow or move the caption as needed
|
1999-04-04 04:06:48 +04:00
|
|
|
if ((nsnull != mCaptionFrame) && (PR_TRUE==NS_SUCCEEDED(rv))) {
|
1998-10-08 19:34:48 +04:00
|
|
|
// remember the old caption height
|
|
|
|
nsRect oldCaptionRect;
|
|
|
|
mCaptionFrame->GetRect(oldCaptionRect);
|
|
|
|
nsHTMLReflowMetrics captionSize(nsnull); // don't ask for MES, it hasn't changed
|
1999-04-04 04:06:48 +04:00
|
|
|
PRBool captionDimChanged = PR_FALSE;
|
|
|
|
PRBool captionWasReflowed = PR_FALSE;
|
|
|
|
if (priorInnerTableRect.width != innerSize.width) {
|
|
|
|
// the table width changed, so reflow the caption
|
|
|
|
nsHTMLReflowState captionReflowState(aPresContext, aReflowState.reflowState, mCaptionFrame,
|
|
|
|
nsSize(innerSize.width, aReflowState.reflowState.availableHeight),
|
|
|
|
eReflowReason_Resize);
|
1999-10-30 06:52:11 +04:00
|
|
|
// reflow the caption
|
|
|
|
mCaptionFrame->WillReflow(aPresContext);
|
|
|
|
rv = mCaptionFrame->Reflow(aPresContext, captionSize, captionReflowState, aStatus);
|
1999-11-19 18:33:29 +03:00
|
|
|
mCaptionFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-10-30 06:52:11 +04:00
|
|
|
captionWasReflowed = PR_TRUE;
|
|
|
|
if ((oldCaptionRect.height!=captionSize.height) ||
|
|
|
|
(oldCaptionRect.width!=captionSize.width)) {
|
|
|
|
captionDimChanged=PR_TRUE;
|
1998-10-08 19:34:48 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-09 23:59:45 +04:00
|
|
|
// XXX: should just call SizeAndPlaceChildren regardless
|
1998-10-08 19:34:48 +04:00
|
|
|
// find where to place the caption
|
|
|
|
const nsStyleSpacing* spacing;
|
1998-12-02 19:45:20 +03:00
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
|
1998-10-08 19:34:48 +04:00
|
|
|
spacing->CalcMarginFor(mCaptionFrame, captionMargin);
|
1999-09-02 04:07:14 +04:00
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Text, ((const nsStyleStruct *&)captionTableStyle));
|
1999-04-04 04:06:48 +04:00
|
|
|
if ((priorInnerTableRect.height!=innerSize.height) ||
|
|
|
|
(PR_TRUE==captionDimChanged)) {
|
1998-10-08 19:34:48 +04:00
|
|
|
// Compute the caption's y-origin
|
|
|
|
nscoord captionY = captionMargin.top;
|
1999-09-02 04:07:14 +04:00
|
|
|
if (NS_SIDE_BOTTOM == captionTableStyle->mCaptionSide) {
|
1998-10-08 19:34:48 +04:00
|
|
|
captionY += innerSize.height;
|
|
|
|
}
|
|
|
|
// Place the caption
|
|
|
|
nsRect captionRect(captionMargin.left, captionY, 0, 0);
|
1999-04-04 04:06:48 +04:00
|
|
|
if (PR_TRUE==captionWasReflowed) {
|
1998-10-08 19:34:48 +04:00
|
|
|
captionRect.SizeTo(captionSize.width, captionSize.height);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-08 19:34:48 +04:00
|
|
|
captionRect.SizeTo(oldCaptionRect.width, oldCaptionRect.height);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1999-11-24 09:03:41 +03:00
|
|
|
mCaptionFrame->SetRect(aPresContext, captionRect);
|
1998-10-08 19:34:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if anything above failed, we just want to return an error at this point
|
1999-04-04 04:06:48 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-10-08 19:34:48 +04:00
|
|
|
return rv;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-08 19:34:48 +04:00
|
|
|
// Place the inner table
|
|
|
|
nsRect updatedCaptionRect(0,0,0,0);
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsnull != mCaptionFrame) {
|
1998-10-08 19:34:48 +04:00
|
|
|
mCaptionFrame->GetRect(updatedCaptionRect);
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
1998-10-08 19:34:48 +04:00
|
|
|
nscoord innerY; // innerY is the y-offset of the inner table
|
1999-04-04 04:06:48 +04:00
|
|
|
if (nsnull != mCaptionFrame) {
|
|
|
|
// factor in caption and it's margin
|
1999-09-02 04:07:14 +04:00
|
|
|
// we're guaranteed that captionMargin and captionTableStyle are set at this point
|
|
|
|
if (NS_SIDE_BOTTOM == captionTableStyle->mCaptionSide) {
|
1999-04-04 04:06:48 +04:00
|
|
|
// bottom caption
|
1998-10-08 19:34:48 +04:00
|
|
|
innerY = 0; // the inner table goes at the top of the outer table
|
|
|
|
// the total v-space consumed is the inner table height + the caption height + the margin between them
|
|
|
|
aReflowState.y = innerSize.height + updatedCaptionRect.YMost() + captionMargin.top;
|
|
|
|
}
|
1999-04-04 04:06:48 +04:00
|
|
|
else { // top caption
|
1998-10-08 19:34:48 +04:00
|
|
|
innerY = updatedCaptionRect.YMost() + captionMargin.bottom;
|
|
|
|
// the total v-space consumed is the inner table height + the caption height + the margin between them
|
|
|
|
aReflowState.y = innerY + innerSize.height;
|
|
|
|
}
|
|
|
|
}
|
1999-04-04 04:06:48 +04:00
|
|
|
else { // no caption
|
1998-10-08 19:34:48 +04:00
|
|
|
innerY=0;
|
|
|
|
aReflowState.y = innerSize.height;
|
|
|
|
}
|
|
|
|
nsRect innerRect(0, innerY, innerSize.width, innerSize.height);
|
1999-11-24 09:03:41 +03:00
|
|
|
mInnerTableFrame->SetRect(aPresContext, innerRect);
|
1998-10-09 23:59:45 +04:00
|
|
|
|
|
|
|
aReflowState.innerTableMaxSize.width = innerSize.width;
|
1998-10-08 19:34:48 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* the only difference between an insert and a replace is a replace
|
|
|
|
checks the old maxElementSize and reflows the table only if it
|
|
|
|
has changed
|
|
|
|
*/
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult nsTableOuterFrame::IR_CaptionInserted(nsIPresContext* aPresContext,
|
1998-10-08 19:34:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
OuterTableReflowState& aReflowState,
|
1999-08-10 07:52:15 +04:00
|
|
|
nsReflowStatus& aStatus)
|
1999-08-19 23:52:37 +04:00
|
|
|
{
|
1998-10-08 19:34:48 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// reflow the caption frame, getting it's MES
|
|
|
|
nsSize maxElementSize;
|
|
|
|
nsHTMLReflowMetrics captionSize(&maxElementSize);
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState captionReflowState(aPresContext, aReflowState.reflowState, mCaptionFrame,
|
1999-01-06 02:31:18 +03:00
|
|
|
nsSize(mRect.width, aReflowState.reflowState.availableHeight),
|
1998-10-08 19:34:48 +04:00
|
|
|
eReflowReason_Initial);
|
1999-10-30 06:52:11 +04:00
|
|
|
// initial reflow of the caption
|
|
|
|
mCaptionFrame->WillReflow(aPresContext);
|
|
|
|
rv = mCaptionFrame->Reflow(aPresContext, captionSize, captionReflowState, aStatus);
|
|
|
|
mMinCaptionWidth = maxElementSize.width;
|
|
|
|
// XXX: caption align = left|right ignored here!
|
|
|
|
// if the caption's MES > table width, reflow the inner table
|
|
|
|
nsHTMLReflowMetrics innerSize(aDesiredSize.maxElementSize);
|
|
|
|
if (mMinCaptionWidth > mRect.width) {
|
|
|
|
nsHTMLReflowState innerReflowState(aPresContext, aReflowState.reflowState, mInnerTableFrame,
|
|
|
|
nsSize(mMinCaptionWidth, aReflowState.reflowState.availableHeight),
|
|
|
|
eReflowReason_Resize);
|
1999-11-19 18:33:29 +03:00
|
|
|
rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
mInnerTableFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-10-30 06:52:11 +04:00
|
|
|
}
|
|
|
|
else { // set innerSize as if the inner table were reflowed
|
|
|
|
innerSize.height = mRect.height;
|
|
|
|
innerSize.width = mRect.width;
|
|
|
|
}
|
|
|
|
// set maxElementSize width if requested
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
((nsTableFrame *)mInnerTableFrame)->SetMaxElementSize(aDesiredSize.maxElementSize);
|
|
|
|
if (mMinCaptionWidth > aDesiredSize.maxElementSize->width) {
|
|
|
|
aDesiredSize.maxElementSize->width = mMinCaptionWidth;
|
1998-10-08 19:34:48 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-30 06:52:11 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
rv = SizeAndPlaceChildren(aPresContext,
|
1999-10-30 06:52:11 +04:00
|
|
|
nsSize (innerSize.width, innerSize.height),
|
|
|
|
nsSize (captionSize.width, captionSize.height),
|
|
|
|
aReflowState);
|
1998-10-08 19:34:48 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-02 04:07:14 +04:00
|
|
|
PRBool nsTableOuterFrame::IR_CaptionChangedAxis(const nsStyleTable* aOldStyle,
|
|
|
|
const nsStyleTable* aNewStyle) const
|
1998-10-09 23:59:45 +04:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
//XXX: write me to support left|right captions!
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
nsresult nsTableOuterFrame::SizeAndPlaceChildren(nsIPresContext* aPresContext,
|
|
|
|
const nsSize& aInnerSize,
|
1999-04-04 04:06:48 +04:00
|
|
|
const nsSize& aCaptionSize,
|
|
|
|
OuterTableReflowState& aReflowState)
|
1998-10-09 23:59:45 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// find where to place the caption
|
|
|
|
nsMargin captionMargin;
|
|
|
|
const nsStyleSpacing* spacing;
|
1998-12-02 19:45:20 +03:00
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
|
1998-10-09 23:59:45 +04:00
|
|
|
spacing->CalcMarginFor(mCaptionFrame, captionMargin);
|
|
|
|
// Compute the caption's y-origin
|
|
|
|
nscoord captionY = captionMargin.top;
|
1999-09-02 04:07:14 +04:00
|
|
|
const nsStyleTable* captionTableStyle;
|
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Table, ((const nsStyleStruct *&)captionTableStyle));
|
|
|
|
if (NS_SIDE_BOTTOM == captionTableStyle->mCaptionSide) {
|
1998-10-09 23:59:45 +04:00
|
|
|
captionY += aInnerSize.height;
|
|
|
|
}
|
|
|
|
// Place the caption
|
|
|
|
nsRect captionRect(captionMargin.left, captionY, 0, 0);
|
|
|
|
captionRect.SizeTo(aCaptionSize.width, aCaptionSize.height);
|
1999-10-26 08:44:41 +04:00
|
|
|
mCaptionFrame->SetRect(aPresContext, captionRect);
|
1998-10-09 23:59:45 +04:00
|
|
|
|
|
|
|
// Place the inner table
|
|
|
|
nscoord innerY;
|
1999-09-02 04:07:14 +04:00
|
|
|
if (NS_SIDE_BOTTOM == captionTableStyle->mCaptionSide) {
|
1999-04-04 04:06:48 +04:00
|
|
|
// bottom caption
|
1998-10-09 23:59:45 +04:00
|
|
|
innerY = 0;
|
|
|
|
aReflowState.y = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
}
|
1999-04-04 04:06:48 +04:00
|
|
|
else { // top caption
|
1998-10-09 23:59:45 +04:00
|
|
|
innerY = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
aReflowState.y = innerY + aInnerSize.height;
|
|
|
|
}
|
|
|
|
nsRect innerRect(0, innerY, aInnerSize.width, aInnerSize.height);
|
1999-10-26 08:44:41 +04:00
|
|
|
mInnerTableFrame->SetRect(aPresContext, innerRect);
|
1998-10-09 23:59:45 +04:00
|
|
|
aReflowState.innerTableMaxSize.width = aInnerSize.width;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-09 18:30:34 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_METHOD nsTableOuterFrame::Reflow(nsIPresContext* aPresContext,
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
1998-10-02 08:10:00 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1999-04-04 04:06:48 +04:00
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-08-27 08:29:05 +04:00
|
|
|
if (nsDebugTable::gRflTableOuter) nsTableFrame::DebugReflow("TO::Rfl en", this, &aReflowState, nsnull);
|
1998-10-09 23:59:45 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-06-23 01:59:43 +04:00
|
|
|
// Initialize out parameters
|
1999-04-04 04:06:48 +04:00
|
|
|
aDesiredSize.width = 0;
|
1998-10-08 19:34:48 +04:00
|
|
|
aDesiredSize.height = 0;
|
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-10-08 19:34:48 +04:00
|
|
|
OuterTableReflowState state(aPresContext, aReflowState);
|
1998-06-19 04:34:12 +04:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
1998-10-09 23:59:45 +04:00
|
|
|
rv = IncrementalReflow(aPresContext, aDesiredSize, state, aStatus);
|
1998-06-19 04:34:12 +04:00
|
|
|
} else {
|
1998-06-23 01:59:43 +04:00
|
|
|
if (eReflowReason_Initial == aReflowState.reason) {
|
|
|
|
// Set up our kids. They're already present, on an overflow list,
|
|
|
|
// or there are none so we'll create them now
|
1999-11-24 09:03:41 +03:00
|
|
|
MoveOverflowToChildList(aPresContext);
|
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-10-01 08:46:11 +04:00
|
|
|
nsSize maxElementSize;
|
|
|
|
nsHTMLReflowMetrics captionSize(&maxElementSize);
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState captionReflowState(aPresContext, aReflowState, mCaptionFrame,
|
1998-10-01 08:46:11 +04:00
|
|
|
nsSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
|
|
|
|
eReflowReason_Initial);
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
mCaptionFrame->WillReflow(aPresContext);
|
|
|
|
rv = mCaptionFrame->Reflow(aPresContext, captionSize, captionReflowState, aStatus);
|
1999-11-19 18:33:29 +03:00
|
|
|
mCaptionFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-10-30 06:52:11 +04:00
|
|
|
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-09-20 08:50:08 +04:00
|
|
|
// At this point, we must have an inner table frame, and we might have a caption
|
1999-01-16 01:52:05 +03:00
|
|
|
NS_ASSERTION(mFrames.NotEmpty(), "no children");
|
1998-07-09 00:21:17 +04:00
|
|
|
NS_ASSERTION(nsnull != mInnerTableFrame, "no mInnerTableFrame");
|
1998-07-02 21:40:56 +04:00
|
|
|
|
2000-01-03 01:55:48 +03:00
|
|
|
nscoord availWidth = aReflowState.availableWidth;
|
1998-07-09 18:30:34 +04:00
|
|
|
|
|
|
|
// If the caption max element size is larger, then use it instead.
|
1998-10-08 19:34:48 +04:00
|
|
|
// XXX: caption align = left|right ignored here!
|
2000-01-03 01:55:48 +03:00
|
|
|
if (mMinCaptionWidth > availWidth) {
|
|
|
|
availWidth = mMinCaptionWidth;
|
1998-07-09 18:30:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// First reflow the inner table
|
2000-01-03 01:55:48 +03:00
|
|
|
nsHTMLReflowState innerReflowState(aPresContext, aReflowState, mInnerTableFrame,
|
|
|
|
nsSize(availWidth, aReflowState.availableHeight));
|
|
|
|
innerReflowState.mComputedWidth = PR_MAX(aReflowState.mComputedWidth, mMinCaptionWidth);
|
1999-08-28 01:15:21 +04:00
|
|
|
innerReflowState.mComputedHeight = aReflowState.mComputedHeight;
|
2000-01-03 01:55:48 +03:00
|
|
|
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics innerSize(aDesiredSize.maxElementSize);
|
1999-11-19 18:33:29 +03:00
|
|
|
// XXX To do this efficiently we really need to know where the inner
|
|
|
|
// table will be placed. In the case of a top caption that means
|
|
|
|
// reflowing the caption first and getting its desired height...
|
|
|
|
rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState,
|
|
|
|
0, 0, 0, aStatus);
|
1998-10-06 04:27:22 +04:00
|
|
|
|
2000-01-11 18:55:31 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == innerReflowState.availableWidth) {
|
|
|
|
// Remember the inner table's maximum width
|
|
|
|
mInnerTableMaximumWidth = innerSize.width;
|
|
|
|
}
|
|
|
|
|
1998-10-06 04:27:22 +04:00
|
|
|
// 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
|
1999-11-19 18:33:29 +03:00
|
|
|
nscoord innerY = 0;
|
1998-07-09 18:30:34 +04:00
|
|
|
if (nsnull != mCaptionFrame) {
|
|
|
|
// Get the caption's margin
|
|
|
|
nsMargin captionMargin;
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
|
1998-12-02 19:45:20 +03:00
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing);
|
1998-07-09 18:30:34 +04:00
|
|
|
spacing->CalcMarginFor(mCaptionFrame, captionMargin);
|
|
|
|
|
|
|
|
// Compute the caption's y-origin
|
|
|
|
nscoord captionY = captionMargin.top;
|
1999-09-02 04:07:14 +04:00
|
|
|
const nsStyleTable* captionTableStyle;
|
|
|
|
mCaptionFrame->GetStyleData(eStyleStruct_Table, ((const nsStyleStruct *&)captionTableStyle));
|
|
|
|
if (NS_SIDE_BOTTOM == captionTableStyle->mCaptionSide) {
|
1998-07-09 18:30:34 +04:00
|
|
|
captionY += innerSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow the caption. Let it be as high as it wants
|
1999-04-04 04:06:48 +04:00
|
|
|
nsHTMLReflowState captionReflowState(aPresContext, state.reflowState, mCaptionFrame,
|
1998-10-02 08:10:00 +04:00
|
|
|
nsSize(innerSize.width, NS_UNCONSTRAINEDSIZE),
|
|
|
|
eReflowReason_Resize);
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics captionSize(nsnull);
|
|
|
|
nsRect captionRect(captionMargin.left, captionY, 0, 0);
|
1999-10-30 06:52:11 +04:00
|
|
|
nsReflowStatus captionStatus;
|
1998-10-01 08:46:11 +04:00
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
ReflowChild(mCaptionFrame, aPresContext, captionSize, captionReflowState,
|
|
|
|
captionRect.x, captionRect.y, 0, captionStatus);
|
1999-10-30 06:52:11 +04:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(captionStatus), "unexpected reflow status");
|
1998-10-01 08:46:11 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// XXX If the height is constrained then we need to check whether the inner
|
|
|
|
// table still fits...
|
1998-10-01 08:46:11 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Place the caption
|
|
|
|
captionRect.SizeTo(captionSize.width, captionSize.height);
|
1999-11-19 18:33:29 +03:00
|
|
|
FinishReflowChild(mCaptionFrame, aPresContext, captionSize,
|
|
|
|
captionRect.x, captionRect.y, 0);
|
1998-07-09 18:30:34 +04:00
|
|
|
|
|
|
|
// Place the inner table
|
1999-09-02 04:07:14 +04:00
|
|
|
if (NS_SIDE_BOTTOM != captionTableStyle->mCaptionSide) {
|
1998-09-20 08:50:08 +04:00
|
|
|
// top caption
|
1998-07-09 18:30:34 +04:00
|
|
|
innerY = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
state.y = innerY + innerSize.height;
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-09-20 08:50:08 +04:00
|
|
|
// bottom caption
|
1999-04-04 04:06:48 +04:00
|
|
|
innerY = 0;
|
1998-07-09 18:30:34 +04:00
|
|
|
state.y = captionRect.YMost() + captionMargin.bottom;
|
|
|
|
}
|
|
|
|
|
1999-04-04 04:06:48 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-11-19 18:33:29 +03:00
|
|
|
// Place the inner table at 0
|
|
|
|
innerY = 0;
|
1998-07-09 18:30:34 +04:00
|
|
|
state.y = innerSize.height;
|
1998-06-19 04:34:12 +04:00
|
|
|
}
|
1999-11-19 18:33:29 +03:00
|
|
|
|
|
|
|
// Finish the inner table reflow
|
|
|
|
FinishReflowChild(mInnerTableFrame, aPresContext, innerSize,
|
|
|
|
0, innerY, 0);
|
1998-06-19 09:21:45 +04:00
|
|
|
}
|
1998-06-19 04:34:12 +04:00
|
|
|
|
1998-07-09 18:30:34 +04:00
|
|
|
// Return our desired rect
|
1999-04-04 04:06:48 +04:00
|
|
|
aDesiredSize.width = state.innerTableMaxSize.width;
|
|
|
|
aDesiredSize.height = state.y;
|
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
1998-07-03 01:24:56 +04:00
|
|
|
aDesiredSize.descent = 0;
|
1998-06-19 09:21:45 +04:00
|
|
|
|
2000-01-03 01:55:48 +03:00
|
|
|
if (nsDebugTable::gRflTableOuter) nsTableFrame::DebugReflow("TO::Rfl ex", this, nsnull, &aDesiredSize, aStatus);
|
1998-10-09 23:59:45 +04:00
|
|
|
return rv;
|
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
|
|
|
{
|
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
|
|
|
|
*/
|
1999-11-24 09:03:41 +03:00
|
|
|
void nsTableOuterFrame::DeleteChildsNextInFlow(nsIPresContext* aPresContext,
|
1999-04-04 04:06:48 +04:00
|
|
|
nsIFrame* aChild)
|
1998-04-17 02:21:32 +04:00
|
|
|
{
|
1999-04-13 03:46:02 +04:00
|
|
|
NS_PRECONDITION(mFrames.ContainsFrame(aChild), "bad geometric parent");
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
|
1999-02-24 07:48:08 +03:00
|
|
|
aChild->GetNextInFlow(&nextInFlow);
|
1998-04-17 05:41:24 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != nextInFlow, "null next-in-flow");
|
|
|
|
nsTableOuterFrame* parent;
|
|
|
|
|
1999-02-10 04:36:30 +03:00
|
|
|
nextInFlow->GetParent((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;
|
|
|
|
|
1999-02-24 07:48:08 +03:00
|
|
|
nextInFlow->GetNextInFlow(&nextNextInFlow);
|
1998-04-17 05:41:24 +04:00
|
|
|
if (nsnull != nextNextInFlow) {
|
1998-08-28 07:02:39 +04:00
|
|
|
parent->DeleteChildsNextInFlow(aPresContext, nextInFlow);
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect the next-in-flow from the flow list
|
1999-10-22 18:53:52 +04:00
|
|
|
nsSplittableFrame::BreakFromPrevFlow(nextInFlow);
|
1998-04-17 02:21:32 +04:00
|
|
|
|
|
|
|
// Take the next-in-flow out of the parent's child list
|
1999-01-16 01:52:05 +03:00
|
|
|
if (parent->mFrames.FirstChild() == nextInFlow) {
|
|
|
|
nsIFrame* nextSibling;
|
1999-02-10 09:13:38 +03:00
|
|
|
nextInFlow->GetNextSibling(&nextSibling);
|
1999-01-16 01:52:05 +03:00
|
|
|
parent->mFrames.SetFrames(nextSibling);
|
1998-04-17 02:21:32 +04:00
|
|
|
|
|
|
|
} 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)
|
1999-02-10 09:13:38 +03:00
|
|
|
aChild->GetNextSibling(&nextSibling);
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_ASSERTION(nextSibling == nextInFlow, "unexpected sibling");
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1999-02-10 09:13:38 +03:00
|
|
|
nextInFlow->GetNextSibling(&nextSibling);
|
1998-04-17 05:41:24 +04:00
|
|
|
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
|
1999-07-22 06:24:52 +04:00
|
|
|
nextInFlow->Destroy(aPresContext);
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
#ifdef NS_DEBUG
|
1999-02-24 07:48:08 +03:00
|
|
|
aChild->GetNextInFlow(&nextInFlow);
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_POSTCONDITION(nsnull == nextInFlow, "non null next-in-flow");
|
|
|
|
#endif
|
1998-04-17 02:21:32 +04:00
|
|
|
}
|
|
|
|
|
1999-02-24 08:54:31 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::tableOuterFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-17 02:21:32 +04:00
|
|
|
|
1999-08-01 20:20:14 +04:00
|
|
|
/* ----- global methods ----- */
|
|
|
|
|
|
|
|
/*------------------ nsITableLayout methods ------------------------------*/
|
1999-08-01 02:11:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::GetCellDataAt(PRInt32 aRowIndex, PRInt32 aColIndex,
|
|
|
|
nsIDOMElement* &aCell, //out params
|
|
|
|
PRInt32& aStartRowIndex, PRInt32& aStartColIndex,
|
|
|
|
PRInt32& aRowSpan, PRInt32& aColSpan,
|
2000-01-26 17:56:06 +03:00
|
|
|
PRInt32& aActualRowSpan, PRInt32& aActualColSpan,
|
1999-08-01 02:11:50 +04:00
|
|
|
PRBool& aIsSelected)
|
|
|
|
{
|
|
|
|
if (!mInnerTableFrame) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
nsITableLayout *inner;
|
|
|
|
nsresult result = mInnerTableFrame->QueryInterface(nsITableLayout::GetIID(), (void **)&inner);
|
|
|
|
if (NS_SUCCEEDED(result) && inner)
|
|
|
|
{
|
|
|
|
return (inner->GetCellDataAt(aRowIndex, aColIndex, aCell,
|
|
|
|
aStartRowIndex, aStartColIndex,
|
2000-01-26 17:56:06 +03:00
|
|
|
aRowSpan, aColSpan, aActualRowSpan, aActualColSpan,
|
|
|
|
aIsSelected));
|
1999-08-01 02:11:50 +04:00
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-08-01 20:20:14 +04:00
|
|
|
NS_IMETHODIMP nsTableOuterFrame::GetTableSize(PRInt32& aRowCount, PRInt32& aColCount)
|
|
|
|
{
|
|
|
|
if (!mInnerTableFrame) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
nsITableLayout *inner;
|
|
|
|
nsresult result = mInnerTableFrame->QueryInterface(nsITableLayout::GetIID(), (void **)&inner);
|
|
|
|
if (NS_SUCCEEDED(result) && inner)
|
|
|
|
{
|
|
|
|
return (inner->GetTableSize(aRowCount, aColCount));
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- end of nsITableLayout implementation ------------------*/
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewTableOuterFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsTableOuterFrame* it = new (aPresShell) nsTableOuterFrame;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-03 01:59:54 +04:00
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("TableOuter", aResult);
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableOuterFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
1999-09-01 05:02:16 +04:00
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-08-31 07:09:40 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
*aResult = sum;
|
|
|
|
return NS_OK;
|
1999-08-31 07:09:40 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|