Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
// vim:cindent:ts=4:et:sw=4:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-23 06:32:15 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
1998-09-23 06:32:15 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-09-23 06:32:15 +04:00
|
|
|
*
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* The Original Code is Mozilla's table layout code.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
2001-09-29 00:14:13 +04:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org> (original author)
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* either 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-23 06:32:15 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/*
|
|
|
|
* Algorithms that determine column and table widths used for CSS2's
|
|
|
|
* 'table-layout: fixed'.
|
|
|
|
*/
|
|
|
|
|
1998-09-23 06:32:15 +04:00
|
|
|
#include "FixedTableLayoutStrategy.h"
|
|
|
|
#include "nsTableFrame.h"
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#include "nsTableColFrame.h"
|
1998-09-23 06:32:15 +04:00
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
FixedTableLayoutStrategy::FixedTableLayoutStrategy(nsTableFrame *aTableFrame)
|
|
|
|
: mTableFrame(aTableFrame)
|
1998-09-23 06:32:15 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
MarkIntrinsicWidthsDirty();
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */
|
1998-09-23 06:32:15 +04:00
|
|
|
FixedTableLayoutStrategy::~FixedTableLayoutStrategy()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ nscoord
|
|
|
|
FixedTableLayoutStrategy::GetMinWidth(nsIRenderingContext* aRenderingContext)
|
1998-09-23 06:32:15 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_MIN_WIDTH(mTableFrame, mMinWidth);
|
|
|
|
if (mMinWidth != NS_INTRINSIC_WIDTH_UNKNOWN)
|
|
|
|
return mMinWidth;
|
1998-09-23 06:32:15 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// It's theoretically possible to do something much better here that
|
|
|
|
// depends only on the columns and the first row, but it wouldn't be
|
|
|
|
// compatible with other browsers, or with the use of GetMinWidth by
|
|
|
|
// nsHTMLReflowState to determine the width of a fixed-layout table,
|
|
|
|
// since CSS2.1 says:
|
|
|
|
// The width of the table is then the greater of the value of the
|
|
|
|
// 'width' property for the table element and the sum of the
|
|
|
|
// column widths (plus cell spacing or borders).
|
1998-09-23 06:32:15 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXX Should we really ignore 'min-width' and 'max-width'?
|
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
|
|
|
PRInt32 colCount = cellMap->GetColCount();
|
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX();
|
|
|
|
|
|
|
|
// XXX Should this code do any pixel rounding?
|
|
|
|
|
|
|
|
nscoord result = 0;
|
|
|
|
|
|
|
|
// XXX Consider widths on columns or column groups?
|
|
|
|
|
|
|
|
if (colCount > 0) {
|
|
|
|
// XXX Should only add columns that have cells originating in them!
|
|
|
|
result += spacing * (colCount + 1);
|
1999-08-29 10:00:32 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
for (PRInt32 col = 0; col < colCount; ++col) {
|
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
1999-06-03 06:42:33 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
const nsStyleCoord *styleWidth =
|
|
|
|
&colFrame->GetStylePosition()->mWidth;
|
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
|
|
|
result += styleWidth->GetCoordValue();
|
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
// do nothing
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto, "bad width");
|
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
|
|
|
styleWidth = &cellFrame->GetStylePosition()->mWidth;
|
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
|
|
|
nscoord cellWidth = nsLayoutUtils::IntrinsicForContainer(
|
|
|
|
aRenderingContext, cellFrame, nsLayoutUtils::MIN_WIDTH);
|
|
|
|
if (colSpan > 1) {
|
|
|
|
// If a column-spanning cell is in the first
|
|
|
|
// row, split up the space evenly. (XXX This
|
|
|
|
// isn't quite right if some of the columns it's
|
|
|
|
// in have specified widths. Should we care?)
|
|
|
|
cellWidth = ((cellWidth + spacing) / colSpan) - spacing;
|
|
|
|
}
|
|
|
|
result += cellWidth;
|
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
if (colSpan > 1) {
|
|
|
|
// XXX Can this force columns to negative
|
|
|
|
// widths?
|
|
|
|
result -= spacing * (colSpan - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return (mMinWidth = result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
FixedTableLayoutStrategy::GetPrefWidth(nsIRenderingContext* aRenderingContext,
|
|
|
|
PRBool aComputingSize)
|
|
|
|
{
|
|
|
|
// It's theoretically possible to do something much better here that
|
|
|
|
// depends only on the columns and the first row, but it wouldn't be
|
|
|
|
// compatible with other browsers.
|
|
|
|
nscoord result = nscoord_MAX;
|
|
|
|
DISPLAY_PREF_WIDTH(mTableFrame, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
FixedTableLayoutStrategy::MarkIntrinsicWidthsDirty()
|
|
|
|
{
|
|
|
|
mMinWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
|
|
|
|
mLastCalcWidth = nscoord_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nscoord tableWidth = aReflowState.mComputedWidth;
|
|
|
|
|
|
|
|
if (mLastCalcWidth == tableWidth)
|
|
|
|
return;
|
|
|
|
mLastCalcWidth = tableWidth;
|
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
|
|
|
PRInt32 colCount = cellMap->GetColCount();
|
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX();
|
|
|
|
|
|
|
|
// XXX Should this code do any pixel rounding?
|
|
|
|
|
|
|
|
// border-spacing isn't part of the basis for percentages.
|
|
|
|
if (colCount > 0) {
|
|
|
|
// XXX Should only add columns that have cells originating in them!
|
|
|
|
nscoord subtract = spacing * (colCount + 1);
|
|
|
|
tableWidth -= subtract;
|
|
|
|
} else {
|
|
|
|
// No Columns - nothing to compute
|
|
|
|
return;
|
1999-06-03 06:42:33 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
// XXX This ignores the 'min-width' and 'max-width' properties
|
|
|
|
// throughout. Then again, that's what the CSS spec says to do.
|
|
|
|
|
|
|
|
// XXX Consider widths on columns or column groups?
|
|
|
|
|
|
|
|
PRUint32 unassignedCount = 0;
|
|
|
|
nscoord unassignedSpace = tableWidth;
|
|
|
|
const nscoord unassignedMarker = nscoord_MIN;
|
|
|
|
|
|
|
|
// We use the PrefPercent on the columns to store the percentages
|
|
|
|
// used to compute column widths in case we need to reduce their
|
|
|
|
// basis.
|
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
|
|
|
for (PRInt32 col = 0; col < colCount; ++col) {
|
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
colFrame->ResetPrefPercent();
|
|
|
|
const nsStyleCoord *styleWidth =
|
|
|
|
&colFrame->GetStylePosition()->mWidth;
|
|
|
|
nscoord colWidth;
|
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
|
|
|
colWidth = styleWidth->GetCoordValue();
|
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
float pct = styleWidth->GetPercentValue();
|
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth));
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto, "bad width");
|
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
|
|
|
PRBool originates;
|
|
|
|
PRInt32 colSpan;
|
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
|
|
|
styleWidth = &cellFrame->GetStylePosition()->mWidth;
|
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
|
|
|
colWidth = styleWidth->GetCoordValue();
|
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
float pct = styleWidth->GetPercentValue();
|
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth));
|
|
|
|
pct /= float(colSpan);
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
|
|
|
colWidth = unassignedMarker;
|
|
|
|
}
|
|
|
|
if (colWidth != unassignedMarker) {
|
|
|
|
// Add in cell's padding and border.
|
|
|
|
// XXX This should use real percentage padding
|
|
|
|
nsIFrame::IntrinsicWidthOffsetData offsets =
|
2006-12-17 17:06:42 +03:00
|
|
|
cellFrame->IntrinsicWidthOffsets(aReflowState.rendContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
colWidth += offsets.hPadding + offsets.hBorder;
|
|
|
|
|
|
|
|
if (colSpan > 1) {
|
|
|
|
// If a column-spanning cell is in the first
|
|
|
|
// row, split up the space evenly. (XXX This
|
|
|
|
// isn't quite right if some of the columns it's
|
|
|
|
// in have specified widths. Should we care?)
|
|
|
|
colWidth = ((colWidth + spacing) / colSpan) - spacing;
|
|
|
|
if (colWidth < 0)
|
|
|
|
colWidth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
colWidth = unassignedMarker;
|
|
|
|
}
|
1999-06-03 06:42:33 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
colFrame->SetFinalWidth(colWidth);
|
|
|
|
|
|
|
|
if (colWidth == unassignedMarker) {
|
|
|
|
++unassignedCount;
|
|
|
|
} else {
|
|
|
|
unassignedSpace -= colWidth;
|
1999-08-29 10:00:32 +04:00
|
|
|
}
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
if (unassignedSpace < 0) {
|
|
|
|
if (pctTotal > 0) {
|
|
|
|
// If the columns took up too much space, reduce those that
|
|
|
|
// had percentage widths. The spec doesn't say to do this,
|
|
|
|
// but we've always done it in the past, and so does WinIE6.
|
|
|
|
nscoord pctUsed = NSToCoordFloor(pctTotal * float(tableWidth));
|
|
|
|
nscoord reduce = PR_MIN(pctUsed, -unassignedSpace);
|
|
|
|
float reduceRatio = float(reduce) / pctTotal;
|
|
|
|
for (PRInt32 col = 0; col < colCount; ++col) {
|
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nscoord colWidth = colFrame->GetFinalWidth();
|
|
|
|
colWidth -= NSToCoordFloor(colFrame->GetPrefPercent() *
|
|
|
|
reduceRatio);
|
|
|
|
if (colWidth < 0)
|
|
|
|
colWidth = 0;
|
|
|
|
colFrame->SetFinalWidth(colWidth);
|
|
|
|
}
|
2006-02-11 14:12:40 +03:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
unassignedSpace = 0;
|
1999-06-03 06:42:33 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
if (unassignedCount > 0) {
|
|
|
|
nscoord toAssign = unassignedSpace / unassignedCount;
|
|
|
|
for (PRInt32 col = 0; col < colCount; ++col) {
|
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (colFrame->GetFinalWidth() == unassignedMarker)
|
|
|
|
colFrame->SetFinalWidth(toAssign);
|
|
|
|
}
|
|
|
|
} else if (unassignedSpace > 0) {
|
|
|
|
// The spec says to distribute extra space evenly. (That's not
|
|
|
|
// what WinIE6 does, though. It treats percentages and
|
|
|
|
// nonpercentages differently.)
|
|
|
|
nscoord toAdd = unassignedSpace / colCount;
|
|
|
|
for (PRInt32 col = 0; col < colCount; ++col) {
|
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd);
|
|
|
|
}
|
2001-01-27 02:44:59 +03:00
|
|
|
}
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|