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)
|
2008-09-24 21:14:35 +04:00
|
|
|
: nsITableLayoutStrategy(nsITableLayoutStrategy::Fixed)
|
|
|
|
, 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
|
2008-09-24 21:14:35 +04:00
|
|
|
// depends only on the columns and the first row (where we look at
|
|
|
|
// intrinsic widths inside the first row and then reverse the
|
|
|
|
// algorithm to find the narrowest width that would hold all of
|
|
|
|
// those intrinsic widths), but it wouldn't be compatible with other
|
|
|
|
// browsers, or with the use of GetMinWidth by
|
|
|
|
// nsTableFrame::ComputeSize to determine the width of a fixed
|
|
|
|
// layout table, since CSS2.1 says:
|
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 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'?
|
2008-09-24 21:14:35 +04:00
|
|
|
// XXX Should we really ignore widths on column groups?
|
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
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
|
|
|
PRInt32 colCount = cellMap->GetColCount();
|
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX();
|
|
|
|
|
|
|
|
nscoord result = 0;
|
|
|
|
|
|
|
|
if (colCount > 0) {
|
|
|
|
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;
|
2008-07-16 01:31:36 +04:00
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
2007-05-04 03:11:00 +04:00
|
|
|
result += nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
colFrame, 0, 0, 0, *styleWidth);
|
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
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
// do nothing
|
|
|
|
} else {
|
2007-05-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
|
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated,
|
|
|
|
"bad width");
|
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 '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;
|
2007-05-04 03:11:00 +04:00
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord ||
|
|
|
|
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 21:10:31 +03:00
|
|
|
(styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
|
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
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 21:10:31 +03:00
|
|
|
// else, for 'auto', '-moz-available', and '-moz-fit-content'
|
2007-05-04 03:11:00 +04:00
|
|
|
// do nothing
|
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
|
|
|
}
|
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
|
2008-09-24 21:14:35 +04:00
|
|
|
// depends only on the columns and the first row (where we look at
|
|
|
|
// intrinsic widths inside the first row and then reverse the
|
|
|
|
// algorithm to find the narrowest width that would hold all of
|
|
|
|
// those intrinsic widths), but it wouldn't be compatible with other
|
|
|
|
// browsers.
|
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
|
|
|
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)
|
|
|
|
{
|
2007-01-26 03:05:12 +03:00
|
|
|
nscoord tableWidth = aReflowState.ComputedWidth();
|
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 (mLastCalcWidth == tableWidth)
|
|
|
|
return;
|
|
|
|
mLastCalcWidth = tableWidth;
|
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
|
|
|
PRInt32 colCount = cellMap->GetColCount();
|
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX();
|
|
|
|
|
2008-09-24 21:14:35 +04:00
|
|
|
if (colCount == 0) {
|
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
|
|
|
// No Columns - nothing to compute
|
2006-12-25 22:44:34 +03:00
|
|
|
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
|
|
|
|
2008-09-24 21:14:35 +04:00
|
|
|
// border-spacing isn't part of the basis for percentages.
|
|
|
|
tableWidth -= spacing * (colCount + 1);
|
2008-11-28 05:23:52 +03:00
|
|
|
|
|
|
|
// store the old column widths. We might call multiple times SetFinalWidth
|
|
|
|
// on the columns, due to this we can't compare at the last call that the
|
|
|
|
// width has changed with the respect to the last call to
|
|
|
|
// ComputeColumnWidths. In order to overcome this we store the old values
|
|
|
|
// in this array. A single call to SetFinalWidth would make it possible to
|
|
|
|
// call GetFinalWidth before and to compare when setting the final width.
|
|
|
|
nsTArray<nscoord> oldColWidths;
|
2008-09-24 21:14:35 +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.
|
|
|
|
|
2008-09-24 21:14:35 +04:00
|
|
|
// XXX Should we really ignore widths on column groups?
|
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
|
|
|
|
|
|
|
PRUint32 unassignedCount = 0;
|
|
|
|
nscoord unassignedSpace = tableWidth;
|
|
|
|
const nscoord unassignedMarker = nscoord_MIN;
|
|
|
|
|
|
|
|
// We use the PrefPercent on the columns to store the percentages
|
2008-11-26 02:22:39 +03:00
|
|
|
// used to compute column widths in case we need to shrink or expand
|
|
|
|
// the columns.
|
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
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
2008-11-26 02:22:39 +03:00
|
|
|
// Accumulate the total specified (non-percent) on the columns for
|
|
|
|
// distributing excess width to the columns.
|
|
|
|
nscoord specTotal = 0;
|
|
|
|
|
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) {
|
2008-11-28 05:23:52 +03:00
|
|
|
oldColWidths.AppendElement(0);
|
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
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|
2008-11-28 05:23:52 +03:00
|
|
|
oldColWidths.AppendElement(colFrame->GetFinalWidth());
|
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;
|
2008-07-16 01:31:36 +04:00
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
|
2007-05-04 03:11:00 +04:00
|
|
|
colWidth = nsLayoutUtils::ComputeWidthValue(
|
|
|
|
aReflowState.rendContext,
|
|
|
|
colFrame, 0, 0, 0, *styleWidth);
|
2008-11-26 02:22:39 +03:00
|
|
|
specTotal += colWidth;
|
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
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
float pct = styleWidth->GetPercentValue();
|
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth));
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
2007-05-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
|
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated,
|
|
|
|
"bad width");
|
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 '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;
|
2007-05-04 03:11:00 +04:00
|
|
|
if (styleWidth->GetUnit() == eStyleUnit_Coord ||
|
|
|
|
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 21:10:31 +03:00
|
|
|
(styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
|
2007-05-04 03:11:00 +04:00
|
|
|
// XXX This should use real percentage padding
|
|
|
|
// Note that the difference between MIN_WIDTH and
|
|
|
|
// PREF_WIDTH shouldn't matter for any of these
|
|
|
|
// values of styleWidth; use MIN_WIDTH for symmetry
|
|
|
|
// with GetMinWidth above, just in case there is a
|
|
|
|
// difference.
|
|
|
|
colWidth = nsLayoutUtils::IntrinsicForContainer(
|
|
|
|
aReflowState.rendContext,
|
|
|
|
cellFrame, nsLayoutUtils::MIN_WIDTH);
|
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
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
2007-05-04 03:11:00 +04:00
|
|
|
// XXX This should use real percentage padding
|
|
|
|
nsIFrame::IntrinsicWidthOffsetData offsets =
|
|
|
|
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
|
|
|
float pct = styleWidth->GetPercentValue();
|
2007-05-04 03:11:00 +04:00
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth)) +
|
|
|
|
offsets.hPadding + offsets.hBorder;
|
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
|
|
|
pct /= float(colSpan);
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
2007-11-15 21:10:31 +03:00
|
|
|
// 'auto', '-moz-available', and '-moz-fit-content'
|
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 = unassignedMarker;
|
|
|
|
}
|
|
|
|
if (colWidth != unassignedMarker) {
|
|
|
|
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;
|
|
|
|
}
|
2008-11-26 02:22:39 +03:00
|
|
|
if (styleWidth->GetUnit() != eStyleUnit_Percent) {
|
|
|
|
specTotal += colWidth;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
} 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) {
|
2008-11-26 02:22:39 +03:00
|
|
|
// The spec says to distribute the remaining space evenly among
|
|
|
|
// the columns.
|
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
|
|
|
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) {
|
2008-11-26 02:22:39 +03:00
|
|
|
// The spec doesn't say how to distribute the unassigned space.
|
|
|
|
if (specTotal > 0) {
|
|
|
|
// Distribute proportionally to non-percentage columns.
|
|
|
|
nscoord specUndist = specTotal;
|
|
|
|
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->GetPrefPercent() == 0.0f) {
|
|
|
|
NS_ASSERTION(colFrame->GetFinalWidth() <= specUndist,
|
|
|
|
"widths don't add up");
|
|
|
|
nscoord toAdd = NSToCoordRound(float(unassignedSpace) *
|
|
|
|
(float(colFrame->GetFinalWidth()) / float(specUndist)));
|
|
|
|
specUndist -= colFrame->GetFinalWidth();
|
|
|
|
colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd);
|
|
|
|
unassignedSpace -= toAdd;
|
|
|
|
if (specUndist <= 0) {
|
|
|
|
NS_ASSERTION(specUndist == 0,
|
|
|
|
"math should be exact");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(unassignedSpace == 0, "failed to redistribute");
|
|
|
|
} else if (pctTotal > 0) {
|
|
|
|
// Distribute proportionally to percentage columns.
|
|
|
|
float pctUndist = 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;
|
|
|
|
}
|
|
|
|
if (pctUndist < colFrame->GetPrefPercent()) {
|
|
|
|
// This can happen with floating-point math.
|
|
|
|
NS_ASSERTION(colFrame->GetPrefPercent() - pctUndist
|
|
|
|
< 0.0001,
|
|
|
|
"widths don't add up");
|
|
|
|
pctUndist = colFrame->GetPrefPercent();
|
|
|
|
}
|
|
|
|
nscoord toAdd = NSToCoordRound(float(unassignedSpace) *
|
|
|
|
(colFrame->GetPrefPercent() / pctUndist));
|
|
|
|
colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd);
|
|
|
|
unassignedSpace -= toAdd;
|
|
|
|
pctUndist -= colFrame->GetPrefPercent();
|
|
|
|
if (pctUndist <= 0.0f) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(unassignedSpace == 0, "failed to redistribute");
|
|
|
|
} else {
|
|
|
|
// Distribute equally to the zero-width columns.
|
|
|
|
PRInt32 colsLeft = 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;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(colFrame->GetFinalWidth() == 0, "yikes");
|
|
|
|
nscoord toAdd = NSToCoordRound(float(unassignedSpace) /
|
|
|
|
float(colsLeft));
|
|
|
|
colFrame->SetFinalWidth(toAdd);
|
|
|
|
unassignedSpace -= toAdd;
|
|
|
|
--colsLeft;
|
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
|
|
|
}
|
|
|
|
}
|
2001-01-27 02:44:59 +03:00
|
|
|
}
|
2008-11-28 05:23:52 +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;
|
|
|
|
}
|
|
|
|
if (oldColWidths.ElementAt(col) != colFrame->GetFinalWidth()) {
|
|
|
|
mTableFrame->DidResizeColumns();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|