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 "nsTableRowFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
1999-07-28 12:09:02 +04:00
|
|
|
#include "nsIPresShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-08-26 21:26:38 +04:00
|
|
|
#include "nsIHTMLAttributes.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsTableFrame.h"
|
|
|
|
#include "nsTableCellFrame.h"
|
1998-04-15 01:49:29 +04:00
|
|
|
#include "nsIView.h"
|
1998-06-03 04:43:53 +04:00
|
|
|
#include "nsIPtr.h"
|
1998-06-23 09:43:27 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-07-21 03:56:17 +04:00
|
|
|
#include "nsCSSRendering.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1999-02-24 08:54:31 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-07-28 12:09:02 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsTableColGroupFrame.h"
|
|
|
|
#include "nsTableColFrame.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1998-09-01 01:23:28 +04:00
|
|
|
// the following header files are required for style optimizations that work only when the child content is really a cell
|
1998-09-15 21:58:24 +04:00
|
|
|
#include "nsIHTMLTableCellElement.h"
|
|
|
|
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
|
1998-09-01 01:23:28 +04:00
|
|
|
// end includes for style optimizations that require real content knowledge
|
1998-06-03 04:43:53 +04:00
|
|
|
|
|
|
|
NS_DEF_PTR(nsIStyleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
|
|
|
|
/* ----------- nsTableRowpFrame ---------- */
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
nsTableRowFrame::nsTableRowFrame()
|
|
|
|
: nsHTMLContainerFrame(),
|
1998-05-22 03:43:18 +04:00
|
|
|
mTallestCell(0),
|
1999-10-24 03:08:30 +04:00
|
|
|
mAllBits(0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-24 03:08:30 +04:00
|
|
|
mBits.mMinRowSpan = 1;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-25 08:31:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::Init(nsIPresContext& aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Let the the base class do its initialization
|
|
|
|
rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext,
|
|
|
|
aPrevInFlow);
|
|
|
|
|
|
|
|
if (aPrevInFlow) {
|
|
|
|
// Set the row index
|
|
|
|
nsTableRowFrame* rowFrame = (nsTableRowFrame*)aPrevInFlow;
|
|
|
|
|
|
|
|
SetRowIndex(rowFrame->GetRowIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-08-03 06:41:27 +04:00
|
|
|
// Helper function. It marks the table frame as dirty and generates
|
|
|
|
// a reflow command
|
|
|
|
nsresult
|
|
|
|
nsTableRowFrame::AddTableDirtyReflowCommand(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aTableFrame)
|
|
|
|
{
|
|
|
|
nsFrameState frameState;
|
|
|
|
nsIFrame* tableParentFrame;
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Mark the table frame as dirty
|
|
|
|
aTableFrame->GetFrameState(&frameState);
|
|
|
|
frameState |= NS_FRAME_IS_DIRTY;
|
|
|
|
aTableFrame->SetFrameState(frameState);
|
|
|
|
|
|
|
|
// Target the reflow comamnd at its parent frame
|
|
|
|
aTableFrame->GetParent(&tableParentFrame);
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, tableParentFrame,
|
|
|
|
nsIReflowCommand::ReflowDirty);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Add the reflow command
|
|
|
|
rv = aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::AppendFrames(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
// Append the frames
|
|
|
|
mFrames.AppendFrames(nsnull, aFrameList);
|
|
|
|
|
|
|
|
// Add the new cell frames to the table
|
|
|
|
nsTableFrame *tableFrame = nsnull;
|
|
|
|
nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
for (nsIFrame* childFrame = aFrameList; childFrame; childFrame->GetNextSibling(&childFrame)) {
|
|
|
|
const nsStyleDisplay *display;
|
|
|
|
childFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display));
|
|
|
|
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == display->mDisplay) {
|
|
|
|
// Add the cell to the cell map
|
|
|
|
PRInt32 colIndex = tableFrame->AddCellToTable((nsTableCellFrame*)childFrame,
|
|
|
|
GetRowIndex());
|
|
|
|
|
|
|
|
// Initialize the cell frame and give it its column index
|
|
|
|
((nsTableCellFrame*)childFrame)->InitCellFrame(colIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-07 19:12:50 +04:00
|
|
|
// See if any implicit column frames need to be created as a result of
|
|
|
|
// adding the new rows
|
|
|
|
PRBool createdColFrames;
|
|
|
|
tableFrame->EnsureColumns(aPresContext, createdColFrames);
|
|
|
|
if (createdColFrames) {
|
|
|
|
// We need to rebuild the column cache
|
|
|
|
// XXX It would be nice if this could be done incrementally
|
|
|
|
tableFrame->InvalidateColumnCache();
|
|
|
|
}
|
|
|
|
|
1999-08-03 06:41:27 +04:00
|
|
|
// Reflow the new frames. They're already marked dirty, so generate a reflow
|
|
|
|
// command that tells us to reflow our dirty child frames
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(NS_NewHTMLReflowCommand(&reflowCmd, this,
|
|
|
|
nsIReflowCommand::ReflowDirty))) {
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::InsertFrames(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
// Get the table frame
|
|
|
|
nsTableFrame* tableFrame = nsnull;
|
|
|
|
nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
|
|
|
|
// Insert the frames
|
|
|
|
mFrames.InsertFrames(nsnull, aPrevFrame, aFrameList);
|
|
|
|
|
|
|
|
// We need to rebuild the cell map, because currently we can't insert
|
|
|
|
// new frames except at the end (append)
|
|
|
|
tableFrame->InvalidateCellMap();
|
|
|
|
|
|
|
|
// We should try and avoid doing a pass1 reflow on all the cells and just
|
|
|
|
// do it for the newly added frames, but we need to add these frames to the
|
|
|
|
// cell map before we reflow them
|
|
|
|
tableFrame->InvalidateFirstPassCache();
|
|
|
|
|
|
|
|
// Because the number of columns may have changed invalidate the column
|
|
|
|
// cache. Note that this has the side effect of recomputing the column
|
|
|
|
// widths, so we don't need to call InvalidateColumnWidths()
|
|
|
|
tableFrame->InvalidateColumnCache();
|
|
|
|
|
|
|
|
// Generate a reflow command so we reflow the table itself. This will
|
|
|
|
// do a pass-1 reflow of all the rows including any rows we just added
|
|
|
|
AddTableDirtyReflowCommand(aPresContext, aPresShell, tableFrame);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::RemoveFrame(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
// Get the table frame
|
|
|
|
nsTableFrame* tableFrame=nsnull;
|
|
|
|
nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// XXX Currently we can't incrementally remove cells from the cell map
|
|
|
|
PRInt32 colIndex;
|
|
|
|
aDeletedFrame->GetColIndex(colIndex);
|
|
|
|
tableFrame->RemoveCellFromTable(aOldFrame, GetRowIndex());
|
|
|
|
|
|
|
|
// Remove the frame and destroy it
|
|
|
|
mFrames.DestroyFrame(aPresContext, (nsIFrame*)aOldFrame);
|
|
|
|
|
|
|
|
// XXX Reflow the row
|
|
|
|
|
|
|
|
#else
|
|
|
|
// Remove the frame and destroy it
|
|
|
|
mFrames.DestroyFrame(aPresContext, aOldFrame);
|
|
|
|
|
|
|
|
// We need to rebuild the cell map, because currently we can't incrementally
|
|
|
|
// remove rows
|
|
|
|
tableFrame->InvalidateCellMap();
|
|
|
|
|
|
|
|
// Because the number of columns may have changed invalidate the column
|
|
|
|
// cache. Note that this has the side effect of recomputing the column
|
|
|
|
// widths, so we don't need to call InvalidateColumnWidths()
|
|
|
|
tableFrame->InvalidateColumnCache();
|
|
|
|
|
|
|
|
// Because we haven't added any new frames we don't need to do a pass1
|
|
|
|
// reflow. Just generate a reflow command so we reflow the table itself
|
|
|
|
AddTableDirtyReflowCommand(aPresContext, aPresShell, tableFrame);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-30 04:01:09 +04:00
|
|
|
nsTableRowFrame::InitChildrenWithIndex(PRInt32 aRowIndex)
|
1998-10-14 20:32:45 +04:00
|
|
|
{
|
1998-09-24 01:48:26 +04:00
|
|
|
nsTableFrame* table = nsnull;
|
1998-10-14 20:32:45 +04:00
|
|
|
nsresult result=NS_OK;
|
1998-09-24 01:48:26 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
// each child cell can only be added to the table one time.
|
|
|
|
// for now, we remember globally whether we've added all or none
|
1999-10-24 03:08:30 +04:00
|
|
|
if (0 == (mState & NS_TABLE_ROW_FRAME_INITIALIZED_CHILDREN))
|
1998-09-24 01:48:26 +04:00
|
|
|
{
|
1998-10-14 20:32:45 +04:00
|
|
|
result = nsTableFrame::GetTableFrame(this, table);
|
|
|
|
if ((NS_OK==result) && (table != nsnull))
|
1998-09-24 01:48:26 +04:00
|
|
|
{
|
1999-10-24 03:08:30 +04:00
|
|
|
mState |= NS_TABLE_ROW_FRAME_INITIALIZED_CHILDREN;
|
1999-08-30 04:01:09 +04:00
|
|
|
SetRowIndex(aRowIndex);
|
|
|
|
|
1999-02-10 09:13:38 +03:00
|
|
|
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; kidFrame->GetNextSibling(&kidFrame))
|
1998-09-24 20:37:22 +04:00
|
|
|
{
|
1998-10-14 20:32:45 +04:00
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
kidFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1998-10-14 20:32:45 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
|
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
// add the cell frame to the table's cell map and get its col index
|
|
|
|
PRInt32 colIndex;
|
1999-08-30 04:01:09 +04:00
|
|
|
colIndex = table->AddCellToTable((nsTableCellFrame *)kidFrame, aRowIndex);
|
1998-10-14 20:32:45 +04:00
|
|
|
// what column does this cell belong to?
|
1999-08-30 04:01:09 +04:00
|
|
|
// this sets the frame's notion of its column index
|
1998-10-14 20:32:45 +04:00
|
|
|
((nsTableCellFrame *)kidFrame)->InitCellFrame(colIndex);
|
|
|
|
}
|
1998-09-24 01:48:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-30 04:01:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::InitChildren()
|
|
|
|
{
|
|
|
|
nsTableFrame* table = nsnull;
|
|
|
|
nsresult result=NS_OK;
|
|
|
|
|
|
|
|
// each child cell can only be added to the table one time.
|
|
|
|
// for now, we remember globally whether we've added all or none
|
1999-10-24 03:08:30 +04:00
|
|
|
if (0 == (mState & NS_TABLE_ROW_FRAME_INITIALIZED_CHILDREN))
|
1999-08-30 04:01:09 +04:00
|
|
|
{
|
|
|
|
result = nsTableFrame::GetTableFrame(this, table);
|
|
|
|
if ((NS_OK==result) && (table != nsnull))
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = table->GetNextAvailRowIndex();
|
|
|
|
InitChildrenWithIndex(rowIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-03 00:35:23 +04:00
|
|
|
/**
|
|
|
|
* Post-reflow hook. This is where the table row does its post-processing
|
|
|
|
*/
|
1998-11-20 04:01:25 +03:00
|
|
|
void
|
|
|
|
nsTableRowFrame::DidResize(nsIPresContext& aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState)
|
1998-07-03 00:35:23 +04:00
|
|
|
{
|
1998-11-20 04:01:25 +03:00
|
|
|
// Resize and re-align the cell frames based on our row height
|
1999-10-29 18:40:58 +04:00
|
|
|
nscoord cellMaxTopMargin = GetChildMaxTopMargin();
|
|
|
|
nscoord cellMaxBottomMargin = GetChildMaxBottomMargin();
|
|
|
|
nscoord rowCellHeight = mRect.height - cellMaxTopMargin - cellMaxBottomMargin;
|
1998-11-20 04:01:25 +03:00
|
|
|
nsTableFrame* tableFrame;
|
|
|
|
nsTableFrame::GetTableFrame(this, tableFrame);
|
1999-05-04 23:15:56 +04:00
|
|
|
|
|
|
|
nsTableIterator iter(*this, eTableDIR);
|
|
|
|
nsIFrame* cellFrame = iter.First();
|
|
|
|
|
|
|
|
while (nsnull != cellFrame) {
|
1998-11-20 04:01:25 +03:00
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
cellFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1999-05-04 23:15:56 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay) {
|
1999-10-24 03:08:30 +04:00
|
|
|
PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(GetRowIndex(), (nsTableCellFrame *)cellFrame);
|
1999-05-04 23:15:56 +04:00
|
|
|
nscoord cellHeight = rowCellHeight;
|
|
|
|
// add in height of rows spanned beyond the 1st one
|
|
|
|
nsIFrame* nextRow = nsnull;
|
|
|
|
GetNextSibling(&nextRow);
|
|
|
|
for (int i = 1; ((i < rowSpan) && nextRow);) {
|
|
|
|
const nsStyleDisplay *nextDisplay;
|
|
|
|
nextRow->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)nextDisplay));
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_ROW == nextDisplay->mDisplay) {
|
|
|
|
nsRect rect;
|
|
|
|
nextRow->GetRect(rect);
|
|
|
|
cellHeight += rect.height;
|
|
|
|
i++;
|
1998-09-24 20:37:22 +04:00
|
|
|
}
|
1999-05-04 23:15:56 +04:00
|
|
|
nextRow->GetNextSibling(&nextRow);
|
1998-11-20 04:01:25 +03:00
|
|
|
}
|
1999-05-04 23:15:56 +04:00
|
|
|
|
|
|
|
// resize the cell's height
|
|
|
|
nsSize cellFrameSize;
|
|
|
|
cellFrame->GetSize(cellFrameSize);
|
|
|
|
//if (cellFrameSize.height!=cellHeight)
|
1998-11-20 04:01:25 +03:00
|
|
|
{
|
1999-10-26 08:44:41 +04:00
|
|
|
cellFrame->SizeTo(&aPresContext, cellFrameSize.width, cellHeight);
|
1999-05-04 23:15:56 +04:00
|
|
|
// realign cell content based on the new height
|
|
|
|
/*nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
cellFrame,
|
|
|
|
nsSize(cellFrameSize.width, cellHeight),
|
|
|
|
eReflowReason_Resize);*/
|
|
|
|
//XXX: the following reflow is necessary for any content of the cell
|
|
|
|
// whose height is a percent of the cell's height (maybe indirectly.)
|
|
|
|
// But some content crashes when this reflow is issued, to be investigated
|
|
|
|
//XXX nsReflowStatus status;
|
|
|
|
//ReflowChild(cellFrame, aPresContext, desiredSize, kidReflowState, status);
|
1999-10-26 08:44:41 +04:00
|
|
|
((nsTableCellFrame *)cellFrame)->VerticallyAlignChild(&aPresContext);
|
1999-05-04 23:15:56 +04:00
|
|
|
/* if we're collapsing borders, notify the cell that the border edge length has changed */
|
1999-08-10 04:49:10 +04:00
|
|
|
if (NS_STYLE_BORDER_COLLAPSE == tableFrame->GetBorderCollapseStyle()) {
|
1999-05-04 23:15:56 +04:00
|
|
|
((nsTableCellFrame *)(cellFrame))->SetBorderEdgeLength(NS_SIDE_LEFT,
|
|
|
|
GetRowIndex(),
|
|
|
|
cellHeight);
|
|
|
|
((nsTableCellFrame *)(cellFrame))->SetBorderEdgeLength(NS_SIDE_RIGHT,
|
|
|
|
GetRowIndex(),
|
|
|
|
cellHeight);
|
1998-11-02 21:32:14 +03:00
|
|
|
}
|
1998-07-03 00:35:23 +04:00
|
|
|
}
|
|
|
|
}
|
1998-11-20 04:01:25 +03:00
|
|
|
// Get the next cell
|
1999-04-22 07:51:58 +04:00
|
|
|
cellFrame = iter.Next();
|
1998-07-03 00:35:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Let our base class do the usual work
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void nsTableRowFrame::ResetMaxChildHeight()
|
|
|
|
{
|
|
|
|
mTallestCell=0;
|
|
|
|
}
|
|
|
|
|
1999-10-29 18:40:58 +04:00
|
|
|
void nsTableRowFrame::SetMaxChildHeight(nscoord aChildHeight)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (mTallestCell<aChildHeight)
|
|
|
|
mTallestCell = aChildHeight;
|
|
|
|
}
|
|
|
|
|
1999-08-20 17:32:23 +04:00
|
|
|
static
|
1999-06-08 01:10:25 +04:00
|
|
|
PRBool IsFirstRow(nsTableFrame& aTable,
|
|
|
|
nsTableRowFrame& aRow)
|
|
|
|
{
|
|
|
|
nsIFrame* firstRowGroup = nsnull;
|
|
|
|
aTable.FirstChild(nsnull, &firstRowGroup);
|
|
|
|
nsIFrame* rowGroupFrame = nsnull;
|
|
|
|
nsresult rv = aRow.GetParent(&rowGroupFrame);
|
|
|
|
if (NS_SUCCEEDED(rv) && (rowGroupFrame == firstRowGroup)) {
|
|
|
|
nsIFrame* firstRow;
|
|
|
|
rowGroupFrame->FirstChild(nsnull, &firstRow);
|
|
|
|
return (&aRow == firstRow);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsTableRowFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext.GetCompatibilityMode(&mode);
|
|
|
|
if (eCompatibility_Standard == mode) {
|
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (disp->mVisible) {
|
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
const nsStyleColor* color =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
nsTableFrame* tableFrame = nsnull;
|
|
|
|
rv = nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
if (NS_FAILED(rv) || (nsnull == tableFrame)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nscoord cellSpacingX = tableFrame->GetCellSpacingX();
|
|
|
|
nscoord halfCellSpacingY =
|
|
|
|
NSToCoordRound(((float)tableFrame->GetCellSpacingY()) / (float)2);
|
|
|
|
// every row is short by the ending cell spacing X
|
|
|
|
nsRect rect(0, 0, mRect.width + cellSpacingX, mRect.height);
|
|
|
|
// first row may have gotten too much cell spacing Y
|
|
|
|
if (tableFrame->GetRowCount() != 1) {
|
|
|
|
if (IsFirstRow(*tableFrame, *this)) {
|
|
|
|
rect.height -= halfCellSpacingY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rect.height += halfCellSpacingY;
|
|
|
|
rect.y -= halfCellSpacingY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, rect, *color, *spacing, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-06-08 01:10:25 +04:00
|
|
|
// for debug...
|
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,255,0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-06-08 01:10:25 +04:00
|
|
|
|
1998-12-18 18:54:23 +03:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-06-11 01:08:17 +04:00
|
|
|
return NS_OK;
|
1999-06-08 01:10:25 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-20 21:45:07 +04:00
|
|
|
PRIntn
|
|
|
|
nsTableRowFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
PRIntn skip = 0;
|
|
|
|
if (nsnull != mPrevInFlow) {
|
|
|
|
skip |= 1 << NS_SIDE_TOP;
|
|
|
|
}
|
|
|
|
if (nsnull != mNextInFlow) {
|
|
|
|
skip |= 1 << NS_SIDE_BOTTOM;
|
|
|
|
}
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/** overloaded method from nsContainerFrame. The difference is that
|
|
|
|
* we don't want to clip our children, so a cell can do a rowspan
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::PaintChildren(nsIPresContext& aPresContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
1998-04-14 00:24:54 +04:00
|
|
|
while (nsnull != kid) {
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIView *pView;
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
kid->GetView(&aPresContext, &pView);
|
1998-04-15 01:49:29 +04:00
|
|
|
if (nsnull == pView) {
|
|
|
|
nsRect kidRect;
|
|
|
|
kid->GetRect(kidRect);
|
1998-06-14 04:45:21 +04:00
|
|
|
nsRect damageArea;
|
|
|
|
PRBool overlap = damageArea.IntersectRect(aDirtyRect, kidRect);
|
|
|
|
if (overlap) {
|
1998-10-30 05:08:25 +03:00
|
|
|
PRBool clipState;
|
1998-06-14 04:45:21 +04:00
|
|
|
// Translate damage area into kid's coordinate system
|
|
|
|
nsRect kidDamageArea(damageArea.x - kidRect.x,
|
|
|
|
damageArea.y - kidRect.y,
|
|
|
|
damageArea.width, damageArea.height);
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(kidRect.x, kidRect.y);
|
1998-12-18 18:54:23 +03:00
|
|
|
kid->Paint(aPresContext, aRenderingContext, kidDamageArea,
|
|
|
|
aWhichLayer);
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-26 03:39:35 +03:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
|
1998-12-18 18:54:23 +03:00
|
|
|
GetShowFrameBorders()) {
|
1998-06-14 04:45:21 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, kidRect.width, kidRect.height);
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-10-30 05:08:25 +03:00
|
|
|
aRenderingContext.PopState(clipState);
|
1998-04-15 01:49:29 +04:00
|
|
|
}
|
1998-04-17 05:41:24 +04:00
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
/** returns the height of the tallest child in this row (ignoring any cell with rowspans) */
|
|
|
|
nscoord nsTableRowFrame::GetTallestChild() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
return mTallestCell;
|
|
|
|
}
|
|
|
|
|
1998-05-22 03:43:18 +04:00
|
|
|
nscoord nsTableRowFrame::GetChildMaxTopMargin() const
|
|
|
|
{
|
1999-10-29 18:40:58 +04:00
|
|
|
nsTableFrame *tableFrame;
|
|
|
|
nsTableFrame::GetTableFrame((nsIFrame*)this, tableFrame);
|
|
|
|
|
|
|
|
// Only cells in the first row have a top margin
|
|
|
|
return (GetRowIndex() == 0) ? tableFrame->GetCellSpacingY() : 0;
|
1998-05-22 03:43:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord nsTableRowFrame::GetChildMaxBottomMargin() const
|
|
|
|
{
|
1999-10-29 18:40:58 +04:00
|
|
|
nsTableFrame *tableFrame;
|
|
|
|
nsTableFrame::GetTableFrame((nsIFrame*)this, tableFrame);
|
|
|
|
|
|
|
|
// All cells have the same bottom margin
|
|
|
|
return tableFrame->GetCellSpacingY();
|
1998-05-22 03:43:18 +04:00
|
|
|
}
|
|
|
|
|
1998-06-17 20:38:24 +04:00
|
|
|
PRInt32 nsTableRowFrame::GetMaxColumns() const
|
|
|
|
{
|
|
|
|
int sum = 0;
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame *cell=mFrames.FirstChild();
|
1998-09-24 20:37:22 +04:00
|
|
|
while (nsnull!=cell)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
cell->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1998-09-24 20:37:22 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
|
|
|
|
{
|
|
|
|
sum += ((nsTableCellFrame *)cell)->GetColSpan();
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
cell->GetNextSibling(&cell);
|
1998-06-17 20:38:24 +04:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
1998-06-24 23:13:19 +04:00
|
|
|
/* GetMinRowSpan is needed for deviant cases where every cell in a row has a rowspan > 1.
|
|
|
|
* It sets mMinRowSpan, which is used in FixMinCellHeight and PlaceChild
|
|
|
|
*/
|
1998-07-24 04:43:09 +04:00
|
|
|
void nsTableRowFrame::GetMinRowSpan(nsTableFrame *aTableFrame)
|
1998-06-24 23:13:19 +04:00
|
|
|
{
|
|
|
|
PRInt32 minRowSpan=-1;
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame *frame=mFrames.FirstChild();
|
1998-06-24 23:13:19 +04:00
|
|
|
while (nsnull!=frame)
|
|
|
|
{
|
1998-09-24 20:37:22 +04:00
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
frame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1998-09-24 20:37:22 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
|
|
|
|
{
|
1999-10-24 03:08:30 +04:00
|
|
|
PRInt32 rowSpan = aTableFrame->GetEffectiveRowSpan(GetRowIndex(), ((nsTableCellFrame *)frame));
|
1998-09-24 20:37:22 +04:00
|
|
|
if (-1==minRowSpan)
|
|
|
|
minRowSpan = rowSpan;
|
|
|
|
else if (minRowSpan>rowSpan)
|
|
|
|
minRowSpan = rowSpan;
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-06-24 23:13:19 +04:00
|
|
|
}
|
1999-10-24 03:08:30 +04:00
|
|
|
mBits.mMinRowSpan = unsigned(minRowSpan);
|
1998-06-24 23:13:19 +04:00
|
|
|
}
|
|
|
|
|
1998-07-24 04:43:09 +04:00
|
|
|
void nsTableRowFrame::FixMinCellHeight(nsTableFrame *aTableFrame)
|
1998-06-24 23:13:19 +04:00
|
|
|
{
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame *frame=mFrames.FirstChild();
|
1998-06-24 23:13:19 +04:00
|
|
|
while (nsnull!=frame)
|
|
|
|
{
|
1998-09-24 20:37:22 +04:00
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
frame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1998-09-24 20:37:22 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
|
1998-06-24 23:13:19 +04:00
|
|
|
{
|
1999-10-24 03:08:30 +04:00
|
|
|
PRInt32 rowSpan = aTableFrame->GetEffectiveRowSpan(GetRowIndex(), ((nsTableCellFrame *)frame));
|
|
|
|
if (PRInt32(mBits.mMinRowSpan) ==rowSpan)
|
1998-09-24 20:37:22 +04:00
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
frame->GetRect(rect);
|
|
|
|
if (rect.height > mTallestCell)
|
|
|
|
mTallestCell = rect.height;
|
|
|
|
}
|
1998-06-24 23:13:19 +04:00
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-06-24 23:13:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Position and size aKidFrame and update our reflow state. The origin of
|
|
|
|
// aKidRect is relative to the upper-left origin of our frame, and includes
|
|
|
|
// any left/top margin.
|
1998-07-15 21:05:21 +04:00
|
|
|
void nsTableRowFrame::PlaceChild(nsIPresContext& aPresContext,
|
1998-10-14 20:32:45 +04:00
|
|
|
RowReflowState& aReflowState,
|
1998-04-23 21:29:07 +04:00
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
const nsRect& aKidRect,
|
|
|
|
nsSize* aMaxElementSize,
|
1998-07-02 21:40:56 +04:00
|
|
|
nsSize* aKidMaxElementSize)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
|
|
|
// Place and size the child
|
1999-10-26 08:44:41 +04:00
|
|
|
aKidFrame->SetRect(&aPresContext, aKidRect);
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
// update the running total for the row width
|
1998-10-14 20:32:45 +04:00
|
|
|
aReflowState.x += aKidRect.width;
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
// Update the maximum element size
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan((nsTableCellFrame*)aKidFrame);
|
|
|
|
if (nsnull != aMaxElementSize) {
|
1998-07-02 21:40:56 +04:00
|
|
|
aMaxElementSize->width += aKidMaxElementSize->width;
|
1999-07-28 12:09:02 +04:00
|
|
|
if (1 == rowSpan) {
|
|
|
|
aMaxElementSize->height = PR_MAX(aMaxElementSize->height, aKidMaxElementSize->height);
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
}
|
1998-07-01 08:55:15 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// XXX this will be fixed when row spans deal with dead rows
|
|
|
|
#if 0
|
1998-11-24 22:41:33 +03:00
|
|
|
// this accounts for cases where all cells in a row have a rowspan>1
|
|
|
|
// XXX "numColsInThisRow==numColsInTable" probably isn't the right metric to use here
|
|
|
|
// the point is to skip a cell who's span effects another row, maybe use cellmap?
|
|
|
|
PRInt32 numColsInThisRow = GetMaxColumns();
|
|
|
|
PRInt32 numColsInTable = aReflowState.tableFrame->GetColCount();
|
|
|
|
if ((1==rowSpan) || (mMinRowSpan == rowSpan && numColsInThisRow==numColsInTable))
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
1998-07-01 08:55:15 +04:00
|
|
|
// Update maxCellHeight
|
1998-10-14 20:32:45 +04:00
|
|
|
if (aKidRect.height > aReflowState.maxCellHeight)
|
|
|
|
aReflowState.maxCellHeight = aKidRect.height;
|
1998-07-01 08:55:15 +04:00
|
|
|
|
|
|
|
// Update maxCellVertSpace
|
|
|
|
nsMargin margin;
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
if (aReflowState.tableFrame->GetCellMarginData((nsTableCellFrame *)aKidFrame, margin) == NS_OK)
|
1998-05-22 03:43:18 +04:00
|
|
|
{
|
|
|
|
nscoord height = aKidRect.height + margin.top + margin.bottom;
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
if (height > aReflowState.maxCellVertSpace)
|
|
|
|
aReflowState.maxCellVertSpace = height;
|
1998-05-22 03:43:18 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
#else
|
|
|
|
if (1 == rowSpan) {
|
|
|
|
// Update maxCellHeight
|
|
|
|
if (aKidRect.height > aReflowState.maxCellHeight)
|
|
|
|
aReflowState.maxCellHeight = aKidRect.height;
|
|
|
|
|
|
|
|
// Update maxCellVertSpace
|
|
|
|
nsMargin margin;
|
|
|
|
|
|
|
|
if (aReflowState.tableFrame->GetCellMarginData((nsTableCellFrame *)aKidFrame, margin) == NS_OK) {
|
|
|
|
nscoord height = aKidRect.height + margin.top + margin.bottom;
|
|
|
|
|
|
|
|
if (height > aReflowState.maxCellVertSpace)
|
|
|
|
aReflowState.maxCellVertSpace = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
// Calculate the cell's actual size given its pass2 desired width and height.
|
|
|
|
// Takes into account the specified height (in the style), and any special logic
|
|
|
|
// needed for backwards compatibility.
|
|
|
|
// Modifies the desired width and height that are passed in.
|
|
|
|
nsresult
|
1999-08-26 01:49:18 +04:00
|
|
|
nsTableRowFrame::CalculateCellActualSize(RowReflowState& aReflowState,
|
|
|
|
nsIFrame* aCellFrame,
|
|
|
|
nscoord& aDesiredWidth,
|
|
|
|
nscoord& aDesiredHeight,
|
|
|
|
nscoord aAvailWidth)
|
1999-08-22 00:16:32 +04:00
|
|
|
{
|
|
|
|
nscoord specifiedHeight = 0;
|
|
|
|
const nsStylePosition* position;
|
|
|
|
|
|
|
|
// Get the height specified in the style information
|
|
|
|
aCellFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position);
|
|
|
|
|
|
|
|
switch (position->mHeight.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
specifiedHeight = position->mHeight.GetCoordValue();
|
|
|
|
break;
|
1999-08-26 01:49:18 +04:00
|
|
|
case eStyleUnit_Percent:
|
|
|
|
{
|
|
|
|
nsTableFrame* table = nsnull;
|
|
|
|
nsTableFrame::GetTableFrame(this, table);
|
|
|
|
if (table) {
|
|
|
|
nscoord basis = table->GetPercentBasisForRows();
|
|
|
|
if (basis > 0) {
|
|
|
|
float percent = position->mHeight.GetPercentValue();
|
|
|
|
specifiedHeight = NSToCoordRound(percent * ((float)basis));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-08-22 00:16:32 +04:00
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
// XXX for now, do nothing
|
|
|
|
default:
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the specified height is greater than the desired height, then use the
|
|
|
|
// specified height
|
|
|
|
if (specifiedHeight > aDesiredHeight)
|
|
|
|
aDesiredHeight = specifiedHeight;
|
|
|
|
|
|
|
|
// begin special Nav4 compatibility code for the width
|
|
|
|
if (0 == aDesiredWidth)
|
|
|
|
{
|
|
|
|
aDesiredWidth = aAvailWidth;
|
|
|
|
}
|
|
|
|
// end special Nav4 compatibility code
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculates the available width for the table cell based on the known
|
|
|
|
// column widths taking into account column spans and column spacing
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::CalculateCellAvailableWidth(nsTableFrame* aTableFrame,
|
|
|
|
nsIFrame* aCellFrame,
|
|
|
|
PRInt32 aCellColIndex,
|
|
|
|
PRInt32 aNumColSpans,
|
|
|
|
nscoord aCellSpacingX)
|
|
|
|
{
|
|
|
|
nscoord availWidth = 0;
|
|
|
|
for (PRInt32 index = 0; index < aNumColSpans; index++) {
|
|
|
|
// Add in the width of this column
|
|
|
|
availWidth += aTableFrame->GetColumnWidth(aCellColIndex + index);
|
|
|
|
|
|
|
|
// If the cell spans columns, then for all columns except the first column
|
|
|
|
// add in the column spacing
|
1999-08-26 01:49:18 +04:00
|
|
|
if ((index != 0) && (aTableFrame->GetNumCellsOriginatingInCol(aCellColIndex + index) > 0)) {
|
1999-08-22 00:16:32 +04:00
|
|
|
availWidth += aCellSpacingX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return availWidth;
|
|
|
|
}
|
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
/**
|
1998-07-11 02:56:13 +04:00
|
|
|
* Called for a resize reflow. Typically because the column widths have
|
1999-08-03 06:41:27 +04:00
|
|
|
* changed. Reflows all the existing table cell frames unless aDirtyOnly
|
|
|
|
* is PR_TRUE in which case only reflow the dirty frames
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
1998-10-20 19:59:56 +04:00
|
|
|
NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
RowReflowState& aReflowState,
|
1999-08-03 06:41:27 +04:00
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
PRBool aDirtyOnly)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-12-15 19:39:09 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1999-04-22 07:51:58 +04:00
|
|
|
if (nsnull == mFrames.FirstChild()) {
|
1998-07-17 21:51:43 +04:00
|
|
|
return NS_OK;
|
1999-04-22 07:51:58 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 04:01:25 +03:00
|
|
|
nsresult rv=NS_OK;
|
1999-10-17 07:17:53 +04:00
|
|
|
|
|
|
|
nsSize localKidMaxElementSize(0,0);
|
|
|
|
nsSize* kidMaxElementSize = (aDesiredSize.maxElementSize) ? &localKidMaxElementSize : nsnull;
|
|
|
|
|
1998-12-09 09:37:18 +03:00
|
|
|
nscoord cellSpacingX = aReflowState.tableFrame->GetCellSpacingX();
|
1998-09-16 04:48:14 +04:00
|
|
|
PRInt32 cellColSpan=1; // must be defined here so it's set properly for non-cell kids
|
1999-04-22 07:51:58 +04:00
|
|
|
|
|
|
|
PRInt32 prevColIndex; // remember the col index of the previous cell to handle rowspans into this row
|
1998-11-20 04:01:25 +03:00
|
|
|
|
1999-05-04 23:15:56 +04:00
|
|
|
nsTableIteration dir = (aReflowState.reflowState.availableWidth == NS_UNCONSTRAINEDSIZE)
|
|
|
|
? eTableLTR : eTableDIR;
|
|
|
|
nsTableIterator iter(*this, dir);
|
1999-05-04 07:31:07 +04:00
|
|
|
if (iter.IsLeftToRight()) {
|
|
|
|
prevColIndex = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsTableFrame* tableFrame = nsnull;
|
|
|
|
rv = nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
if (NS_FAILED(rv) || (nsnull == tableFrame)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
prevColIndex = tableFrame->GetColCount();
|
|
|
|
}
|
1999-05-04 23:15:56 +04:00
|
|
|
|
1998-07-11 02:56:13 +04:00
|
|
|
// Reflow each of our existing cell frames
|
1999-04-22 07:51:58 +04:00
|
|
|
nsIFrame* kidFrame = iter.First();
|
|
|
|
while (nsnull != kidFrame) {
|
1999-08-03 06:41:27 +04:00
|
|
|
// Get the frame state bits
|
|
|
|
nsFrameState frameState;
|
|
|
|
kidFrame->GetFrameState(&frameState);
|
|
|
|
|
|
|
|
// See if we should only reflow the dirty child frames
|
|
|
|
PRBool doReflowChild = PR_TRUE;
|
|
|
|
if (aDirtyOnly) {
|
|
|
|
if ((frameState & NS_FRAME_IS_DIRTY) == 0) {
|
|
|
|
doReflowChild = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow the child frame
|
|
|
|
if (doReflowChild) {
|
|
|
|
const nsStyleDisplay *kidDisplay;
|
|
|
|
kidFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay) {
|
|
|
|
PRInt32 cellColIndex;
|
|
|
|
((nsTableCellFrame *)kidFrame)->GetColIndex(cellColIndex);
|
|
|
|
cellColSpan = aReflowState.tableFrame->GetEffectiveColSpan(cellColIndex,
|
|
|
|
((nsTableCellFrame *)kidFrame));
|
|
|
|
|
|
|
|
// Compute the x-origin for the child, taking into account straddlers (cells from prior
|
|
|
|
// rows with rowspans > 1)
|
|
|
|
// if this cell is not immediately adjacent to the previous cell, factor in missing col info
|
|
|
|
if (iter.IsLeftToRight()) {
|
|
|
|
if (prevColIndex != (cellColIndex - 1)) {
|
|
|
|
for (PRInt32 colIndex = prevColIndex + 1; cellColIndex > colIndex; colIndex++) {
|
|
|
|
aReflowState.x += aReflowState.tableFrame->GetColumnWidth(colIndex);
|
1999-08-26 01:49:18 +04:00
|
|
|
if (aReflowState.tableFrame->GetNumCellsOriginatingInCol(colIndex) > 0) {
|
1999-08-03 06:41:27 +04:00
|
|
|
aReflowState.x += cellSpacingX;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1999-04-22 07:51:58 +04:00
|
|
|
}
|
1998-09-16 04:48:14 +04:00
|
|
|
}
|
1999-08-03 06:41:27 +04:00
|
|
|
else {
|
|
|
|
if (prevColIndex != cellColIndex + cellColSpan) {
|
|
|
|
PRInt32 lastCol = cellColIndex + cellColSpan - 1;
|
|
|
|
for (PRInt32 colIndex = prevColIndex - 1; colIndex > lastCol; colIndex--) {
|
|
|
|
aReflowState.x += aReflowState.tableFrame->GetColumnWidth(colIndex);
|
1999-08-26 01:49:18 +04:00
|
|
|
if (aReflowState.tableFrame->GetNumCellsOriginatingInCol(colIndex) > 0) {
|
1999-08-03 06:41:27 +04:00
|
|
|
aReflowState.x += cellSpacingX;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1999-04-22 07:51:58 +04:00
|
|
|
}
|
|
|
|
}
|
1999-08-03 06:41:27 +04:00
|
|
|
|
|
|
|
aReflowState.x += cellSpacingX;
|
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
// Calculate the available width for the table cell using the known
|
|
|
|
// column widths
|
1999-10-05 03:48:05 +04:00
|
|
|
nscoord availWidth;
|
|
|
|
if (aDirtyOnly && (frameState & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
// This is the initial reflow for the cell and so we do an unconstrained
|
|
|
|
// reflow.
|
|
|
|
// Note: don't assume that we have known column widths. If we don't, then
|
|
|
|
// CalculateCellAvailableWidth() may assert if called now...
|
|
|
|
availWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
|
|
|
availWidth = CalculateCellAvailableWidth(aReflowState.tableFrame,
|
|
|
|
kidFrame, cellColIndex,
|
|
|
|
cellColSpan, cellSpacingX);
|
|
|
|
}
|
1999-08-22 00:16:32 +04:00
|
|
|
|
1999-08-03 06:41:27 +04:00
|
|
|
// remember the rightmost (ltr) or leftmost (rtl) column this cell spans into
|
|
|
|
prevColIndex = (iter.IsLeftToRight()) ? cellColIndex + (cellColSpan - 1) : cellColIndex;
|
1999-10-17 07:17:53 +04:00
|
|
|
nsHTMLReflowMetrics desiredSize(kidMaxElementSize);
|
1999-08-03 06:41:27 +04:00
|
|
|
|
|
|
|
// If the available width is the same as last time we reflowed the cell,
|
|
|
|
// then just use the previous desired size and max element size.
|
|
|
|
// if we need the max-element-size we don't need to reflow.
|
|
|
|
// we just grab it from the cell frame which remembers it (see the else clause below).
|
|
|
|
// Note: we can't do that optimization if our height is constrained or the
|
|
|
|
// cell frame has a next-in-flow
|
|
|
|
nsIFrame* kidNextInFlow;
|
|
|
|
kidFrame->GetNextInFlow(&kidNextInFlow);
|
|
|
|
if ((aReflowState.reflowState.availableHeight != NS_UNCONSTRAINEDSIZE) ||
|
|
|
|
(availWidth != ((nsTableCellFrame *)kidFrame)->GetPriorAvailWidth()) ||
|
|
|
|
(nsnull != kidNextInFlow))
|
|
|
|
{
|
|
|
|
// Reflow the cell to fit the available height
|
|
|
|
nsSize kidAvailSize(availWidth, aReflowState.reflowState.availableHeight);
|
|
|
|
|
|
|
|
// If it's a dirty frame, then check whether it's the initial reflow
|
|
|
|
nsReflowReason reason = eReflowReason_Resize;
|
|
|
|
if (aDirtyOnly) {
|
|
|
|
if (frameState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Newly inserted frame
|
|
|
|
reason = eReflowReason_Initial;
|
|
|
|
|
|
|
|
// Use an unconstrained width so we can get the child's maximum
|
|
|
|
// width
|
|
|
|
// XXX What about fixed layout tables?
|
|
|
|
kidAvailSize.SizeTo(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow the child
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext,
|
|
|
|
aReflowState.reflowState, kidFrame,
|
|
|
|
kidAvailSize,
|
|
|
|
reason);
|
|
|
|
nsReflowStatus status;
|
|
|
|
rv = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState, status);
|
1998-09-16 04:48:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
1999-08-03 06:41:27 +04:00
|
|
|
if (desiredSize.width > availWidth)
|
|
|
|
{
|
|
|
|
printf("WARNING: cell returned desired width %d given avail width %d\n",
|
|
|
|
desiredSize.width, availWidth);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (eReflowReason_Initial == reason) {
|
|
|
|
// Save the pass1 reflow information
|
|
|
|
((nsTableCellFrame *)kidFrame)->SetPass1DesiredSize(desiredSize);
|
1999-10-17 07:17:53 +04:00
|
|
|
if (kidMaxElementSize) {
|
|
|
|
((nsTableCellFrame *)kidFrame)->SetPass1MaxElementSize(*kidMaxElementSize);
|
|
|
|
}
|
1999-08-03 06:41:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If any of the cells are not complete, then we're not complete
|
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(status)) {
|
|
|
|
aStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1998-10-06 04:27:22 +04:00
|
|
|
{
|
1999-08-03 06:41:27 +04:00
|
|
|
nsSize priorSize = ((nsTableCellFrame *)kidFrame)->GetDesiredSize();
|
|
|
|
desiredSize.width = priorSize.width;
|
|
|
|
desiredSize.height = priorSize.height;
|
1999-10-17 07:17:53 +04:00
|
|
|
if (kidMaxElementSize)
|
|
|
|
*kidMaxElementSize = ((nsTableCellFrame *)kidFrame)->GetPass1MaxElementSize();
|
1998-10-06 04:27:22 +04:00
|
|
|
}
|
1999-08-03 06:41:27 +04:00
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
// Calculate the cell's actual size given its pass2 size. This function
|
|
|
|
// takes into account the specified height (in the style), and any special
|
|
|
|
// logic needed for backwards compatibility
|
1999-08-26 01:49:18 +04:00
|
|
|
CalculateCellActualSize(aReflowState, kidFrame, desiredSize.width,
|
|
|
|
desiredSize.height, availWidth);
|
1999-08-03 06:41:27 +04:00
|
|
|
|
|
|
|
// Place the child
|
1999-10-29 18:40:58 +04:00
|
|
|
nsRect kidRect (aReflowState.x, GetChildMaxTopMargin(), desiredSize.width,
|
1999-08-22 00:16:32 +04:00
|
|
|
desiredSize.height);
|
1999-08-03 06:41:27 +04:00
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
PlaceChild(aPresContext, aReflowState, kidFrame, kidRect,
|
1999-10-17 07:17:53 +04:00
|
|
|
aDesiredSize.maxElementSize, kidMaxElementSize);
|
1999-08-03 06:41:27 +04:00
|
|
|
|
1998-09-16 04:48:14 +04:00
|
|
|
}
|
|
|
|
else
|
1999-08-03 06:41:27 +04:00
|
|
|
{// it's an unknown frame type, give it a generic reflow and ignore the results
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState,
|
|
|
|
kidFrame,
|
|
|
|
nsSize(0,0), eReflowReason_Resize);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState, status);
|
1998-09-16 04:48:14 +04:00
|
|
|
}
|
1998-10-23 21:24:57 +04:00
|
|
|
}
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1999-04-22 07:51:58 +04:00
|
|
|
kidFrame = iter.Next(); // Get the next child
|
1998-09-16 04:48:14 +04:00
|
|
|
// if this was the last child, and it had a colspan>1, add in the cellSpacing for the colspan
|
|
|
|
// if the last kid wasn't a colspan, then we still have the colspan of the last real cell
|
|
|
|
if ((nsnull==kidFrame) && (cellColSpan>1))
|
1998-12-09 09:37:18 +03:00
|
|
|
aReflowState.x += cellSpacingX;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 18:40:58 +04:00
|
|
|
SetMaxChildHeight(aReflowState.maxCellHeight); // remember height of tallest child who doesn't have a row span
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-07-11 02:56:13 +04:00
|
|
|
// Return our desired size. Note that our desired width is just whatever width
|
|
|
|
// we were given by the row group frame
|
1998-10-14 20:32:45 +04:00
|
|
|
aDesiredSize.width = aReflowState.x;
|
|
|
|
aDesiredSize.height = aReflowState.maxCellVertSpace;
|
1999-10-26 03:02:43 +04:00
|
|
|
#ifdef DEBUG_karnaze
|
1999-07-28 12:09:02 +04:00
|
|
|
nscoord overAllocated = aDesiredSize.width - aReflowState.reflowState.availableWidth;
|
|
|
|
if (overAllocated > 0) {
|
|
|
|
float p2t;
|
|
|
|
aPresContext.GetScaledPixelsToTwips(&p2t);
|
|
|
|
if (overAllocated > p2t) {
|
1999-10-26 03:02:43 +04:00
|
|
|
printf("row over allocated by %d\n twips", overAllocated);
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-10-23 21:24:57 +04:00
|
|
|
return rv;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-07-11 02:56:13 +04:00
|
|
|
* Called for the initial reflow. Creates each table cell frame, and
|
|
|
|
* reflows it to gets its minimum and maximum sizes
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
1998-10-20 19:59:56 +04:00
|
|
|
NS_METHOD
|
|
|
|
nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
RowReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nsTableCellFrame * aStartFrame,
|
|
|
|
PRBool aDoSiblings)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
|
|
|
// Place our children, one at a time, until we are out of children
|
1998-09-24 01:48:26 +04:00
|
|
|
nsSize kidMaxElementSize(0,0);
|
1998-07-11 02:56:13 +04:00
|
|
|
nscoord x = 0;
|
1998-09-24 01:48:26 +04:00
|
|
|
PRBool tableLayoutStrategy=NS_STYLE_TABLE_LAYOUT_AUTO;
|
1998-11-04 23:09:19 +03:00
|
|
|
nsTableFrame* table = aReflowState.tableFrame;
|
|
|
|
nsresult rv = NS_OK;
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsStyleTable* tableStyle;
|
|
|
|
table->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle);
|
1998-11-04 23:09:19 +03:00
|
|
|
tableLayoutStrategy = tableStyle->mLayoutStrategy;
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-10-20 19:59:56 +04:00
|
|
|
nsIFrame* kidFrame;
|
|
|
|
if (nsnull==aStartFrame)
|
1999-01-16 01:52:05 +03:00
|
|
|
kidFrame = mFrames.FirstChild();
|
1998-10-20 19:59:56 +04:00
|
|
|
else
|
|
|
|
kidFrame = aStartFrame;
|
|
|
|
|
1999-02-10 09:13:38 +03:00
|
|
|
for ( ; nsnull != kidFrame; kidFrame->GetNextSibling(&kidFrame))
|
1998-09-24 01:48:26 +04:00
|
|
|
{
|
1998-09-24 20:37:22 +04:00
|
|
|
const nsStyleDisplay *kidDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
kidFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
1998-09-24 20:37:22 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay)
|
1998-09-16 21:19:20 +04:00
|
|
|
{
|
1998-09-24 20:37:22 +04:00
|
|
|
// Get the child's margins
|
1999-10-29 18:40:58 +04:00
|
|
|
// Get the frame's margins
|
|
|
|
nsMargin kidMargin;
|
|
|
|
aReflowState.tableFrame->GetCellMarginData((nsTableCellFrame *)kidFrame, kidMargin);
|
1998-09-24 20:37:22 +04:00
|
|
|
|
1998-10-30 10:57:44 +03:00
|
|
|
// get border padding values
|
|
|
|
nsMargin borderPadding;
|
1998-12-09 09:37:18 +03:00
|
|
|
const nsStyleSpacing* cellSpacingStyle;
|
|
|
|
kidFrame->GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)cellSpacingStyle));
|
|
|
|
cellSpacingStyle->CalcBorderPaddingFor(kidFrame, borderPadding);
|
1998-10-30 10:57:44 +03:00
|
|
|
|
1999-02-19 05:05:00 +03:00
|
|
|
// For the initial reflow always allow the child to be as high as it
|
|
|
|
// wants. The default available width is also unconstrained so we can
|
1998-09-24 20:37:22 +04:00
|
|
|
// get the child's maximum width
|
|
|
|
nsSize kidAvailSize;
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics kidSize(nsnull);
|
1998-09-24 20:37:22 +04:00
|
|
|
if (NS_STYLE_TABLE_LAYOUT_AUTO==tableLayoutStrategy)
|
|
|
|
{
|
|
|
|
kidAvailSize.SizeTo(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
kidSize.maxElementSize=&kidMaxElementSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-11 04:16:28 +03:00
|
|
|
PRInt32 colIndex;
|
|
|
|
((nsTableCellFrame *)kidFrame)->GetColIndex(colIndex);
|
1998-09-24 20:37:22 +04:00
|
|
|
kidAvailSize.SizeTo(table->GetColumnWidth(colIndex), NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
1998-09-24 01:48:26 +04:00
|
|
|
|
1999-03-05 07:19:09 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext,
|
|
|
|
aReflowState.reflowState,
|
|
|
|
kidFrame, kidAvailSize,
|
1998-10-02 08:10:00 +04:00
|
|
|
eReflowReason_Initial);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-10-20 19:59:56 +04:00
|
|
|
rv = ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, aStatus);
|
1999-02-24 00:03:57 +03:00
|
|
|
|
1999-03-13 15:49:37 +03:00
|
|
|
// the following signals bugs in the content frames.
|
1999-02-24 00:03:57 +03:00
|
|
|
if (kidMaxElementSize.width > kidSize.width) {
|
1999-03-13 15:49:37 +03:00
|
|
|
printf("WARNING - table cell content max element width %d greater than desired width %d\n",
|
|
|
|
kidMaxElementSize.width, kidSize.width);
|
1998-10-06 04:27:22 +04:00
|
|
|
kidSize.width = kidMaxElementSize.width;
|
1999-02-24 00:03:57 +03:00
|
|
|
}
|
|
|
|
if (kidMaxElementSize.height > kidSize.height) {
|
1999-03-13 15:49:37 +03:00
|
|
|
printf("Warning - table cell content max element height %d greater than desired height %d\n",
|
|
|
|
kidMaxElementSize.height, kidSize.height);
|
1998-10-06 04:27:22 +04:00
|
|
|
kidSize.height = kidMaxElementSize.height;
|
1999-02-24 00:03:57 +03:00
|
|
|
}
|
|
|
|
|
1998-10-06 04:27:22 +04:00
|
|
|
((nsTableCellFrame *)kidFrame)->SetPass1DesiredSize(kidSize);
|
|
|
|
((nsTableCellFrame *)kidFrame)->SetPass1MaxElementSize(kidMaxElementSize);
|
1998-10-20 19:59:56 +04:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "unexpected child reflow status");
|
1998-10-06 04:27:22 +04:00
|
|
|
|
|
|
|
// Place the child
|
1999-10-29 18:40:58 +04:00
|
|
|
x += kidMargin.left;
|
|
|
|
nsRect kidRect(x, kidMargin.top, kidSize.width, kidSize.height);
|
1998-10-14 20:32:45 +04:00
|
|
|
PlaceChild(aPresContext, aReflowState, kidFrame, kidRect, aDesiredSize.maxElementSize,
|
1998-10-06 04:27:22 +04:00
|
|
|
&kidMaxElementSize);
|
1999-10-29 18:40:58 +04:00
|
|
|
x += kidSize.width + kidMargin.right;
|
1998-09-24 20:37:22 +04:00
|
|
|
}
|
1998-10-23 21:24:57 +04:00
|
|
|
else
|
|
|
|
{// it's an unknown frame type, give it a generic reflow and ignore the results
|
1999-03-05 07:19:09 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState,
|
|
|
|
kidFrame, nsSize(0,0), eReflowReason_Initial);
|
1998-10-23 21:24:57 +04:00
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState, aStatus);
|
|
|
|
}
|
|
|
|
if (PR_FALSE==aDoSiblings)
|
|
|
|
break;
|
1998-09-16 21:19:20 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 18:40:58 +04:00
|
|
|
SetMaxChildHeight(aReflowState.maxCellHeight); // remember height of tallest child who doesn't have a row span
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.width = x;
|
1998-10-14 20:32:45 +04:00
|
|
|
aDesiredSize.height = aReflowState.maxCellVertSpace;
|
1998-07-10 08:00:38 +04:00
|
|
|
|
1998-10-20 19:59:56 +04:00
|
|
|
return rv;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
|
|
|
|
1998-07-01 07:03:32 +04:00
|
|
|
// Recover the reflow state to what it should be if aKidFrame is about
|
|
|
|
// to be reflowed
|
1998-07-11 02:56:13 +04:00
|
|
|
//
|
|
|
|
// The things in the RowReflowState object we need to restore are:
|
|
|
|
// - maxCellHeight
|
|
|
|
// - maxVertCellSpace
|
1998-07-14 19:29:50 +04:00
|
|
|
// - x
|
1998-10-20 19:59:56 +04:00
|
|
|
NS_METHOD nsTableRowFrame::RecoverState(nsIPresContext& aPresContext,
|
|
|
|
RowReflowState& aReflowState,
|
|
|
|
nsIFrame* aKidFrame,
|
1999-08-31 02:30:32 +04:00
|
|
|
nsSize* aMaxElementSize)
|
1998-07-01 07:03:32 +04:00
|
|
|
{
|
1999-08-22 01:24:42 +04:00
|
|
|
// Initialize OUT parameters
|
1999-08-31 02:30:32 +04:00
|
|
|
if (aMaxElementSize) {
|
|
|
|
aMaxElementSize->width = 0;
|
|
|
|
aMaxElementSize->height = 0;
|
|
|
|
}
|
1998-07-15 08:45:58 +04:00
|
|
|
|
1999-08-22 01:24:42 +04:00
|
|
|
// Walk the child frames (except aKidFrame) and find the table cell frames
|
|
|
|
for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) {
|
|
|
|
if (frame != aKidFrame) {
|
|
|
|
// See if the frame is a table cell frame
|
|
|
|
const nsStyleDisplay *kidDisplay;
|
|
|
|
frame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)kidDisplay));
|
|
|
|
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay) {
|
1999-10-29 18:40:58 +04:00
|
|
|
// Get the child's margins
|
1999-08-22 01:24:42 +04:00
|
|
|
nsMargin kidMargin;
|
1998-10-14 20:32:45 +04:00
|
|
|
aReflowState.tableFrame->GetCellMarginData((nsTableCellFrame *)frame, kidMargin);
|
1998-09-24 20:37:22 +04:00
|
|
|
|
1999-08-22 01:24:42 +04:00
|
|
|
// Update maxCellHeight and maxVertCellSpace. When determining this we
|
|
|
|
// don't include cells that span rows
|
1999-10-24 03:08:30 +04:00
|
|
|
PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan(GetRowIndex(), ((nsTableCellFrame *)frame));
|
|
|
|
if (PRInt32(mBits.mMinRowSpan) == rowSpan) {
|
1998-09-24 20:37:22 +04:00
|
|
|
// Get the cell's desired height the last time it was reflowed
|
|
|
|
nsSize desiredSize = ((nsTableCellFrame *)frame)->GetDesiredSize();
|
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
// See if it has a specified height that overrides the desired size.
|
|
|
|
// Note: we don't care about the width so don't compute the column
|
|
|
|
// width and just pass in the desired width for the available width
|
1999-08-26 01:49:18 +04:00
|
|
|
CalculateCellActualSize(aReflowState, frame, desiredSize.width, desiredSize.height,
|
1999-08-22 00:16:32 +04:00
|
|
|
desiredSize.width);
|
|
|
|
|
1998-09-24 20:37:22 +04:00
|
|
|
// Update maxCellHeight
|
1998-10-14 20:32:45 +04:00
|
|
|
if (desiredSize.height > aReflowState.maxCellHeight) {
|
|
|
|
aReflowState.maxCellHeight = desiredSize.height;
|
1998-09-24 20:37:22 +04:00
|
|
|
}
|
1998-07-01 08:55:15 +04:00
|
|
|
|
1998-09-24 20:37:22 +04:00
|
|
|
// Update maxCellVertHeight
|
1999-08-22 01:24:42 +04:00
|
|
|
nscoord vertHeight = desiredSize.height + kidMargin.top + kidMargin.bottom;
|
|
|
|
if (vertHeight > aReflowState.maxCellVertSpace) {
|
|
|
|
aReflowState.maxCellVertSpace = vertHeight;
|
1998-07-14 19:29:50 +04:00
|
|
|
}
|
1998-07-01 08:55:15 +04:00
|
|
|
}
|
|
|
|
|
1999-08-31 02:30:32 +04:00
|
|
|
// Recover the max element size if requested
|
|
|
|
if (aMaxElementSize) {
|
|
|
|
nsSize kidMaxElementSize = ((nsTableCellFrame *)frame)->GetPass1MaxElementSize();
|
|
|
|
|
|
|
|
aMaxElementSize->width += kidMaxElementSize.width;
|
|
|
|
if (1 == rowSpan) {
|
|
|
|
aMaxElementSize->height = PR_MAX(aMaxElementSize->height, kidMaxElementSize.height);
|
|
|
|
}
|
|
|
|
}
|
1998-09-24 20:37:22 +04:00
|
|
|
}
|
1998-07-14 19:29:50 +04:00
|
|
|
}
|
1998-07-01 07:03:32 +04:00
|
|
|
}
|
|
|
|
|
1998-07-14 19:29:50 +04:00
|
|
|
// Update the running x-offset based on the frame's current x-origin
|
|
|
|
nsPoint origin;
|
|
|
|
aKidFrame->GetOrigin(origin);
|
1998-10-14 20:32:45 +04:00
|
|
|
aReflowState.x = origin.x;
|
1998-07-14 19:29:50 +04:00
|
|
|
|
1998-07-02 09:39:10 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsTableRowFrame::IncrementalReflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
1998-10-20 19:59:56 +04:00
|
|
|
RowReflowState& aReflowState,
|
1998-10-14 20:32:45 +04:00
|
|
|
nsReflowStatus& aStatus)
|
1998-07-02 09:39:10 +04:00
|
|
|
{
|
1998-10-14 20:32:45 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-02 09:39:10 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
// determine if this frame is the target or not
|
|
|
|
nsIFrame *target=nsnull;
|
|
|
|
rv = aReflowState.reflowState.reflowCommand->GetTarget(target);
|
|
|
|
if ((PR_TRUE==NS_SUCCEEDED(rv)) && (nsnull!=target))
|
1998-07-14 19:29:50 +04:00
|
|
|
{
|
1998-10-14 20:32:45 +04:00
|
|
|
if (this==target)
|
|
|
|
rv = IR_TargetIsMe(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
else
|
1998-07-14 19:29:50 +04:00
|
|
|
{
|
1998-10-14 20:32:45 +04:00
|
|
|
// Get the next frame in the reflow chain
|
|
|
|
nsIFrame* nextFrame;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetNext(nextFrame);
|
|
|
|
rv = IR_TargetIsChild(aPresContext, aDesiredSize, aReflowState, aStatus, nextFrame);
|
1998-07-14 19:29:50 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-14 20:32:45 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-07-14 19:29:50 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
NS_METHOD nsTableRowFrame::IR_TargetIsMe(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
RowReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_FRAME_COMPLETE;
|
|
|
|
nsIReflowCommand::ReflowType type;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetType(type);
|
|
|
|
nsIFrame *objectFrame;
|
|
|
|
aReflowState.reflowState.reflowCommand->GetChildFrame(objectFrame);
|
1998-10-30 10:57:44 +03:00
|
|
|
const nsStyleDisplay *childDisplay=nsnull;
|
|
|
|
if (nsnull!=objectFrame)
|
1998-12-02 19:45:20 +03:00
|
|
|
objectFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)childDisplay));
|
1998-10-14 20:32:45 +04:00
|
|
|
switch (type)
|
|
|
|
{
|
1999-08-03 06:41:27 +04:00
|
|
|
case nsIReflowCommand::ReflowDirty:
|
|
|
|
{
|
|
|
|
// Reflow the dirty child frames. Typically this is newly added frames.
|
|
|
|
// XXX What we really should do is do a pass-1 reflow of newly added
|
|
|
|
// frames (only if necessary, i.e., the table isn't fixed layout), then
|
|
|
|
// see if column widtsh changed and decide whether to do the pass-2 reflow
|
|
|
|
// of just the dirty rows or have the table rebalance column widths and
|
|
|
|
// do a pass-2 reflow of all rows
|
|
|
|
rv = ResizeReflow(aPresContext, aDesiredSize, aReflowState, aStatus, PR_TRUE);
|
|
|
|
|
|
|
|
// If any column widths have to change due to this, rebalance column widths.
|
|
|
|
// XXX need to calculate this, but for now just do it
|
|
|
|
aReflowState.tableFrame->InvalidateColumnWidths();
|
1998-10-06 04:27:22 +04:00
|
|
|
break;
|
1999-08-03 06:41:27 +04:00
|
|
|
}
|
1998-10-06 04:27:22 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
case nsIReflowCommand::StyleChanged :
|
1998-10-30 10:57:44 +03:00
|
|
|
rv = IR_StyleChanged(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1998-10-14 20:32:45 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIReflowCommand::ContentChanged :
|
|
|
|
NS_ASSERTION(PR_FALSE, "illegal reflow type: ContentChanged");
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
break;
|
|
|
|
|
1999-03-05 07:19:09 +03:00
|
|
|
default:
|
1999-08-03 06:41:27 +04:00
|
|
|
NS_NOTYETIMPLEMENTED("unexpected reflow command type");
|
1998-10-14 20:32:45 +04:00
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
1998-10-06 04:27:22 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-30 10:57:44 +03:00
|
|
|
NS_METHOD nsTableRowFrame::IR_StyleChanged(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
RowReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// we presume that all the easy optimizations were done in the nsHTMLStyleSheet before we were called here
|
|
|
|
// XXX: we can optimize this when we know which style attribute changed
|
1998-11-04 23:09:19 +03:00
|
|
|
aReflowState.tableFrame->InvalidateFirstPassCache();
|
1998-10-30 10:57:44 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
RowReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nsIFrame * aNextFrame)
|
|
|
|
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
const nsStyleDisplay *childDisplay;
|
1998-12-02 19:45:20 +03:00
|
|
|
aNextFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)childDisplay));
|
1998-10-14 20:32:45 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CELL == childDisplay->mDisplay)
|
|
|
|
{
|
|
|
|
// Recover our reflow state
|
1999-10-29 18:40:58 +04:00
|
|
|
RecoverState(aPresContext, aReflowState, aNextFrame, aDesiredSize.maxElementSize);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1999-08-22 01:24:42 +04:00
|
|
|
// At this point, we know the column widths. Compute the cell available width
|
1999-02-11 04:16:28 +03:00
|
|
|
PRInt32 cellColIndex;
|
|
|
|
((nsTableCellFrame *)aNextFrame)->GetColIndex(cellColIndex);
|
|
|
|
PRInt32 cellColSpan = aReflowState.tableFrame->GetEffectiveColSpan(cellColIndex,
|
|
|
|
((nsTableCellFrame *)aNextFrame));
|
1999-08-22 00:16:32 +04:00
|
|
|
nscoord cellSpacingX = aReflowState.tableFrame->GetCellSpacingX();
|
|
|
|
|
|
|
|
nscoord cellAvailWidth = CalculateCellAvailableWidth(aReflowState.tableFrame, aNextFrame,
|
|
|
|
cellColIndex, cellColSpan, cellSpacingX);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
|
|
|
// Always let the cell be as high as it wants. We ignore the height that's
|
|
|
|
// passed in and always place the entire row. Let the row group decide
|
|
|
|
// whether we fit or wehther the entire row is pushed
|
1999-08-22 00:16:32 +04:00
|
|
|
nsSize kidAvailSize(cellAvailWidth, NS_UNCONSTRAINEDSIZE);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
|
|
|
// Pass along the reflow command
|
1999-08-31 02:30:32 +04:00
|
|
|
nsSize kidMaxElementSize;
|
1998-10-14 20:32:45 +04:00
|
|
|
nsHTMLReflowMetrics desiredSize(&kidMaxElementSize);
|
1999-08-31 02:30:32 +04:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext,
|
|
|
|
aReflowState.reflowState,
|
|
|
|
aNextFrame, kidAvailSize);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1999-08-29 08:18:00 +04:00
|
|
|
// Remember the current desired size, we'll need it later
|
|
|
|
nsSize oldMinSize = ((nsTableCellFrame*)aNextFrame)->GetPass1MaxElementSize();
|
|
|
|
nsSize oldDesiredSize = ((nsTableCellFrame*)aNextFrame)->GetPass1DesiredSize();
|
|
|
|
|
|
|
|
// Reflow the cell passing it the incremental reflow command. We can't pass
|
|
|
|
// in a max width of NS_UNCONSTRAINEDSIZE, because the max width must match
|
1998-10-14 20:32:45 +04:00
|
|
|
// the width of the previous reflow...
|
|
|
|
rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, aStatus);
|
1999-08-29 08:18:00 +04:00
|
|
|
|
|
|
|
//XXX: this is a hack, shouldn't it be the case that a min size is
|
|
|
|
// never larger than a desired size?
|
1999-10-02 04:02:54 +04:00
|
|
|
#if 0
|
1999-08-29 08:18:00 +04:00
|
|
|
if (kidMaxElementSize.width>desiredSize.width)
|
|
|
|
desiredSize.width = kidMaxElementSize.width;
|
|
|
|
if (kidMaxElementSize.height>desiredSize.height)
|
|
|
|
desiredSize.height = kidMaxElementSize.height;
|
1999-10-02 04:02:54 +04:00
|
|
|
#endif
|
1999-08-29 08:18:00 +04:00
|
|
|
|
|
|
|
// Update the cell layout data.
|
|
|
|
((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1999-08-29 08:18:00 +04:00
|
|
|
// Now see if we need to do the regular pass 1 reflow and gather the preferred
|
|
|
|
// width. If the new minimum width is different from the old minimum width,
|
|
|
|
// then we should consider the max element size
|
1999-08-22 00:16:32 +04:00
|
|
|
if (aReflowState.tableFrame->ColumnsCanBeInvalidatedBy(*(nsTableCellFrame*)aNextFrame,
|
1999-08-29 08:18:00 +04:00
|
|
|
oldMinSize.width != kidMaxElementSize.width)) {
|
|
|
|
// For fixed-layout tables we don't need to know the preferred width
|
|
|
|
if (aReflowState.tableFrame->RequiresPass1Layout()) {
|
1999-09-09 00:29:56 +04:00
|
|
|
#ifdef DEBUG_troy
|
1999-08-29 08:18:00 +04:00
|
|
|
// Changes to the cell frame could require the columns to be rebalanced.
|
|
|
|
// XXX We don't really need to compute the max element size again, we just
|
|
|
|
// computed it above. However, for the time being do compute it again and
|
|
|
|
// make sure it's consistent...
|
|
|
|
nscoord prevMaxElementWidth = kidMaxElementSize.width;
|
1999-09-09 00:29:56 +04:00
|
|
|
#endif
|
1999-08-29 08:18:00 +04:00
|
|
|
|
|
|
|
// Do the unconstrained reflow and get the pass1 information
|
|
|
|
// XXX Why the reflow reason of eReflowReason_Initial?
|
|
|
|
kidReflowState.reason = eReflowReason_Initial;
|
|
|
|
kidReflowState.reflowCommand = nsnull;
|
|
|
|
kidReflowState.availableWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, aStatus);
|
|
|
|
|
|
|
|
//XXX: this is a hack, shouldn't it be the case that a min size is
|
|
|
|
// never larger than a desired size?
|
|
|
|
if (kidMaxElementSize.width>desiredSize.width)
|
|
|
|
desiredSize.width = kidMaxElementSize.width;
|
|
|
|
if (kidMaxElementSize.height>desiredSize.height)
|
|
|
|
desiredSize.height = kidMaxElementSize.height;
|
|
|
|
|
1999-09-09 00:29:56 +04:00
|
|
|
#ifdef DEBUG_troy
|
1999-08-29 08:18:00 +04:00
|
|
|
// XXX See above
|
|
|
|
NS_ASSERTION(prevMaxElementWidth == kidMaxElementSize.width,
|
|
|
|
"different max element width!");
|
|
|
|
#else
|
|
|
|
((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Update the cell layout data.
|
|
|
|
((nsTableCellFrame *)aNextFrame)->SetPass1DesiredSize(desiredSize);
|
|
|
|
}
|
1999-08-22 00:16:32 +04:00
|
|
|
|
|
|
|
// Now that we know the minimum and preferred widths see if the column
|
|
|
|
// widths need to be rebalanced
|
|
|
|
if (aReflowState.tableFrame->ColumnsAreValidFor(*(nsTableCellFrame*)aNextFrame,
|
|
|
|
oldMinSize.width,
|
|
|
|
oldDesiredSize.width)) {
|
|
|
|
// The column widths don't need to be rebalanced. Now reflow the cell
|
|
|
|
// again this time constraining the width back to the column width again
|
|
|
|
kidReflowState.reason = eReflowReason_Resize;
|
|
|
|
kidReflowState.availableWidth = cellAvailWidth;
|
|
|
|
rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, aStatus);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// The column widths need to be rebalanced, so don't waste time reflowing
|
|
|
|
// the cell again. Tell the table to rebalance the column widths
|
|
|
|
aReflowState.tableFrame->InvalidateColumnWidths();
|
|
|
|
}
|
1999-08-19 07:51:25 +04:00
|
|
|
}
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1999-08-22 00:16:32 +04:00
|
|
|
// Calculate the cell's actual size given its pass2 size. This function
|
|
|
|
// takes into account the specified height (in the style), and any special
|
|
|
|
// logic needed for backwards compatibility
|
1999-08-26 01:49:18 +04:00
|
|
|
CalculateCellActualSize(aReflowState, aNextFrame, desiredSize.width, desiredSize.height,
|
1999-08-22 00:16:32 +04:00
|
|
|
cellAvailWidth);
|
1998-08-07 06:11:51 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
// Now place the child
|
1999-10-29 18:40:58 +04:00
|
|
|
nsRect kidRect (aReflowState.x, GetChildMaxTopMargin(), desiredSize.width,
|
1999-08-22 00:16:32 +04:00
|
|
|
desiredSize.height);
|
|
|
|
PlaceChild(aPresContext, aReflowState, aNextFrame, kidRect,
|
|
|
|
aDesiredSize.maxElementSize, &kidMaxElementSize);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1999-10-29 18:40:58 +04:00
|
|
|
SetMaxChildHeight(aReflowState.maxCellHeight);
|
1998-10-14 20:32:45 +04:00
|
|
|
|
|
|
|
// Return our desired size. Note that our desired width is just whatever width
|
|
|
|
// we were given by the row group frame
|
|
|
|
aDesiredSize.width = aReflowState.availSize.width;
|
1999-08-31 02:30:32 +04:00
|
|
|
aDesiredSize.height = aReflowState.maxCellVertSpace;
|
1998-10-14 20:32:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // pass reflow to unknown frame child
|
|
|
|
// aDesiredSize does not change
|
|
|
|
}
|
|
|
|
return rv;
|
1998-07-01 07:03:32 +04:00
|
|
|
}
|
1998-05-22 03:43:18 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
|
1998-04-23 21:29:07 +04:00
|
|
|
/** Layout the entire row.
|
1998-07-02 09:39:10 +04:00
|
|
|
* This method stacks cells horizontally according to HTML 4.0 rules.
|
1998-04-23 21:29:07 +04:00
|
|
|
*/
|
|
|
|
NS_METHOD
|
1998-10-02 08:10:00 +04:00
|
|
|
nsTableRowFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-23 21:29:07 +04:00
|
|
|
{
|
1999-08-24 16:01:31 +04:00
|
|
|
if (nsDebugTable::gRflRow) nsTableFrame::DebugReflow("TR::Rfl en", this, &aReflowState, nsnull);
|
1999-08-19 23:52:37 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
// Initialize 'out' parameters (aStatus set below, undefined if rv returns an error)
|
1998-07-11 02:56:13 +04:00
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = 0;
|
|
|
|
aDesiredSize.maxElementSize->height = 0;
|
1998-04-23 21:29:07 +04:00
|
|
|
}
|
1998-07-11 02:56:13 +04:00
|
|
|
|
|
|
|
// Initialize our internal data
|
|
|
|
ResetMaxChildHeight();
|
1998-04-23 21:29:07 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
// Create a reflow state
|
|
|
|
nsTableFrame *tableFrame=nsnull;
|
|
|
|
rv = nsTableFrame::GetTableFrame(this, tableFrame);
|
|
|
|
if (NS_FAILED(rv) || nsnull==tableFrame)
|
|
|
|
return rv;
|
1998-07-15 08:45:58 +04:00
|
|
|
RowReflowState state(aReflowState, tableFrame);
|
1998-07-11 02:56:13 +04:00
|
|
|
|
|
|
|
// Do the reflow
|
1999-08-02 02:01:37 +04:00
|
|
|
// XXX If the width is unconstrained, then treat it like we would treat the
|
|
|
|
// initial reflow instead. This needs to be cleaned up
|
|
|
|
nsReflowReason reason = aReflowState.reason;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) {
|
|
|
|
reason = eReflowReason_Initial;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reason) {
|
1998-07-11 02:56:13 +04:00
|
|
|
case eReflowReason_Initial:
|
1998-10-20 19:59:56 +04:00
|
|
|
rv = InitialReflow(aPresContext, aDesiredSize, state, aStatus, nsnull, PR_TRUE);
|
1999-01-03 22:20:13 +03:00
|
|
|
if (PR_FALSE==tableFrame->RequiresPass1Layout())
|
|
|
|
{ // this resize reflow is necessary to place the cells correctly in the case of rowspans and colspans.
|
|
|
|
// It is very efficient. It does not actually need to pass a reflow down to the cells.
|
1999-01-06 02:31:18 +03:00
|
|
|
nsSize availSpace(aReflowState.availableWidth, aReflowState.availableHeight);
|
1999-03-05 07:19:09 +03:00
|
|
|
nsHTMLReflowState resizeReflowState(aPresContext,
|
1999-01-03 22:20:13 +03:00
|
|
|
(const nsHTMLReflowState&)(*(aReflowState.parentReflowState)),
|
1999-03-05 07:19:09 +03:00
|
|
|
(nsIFrame *)this,
|
1999-01-06 02:31:18 +03:00
|
|
|
availSpace,
|
1999-01-03 22:20:13 +03:00
|
|
|
eReflowReason_Resize);
|
|
|
|
RowReflowState rowResizeReflowState(resizeReflowState, tableFrame);
|
|
|
|
rv = ResizeReflow(aPresContext, aDesiredSize, rowResizeReflowState, aStatus);
|
|
|
|
}
|
1998-07-24 04:43:09 +04:00
|
|
|
GetMinRowSpan(tableFrame);
|
|
|
|
FixMinCellHeight(tableFrame);
|
1998-12-15 19:39:09 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-07-11 02:56:13 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eReflowReason_Resize:
|
1999-09-09 00:29:56 +04:00
|
|
|
case eReflowReason_StyleChange:
|
1998-10-20 19:59:56 +04:00
|
|
|
rv = ResizeReflow(aPresContext, aDesiredSize, state, aStatus);
|
1998-07-11 02:56:13 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eReflowReason_Incremental:
|
1998-10-14 20:32:45 +04:00
|
|
|
rv = IncrementalReflow(aPresContext, aDesiredSize, state, aStatus);
|
1998-07-11 02:56:13 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-07-02 09:39:10 +04:00
|
|
|
|
1999-08-31 02:30:32 +04:00
|
|
|
// If we computed our max element element size, then cache it so we can return
|
|
|
|
// it later when asked
|
|
|
|
if (aDesiredSize.maxElementSize) {
|
|
|
|
mMaxElementSize = *aDesiredSize.maxElementSize;
|
|
|
|
}
|
|
|
|
|
1999-08-24 16:01:31 +04:00
|
|
|
if (nsDebugTable::gRflRow) nsTableFrame::DebugReflow("TR::Rfl ex", this, nsnull, &aDesiredSize);
|
1998-10-14 20:32:45 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-11-07 03:36:37 +03:00
|
|
|
/* we overload this here because rows have children that can span outside of themselves.
|
|
|
|
* so the default "get the child rect, see if it contains the event point" action isn't
|
|
|
|
* sufficient. We have to ask the row if it has a child that contains the point.
|
|
|
|
*/
|
1998-11-18 08:25:26 +03:00
|
|
|
PRBool nsTableRowFrame::Contains(const nsPoint& aPoint)
|
1998-11-07 03:36:37 +03:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
// first, check the row rect and see if the point is in their
|
|
|
|
if (mRect.Contains(aPoint)) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
// if that fails, check the cells, they might span outside the row rect
|
|
|
|
else {
|
|
|
|
nsIFrame* kid;
|
1999-02-10 05:25:01 +03:00
|
|
|
FirstChild(nsnull, &kid);
|
1998-11-07 03:36:37 +03:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsRect kidRect;
|
|
|
|
kid->GetRect(kidRect);
|
|
|
|
nsPoint point(aPoint);
|
|
|
|
point.MoveBy(-mRect.x, -mRect.y); // offset the point to check by the row container
|
|
|
|
if (kidRect.Contains(point)) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-11-07 03:36:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-02-22 06:28:00 +03:00
|
|
|
/**
|
|
|
|
* This function is called by the row group frame's SplitRowGroup() code when
|
|
|
|
* pushing a row frame that has cell frames that span into it. The cell frame
|
|
|
|
* should be reflowed with the specified height
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::ReflowCellFrame(nsIPresContext& aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
|
|
|
nscoord aAvailableHeight,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// Reflow the cell frame with the specified height. Use the existing width
|
|
|
|
nsSize cellSize;
|
|
|
|
aCellFrame->GetSize(cellSize);
|
|
|
|
|
|
|
|
nsSize availSize(cellSize.width, aAvailableHeight);
|
1999-03-05 07:19:09 +03:00
|
|
|
nsHTMLReflowState cellReflowState(aPresContext, aReflowState, aCellFrame, availSize,
|
1999-02-22 06:28:00 +03:00
|
|
|
eReflowReason_Resize);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
|
|
|
|
ReflowChild(aCellFrame, aPresContext, desiredSize, cellReflowState, aStatus);
|
1999-10-26 08:44:41 +04:00
|
|
|
aCellFrame->SizeTo(&aPresContext, cellSize.width, aAvailableHeight);
|
|
|
|
aCellFrame->VerticallyAlignChild(&aPresContext);
|
1999-02-22 06:28:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called by the row group frame's SplitRowGroup() code when
|
|
|
|
* it creates a continuing cell frame and wants to insert it into the row's
|
|
|
|
* child list
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame,
|
|
|
|
nsTableCellFrame* aPrevSibling)
|
|
|
|
{
|
|
|
|
mFrames.InsertFrame(nsnull, aPrevSibling, aFrame);
|
|
|
|
}
|
|
|
|
|
1999-02-24 08:54:31 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::tableRowFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
/* ----- global methods ----- */
|
|
|
|
|
|
|
|
nsresult
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_NewTableRowFrame(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;
|
|
|
|
}
|
|
|
|
nsTableRowFrame* it = new nsTableRowFrame;
|
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;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("TableRow", aResult);
|
|
|
|
}
|
1999-04-22 07:51:58 +04:00
|
|
|
|
1999-08-31 07:09:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::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
|