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 "nsTableCellFrame.h"
|
1998-06-17 20:38:24 +04:00
|
|
|
#include "nsCellLayoutData.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#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"
|
1998-06-11 04:13:18 +04:00
|
|
|
#include "nsHTMLValue.h"
|
1998-05-02 00:44:55 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-06-05 06:36:25 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPtr.h"
|
1998-05-22 03:43:18 +04:00
|
|
|
#include "nsIView.h"
|
1998-06-11 19:46:37 +04:00
|
|
|
// dependancy on content
|
|
|
|
#include "nsHTMLTagContent.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-05 06:36:25 +04:00
|
|
|
NS_DEF_PTR(nsIStyleContext);
|
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
const nsIID kTableCellFrameCID = NS_TABLECELLFRAME_CID;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRBool gsDebug = PR_FALSE;
|
1998-06-24 03:23:21 +04:00
|
|
|
static PRBool gsDebugNT = PR_FALSE;
|
1998-05-03 07:51:48 +04:00
|
|
|
//#define NOISY_STYLE
|
1998-04-14 00:24:54 +04:00
|
|
|
//#define NOISY_FLOW
|
|
|
|
#else
|
|
|
|
static const PRBool gsDebug = PR_FALSE;
|
1998-06-24 03:23:21 +04:00
|
|
|
static const PRBool gsDebugNT = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
nsTableCellFrame::nsTableCellFrame(nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame)
|
1998-06-17 20:38:24 +04:00
|
|
|
: nsContainerFrame(aContent, aParentFrame),
|
|
|
|
mCellLayoutData(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-11 04:13:18 +04:00
|
|
|
mRowSpan=1;
|
|
|
|
mColSpan=1;
|
|
|
|
mColIndex=0;
|
1998-07-02 21:40:56 +04:00
|
|
|
mPriorAvailWidth=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTableCellFrame::~nsTableCellFrame()
|
|
|
|
{
|
1998-06-17 20:38:24 +04:00
|
|
|
if (nsnull!=mCellLayoutData)
|
|
|
|
delete mCellLayoutData;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-27 03:17:29 +04:00
|
|
|
if (disp->mVisible) {
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleColor* myColor =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleSpacing* mySpacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-27 03:17:29 +04:00
|
|
|
NS_ASSERTION(nsnull!=myColor, "bad style color");
|
|
|
|
NS_ASSERTION(nsnull!=mySpacing, "bad style spacing");
|
1998-04-30 04:27:59 +04:00
|
|
|
|
1998-05-27 03:17:29 +04:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, mRect, *myColor);
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, mRect, *mySpacing, 0);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// for debug...
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,128,128));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Align the cell's child frame within the cell
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
void nsTableCellFrame::VerticallyAlignChild(nsIPresContext* aPresContext)
|
1998-04-25 22:48:48 +04:00
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
const nsStyleText* textStyle =
|
|
|
|
(const nsStyleText*)mStyleContext->GetStyleData(eStyleStruct_Text);
|
1998-05-13 02:28:01 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-13 02:28:01 +04:00
|
|
|
nscoord topInset = borderPadding.top;
|
|
|
|
nscoord bottomInset = borderPadding.bottom;
|
1998-04-29 03:57:01 +04:00
|
|
|
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
|
|
|
|
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
|
|
|
|
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
nscoord height = mRect.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsRect kidRect;
|
|
|
|
mFirstChild->GetRect(kidRect);
|
|
|
|
nscoord childHeight = kidRect.height;
|
|
|
|
|
|
|
|
|
|
|
|
// Vertically align the child
|
|
|
|
nscoord kidYTop = 0;
|
1998-04-28 01:26:48 +04:00
|
|
|
switch (verticalAlignFlags)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
|
|
|
// Align the child's baseline at the max baseline
|
|
|
|
//kidYTop = aMaxAscent - kidAscent;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
|
|
|
// Align the top of the child frame with the top of the box,
|
|
|
|
// minus the top padding
|
|
|
|
kidYTop = topInset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
|
|
|
kidYTop = height - childHeight - bottomInset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
|
|
|
kidYTop = height/2 - childHeight/2;
|
|
|
|
}
|
|
|
|
mFirstChild->MoveTo(kidRect.x, kidYTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTableCellFrame::CreatePsuedoFrame(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// Do we have a prev-in-flow?
|
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
// No, create a column pseudo frame
|
1998-05-06 03:56:50 +04:00
|
|
|
nsBodyFrame::NewFrame(&mFirstChild, mContent, this);
|
1998-04-14 00:24:54 +04:00
|
|
|
mChildCount = 1;
|
|
|
|
|
|
|
|
// Resolve style and set the style context
|
|
|
|
nsIStyleContext* styleContext =
|
|
|
|
aPresContext->ResolveStyleContextFor(mContent, this); // styleContext: ADDREF++
|
1998-05-02 00:44:55 +04:00
|
|
|
mFirstChild->SetStyleContext(aPresContext,styleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(styleContext); // styleContext: ADDREF--
|
|
|
|
} else {
|
|
|
|
nsTableCellFrame* prevFrame = (nsTableCellFrame *)mPrevInFlow;
|
|
|
|
|
|
|
|
nsIFrame* prevPseudoFrame = prevFrame->mFirstChild;
|
|
|
|
NS_ASSERTION(prevFrame->ChildIsPseudoFrame(prevPseudoFrame), "bad previous pseudo-frame");
|
|
|
|
|
|
|
|
// Create a continuing column
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
prevPseudoFrame->GetStyleContext(aPresContext, kidSC);
|
|
|
|
prevPseudoFrame->CreateContinuingFrame(aPresContext, this, kidSC, mFirstChild);
|
|
|
|
NS_RELEASE(kidSC);
|
1998-04-14 00:24:54 +04:00
|
|
|
mChildCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
/*
|
|
|
|
* Should this be performanced tuned? This is called
|
|
|
|
* in resize/reflow. Maybe we should cache the table
|
|
|
|
* frame in the table cell frame.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsTableFrame* nsTableCellFrame::GetTableFrame()
|
|
|
|
{
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
result = GetContentParent(frame); // Get RowFrame
|
|
|
|
|
|
|
|
if ((result == NS_OK) && (frame != nsnull))
|
|
|
|
frame->GetContentParent(frame); // Get RowGroupFrame
|
|
|
|
|
|
|
|
if ((result == NS_OK) && (frame != nsnull))
|
|
|
|
frame->GetContentParent(frame); // Get TableFrame
|
|
|
|
|
|
|
|
return (nsTableFrame*)frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
*/
|
1998-05-25 21:31:49 +04:00
|
|
|
NS_METHOD nsTableCellFrame::Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull!=aPresContext, "bad arg");
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
//PreReflowCheck();
|
|
|
|
#endif
|
|
|
|
|
1998-06-03 04:43:53 +04:00
|
|
|
// Initialize out parameter
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = 0;
|
|
|
|
aDesiredSize.maxElementSize->height = 0;
|
|
|
|
}
|
|
|
|
|
1998-05-12 08:17:56 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-06-24 03:23:21 +04:00
|
|
|
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
|
|
|
|
printf("%p nsTableCellFrame::Reflow: maxSize=%d,%d\n",
|
|
|
|
this, aReflowState.maxSize.width, aReflowState.maxSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
mFirstContentOffset = mLastContentOffset = 0;
|
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
nsSize availSize(aReflowState.maxSize);
|
1998-04-14 00:24:54 +04:00
|
|
|
nsSize maxElementSize;
|
1998-05-25 21:31:49 +04:00
|
|
|
nsSize *pMaxElementSize = aDesiredSize.maxElementSize;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE==aReflowState.maxSize.width)
|
1998-04-14 00:24:54 +04:00
|
|
|
pMaxElementSize = &maxElementSize;
|
|
|
|
nscoord x = 0;
|
|
|
|
// SEC: what about ascent and decent???
|
|
|
|
|
|
|
|
// Compute the insets (sum of border and padding)
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-05-13 02:28:01 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
|
|
|
|
nscoord topInset = borderPadding.top;
|
|
|
|
nscoord rightInset = borderPadding.right;
|
|
|
|
nscoord bottomInset = borderPadding.bottom;
|
|
|
|
nscoord leftInset = borderPadding.left;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
// Get the margin information, available space should
|
|
|
|
// be reduced accordingly
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
nsTableFrame* tableFrame = GetTableFrame();
|
|
|
|
tableFrame->GetCellMarginData(this,margin);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
mLastContentIsComplete = PR_TRUE;
|
|
|
|
|
|
|
|
// get frame, creating one if needed
|
|
|
|
if (nsnull==mFirstChild)
|
|
|
|
{
|
|
|
|
CreatePsuedoFrame(aPresContext);
|
|
|
|
}
|
|
|
|
|
1998-07-07 01:00:11 +04:00
|
|
|
// reduce available space by insets, if we're in a constrained situation
|
1998-06-26 04:48:44 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE!=availSize.width)
|
1998-07-07 01:00:11 +04:00
|
|
|
availSize.width -= leftInset+rightInset;
|
1998-06-26 04:48:44 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE!=availSize.height)
|
|
|
|
availSize.height -= topInset+bottomInset+margin.top+margin.bottom;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Try to reflow the child into the available space. It might not
|
|
|
|
// fit or might need continuing.
|
1998-04-23 21:29:07 +04:00
|
|
|
if (availSize.height < 0)
|
|
|
|
availSize.height = 1;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsSize maxKidElementSize;
|
|
|
|
if (gsDebug==PR_TRUE)
|
|
|
|
printf(" nsTableCellFrame::ResizeReflow calling ReflowChild with availSize=%d,%d\n",
|
|
|
|
availSize.width, availSize.height);
|
1998-05-25 21:31:49 +04:00
|
|
|
nsReflowMetrics kidSize(pMaxElementSize);
|
1998-06-03 04:43:53 +04:00
|
|
|
kidSize.width=kidSize.height=kidSize.ascent=kidSize.descent=0;
|
1998-07-02 21:40:56 +04:00
|
|
|
SetPriorAvailWidth(aReflowState.maxSize.width);
|
1998-05-30 00:36:05 +04:00
|
|
|
nsReflowState kidReflowState(mFirstChild, aReflowState, availSize);
|
1998-05-28 22:37:56 +04:00
|
|
|
mFirstChild->WillReflow(*aPresContext);
|
1998-06-24 20:35:21 +04:00
|
|
|
mFirstChild->MoveTo(leftInset, topInset);
|
1998-05-25 21:31:49 +04:00
|
|
|
aStatus = ReflowChild(mFirstChild, aPresContext, kidSize, kidReflowState);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (nsnull!=pMaxElementSize)
|
1998-06-24 03:23:21 +04:00
|
|
|
printf(" %p cellFrame child returned desiredSize=%d,%d,\
|
1998-04-14 00:24:54 +04:00
|
|
|
and maxElementSize=%d,%d\n",
|
1998-06-24 03:23:21 +04:00
|
|
|
this, kidSize.width, kidSize.height,
|
1998-04-14 00:24:54 +04:00
|
|
|
pMaxElementSize->width, pMaxElementSize->height);
|
|
|
|
else
|
1998-06-24 03:23:21 +04:00
|
|
|
printf(" %p cellFrame child returned desiredSize=%d,%d,\
|
1998-04-14 00:24:54 +04:00
|
|
|
and maxElementSize=nsnull\n",
|
1998-06-24 03:23:21 +04:00
|
|
|
this, kidSize.width, kidSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SetFirstContentOffset(mFirstChild);
|
|
|
|
SetLastContentOffset(mFirstChild);
|
|
|
|
|
1998-06-05 06:36:25 +04:00
|
|
|
// Place the child
|
1998-05-22 03:43:18 +04:00
|
|
|
mFirstChild->SetRect(nsRect(leftInset, topInset,
|
1998-06-05 06:36:25 +04:00
|
|
|
kidSize.width, kidSize.height));
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-12 08:17:56 +04:00
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// If the child didn't finish layout then it means that it used
|
|
|
|
// up all of our available space (or needs us to split).
|
|
|
|
mLastContentIsComplete = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return our size and our result
|
1998-06-05 06:36:25 +04:00
|
|
|
|
|
|
|
// first, compute the height
|
|
|
|
// the height can be set w/o being restricted by aMaxSize.height
|
|
|
|
nscoord cellHeight = kidSize.height;
|
1998-07-02 21:40:56 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE!=aReflowState.maxSize.height)
|
1998-06-24 03:23:21 +04:00
|
|
|
{
|
1998-06-05 06:36:25 +04:00
|
|
|
cellHeight += topInset + bottomInset;
|
1998-06-24 03:23:21 +04:00
|
|
|
}
|
|
|
|
if (PR_TRUE==gsDebugNT)
|
|
|
|
printf(" %p cellFrame height set to %d from kidSize=%d and insets %d,%d\n",
|
|
|
|
this, cellHeight, kidSize.height, topInset, bottomInset);
|
1998-06-05 06:36:25 +04:00
|
|
|
// next determine the cell's width
|
1998-07-07 01:00:11 +04:00
|
|
|
nscoord cellWidth = kidSize.width; // at this point, we've factored in the cell's style attributes
|
|
|
|
cellWidth += leftInset + rightInset; // factor in insets
|
1998-07-02 21:40:56 +04:00
|
|
|
|
1998-06-27 03:31:33 +04:00
|
|
|
// Nav4 hack for 0 width cells. If the cell has any content, it must have a desired width of at least 1
|
1998-06-30 00:38:22 +04:00
|
|
|
/*
|
1998-06-27 03:31:33 +04:00
|
|
|
if (0==cellWidth)
|
|
|
|
{
|
|
|
|
PRInt32 childCount;
|
|
|
|
mFirstChild->ChildCount(childCount);
|
|
|
|
if (0!=childCount)
|
|
|
|
{
|
|
|
|
nsIFrame *grandChild;
|
|
|
|
mFirstChild->FirstChild(grandChild);
|
|
|
|
grandChild->ChildCount(childCount);
|
|
|
|
if (0!=childCount)
|
|
|
|
{
|
|
|
|
cellWidth=1;
|
|
|
|
if (nsnull!=aDesiredSize.maxElementSize && 0==pMaxElementSize->width)
|
|
|
|
pMaxElementSize->width=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-06-30 00:38:22 +04:00
|
|
|
*/
|
1998-06-27 03:31:33 +04:00
|
|
|
// end Nav4 hack for 0 width cells
|
1998-06-05 06:36:25 +04:00
|
|
|
|
|
|
|
// set the cell's desired size and max element size
|
|
|
|
aDesiredSize.width = cellWidth;
|
|
|
|
aDesiredSize.height = cellHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
aDesiredSize.ascent = topInset;
|
|
|
|
aDesiredSize.descent = bottomInset;
|
1998-05-25 21:31:49 +04:00
|
|
|
if (nsnull!=aDesiredSize.maxElementSize)
|
1998-04-21 02:49:15 +04:00
|
|
|
{
|
1998-05-25 21:31:49 +04:00
|
|
|
*aDesiredSize.maxElementSize = *pMaxElementSize;
|
1998-07-07 01:00:11 +04:00
|
|
|
aDesiredSize.maxElementSize->height += topInset + bottomInset;
|
|
|
|
aDesiredSize.maxElementSize->width += leftInset + rightInset;
|
1998-04-21 02:49:15 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT)
|
|
|
|
printf(" %p cellFrame returning aDesiredSize=%d,%d\n",
|
|
|
|
this, aDesiredSize.width, aDesiredSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
//PostReflowCheck(result);
|
|
|
|
#endif
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-07 04:08:20 +04:00
|
|
|
NS_METHOD
|
|
|
|
nsTableCellFrame::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-06 03:56:50 +04:00
|
|
|
nsTableCellFrame* cf = new nsTableCellFrame(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-17 05:41:24 +04:00
|
|
|
aContinuingFrame = cf;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-02 00:44:55 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Update the border style to map to the HTML border style
|
|
|
|
*
|
|
|
|
*/
|
1998-05-27 00:57:24 +04:00
|
|
|
void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth)
|
1998-05-02 00:44:55 +04:00
|
|
|
{
|
1998-05-13 02:28:01 +04:00
|
|
|
nsStyleCoord width;
|
|
|
|
width.SetCoordValue(aBorderWidth);
|
|
|
|
aSpacingStyle.mBorder.SetTop(width);
|
|
|
|
aSpacingStyle.mBorder.SetLeft(width);
|
|
|
|
aSpacingStyle.mBorder.SetBottom(width);
|
|
|
|
aSpacingStyle.mBorder.SetRight(width);
|
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_SOLID;
|
|
|
|
aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_SOLID;
|
|
|
|
aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_SOLID;
|
|
|
|
aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_SOLID;
|
1998-05-02 00:44:55 +04:00
|
|
|
|
1998-05-27 00:57:24 +04:00
|
|
|
nsTableFrame* tableFrame = GetTableFrame();
|
|
|
|
nsIStyleContext* styleContext = nsnull;
|
|
|
|
|
|
|
|
tableFrame->GetStyleContext(aPresContext,styleContext);
|
|
|
|
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleColor* colorData = (const nsStyleColor*)styleContext->GetStyleData(eStyleStruct_Color);
|
1998-05-27 00:57:24 +04:00
|
|
|
|
|
|
|
// Look until we find a style context with a NON-transparent background color
|
|
|
|
while (styleContext)
|
|
|
|
{
|
|
|
|
if ((colorData->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)!=0)
|
|
|
|
{
|
|
|
|
nsIStyleContext* temp = styleContext;
|
|
|
|
styleContext = styleContext->GetParent();
|
|
|
|
NS_RELEASE(temp);
|
1998-06-05 10:09:09 +04:00
|
|
|
colorData = (const nsStyleColor*)styleContext->GetStyleData(eStyleStruct_Color);
|
1998-05-27 00:57:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yaahoo, we found a style context which has a background color
|
|
|
|
|
|
|
|
nscolor borderColor = 0xFFC0C0C0;
|
|
|
|
|
|
|
|
if (styleContext != nsnull)
|
|
|
|
borderColor = colorData->mBackgroundColor;
|
|
|
|
|
|
|
|
// if the border color is white, then shift to grey
|
|
|
|
if (borderColor == 0xFFFFFFFF)
|
|
|
|
borderColor = 0xFFC0C0C0;
|
|
|
|
|
1998-05-02 00:44:55 +04:00
|
|
|
|
1998-05-27 00:57:24 +04:00
|
|
|
aSpacingStyle.mBorderColor[NS_SIDE_TOP] =
|
|
|
|
aSpacingStyle.mBorderColor[NS_SIDE_LEFT] =
|
|
|
|
aSpacingStyle.mBorderColor[NS_SIDE_BOTTOM] =
|
|
|
|
aSpacingStyle.mBorderColor[NS_SIDE_RIGHT] = borderColor;
|
1998-05-02 00:44:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
PRBool nsTableCellFrame::ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult)
|
1998-05-02 01:55:36 +04:00
|
|
|
{
|
|
|
|
PRInt32 result = 0;
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
if (aValue.GetUnit() == eHTMLUnit_Pixel)
|
1998-05-02 01:55:36 +04:00
|
|
|
aResult = aValue.GetPixelValue();
|
|
|
|
else if (aValue.GetUnit() == eHTMLUnit_Empty)
|
|
|
|
aResult = aDefault;
|
|
|
|
else
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
|
|
|
NS_ERROR("Unit must be pixel or empty");
|
1998-05-02 01:55:36 +04:00
|
|
|
return PR_FALSE;
|
1998-05-22 03:43:18 +04:00
|
|
|
}
|
1998-05-02 01:55:36 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-05-02 00:44:55 +04:00
|
|
|
|
|
|
|
void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// Check to see if the table has either cell padding or
|
|
|
|
// Cell spacing defined for the table. If true, then
|
|
|
|
// this setting overrides any specific border, margin or
|
|
|
|
// padding information in the cell. If these attributes
|
|
|
|
// are not defined, the the cells attributes are used
|
|
|
|
|
|
|
|
nscoord padding = 0;
|
|
|
|
nscoord spacing = 0;
|
|
|
|
nscoord border = 1;
|
|
|
|
|
|
|
|
float p2t = aPresContext->GetPixelsToTwips();
|
|
|
|
|
1998-06-11 19:46:37 +04:00
|
|
|
nsTableFrame* tableFrame = GetTableFrame();
|
|
|
|
tableFrame->GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame
|
|
|
|
NS_ASSERTION(tableFrame,"Table Must not be null");
|
|
|
|
if (!tableFrame)
|
1998-05-02 00:44:55 +04:00
|
|
|
return;
|
|
|
|
|
1998-06-11 19:46:37 +04:00
|
|
|
// get the table frame style context, and from it get cellpadding, cellspacing, and border info
|
|
|
|
nsIStyleContextPtr tableSC;
|
|
|
|
tableFrame->GetStyleContext(aPresContext, tableSC.AssignRef());
|
|
|
|
nsStyleTable* tableStyle = (nsStyleTable*)tableSC->GetStyleData(eStyleStruct_Table);
|
|
|
|
nsStyleSpacing* tableSpacingStyle = (nsStyleSpacing*)tableSC->GetStyleData(eStyleStruct_Spacing);
|
1998-06-05 10:09:09 +04:00
|
|
|
nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing);
|
1998-05-13 02:28:01 +04:00
|
|
|
|
1998-05-02 00:44:55 +04:00
|
|
|
// check to see if cellpadding or cellspacing is defined
|
1998-06-11 19:46:37 +04:00
|
|
|
if (tableStyle->mCellPadding.GetUnit() != eStyleUnit_Null ||
|
|
|
|
tableStyle->mCellSpacing.GetUnit() != eStyleUnit_Null)
|
1998-05-02 00:44:55 +04:00
|
|
|
{
|
1998-06-11 19:46:37 +04:00
|
|
|
spacingData->mMargin.SetTop(tableStyle->mCellSpacing);
|
|
|
|
spacingData->mMargin.SetLeft(tableStyle->mCellSpacing);
|
|
|
|
spacingData->mMargin.SetBottom(tableStyle->mCellSpacing);
|
|
|
|
spacingData->mMargin.SetRight(tableStyle->mCellSpacing);
|
|
|
|
spacingData->mPadding.SetTop(tableStyle->mCellPadding);
|
|
|
|
spacingData->mPadding.SetLeft(tableStyle->mCellPadding);
|
|
|
|
spacingData->mPadding.SetBottom(tableStyle->mCellPadding);
|
|
|
|
spacingData->mPadding.SetRight(tableStyle->mCellPadding);
|
1998-05-02 00:44:55 +04:00
|
|
|
}
|
1998-05-02 01:55:36 +04:00
|
|
|
|
1998-06-11 19:46:37 +04:00
|
|
|
// get border information from the table
|
1998-06-24 03:23:21 +04:00
|
|
|
if (tableSpacingStyle->mBorder.GetTopUnit() == eStyleUnit_Coord)
|
1998-06-11 19:46:37 +04:00
|
|
|
{
|
1998-06-24 03:23:21 +04:00
|
|
|
nsStyleCoord borderWidth;
|
|
|
|
tableSpacingStyle->mBorder.GetTop(borderWidth);
|
|
|
|
if (0!=borderWidth.GetCoordValue())
|
|
|
|
{
|
|
|
|
// in HTML, cell borders are always 1 pixel by default
|
|
|
|
border = (nscoord)(1*(aPresContext->GetPixelsToTwips()));
|
|
|
|
MapHTMLBorderStyle(aPresContext, *spacingData, border);
|
|
|
|
}
|
1998-05-02 00:44:55 +04:00
|
|
|
}
|
1998-06-24 03:23:21 +04:00
|
|
|
|
1998-05-02 00:44:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsTableCellFrame::MapTextAttributes(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsHTMLValue value;
|
|
|
|
|
1998-06-11 04:13:18 +04:00
|
|
|
((nsHTMLTagContent*)mContent)->GetAttribute(nsHTMLAtoms::align, value);
|
1998-05-02 00:44:55 +04:00
|
|
|
if (value.GetUnit() == eHTMLUnit_Enumerated)
|
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
nsStyleText* text = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
|
1998-05-02 00:44:55 +04:00
|
|
|
text->mTextAlign = value.GetIntValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Subclass hook for style post processing
|
|
|
|
NS_METHOD nsTableCellFrame::DidSetStyleContext(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
#ifdef NOISY_STYLE
|
|
|
|
printf("nsTableCellFrame::DidSetStyleContext \n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MapTextAttributes(aPresContext);
|
|
|
|
MapBorderMarginPadding(aPresContext);
|
1998-05-13 02:28:01 +04:00
|
|
|
mStyleContext->RecalcAutomaticData(aPresContext);
|
1998-05-02 00:44:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-24 03:23:21 +04:00
|
|
|
NS_METHOD
|
|
|
|
nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kTableCellFrameCID)) {
|
|
|
|
*aInstancePtr = (void*) (this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/* ----- static methods ----- */
|
|
|
|
|
|
|
|
nsresult nsTableCellFrame::NewFrame(nsIFrame** aInstancePtrResult,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-05-06 03:56:50 +04:00
|
|
|
nsIFrame* it = new nsTableCellFrame(aContent, aParent);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-22 03:43:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
// For Debugging ONLY
|
|
|
|
NS_METHOD nsTableCellFrame::MoveTo(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
if ((aX != mRect.x) || (aY != mRect.y)) {
|
|
|
|
mRect.x = aX;
|
|
|
|
mRect.y = aY;
|
|
|
|
|
|
|
|
nsIView* view;
|
|
|
|
GetView(view);
|
|
|
|
|
|
|
|
// Let the view know
|
|
|
|
if (nsnull != view) {
|
|
|
|
// Position view relative to it's parent, not relative to our
|
|
|
|
// parent frame (our parent frame may not have a view).
|
|
|
|
nsIView* parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
GetOffsetFromView(origin, parentWithView);
|
|
|
|
view->SetPosition(origin.x, origin.y);
|
|
|
|
NS_IF_RELEASE(parentWithView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsTableCellFrame::SizeTo(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
mRect.width = aWidth;
|
|
|
|
mRect.height = aHeight;
|
|
|
|
|
|
|
|
nsIView* view;
|
|
|
|
GetView(view);
|
|
|
|
|
|
|
|
// Let the view know
|
|
|
|
if (nsnull != view) {
|
|
|
|
view->SetDimensions(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|