2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsTableRowFrame.h"
|
|
|
|
#include "nsTableRowGroupFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsTableFrame.h"
|
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsTableColGroupFrame.h"
|
|
|
|
#include "nsTableColFrame.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct nsTableCellReflowState : public nsHTMLReflowState
|
|
|
|
{
|
|
|
|
nsTableCellReflowState(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
|
|
|
PRBool aInit = PR_TRUE)
|
|
|
|
: nsHTMLReflowState(aPresContext, aParentReflowState, aFrame,
|
|
|
|
aAvailableSpace, -1, -1, aInit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixUp(const nsSize& aAvailSpace);
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsTableCellReflowState::FixUp(const nsSize& aAvailSpace)
|
|
|
|
{
|
|
|
|
// fix the mComputed values during a pass 2 reflow since the cell can be a percentage base
|
2009-10-28 20:22:28 -07:00
|
|
|
NS_WARN_IF_FALSE(NS_UNCONSTRAINEDSIZE != aAvailSpace.width,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != ComputedWidth()) {
|
2007-08-02 11:08:05 -07:00
|
|
|
nscoord computedWidth =
|
|
|
|
aAvailSpace.width - mComputedBorderPadding.LeftRight();
|
2009-09-16 08:01:36 -07:00
|
|
|
computedWidth = NS_MAX(0, computedWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
SetComputedWidth(computedWidth);
|
|
|
|
}
|
2007-08-02 11:08:05 -07:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != ComputedHeight() &&
|
|
|
|
NS_UNCONSTRAINEDSIZE != aAvailSpace.height) {
|
|
|
|
nscoord computedHeight =
|
|
|
|
aAvailSpace.height - mComputedBorderPadding.TopBottom();
|
2009-09-16 08:01:36 -07:00
|
|
|
computedHeight = NS_MAX(0, computedHeight);
|
2007-08-02 11:08:05 -07:00
|
|
|
SetComputedHeight(computedHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableRowFrame::InitChildReflowState(nsPresContext& aPresContext,
|
|
|
|
const nsSize& aAvailSize,
|
|
|
|
PRBool aBorderCollapse,
|
|
|
|
nsTableCellReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nsMargin collapseBorder;
|
|
|
|
nsMargin* pCollapseBorder = nsnull;
|
|
|
|
if (aBorderCollapse) {
|
|
|
|
// we only reflow cells, so don't need to check frame type
|
|
|
|
nsBCTableCellFrame* bcCellFrame = (nsBCTableCellFrame*)aReflowState.frame;
|
|
|
|
if (bcCellFrame) {
|
|
|
|
pCollapseBorder = bcCellFrame->GetBorderWidth(collapseBorder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aReflowState.Init(&aPresContext, -1, -1, pCollapseBorder);
|
|
|
|
aReflowState.FixUp(aAvailSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableRowFrame::SetFixedHeight(nscoord aValue)
|
|
|
|
{
|
2009-09-16 08:01:36 -07:00
|
|
|
nscoord height = NS_MAX(0, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (HasFixedHeight()) {
|
|
|
|
if (height > mStyleFixedHeight) {
|
|
|
|
mStyleFixedHeight = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mStyleFixedHeight = height;
|
|
|
|
if (height > 0) {
|
|
|
|
SetHasFixedHeight(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableRowFrame::SetPctHeight(float aPctValue,
|
|
|
|
PRBool aForce)
|
|
|
|
{
|
2009-09-16 08:01:36 -07:00
|
|
|
nscoord height = NS_MAX(0, NSToCoordRound(aPctValue * 100.0f));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (HasPctHeight()) {
|
|
|
|
if ((height > mStylePctHeight) || aForce) {
|
|
|
|
mStylePctHeight = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mStylePctHeight = height;
|
|
|
|
if (height > 0.0f) {
|
|
|
|
SetHasPctHeight(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------- nsTableRowFrame ---------- */
|
|
|
|
|
2009-03-24 15:10:06 -07:00
|
|
|
NS_QUERYFRAME_HEAD(nsTableRowFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsTableRowFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableRowFrame::nsTableRowFrame(nsStyleContext* aContext)
|
|
|
|
: nsHTMLContainerFrame(aContext)
|
|
|
|
{
|
|
|
|
mBits.mRowIndex = mBits.mFirstInserted = 0;
|
|
|
|
ResetHeight(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTableRowFrame::~nsTableRowFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Let the base class do its initialization
|
|
|
|
rv = nsHTMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
2008-08-13 20:49:57 -07:00
|
|
|
NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW == GetStyleDisplay()->mDisplay,
|
|
|
|
"wrong display on table row frame");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aPrevInFlow) {
|
|
|
|
// Set the row index
|
|
|
|
nsTableRowFrame* rowFrame = (nsTableRowFrame*)aPrevInFlow;
|
|
|
|
|
|
|
|
SetRowIndex(rowFrame->GetRowIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-10-26 03:11:34 -07:00
|
|
|
/* virtual */ void
|
|
|
|
nsTableRowFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
|
|
|
{
|
|
|
|
if (!aOldStyleContext) //avoid this on init
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
|
|
|
|
if (tableFrame->IsBorderCollapse() &&
|
|
|
|
tableFrame->BCRecalcNeeded(aOldStyleContext, GetStyleContext())) {
|
|
|
|
nsRect damageArea(0, GetRowIndex(), tableFrame->GetColCount(), 1);
|
|
|
|
tableFrame->SetBCDamageArea(damageArea);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "unexpected child list");
|
|
|
|
|
|
|
|
// Append the frames
|
2009-07-30 10:23:32 -07:00
|
|
|
// XXXbz why do we append here first, then append to table, while
|
|
|
|
// for InsertFrames we do it in the other order? Bug 507419 covers this.
|
|
|
|
const nsFrameList::Slice& newCells = mFrames.AppendFrames(nsnull, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Add the new cell frames to the table
|
|
|
|
nsTableFrame *tableFrame = nsTableFrame::GetTableFrame(this);
|
2009-07-30 10:23:32 -07:00
|
|
|
for (nsFrameList::Enumerator e(newCells) ; !e.AtEnd(); e.Next()) {
|
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(e.get());
|
2009-04-13 08:31:39 -07:00
|
|
|
NS_ASSERTION(cellFrame, "Unexpected frame");
|
2009-03-24 15:10:06 -07:00
|
|
|
if (cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Add the cell to the cell map
|
2009-03-24 15:10:06 -07:00
|
|
|
tableFrame->AppendCell(*cellFrame, GetRowIndex());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
tableFrame->SetGeometryDirty();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "unexpected child list");
|
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
|
|
|
|
|
|
|
// Get the table frame
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
|
|
|
|
// gather the new frames (only those which are cells) into an array
|
2009-07-30 10:23:32 -07:00
|
|
|
// XXXbz there shouldn't be any other ones here... can we just put
|
|
|
|
// them all in the array and not do all this QI nonsense?
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* cellFrameType = (tableFrame->IsBorderCollapse()) ? nsGkAtoms::bcTableCellFrame : nsGkAtoms::tableCellFrame;
|
|
|
|
nsTableCellFrame* prevCellFrame = (nsTableCellFrame *)nsTableFrame::GetFrameAtOrBefore(this, aPrevFrame, cellFrameType);
|
2009-02-05 01:09:50 -08:00
|
|
|
nsTArray<nsTableCellFrame*> cellChildren;
|
2009-07-30 10:23:32 -07:00
|
|
|
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
|
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(e.get());
|
2009-04-13 08:31:39 -07:00
|
|
|
NS_ASSERTION(cellFrame, "Unexpected frame");
|
2009-03-24 15:10:06 -07:00
|
|
|
if (cellFrame) {
|
|
|
|
cellChildren.AppendElement(cellFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// insert the cells into the cell map
|
|
|
|
PRInt32 colIndex = -1;
|
|
|
|
if (prevCellFrame) {
|
|
|
|
prevCellFrame->GetColIndex(colIndex);
|
|
|
|
}
|
|
|
|
tableFrame->InsertCells(cellChildren, GetRowIndex(), colIndex);
|
|
|
|
|
|
|
|
// Insert the frames in the frame list
|
|
|
|
mFrames.InsertFrames(nsnull, aPrevFrame, aFrameList);
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
tableFrame->SetGeometryDirty();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "unexpected child list");
|
|
|
|
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (tableFrame) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(aOldFrame);
|
|
|
|
if (cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 colIndex;
|
|
|
|
cellFrame->GetColIndex(colIndex);
|
|
|
|
// remove the cell from the cell map
|
|
|
|
tableFrame->RemoveCell(cellFrame, GetRowIndex());
|
|
|
|
|
|
|
|
// Remove the frame and destroy it
|
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
tableFrame->SetGeometryDirty();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("unexpected frame type");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsMargin
|
|
|
|
nsTableRowFrame::GetUsedMargin() const
|
|
|
|
{
|
|
|
|
return nsMargin(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsMargin
|
|
|
|
nsTableRowFrame::GetUsedBorder() const
|
|
|
|
{
|
|
|
|
return nsMargin(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsMargin
|
|
|
|
nsTableRowFrame::GetUsedPadding() const
|
|
|
|
{
|
|
|
|
return nsMargin(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
GetHeightOfRowsSpannedBelowFirst(nsTableCellFrame& aTableCellFrame,
|
|
|
|
nsTableFrame& aTableFrame)
|
|
|
|
{
|
|
|
|
nscoord height = 0;
|
|
|
|
nscoord cellSpacingY = aTableFrame.GetCellSpacingY();
|
|
|
|
PRInt32 rowSpan = aTableFrame.GetEffectiveRowSpan(aTableCellFrame);
|
|
|
|
// add in height of rows spanned beyond the 1st one
|
|
|
|
nsIFrame* nextRow = aTableCellFrame.GetParent()->GetNextSibling();
|
|
|
|
for (PRInt32 rowX = 1; ((rowX < rowSpan) && nextRow);) {
|
|
|
|
if (nsGkAtoms::tableRowFrame == nextRow->GetType()) {
|
|
|
|
height += nextRow->GetSize().height;
|
|
|
|
rowX++;
|
|
|
|
}
|
|
|
|
height += cellSpacingY;
|
|
|
|
nextRow = nextRow->GetNextSibling();
|
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTableCellFrame*
|
|
|
|
nsTableRowFrame::GetFirstCell()
|
|
|
|
{
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
|
|
|
|
if (cellFrame) {
|
|
|
|
return cellFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-reflow hook. This is where the table row does its post-processing
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsTableRowFrame::DidResize()
|
|
|
|
{
|
|
|
|
// Resize and re-align the cell frames based on our row height
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (!tableFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsTableIterator iter(*this);
|
|
|
|
nsIFrame* childFrame = iter.First();
|
|
|
|
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
desiredSize.width = mRect.width;
|
|
|
|
desiredSize.height = mRect.height;
|
2010-10-06 21:25:46 -07:00
|
|
|
desiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (childFrame) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
|
|
|
|
if (cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord cellHeight = mRect.height + GetHeightOfRowsSpannedBelowFirst(*cellFrame, *tableFrame);
|
|
|
|
|
|
|
|
// resize the cell's height
|
2008-02-08 01:36:32 -08:00
|
|
|
nsRect cellRect = cellFrame->GetRect();
|
2010-10-06 21:25:46 -07:00
|
|
|
nsRect cellVisualOverflow = cellFrame->GetVisualOverflowRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
if (cellRect.height != cellHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-08 01:36:32 -08:00
|
|
|
cellFrame->SetSize(nsSize(cellRect.width, cellHeight));
|
2010-10-06 21:25:46 -07:00
|
|
|
nsTableFrame::InvalidateFrame(cellFrame, cellRect,
|
|
|
|
cellVisualOverflow,
|
2008-03-16 13:32:48 -07:00
|
|
|
PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
// realign cell content based on the new height. We might be able to
|
|
|
|
// skip this if the height didn't change... maybe. Hard to tell.
|
|
|
|
cellFrame->VerticallyAlignChild(mMaxCellAscent);
|
|
|
|
|
|
|
|
// Always store the overflow, even if the height didn't change, since
|
|
|
|
// we'll lose part of our overflow area otherwise.
|
2010-10-06 21:25:46 -07:00
|
|
|
ConsiderChildOverflow(desiredSize.mOverflowAreas, cellFrame);
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
// Note that if the cell's *content* needs to change in response
|
|
|
|
// to this height, it will get a special height reflow.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Get the next child
|
|
|
|
childFrame = iter.Next();
|
|
|
|
}
|
|
|
|
FinishAndStoreOverflow(&desiredSize);
|
|
|
|
if (HasView()) {
|
2010-10-06 21:25:46 -07:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(PresContext(), this, GetView(),
|
|
|
|
desiredSize.VisualOverflow(), 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Let our base class do the usual work
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns max-ascent amongst all cells that have 'vertical-align: baseline'
|
|
|
|
// *including* cells with rowspans
|
|
|
|
nscoord nsTableRowFrame::GetMaxCellAscent() const
|
|
|
|
{
|
|
|
|
return mMaxCellAscent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord nsTableRowFrame::GetRowBaseline()
|
|
|
|
{
|
|
|
|
if(mMaxCellAscent)
|
|
|
|
return mMaxCellAscent;
|
|
|
|
|
|
|
|
// If we don't have a baseline on any of the cells we go for the lowest
|
|
|
|
// content edge of the inner block frames.
|
|
|
|
// Every table cell has a cell frame with its border and padding. Inside
|
|
|
|
// the cell is a block frame. The cell is as high as the tallest cell in
|
|
|
|
// the parent row. As a consequence the block frame might not touch both
|
|
|
|
// the top and the bottom padding of it parent cell frame at the same time.
|
|
|
|
//
|
|
|
|
// bbbbbbbbbbbbbbbbbb cell border: b
|
|
|
|
// bppppppppppppppppb cell padding: p
|
|
|
|
// bpxxxxxxxxxxxxxxpb inner block: x
|
|
|
|
// bpx xpb
|
|
|
|
// bpx xpb
|
|
|
|
// bpx xpb
|
|
|
|
// bpxxxxxxxxxxxxxxpb base line
|
|
|
|
// bp pb
|
|
|
|
// bp pb
|
|
|
|
// bppppppppppppppppb
|
|
|
|
// bbbbbbbbbbbbbbbbbb
|
|
|
|
|
|
|
|
nsTableIterator iter(*this);
|
|
|
|
nsIFrame* childFrame = iter.First();
|
|
|
|
nscoord ascent = 0;
|
|
|
|
while (childFrame) {
|
|
|
|
if (IS_TABLE_CELL(childFrame->GetType())) {
|
|
|
|
nsIFrame* firstKid = childFrame->GetFirstChild(nsnull);
|
2009-09-16 08:01:36 -07:00
|
|
|
ascent = NS_MAX(ascent, firstKid->GetRect().YMost());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Get the next child
|
|
|
|
childFrame = iter.Next();
|
|
|
|
}
|
|
|
|
return ascent;
|
|
|
|
}
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::GetHeight(nscoord aPctBasis) const
|
|
|
|
{
|
|
|
|
nscoord height = 0;
|
|
|
|
if ((aPctBasis > 0) && HasPctHeight()) {
|
|
|
|
height = NSToCoordRound(GetPctHeight() * (float)aPctBasis);
|
|
|
|
}
|
|
|
|
if (HasFixedHeight()) {
|
2009-09-16 08:01:36 -07:00
|
|
|
height = NS_MAX(height, GetFixedHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-09-16 08:01:36 -07:00
|
|
|
return NS_MAX(height, GetContentHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableRowFrame::ResetHeight(nscoord aFixedHeight)
|
|
|
|
{
|
|
|
|
SetHasFixedHeight(PR_FALSE);
|
|
|
|
SetHasPctHeight(PR_FALSE);
|
|
|
|
SetFixedHeight(0);
|
|
|
|
SetPctHeight(0);
|
|
|
|
SetContentHeight(0);
|
|
|
|
|
|
|
|
if (aFixedHeight > 0) {
|
|
|
|
SetFixedHeight(aFixedHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxCellAscent = 0;
|
|
|
|
mMaxCellDescent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableRowFrame::UpdateHeight(nscoord aHeight,
|
|
|
|
nscoord aAscent,
|
|
|
|
nscoord aDescent,
|
|
|
|
nsTableFrame* aTableFrame,
|
|
|
|
nsTableCellFrame* aCellFrame)
|
|
|
|
{
|
|
|
|
if (!aTableFrame || !aCellFrame) {
|
|
|
|
NS_ASSERTION(PR_FALSE , "invalid call");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
if (!(aCellFrame->HasVerticalAlignBaseline())) { // only the cell's height matters
|
|
|
|
if (GetHeight() < aHeight) {
|
|
|
|
PRInt32 rowSpan = aTableFrame->GetEffectiveRowSpan(*aCellFrame);
|
|
|
|
if (rowSpan == 1) {
|
|
|
|
SetContentHeight(aHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // the alignment on the baseline can change the height
|
|
|
|
NS_ASSERTION((aAscent != NS_UNCONSTRAINEDSIZE) && (aDescent != NS_UNCONSTRAINEDSIZE), "invalid call");
|
|
|
|
// see if this is a long ascender
|
|
|
|
if (mMaxCellAscent < aAscent) {
|
|
|
|
mMaxCellAscent = aAscent;
|
|
|
|
}
|
|
|
|
// see if this is a long descender and without rowspan
|
|
|
|
if (mMaxCellDescent < aDescent) {
|
|
|
|
PRInt32 rowSpan = aTableFrame->GetEffectiveRowSpan(*aCellFrame);
|
|
|
|
if (rowSpan == 1) {
|
|
|
|
mMaxCellDescent = aDescent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// keep the tallest height in sync
|
|
|
|
if (GetHeight() < mMaxCellAscent + mMaxCellDescent) {
|
|
|
|
SetContentHeight(mMaxCellAscent + mMaxCellDescent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::CalcHeight(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (!tableFrame)
|
|
|
|
return 0;
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
nscoord computedHeight = (NS_UNCONSTRAINEDSIZE == aReflowState.ComputedHeight())
|
|
|
|
? 0 : aReflowState.ComputedHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
ResetHeight(computedHeight);
|
|
|
|
|
|
|
|
const nsStylePosition* position = GetStylePosition();
|
|
|
|
if (eStyleUnit_Coord == position->mHeight.GetUnit()) {
|
|
|
|
SetFixedHeight(position->mHeight.GetCoordValue());
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == position->mHeight.GetUnit()) {
|
|
|
|
SetPctHeight(position->mHeight.GetPercentValue());
|
|
|
|
}
|
2010-08-25 03:17:55 -07:00
|
|
|
// calc() is treated like 'auto' on table rows.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (nsIFrame* kidFrame = mFrames.FirstChild(); kidFrame;
|
|
|
|
kidFrame = kidFrame->GetNextSibling()) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
|
|
|
|
if (cellFrame) {
|
|
|
|
nsSize desSize = cellFrame->GetDesiredSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) && !GetPrevInFlow()) {
|
2010-03-06 01:53:02 -08:00
|
|
|
CalculateCellActualHeight(cellFrame, desSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// height may have changed, adjust descent to absorb any excess difference
|
|
|
|
nscoord ascent;
|
|
|
|
if (!kidFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
|
|
|
|
ascent = desSize.height;
|
|
|
|
else
|
2009-03-24 15:10:06 -07:00
|
|
|
ascent = cellFrame->GetCellBaseline();
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord descent = desSize.height - ascent;
|
2009-03-24 15:10:06 -07:00
|
|
|
UpdateHeight(desSize.height, ascent, descent, tableFrame, cellFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return GetHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We need a custom display item for table row backgrounds. This is only used
|
|
|
|
* when the table row is the root of a stacking context (e.g., has 'opacity').
|
|
|
|
* Table row backgrounds can extend beyond the row frame bounds, when
|
|
|
|
* the row contains row-spanning cells.
|
|
|
|
*/
|
2008-04-06 04:34:14 -07:00
|
|
|
class nsDisplayTableRowBackground : public nsDisplayTableItem {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayTableRowBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsTableRowFrame* aFrame) :
|
|
|
|
nsDisplayTableItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayTableRowBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayTableRowBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayTableRowBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("TableRowBackground", TYPE_TABLE_ROW_BACKGROUND)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayTableRowBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(mFrame);
|
|
|
|
|
|
|
|
TableBackgroundPainter painter(tableFrame,
|
|
|
|
TableBackgroundPainter::eOrigin_TableRow,
|
2007-03-30 14:11:41 -07:00
|
|
|
mFrame->PresContext(), *aCtx,
|
2010-08-13 03:01:58 -07:00
|
|
|
mVisibleRect, ToReferenceFrame(),
|
2009-09-12 15:44:18 -07:00
|
|
|
aBuilder->GetBackgroundPaintFlags());
|
2007-07-08 00:08:04 -07:00
|
|
|
painter.PaintRow(static_cast<nsTableRowFrame*>(mFrame));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleInSelection(aBuilder))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRBool isRoot = aBuilder->IsAtRootOfPseudoStackingContext();
|
2008-04-06 04:34:14 -07:00
|
|
|
nsDisplayTableItem* item = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isRoot) {
|
|
|
|
// This background is created regardless of whether this frame is
|
|
|
|
// visible or not. Visibility decisions are delegated to the
|
|
|
|
// table background painter.
|
|
|
|
// We would use nsDisplayGeneric for this rare case except that we
|
|
|
|
// need the background to be larger than the row frame in some
|
|
|
|
// cases.
|
2010-08-13 03:01:13 -07:00
|
|
|
item = new (aBuilder) nsDisplayTableRowBackground(aBuilder, this);
|
2008-04-06 04:34:14 -07:00
|
|
|
nsresult rv = aLists.BorderBackground()->AppendNewToTop(item);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-04-06 04:34:14 -07:00
|
|
|
return nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists, item);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsTableRowFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
PRIntn skip = 0;
|
|
|
|
if (nsnull != GetPrevInFlow()) {
|
|
|
|
skip |= 1 << NS_SIDE_TOP;
|
|
|
|
}
|
|
|
|
if (nsnull != GetNextInFlow()) {
|
|
|
|
skip |= 1 << NS_SIDE_BOTTOM;
|
|
|
|
}
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2010-03-06 01:53:02 -08:00
|
|
|
// Calculate the cell's actual height given its pass2 height.
|
|
|
|
// Takes into account the specified height (in the style).
|
|
|
|
// Modifies the desired height that is passed in.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-03-06 01:53:02 -08:00
|
|
|
nsTableRowFrame::CalculateCellActualHeight(nsTableCellFrame* aCellFrame,
|
|
|
|
nscoord& aDesiredHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord specifiedHeight = 0;
|
|
|
|
|
|
|
|
// Get the height specified in the style information
|
|
|
|
const nsStylePosition* position = aCellFrame->GetStylePosition();
|
|
|
|
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (!tableFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2010-03-06 01:53:02 -08:00
|
|
|
PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(*aCellFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (position->mHeight.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
specifiedHeight = position->mHeight.GetCoordValue();
|
|
|
|
if (1 == rowSpan)
|
|
|
|
SetFixedHeight(specifiedHeight);
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent: {
|
|
|
|
if (1 == rowSpan)
|
|
|
|
SetPctHeight(position->mHeight.GetPercentValue());
|
|
|
|
// pct heights are handled when all of the cells are finished, so don't set specifiedHeight
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleUnit_Auto:
|
2010-08-25 03:17:55 -07:00
|
|
|
default: // includes calc(), which we treat like 'auto'
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the specified height is greater than the desired height, then use the specified height
|
|
|
|
if (specifiedHeight > aDesiredHeight)
|
|
|
|
aDesiredHeight = specifiedHeight;
|
|
|
|
|
|
|
|
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
|
2009-01-13 11:50:40 -08:00
|
|
|
static nscoord
|
2007-03-22 10:30:00 -07:00
|
|
|
CalcAvailWidth(nsTableFrame& aTableFrame,
|
|
|
|
nsTableCellFrame& aCellFrame,
|
2009-01-13 11:50:40 -08:00
|
|
|
nscoord aCellSpacingX)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-13 11:50:40 -08:00
|
|
|
nscoord cellAvailWidth = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 colIndex;
|
|
|
|
aCellFrame.GetColIndex(colIndex);
|
|
|
|
PRInt32 colspan = aTableFrame.GetEffectiveColSpan(aCellFrame);
|
2009-01-13 11:50:40 -08:00
|
|
|
NS_ASSERTION(colspan > 0, "effective colspan should be positive");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (PRInt32 spanX = 0; spanX < colspan; spanX++) {
|
2009-01-13 11:50:40 -08:00
|
|
|
cellAvailWidth += aTableFrame.GetColumnWidth(colIndex + spanX);
|
|
|
|
if (spanX > 0 &&
|
|
|
|
aTableFrame.ColumnHasCellSpacingBefore(colIndex + spanX)) {
|
|
|
|
cellAvailWidth += aCellSpacingX;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-01-13 11:50:40 -08:00
|
|
|
return cellAvailWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
GetSpaceBetween(PRInt32 aPrevColIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aColSpan,
|
|
|
|
nsTableFrame& aTableFrame,
|
|
|
|
nscoord aCellSpacingX,
|
|
|
|
PRBool aIsLeftToRight,
|
|
|
|
PRBool aCheckVisibility)
|
|
|
|
{
|
|
|
|
nscoord space = 0;
|
|
|
|
PRInt32 colX;
|
|
|
|
if (aIsLeftToRight) {
|
|
|
|
for (colX = aPrevColIndex + 1; aColIndex > colX; colX++) {
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
|
|
|
if (!aCheckVisibility) {
|
|
|
|
space += aTableFrame.GetColumnWidth(colX);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsTableColFrame* colFrame = aTableFrame.GetColFrame(colX);
|
|
|
|
const nsStyleVisibility* colVis = colFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible);
|
|
|
|
nsIFrame* cgFrame = colFrame->GetParent();
|
|
|
|
const nsStyleVisibility* groupVis = cgFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE ==
|
|
|
|
groupVis->mVisible);
|
|
|
|
isCollapsed = collapseCol || collapseGroup;
|
|
|
|
if (!isCollapsed)
|
|
|
|
space += aTableFrame.GetColumnWidth(colX);
|
|
|
|
}
|
2008-09-24 10:14:35 -07:00
|
|
|
if (!isCollapsed && aTableFrame.ColumnHasCellSpacingBefore(colX)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
space += aCellSpacingX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt32 lastCol = aColIndex + aColSpan - 1;
|
|
|
|
for (colX = aPrevColIndex - 1; colX > lastCol; colX--) {
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
|
|
|
if (!aCheckVisibility) {
|
|
|
|
space += aTableFrame.GetColumnWidth(colX);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsTableColFrame* colFrame = aTableFrame.GetColFrame(colX);
|
|
|
|
const nsStyleVisibility* colVis = colFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible);
|
|
|
|
nsIFrame* cgFrame = colFrame->GetParent();
|
|
|
|
const nsStyleVisibility* groupVis = cgFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE ==
|
|
|
|
groupVis->mVisible);
|
|
|
|
isCollapsed = collapseCol || collapseGroup;
|
|
|
|
if (!isCollapsed)
|
|
|
|
space += aTableFrame.GetColumnWidth(colX);
|
|
|
|
}
|
2008-09-24 10:14:35 -07:00
|
|
|
if (!isCollapsed && aTableFrame.ColumnHasCellSpacingBefore(colX)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
space += aCellSpacingX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
|
|
|
// subtract the heights of aRow's prev in flows from the unpaginated height
|
|
|
|
static
|
2009-01-14 14:16:43 -08:00
|
|
|
nscoord CalcHeightFromUnpaginatedHeight(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableRowFrame& aRow)
|
|
|
|
{
|
|
|
|
nscoord height = 0;
|
|
|
|
nsTableRowFrame* firstInFlow = (nsTableRowFrame*)aRow.GetFirstInFlow();
|
|
|
|
if (!firstInFlow) ABORT1(0);
|
|
|
|
if (firstInFlow->HasUnpaginatedHeight()) {
|
|
|
|
height = firstInFlow->GetUnpaginatedHeight(aPresContext);
|
|
|
|
for (nsIFrame* prevInFlow = aRow.GetPrevInFlow(); prevInFlow;
|
|
|
|
prevInFlow = prevInFlow->GetPrevInFlow()) {
|
|
|
|
height -= prevInFlow->GetSize().height;
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 08:01:36 -07:00
|
|
|
return NS_MAX(height, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsTableFrame& aTableFrame,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
PRBool borderCollapse = (((nsTableFrame*)aTableFrame.GetFirstInFlow())->IsBorderCollapse());
|
|
|
|
|
|
|
|
// XXXldb Should we be checking constrained height instead?
|
|
|
|
PRBool isPaginated = aPresContext->IsPaginated();
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nscoord cellSpacingX = aTableFrame.GetCellSpacingX();
|
|
|
|
PRInt32 cellColSpan = 1; // must be defined here so it's set properly for non-cell kids
|
|
|
|
|
|
|
|
nsTableIterator iter(*this);
|
|
|
|
// remember the col index of the previous cell to handle rowspans into this row
|
|
|
|
PRInt32 firstPrevColIndex = (iter.IsLeftToRight()) ? -1 : aTableFrame.GetColCount();
|
|
|
|
PRInt32 prevColIndex = firstPrevColIndex;
|
|
|
|
nscoord x = 0; // running total of children x offset
|
|
|
|
|
2008-04-08 05:28:34 -07:00
|
|
|
// This computes the max of all cell heights
|
|
|
|
nscoord cellMaxHeight = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Reflow each of our existing cell frames
|
|
|
|
for (nsIFrame* kidFrame = iter.First(); kidFrame; kidFrame = iter.Next()) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
|
|
|
|
if (!cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXldb nsCSSFrameConstructor needs to enforce this!
|
|
|
|
NS_NOTREACHED("yikes, a non-row child");
|
|
|
|
|
|
|
|
// it's an unknown frame type, give it a generic reflow and ignore the results
|
|
|
|
nsTableCellReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
kidFrame, nsSize(0,0), PR_FALSE);
|
|
|
|
InitChildReflowState(*aPresContext, nsSize(0,0), PR_FALSE, kidReflowState);
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
nsReflowStatus status;
|
|
|
|
ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState, 0, 0, 0, status);
|
|
|
|
kidFrame->DidReflow(aPresContext, nsnull, NS_FRAME_REFLOW_FINISHED);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we should only reflow the dirty child frames
|
|
|
|
PRBool doReflowChild = PR_TRUE;
|
|
|
|
if (!aReflowState.ShouldReflowAllKids() &&
|
|
|
|
!aTableFrame.IsGeometryDirty() &&
|
2007-05-06 12:16:51 -07:00
|
|
|
!NS_SUBTREE_DIRTY(kidFrame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aReflowState.mFlags.mSpecialHeightReflow)
|
|
|
|
doReflowChild = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if ((NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight)) {
|
|
|
|
// We don't reflow a rowspan >1 cell here with a constrained height.
|
|
|
|
// That happens in nsTableRowGroupFrame::SplitSpanningCells.
|
|
|
|
if (aTableFrame.GetEffectiveRowSpan(*cellFrame) > 1) {
|
|
|
|
doReflowChild = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aReflowState.mFlags.mSpecialHeightReflow) {
|
|
|
|
if (!isPaginated && !(cellFrame->GetStateBits() &
|
|
|
|
NS_FRAME_CONTAINS_RELATIVE_HEIGHT)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 cellColIndex;
|
|
|
|
cellFrame->GetColIndex(cellColIndex);
|
|
|
|
cellColSpan = aTableFrame.GetEffectiveColSpan(*cellFrame);
|
|
|
|
|
|
|
|
// If the adjacent cell is in a prior row (because of a rowspan) add in the space
|
|
|
|
if ((iter.IsLeftToRight() && (prevColIndex != (cellColIndex - 1))) ||
|
|
|
|
(!iter.IsLeftToRight() && (prevColIndex != cellColIndex + cellColSpan))) {
|
|
|
|
x += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, aTableFrame,
|
|
|
|
cellSpacingX, iter.IsLeftToRight(), PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember the rightmost (ltr) or leftmost (rtl) column this cell spans into
|
|
|
|
prevColIndex = (iter.IsLeftToRight()) ? cellColIndex + (cellColSpan - 1) : cellColIndex;
|
|
|
|
|
|
|
|
// Reflow the child frame
|
2008-02-08 01:36:32 -08:00
|
|
|
nsRect kidRect = kidFrame->GetRect();
|
2010-10-06 21:25:46 -07:00
|
|
|
nsRect kidVisualOverflow = kidFrame->GetVisualOverflowRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
PRBool firstReflow =
|
|
|
|
(kidFrame->GetStateBits() & NS_FRAME_FIRST_REFLOW) != 0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (doReflowChild) {
|
|
|
|
// Calculate the available width for the table cell using the known column widths
|
2009-01-13 11:50:40 -08:00
|
|
|
nscoord availCellWidth =
|
|
|
|
CalcAvailWidth(aTableFrame, *cellFrame, cellSpacingX);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
|
|
|
|
// If the avail width is not the same as last time we reflowed the cell or
|
|
|
|
// the cell wants to be bigger than what was available last time or
|
|
|
|
// it is a style change reflow or we are printing, then we must reflow the
|
|
|
|
// cell. Otherwise we can skip the reflow.
|
|
|
|
// XXXldb Why is this condition distinct from doReflowChild above?
|
|
|
|
nsSize cellDesiredSize = cellFrame->GetDesiredSize();
|
|
|
|
if ((availCellWidth != cellFrame->GetPriorAvailWidth()) ||
|
|
|
|
(cellDesiredSize.width > cellFrame->GetPriorAvailWidth()) ||
|
|
|
|
(GetStateBits() & NS_FRAME_IS_DIRTY) ||
|
|
|
|
isPaginated ||
|
2007-05-06 12:16:51 -07:00
|
|
|
NS_SUBTREE_DIRTY(cellFrame) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if it needs a special reflow, or if it had one that we need to undo.
|
|
|
|
(cellFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT) ||
|
|
|
|
HasPctHeight()) {
|
|
|
|
// Reflow the cell to fit the available width, height
|
|
|
|
// XXX The old IR_ChildIsDirty code used availCellWidth here.
|
2009-01-13 11:50:40 -08:00
|
|
|
nsSize kidAvailSize(availCellWidth, aReflowState.availableHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Reflow the child
|
|
|
|
nsTableCellReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
kidFrame, kidAvailSize, PR_FALSE);
|
|
|
|
InitChildReflowState(*aPresContext, kidAvailSize, borderCollapse,
|
|
|
|
kidReflowState);
|
|
|
|
|
|
|
|
nsReflowStatus status;
|
|
|
|
rv = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState,
|
2008-02-08 01:36:32 -08:00
|
|
|
x, 0, NS_FRAME_INVALIDATE_ON_MOVE, status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// allow the table to determine if/how the table needs to be rebalanced
|
|
|
|
// 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 {
|
2008-02-08 01:36:32 -08:00
|
|
|
if (x != kidRect.x) {
|
2010-08-30 17:49:12 -07:00
|
|
|
kidFrame->InvalidateFrameSubtree();
|
2008-02-08 01:36:32 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
desiredSize.width = cellDesiredSize.width;
|
|
|
|
desiredSize.height = cellDesiredSize.height;
|
2010-10-06 21:25:46 -07:00
|
|
|
desiredSize.mOverflowAreas = cellFrame->GetOverflowAreas();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// if we are in a floated table, our position is not yet established, so we cannot reposition our views
|
2009-02-12 15:10:59 -08:00
|
|
|
// the containing block will do this for us after positioning the table
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aTableFrame.GetStyleDisplay()->IsFloating()) {
|
|
|
|
// Because we may have moved the frame we need to make sure any views are
|
|
|
|
// positioned properly. We have to do this, because any one of our parent
|
|
|
|
// frames could have moved and we have no way of knowing...
|
|
|
|
nsTableFrame::RePositionViews(kidFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) {
|
|
|
|
if (!GetPrevInFlow()) {
|
2010-03-06 01:53:02 -08:00
|
|
|
// Calculate the cell's actual height given its pass2 height. This
|
|
|
|
// function takes into account the specified height (in the style)
|
|
|
|
CalculateCellActualHeight(cellFrame, desiredSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// height may have changed, adjust descent to absorb any excess difference
|
|
|
|
nscoord ascent;
|
|
|
|
if (!kidFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
|
|
|
|
ascent = desiredSize.height;
|
|
|
|
else
|
|
|
|
ascent = ((nsTableCellFrame *)kidFrame)->GetCellBaseline();
|
|
|
|
nscoord descent = desiredSize.height - ascent;
|
|
|
|
UpdateHeight(desiredSize.height, ascent, descent, &aTableFrame, cellFrame);
|
|
|
|
}
|
|
|
|
else {
|
2009-09-16 08:01:36 -07:00
|
|
|
cellMaxHeight = NS_MAX(cellMaxHeight, desiredSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 rowSpan = aTableFrame.GetEffectiveRowSpan((nsTableCellFrame&)*kidFrame);
|
|
|
|
if (1 == rowSpan) {
|
2008-04-08 05:28:34 -07:00
|
|
|
SetContentHeight(cellMaxHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place the child
|
2009-01-13 11:50:40 -08:00
|
|
|
desiredSize.width = availCellWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
FinishReflowChild(kidFrame, aPresContext, nsnull, desiredSize, x, 0, 0);
|
2008-02-08 01:36:32 -08:00
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
nsTableFrame::InvalidateFrame(kidFrame, kidRect, kidVisualOverflow,
|
2008-03-16 13:32:48 -07:00
|
|
|
firstReflow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
x += desiredSize.width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (kidRect.x != x) {
|
2008-02-08 01:36:32 -08:00
|
|
|
// Invalidate the old position
|
2010-08-30 17:49:12 -07:00
|
|
|
kidFrame->InvalidateFrameSubtree();
|
2008-02-08 01:36:32 -08:00
|
|
|
// move to the new position
|
|
|
|
kidFrame->SetPosition(nsPoint(x, kidRect.y));
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableFrame::RePositionViews(kidFrame);
|
2008-02-08 01:36:32 -08:00
|
|
|
// invalidate the new position
|
2010-08-30 17:49:12 -07:00
|
|
|
kidFrame->InvalidateFrameSubtree();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// we need to account for the cell's width even if it isn't reflowed
|
|
|
|
x += kidRect.width;
|
|
|
|
|
|
|
|
if (kidFrame->GetNextInFlow()) {
|
|
|
|
aStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
2010-10-06 21:25:46 -07:00
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, kidFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
x += cellSpacingX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// just set our width to what was available. The table will calculate the width and not use our value.
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
|
|
|
|
if (aReflowState.mFlags.mSpecialHeightReflow) {
|
|
|
|
aDesiredSize.height = mRect.height;
|
|
|
|
}
|
|
|
|
else if (NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) {
|
|
|
|
aDesiredSize.height = CalcHeight(aReflowState);
|
|
|
|
if (GetPrevInFlow()) {
|
|
|
|
nscoord height = CalcHeightFromUnpaginatedHeight(aPresContext, *this);
|
2009-09-16 08:01:36 -07:00
|
|
|
aDesiredSize.height = NS_MAX(aDesiredSize.height, height);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isPaginated && HasStyleHeight()) {
|
|
|
|
// set the unpaginated height so next in flows can try to honor it
|
|
|
|
SetHasUnpaginatedHeight(PR_TRUE);
|
|
|
|
SetUnpaginatedHeight(aPresContext, aDesiredSize.height);
|
|
|
|
}
|
|
|
|
if (isPaginated && HasUnpaginatedHeight()) {
|
2009-09-16 08:01:36 -07:00
|
|
|
aDesiredSize.height = NS_MAX(aDesiredSize.height, GetUnpaginatedHeight(aPresContext));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // constrained height, paginated
|
2008-04-08 05:28:34 -07:00
|
|
|
// Compute the height we should have from style (subtracting the
|
|
|
|
// height from our prev-in-flows from the style height)
|
|
|
|
nscoord styleHeight = CalcHeightFromUnpaginatedHeight(aPresContext, *this);
|
|
|
|
if (styleHeight > aReflowState.availableHeight) {
|
|
|
|
styleHeight = aReflowState.availableHeight;
|
|
|
|
NS_FRAME_SET_INCOMPLETE(aStatus);
|
|
|
|
}
|
2009-09-16 08:01:36 -07:00
|
|
|
aDesiredSize.height = NS_MAX(cellMaxHeight, styleHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.UnionOverflowAreasWithDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Layout the entire row.
|
|
|
|
* This method stacks cells horizontally according to HTML 4.0 rules.
|
|
|
|
*/
|
|
|
|
NS_METHOD
|
|
|
|
nsTableRowFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsTableRowFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (!tableFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
const nsStyleVisibility* rowVis = GetStyleVisibility();
|
|
|
|
PRBool collapseRow = (NS_STYLE_VISIBILITY_COLLAPSE == rowVis->mVisible);
|
|
|
|
if (collapseRow) {
|
|
|
|
tableFrame->SetNeedToCollapse(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if a special height reflow needs to occur due to having a pct height
|
|
|
|
nsTableFrame::CheckRequestSpecialHeightReflow(aReflowState);
|
|
|
|
|
2007-06-25 13:34:35 -07:00
|
|
|
// See if we have a cell with specified/pct height
|
|
|
|
InitHasCellWithStyleHeight(tableFrame);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = ReflowChildren(aPresContext, aDesiredSize, aReflowState, *tableFrame,
|
|
|
|
aStatus);
|
|
|
|
|
|
|
|
// just set our width to what was available. The table will calculate the width and not use our value.
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
|
2008-03-16 13:32:48 -07:00
|
|
|
// If our parent is in initial reflow, it'll handle invalidating our
|
|
|
|
// entire overflow rect.
|
2008-04-01 14:53:19 -07:00
|
|
|
if (!(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2008-08-19 23:45:29 -07:00
|
|
|
CheckInvalidateSizeChange(aDesiredSize);
|
2008-03-16 13:32:48 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::ReflowCellFrame(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
PRBool aIsTopOfPage,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
|
|
|
nscoord aAvailableHeight,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
if (!tableFrame)
|
|
|
|
ABORT1(NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
// Reflow the cell frame with the specified height. Use the existing width
|
2008-02-08 01:36:32 -08:00
|
|
|
nsRect cellRect = aCellFrame->GetRect();
|
2010-10-06 21:25:46 -07:00
|
|
|
nsRect cellVisualOverflow = aCellFrame->GetVisualOverflowRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-08 01:36:32 -08:00
|
|
|
nsSize availSize(cellRect.width, aAvailableHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool borderCollapse = ((nsTableFrame*)tableFrame->GetFirstInFlow())->IsBorderCollapse();
|
|
|
|
nsTableCellReflowState cellReflowState(aPresContext, aReflowState,
|
|
|
|
aCellFrame, availSize, PR_FALSE);
|
|
|
|
InitChildReflowState(*aPresContext, availSize, borderCollapse, cellReflowState);
|
|
|
|
cellReflowState.mFlags.mIsTopOfPage = aIsTopOfPage;
|
|
|
|
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
|
|
|
|
ReflowChild(aCellFrame, aPresContext, desiredSize, cellReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
PRBool fullyComplete = NS_FRAME_IS_COMPLETE(aStatus) && !NS_FRAME_IS_TRUNCATED(aStatus);
|
2007-12-02 11:19:00 -08:00
|
|
|
if (fullyComplete) {
|
|
|
|
desiredSize.height = aAvailableHeight;
|
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
aCellFrame->SetSize(nsSize(cellRect.width, desiredSize.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-16 13:32:48 -07:00
|
|
|
// Note: VerticallyAlignChild can affect the overflow rect.
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX What happens if this cell has 'vertical-align: baseline' ?
|
|
|
|
// XXX Why is it assumed that the cell's ascent hasn't changed ?
|
|
|
|
if (fullyComplete) {
|
|
|
|
aCellFrame->VerticallyAlignChild(mMaxCellAscent);
|
|
|
|
}
|
2008-03-16 13:32:48 -07:00
|
|
|
|
|
|
|
nsTableFrame::InvalidateFrame(aCellFrame, cellRect,
|
2010-10-06 21:25:46 -07:00
|
|
|
cellVisualOverflow,
|
2008-03-16 13:32:48 -07:00
|
|
|
(aCellFrame->GetStateBits() &
|
|
|
|
NS_FRAME_FIRST_REFLOW) != 0);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aCellFrame->DidReflow(aPresContext, nsnull, NS_FRAME_REFLOW_FINISHED);
|
|
|
|
|
|
|
|
return desiredSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset,
|
|
|
|
nscoord aWidth,
|
|
|
|
PRBool aCollapseGroup,
|
|
|
|
PRBool& aDidCollapse)
|
|
|
|
{
|
|
|
|
const nsStyleVisibility* rowVis = GetStyleVisibility();
|
|
|
|
PRBool collapseRow = (NS_STYLE_VISIBILITY_COLLAPSE == rowVis->mVisible);
|
2007-07-08 00:08:04 -07:00
|
|
|
nsTableFrame* tableFrame = static_cast<nsTableFrame*>(nsTableFrame::GetTableFrame(this)->GetFirstInFlow());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!tableFrame)
|
|
|
|
return 0;
|
|
|
|
if (collapseRow) {
|
|
|
|
tableFrame->SetNeedToCollapse(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2008-02-08 01:36:32 -08:00
|
|
|
if (aRowOffset != 0) {
|
|
|
|
// We're moving, so invalidate our old position
|
2010-08-30 17:49:12 -07:00
|
|
|
InvalidateFrameSubtree();
|
2008-02-08 01:36:32 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect rowRect = GetRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
nsRect oldRect = rowRect;
|
2010-10-06 21:25:46 -07:00
|
|
|
nsRect oldVisualOverflow = GetVisualOverflowRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rowRect.y -= aRowOffset;
|
|
|
|
rowRect.width = aWidth;
|
2010-10-06 21:25:45 -07:00
|
|
|
nsOverflowAreas overflow;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord shift = 0;
|
|
|
|
nscoord cellSpacingX = tableFrame->GetCellSpacingX();
|
|
|
|
nscoord cellSpacingY = tableFrame->GetCellSpacingY();
|
|
|
|
|
|
|
|
if (aCollapseGroup || collapseRow) {
|
|
|
|
nsTableCellFrame* cellFrame = GetFirstCell();
|
|
|
|
aDidCollapse = PR_TRUE;
|
|
|
|
shift = rowRect.height + cellSpacingY;
|
|
|
|
while (cellFrame) {
|
|
|
|
nsRect cRect = cellFrame->GetRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
// If aRowOffset != 0, there's no point in invalidating the cells, since
|
|
|
|
// we've already invalidated our overflow area. Note that we _do_ still
|
|
|
|
// need to invalidate if our row is not moving, because the cell might
|
|
|
|
// span out of this row, so invalidating our row rect won't do enough.
|
|
|
|
if (aRowOffset == 0) {
|
|
|
|
Invalidate(cRect);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
cRect.height = 0;
|
|
|
|
cellFrame->SetRect(cRect);
|
|
|
|
cellFrame = cellFrame->GetNextCell();
|
|
|
|
}
|
|
|
|
rowRect.height = 0;
|
|
|
|
}
|
|
|
|
else { // row is not collapsed
|
|
|
|
nsTableIterator iter(*this);
|
|
|
|
// remember the col index of the previous cell to handle rowspans into this
|
|
|
|
// row
|
|
|
|
PRInt32 firstPrevColIndex = (iter.IsLeftToRight()) ? -1 :
|
|
|
|
tableFrame->GetColCount();
|
|
|
|
PRInt32 prevColIndex = firstPrevColIndex;
|
|
|
|
nscoord x = 0; // running total of children x offset
|
|
|
|
|
|
|
|
PRInt32 colIncrement = iter.IsLeftToRight() ? 1 : -1;
|
|
|
|
|
|
|
|
//nscoord x = cellSpacingX;
|
|
|
|
|
|
|
|
nsIFrame* kidFrame = iter.First();
|
|
|
|
while (kidFrame) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
|
|
|
|
if (cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 cellColIndex;
|
|
|
|
cellFrame->GetColIndex(cellColIndex);
|
|
|
|
PRInt32 cellColSpan = tableFrame->GetEffectiveColSpan(*cellFrame);
|
|
|
|
|
|
|
|
// If the adjacent cell is in a prior row (because of a rowspan) add in
|
|
|
|
// the space
|
|
|
|
if ((iter.IsLeftToRight() && (prevColIndex != (cellColIndex - 1))) ||
|
|
|
|
(!iter.IsLeftToRight() &&
|
|
|
|
(prevColIndex != cellColIndex + cellColSpan))) {
|
|
|
|
x += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan,
|
|
|
|
*tableFrame, cellSpacingX, iter.IsLeftToRight(),
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
nsRect cRect(x, 0, 0, rowRect.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// remember the rightmost (ltr) or leftmost (rtl) column this cell
|
|
|
|
// spans into
|
|
|
|
prevColIndex = (iter.IsLeftToRight()) ?
|
|
|
|
cellColIndex + (cellColSpan - 1) : cellColIndex;
|
|
|
|
PRInt32 startIndex = (iter.IsLeftToRight()) ?
|
|
|
|
cellColIndex : cellColIndex + (cellColSpan - 1);
|
|
|
|
PRInt32 actualColSpan = cellColSpan;
|
|
|
|
PRBool isVisible = PR_FALSE;
|
|
|
|
for (PRInt32 colX = startIndex; actualColSpan > 0;
|
|
|
|
colX += colIncrement, actualColSpan--) {
|
|
|
|
|
|
|
|
nsTableColFrame* colFrame = tableFrame->GetColFrame(colX);
|
|
|
|
const nsStyleVisibility* colVis = colFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE ==
|
|
|
|
colVis->mVisible);
|
|
|
|
nsIFrame* cgFrame = colFrame->GetParent();
|
|
|
|
const nsStyleVisibility* groupVis = cgFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE ==
|
|
|
|
groupVis->mVisible);
|
|
|
|
PRBool isCollapsed = collapseCol || collapseGroup;
|
2009-05-16 07:22:56 -07:00
|
|
|
if (!isCollapsed) {
|
2007-03-22 10:30:00 -07:00
|
|
|
cRect.width += tableFrame->GetColumnWidth(colX);
|
|
|
|
isVisible = PR_TRUE;
|
2009-05-16 07:22:56 -07:00
|
|
|
if ((actualColSpan > 1)) {
|
|
|
|
nsTableColFrame* nextColFrame =
|
|
|
|
tableFrame->GetColFrame(colX + colIncrement);
|
|
|
|
const nsStyleVisibility* nextColVis =
|
2007-03-22 10:30:00 -07:00
|
|
|
nextColFrame->GetStyleVisibility();
|
2009-05-16 07:22:56 -07:00
|
|
|
if ( (NS_STYLE_VISIBILITY_COLLAPSE != nextColVis->mVisible) &&
|
|
|
|
tableFrame->ColumnHasCellSpacingBefore(colX + colIncrement)) {
|
|
|
|
cRect.width += cellSpacingX;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x += cRect.width;
|
|
|
|
if (isVisible)
|
|
|
|
x += cellSpacingX;
|
|
|
|
PRInt32 actualRowSpan = tableFrame->GetEffectiveRowSpan(*cellFrame);
|
|
|
|
nsTableRowFrame* rowFrame = GetNextRow();
|
|
|
|
for (actualRowSpan--; actualRowSpan > 0 && rowFrame; actualRowSpan--) {
|
|
|
|
const nsStyleVisibility* nextRowVis = rowFrame->GetStyleVisibility();
|
|
|
|
PRBool collapseNextRow = (NS_STYLE_VISIBILITY_COLLAPSE ==
|
|
|
|
nextRowVis->mVisible);
|
|
|
|
if (!collapseNextRow) {
|
|
|
|
nsRect nextRect = rowFrame->GetRect();
|
|
|
|
cRect.height += nextRect.height + cellSpacingY;
|
|
|
|
}
|
|
|
|
rowFrame = rowFrame->GetNextRow();
|
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
nsRect oldCellRect = cellFrame->GetRect();
|
2010-10-06 21:25:46 -07:00
|
|
|
nsRect oldCellVisualOverflow = cellFrame->GetVisualOverflowRect();
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
if (aRowOffset == 0 && cRect.TopLeft() != oldCellRect.TopLeft()) {
|
|
|
|
// We're moving the cell. Invalidate the old overflow area
|
2010-08-30 17:49:12 -07:00
|
|
|
cellFrame->InvalidateFrameSubtree();
|
2008-02-08 01:36:32 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
cellFrame->SetRect(cRect);
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
// XXXbz This looks completely bogus in the cases when we didn't
|
|
|
|
// collapse the cell!
|
2010-10-06 21:25:45 -07:00
|
|
|
nsRect cellBounds(0, 0, cRect.width, cRect.height);
|
|
|
|
nsOverflowAreas cellOverflow(cellBounds, cellBounds);
|
|
|
|
cellFrame->FinishAndStoreOverflow(cellOverflow,
|
|
|
|
nsSize(cRect.width, cRect.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableFrame::RePositionViews(cellFrame);
|
2010-10-06 21:25:45 -07:00
|
|
|
ConsiderChildOverflow(overflow, cellFrame);
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
if (aRowOffset == 0) {
|
2008-03-16 13:32:48 -07:00
|
|
|
nsTableFrame::InvalidateFrame(cellFrame, oldCellRect,
|
2010-10-06 21:25:46 -07:00
|
|
|
oldCellVisualOverflow,
|
|
|
|
PR_FALSE);
|
2008-02-08 01:36:32 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
kidFrame = iter.Next(); // Get the next child
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
SetRect(rowRect);
|
2010-10-06 21:25:45 -07:00
|
|
|
overflow.UnionAllWith(nsRect(0,0,rowRect.width, rowRect.height));
|
|
|
|
FinishAndStoreOverflow(overflow, nsSize(rowRect.width, rowRect.height));
|
2008-02-08 01:36:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTableFrame::RePositionViews(this);
|
2010-10-06 21:25:46 -07:00
|
|
|
nsTableFrame::InvalidateFrame(this, oldRect, oldVisualOverflow, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
2009-09-04 14:07:43 -07:00
|
|
|
/*
|
|
|
|
* The following method is called by the row group frame's SplitRowGroup()
|
|
|
|
* when it creates a continuing cell frame and wants to insert it into the
|
|
|
|
* row's child list.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame,
|
|
|
|
PRInt32 aColIndex)
|
|
|
|
{
|
|
|
|
// Find the cell frame where col index < aColIndex
|
|
|
|
nsTableCellFrame* priorCell = nsnull;
|
|
|
|
for (nsIFrame* child = mFrames.FirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(child);
|
|
|
|
if (cellFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 colIndex;
|
|
|
|
cellFrame->GetColIndex(colIndex);
|
|
|
|
if (colIndex < aColIndex) {
|
|
|
|
priorCell = cellFrame;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 14:07:43 -07:00
|
|
|
mFrames.InsertFrame(this, priorCell, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsTableRowFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::tableRowFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTableRowFrame*
|
|
|
|
nsTableRowFrame::GetNextRow() const
|
|
|
|
{
|
|
|
|
nsIFrame* childFrame = GetNextSibling();
|
|
|
|
while (childFrame) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
|
|
|
|
if (rowFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW == childFrame->GetStyleDisplay()->mDisplay, "wrong display type on rowframe");
|
2009-03-24 15:10:06 -07:00
|
|
|
return rowFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(RowUnpaginatedHeightProperty, nsnull)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsTableRowFrame::SetUnpaginatedHeight(nsPresContext* aPresContext,
|
2009-01-14 14:16:43 -08:00
|
|
|
nscoord aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!GetPrevInFlow(), "program error");
|
2010-03-28 18:46:55 -07:00
|
|
|
// Get the property
|
|
|
|
aPresContext->PropertyTable()->
|
|
|
|
Set(this, RowUnpaginatedHeightProperty(), NS_INT32_TO_PTR(aValue));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTableRowFrame::GetUnpaginatedHeight(nsPresContext* aPresContext)
|
|
|
|
{
|
2010-03-28 18:46:55 -07:00
|
|
|
FrameProperties props = GetFirstInFlow()->Properties();
|
|
|
|
return NS_PTR_TO_INT32(props.Get(RowUnpaginatedHeightProperty()));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsTableRowFrame::SetContinuousBCBorderWidth(PRUint8 aForSide,
|
|
|
|
BCPixelSize aPixelValue)
|
|
|
|
{
|
|
|
|
switch (aForSide) {
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
mRightContBorderWidth = aPixelValue;
|
|
|
|
return;
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
mTopContBorderWidth = aPixelValue;
|
|
|
|
return;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
mLeftContBorderWidth = aPixelValue;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
NS_ERROR("invalid NS_SIDE arg");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-25 13:34:35 -07:00
|
|
|
/**
|
|
|
|
* Sets the NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT bit to indicate whether
|
|
|
|
* this row has any cells that have non-auto-height. (Row-spanning
|
|
|
|
* cells are ignored.)
|
|
|
|
*/
|
|
|
|
void nsTableRowFrame::InitHasCellWithStyleHeight(nsTableFrame* aTableFrame)
|
|
|
|
{
|
|
|
|
nsTableIterator iter(*this);
|
|
|
|
|
|
|
|
for (nsIFrame* kidFrame = iter.First(); kidFrame; kidFrame = iter.Next()) {
|
2009-03-24 15:10:06 -07:00
|
|
|
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
|
|
|
|
if (!cellFrame) {
|
2007-06-25 13:34:35 -07:00
|
|
|
NS_NOTREACHED("Table row has a non-cell child.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Ignore row-spanning cells
|
2010-08-25 03:17:55 -07:00
|
|
|
const nsStyleCoord &cellHeight = cellFrame->GetStylePosition()->mHeight;
|
2007-06-25 13:34:35 -07:00
|
|
|
if (aTableFrame->GetEffectiveRowSpan(*cellFrame) == 1 &&
|
2010-08-25 03:17:55 -07:00
|
|
|
cellHeight.GetUnit() != eStyleUnit_Auto &&
|
|
|
|
!cellHeight.IsCalcUnit() /* calc() treated like 'auto' */) {
|
2007-06-25 13:34:35 -07:00
|
|
|
AddStateBits(NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RemoveStateBits(NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ----- global methods ----- */
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewTableRowFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsTableRowFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTableRowFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTableRowFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("TableRow"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|