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 05:38:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
// vim:cindent:ts=4:et:sw=4:
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
/*
|
|
|
|
* Algorithms that determine column and table widths used for CSS2's
|
|
|
|
* 'table-layout: fixed'.
|
|
|
|
*/
|
|
|
|
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
#include "nsTableColFrame.h"
|
1998-09-23 02:32:15 +00:00
|
|
|
#include "nsTableCellFrame.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
FixedTableLayoutStrategy::FixedTableLayoutStrategy(nsTableFrame *aTableFrame)
|
2008-09-24 17:14:35 +00:00
|
|
|
: nsITableLayoutStrategy(nsITableLayoutStrategy::Fixed)
|
|
|
|
, mTableFrame(aTableFrame)
|
1998-09-23 02:32:15 +00:00
|
|
|
{
|
2014-07-24 17:03:26 +00:00
|
|
|
MarkIntrinsicISizesDirty();
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
/* virtual */
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
/* virtual */ nscoord
|
2014-07-24 17:03:25 +00:00
|
|
|
FixedTableLayoutStrategy::GetMinISize(nsRenderingContext* aRenderingContext)
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
DISPLAY_MIN_WIDTH(mTableFrame, mMinWidth);
|
|
|
|
if (mMinWidth != NS_INTRINSIC_WIDTH_UNKNOWN)
|
|
|
|
return mMinWidth;
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
// It's theoretically possible to do something much better here that
|
2008-09-24 17:14:35 +00: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
|
2014-07-24 17:03:25 +00:00
|
|
|
// browsers, or with the use of GetMinISize by
|
2008-09-24 17:14:35 +00:00
|
|
|
// 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 05:38:33 +00: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 02:32:15 +00: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 05:38:33 +00:00
|
|
|
// XXX Should we really ignore 'min-width' and 'max-width'?
|
2008-09-24 17:14:35 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t colCount = cellMap->GetColCount();
|
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 05:38:33 +00:00
|
|
|
|
|
|
|
nscoord result = 0;
|
|
|
|
|
|
|
|
if (colCount > 0) {
|
2014-06-18 10:47:00 +00:00
|
|
|
result += mTableFrame->GetCellSpacingX(-1, colCount);
|
1999-08-29 06:00:32 +00: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 05:38:33 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
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 05:38:33 +00:00
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
1999-06-03 02:42:33 +00:00
|
|
|
}
|
2014-06-18 10:47:00 +00:00
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX(col);
|
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 05:38:33 +00:00
|
|
|
const nsStyleCoord *styleWidth =
|
2013-02-16 21:51:02 +00:00
|
|
|
&colFrame->StylePosition()->mWidth;
|
2012-11-21 16:19:37 +00:00
|
|
|
if (styleWidth->ConvertsToLength()) {
|
2007-05-03 23:11:00 +00: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 05:38:33 +00:00
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
// do nothing
|
|
|
|
} else {
|
2007-05-03 23:11:00 +00:00
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
|
2010-08-11 19:32:53 +00:00
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
|
2012-11-21 16:19:37 +00:00
|
|
|
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
|
2007-05-03 23:11:00 +00:00
|
|
|
"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 05:38:33 +00:00
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool originates;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t colSpan;
|
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 05:38:33 +00:00
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
2013-02-16 21:51:02 +00:00
|
|
|
styleWidth = &cellFrame->StylePosition()->mWidth;
|
2012-11-21 16:19:37 +00:00
|
|
|
if (styleWidth->ConvertsToLength() ||
|
2007-05-03 23:11:00 +00:00
|
|
|
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 18:10:31 +00: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 05:38:33 +00:00
|
|
|
nscoord cellWidth = nsLayoutUtils::IntrinsicForContainer(
|
2014-07-24 17:03:26 +00:00
|
|
|
aRenderingContext, cellFrame, nsLayoutUtils::MIN_ISIZE);
|
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 05:38:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 19:32:53 +00:00
|
|
|
// else, for 'auto', '-moz-available', '-moz-fit-content',
|
2012-11-21 16:19:37 +00:00
|
|
|
// and 'calc()' with percentages, 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 05:38:33 +00:00
|
|
|
}
|
1998-09-23 02:32:15 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
return (mMinWidth = result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 17:03:25 +00:00
|
|
|
FixedTableLayoutStrategy::GetPrefISize(nsRenderingContext* aRenderingContext,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aComputingSize)
|
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 05:38:33 +00:00
|
|
|
{
|
|
|
|
// It's theoretically possible to do something much better here that
|
2008-09-24 17:14:35 +00: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 05:38:33 +00:00
|
|
|
nscoord result = nscoord_MAX;
|
|
|
|
DISPLAY_PREF_WIDTH(mTableFrame, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2014-07-24 17:03:26 +00:00
|
|
|
FixedTableLayoutStrategy::MarkIntrinsicISizesDirty()
|
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 05:38:33 +00:00
|
|
|
{
|
|
|
|
mMinWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
|
|
|
|
mLastCalcWidth = nscoord_MIN;
|
|
|
|
}
|
|
|
|
|
2008-12-04 16:09:53 +00:00
|
|
|
static inline nscoord
|
|
|
|
AllocateUnassigned(nscoord aUnassignedSpace, float aShare)
|
|
|
|
{
|
|
|
|
if (aShare == 1.0f) {
|
|
|
|
// This happens when the numbers we're dividing to get aShare
|
|
|
|
// are equal. We want to return unassignedSpace exactly, even
|
|
|
|
// if it can't be precisely round-tripped through float.
|
|
|
|
return aUnassignedSpace;
|
|
|
|
}
|
|
|
|
return NSToCoordRound(float(aUnassignedSpace) * aShare);
|
|
|
|
}
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
/* virtual */ void
|
|
|
|
FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
2007-01-26 00:05:12 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
if (mLastCalcWidth == tableWidth)
|
|
|
|
return;
|
|
|
|
mLastCalcWidth = tableWidth;
|
|
|
|
|
|
|
|
nsTableCellMap *cellMap = mTableFrame->GetCellMap();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t colCount = cellMap->GetColCount();
|
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 05:38:33 +00:00
|
|
|
|
2008-09-24 17:14:35 +00: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 05:38:33 +00:00
|
|
|
// No Columns - nothing to compute
|
2006-12-25 19:44:34 +00:00
|
|
|
return;
|
1999-06-03 02:42:33 +00: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 05:38:33 +00:00
|
|
|
|
2008-09-24 17:14:35 +00:00
|
|
|
// border-spacing isn't part of the basis for percentages.
|
2014-06-18 10:47:00 +00:00
|
|
|
tableWidth -= mTableFrame->GetCellSpacingX(-1, colCount);
|
|
|
|
|
2008-11-28 02:23:52 +00: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 17:14:35 +00: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 05:38:33 +00: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 17:14:35 +00: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 05:38:33 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t unassignedCount = 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 05:38:33 +00:00
|
|
|
nscoord unassignedSpace = tableWidth;
|
|
|
|
const nscoord unassignedMarker = nscoord_MIN;
|
|
|
|
|
|
|
|
// We use the PrefPercent on the columns to store the percentages
|
2008-11-25 23:22:39 +00: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 05:38:33 +00:00
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
2008-11-25 23:22:39 +00:00
|
|
|
// Accumulate the total specified (non-percent) on the columns for
|
|
|
|
// distributing excess width to the columns.
|
|
|
|
nscoord specTotal = 0;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
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 05:38:33 +00:00
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
2008-11-28 02:23:52 +00: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 05:38:33 +00:00
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
1998-09-23 02:32:15 +00:00
|
|
|
}
|
2008-11-28 02:23:52 +00: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 05:38:33 +00:00
|
|
|
colFrame->ResetPrefPercent();
|
|
|
|
const nsStyleCoord *styleWidth =
|
2013-02-16 21:51:02 +00:00
|
|
|
&colFrame->StylePosition()->mWidth;
|
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 05:38:33 +00:00
|
|
|
nscoord colWidth;
|
2012-11-21 16:19:37 +00:00
|
|
|
if (styleWidth->ConvertsToLength()) {
|
2007-05-03 23:11:00 +00:00
|
|
|
colWidth = nsLayoutUtils::ComputeWidthValue(
|
|
|
|
aReflowState.rendContext,
|
|
|
|
colFrame, 0, 0, 0, *styleWidth);
|
2008-11-25 23:22:39 +00: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 05:38:33 +00:00
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
|
|
|
float pct = styleWidth->GetPercentValue();
|
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth));
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
2007-05-03 23:11:00 +00:00
|
|
|
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
|
2010-08-11 19:32:53 +00:00
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
|
2012-11-21 16:19:37 +00:00
|
|
|
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
|
2007-05-03 23:11:00 +00:00
|
|
|
"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 05:38:33 +00:00
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool originates;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t colSpan;
|
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 05:38:33 +00:00
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
2013-02-16 21:51:02 +00:00
|
|
|
styleWidth = &cellFrame->StylePosition()->mWidth;
|
2012-11-21 16:19:37 +00:00
|
|
|
if (styleWidth->ConvertsToLength() ||
|
2007-05-03 23:11:00 +00:00
|
|
|
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 18:10:31 +00:00
|
|
|
(styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
|
2007-05-03 23:11:00 +00:00
|
|
|
// XXX This should use real percentage padding
|
2014-07-24 17:03:26 +00:00
|
|
|
// Note that the difference between MIN_ISIZE and
|
|
|
|
// PREF_ISIZE shouldn't matter for any of these
|
|
|
|
// values of styleWidth; use MIN_ISIZE for symmetry
|
2014-07-24 17:03:25 +00:00
|
|
|
// with GetMinISize above, just in case there is a
|
2007-05-03 23:11:00 +00:00
|
|
|
// difference.
|
|
|
|
colWidth = nsLayoutUtils::IntrinsicForContainer(
|
|
|
|
aReflowState.rendContext,
|
2014-07-24 17:03:26 +00:00
|
|
|
cellFrame, nsLayoutUtils::MIN_ISIZE);
|
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 05:38:33 +00:00
|
|
|
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
|
2007-05-03 23:11:00 +00:00
|
|
|
// XXX This should use real percentage padding
|
2014-07-24 17:03:26 +00:00
|
|
|
nsIFrame::IntrinsicISizeOffsetData offsets =
|
|
|
|
cellFrame->IntrinsicISizeOffsets(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 05:38:33 +00:00
|
|
|
float pct = styleWidth->GetPercentValue();
|
2013-07-11 23:46:06 +00:00
|
|
|
colWidth = NSToCoordFloor(pct * float(tableWidth));
|
|
|
|
|
|
|
|
nscoord boxSizingAdjust = 0;
|
|
|
|
switch (cellFrame->StylePosition()->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_CONTENT:
|
|
|
|
boxSizingAdjust += offsets.hPadding;
|
|
|
|
// Fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
boxSizingAdjust += offsets.hBorder;
|
|
|
|
// Fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
// Don't add anything
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
colWidth += boxSizingAdjust;
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
pct /= float(colSpan);
|
|
|
|
colFrame->AddPrefPercent(pct);
|
|
|
|
pctTotal += pct;
|
|
|
|
} else {
|
2010-08-11 19:32:53 +00:00
|
|
|
// 'auto', '-moz-available', '-moz-fit-content', and
|
2012-11-21 16:19:37 +00:00
|
|
|
// 'calc()' with percentages
|
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 05:38:33 +00: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?)
|
2014-06-18 10:47:00 +00:00
|
|
|
nscoord spacing = mTableFrame->GetCellSpacingX(col);
|
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 05:38:33 +00:00
|
|
|
colWidth = ((colWidth + spacing) / colSpan) - spacing;
|
|
|
|
if (colWidth < 0)
|
|
|
|
colWidth = 0;
|
|
|
|
}
|
2008-11-25 23:22:39 +00: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 05:38:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
colWidth = unassignedMarker;
|
|
|
|
}
|
1999-06-03 02:42:33 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
colFrame->SetFinalWidth(colWidth);
|
|
|
|
|
|
|
|
if (colWidth == unassignedMarker) {
|
|
|
|
++unassignedCount;
|
|
|
|
} else {
|
|
|
|
unassignedSpace -= colWidth;
|
1999-08-29 06:00:32 +00: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 05:38:33 +00: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));
|
2013-01-15 12:22:03 +00:00
|
|
|
nscoord reduce = std::min(pctUsed, -unassignedSpace);
|
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 05:38:33 +00:00
|
|
|
float reduceRatio = float(reduce) / pctTotal;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
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 05:38:33 +00:00
|
|
|
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 11:12:40 +00: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 05:38:33 +00:00
|
|
|
unassignedSpace = 0;
|
1999-06-03 02:42:33 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
if (unassignedCount > 0) {
|
2008-11-25 23:22:39 +00: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 05:38:33 +00:00
|
|
|
nscoord toAssign = unassignedSpace / unassignedCount;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
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 05:38:33 +00:00
|
|
|
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-25 23:22:39 +00:00
|
|
|
// The spec doesn't say how to distribute the unassigned space.
|
|
|
|
if (specTotal > 0) {
|
|
|
|
// Distribute proportionally to non-percentage columns.
|
|
|
|
nscoord specUndist = specTotal;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-25 23:22:39 +00:00
|
|
|
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");
|
2008-12-04 16:09:53 +00:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
float(colFrame->GetFinalWidth()) / float(specUndist));
|
2008-11-25 23:22:39 +00:00
|
|
|
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;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-25 23:22:39 +00:00
|
|
|
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();
|
|
|
|
}
|
2008-12-04 16:09:53 +00:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
colFrame->GetPrefPercent() / pctUndist);
|
2008-11-25 23:22:39 +00:00
|
|
|
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.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t colsLeft = colCount;
|
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-25 23:22:39 +00:00
|
|
|
nsTableColFrame *colFrame = mTableFrame->GetColFrame(col);
|
|
|
|
if (!colFrame) {
|
|
|
|
NS_ERROR("column frames out of sync with cell map");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(colFrame->GetFinalWidth() == 0, "yikes");
|
2008-12-04 16:09:53 +00:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
1.0f / float(colsLeft));
|
2008-11-25 23:22:39 +00:00
|
|
|
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 05:38:33 +00:00
|
|
|
}
|
2008-12-04 16:09:53 +00:00
|
|
|
NS_ASSERTION(unassignedSpace == 0, "failed to redistribute");
|
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 05:38:33 +00:00
|
|
|
}
|
2001-01-26 23:44:59 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-28 02:23:52 +00:00
|
|
|
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;
|
2012-03-16 19:56:41 +00:00
|
|
|
}
|
2008-11-28 02:23:52 +00:00
|
|
|
}
|
1998-09-23 02:32:15 +00:00
|
|
|
}
|