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:
|
2012-05-21 15:12:37 +04: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 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
|
2011-04-08 05:04:40 +04:00
|
|
|
FixedTableLayoutStrategy::GetMinWidth(nsRenderingContext* 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();
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
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
|
|
|
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
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;
|
2012-11-21 20:19:37 +04:00
|
|
|
if (styleWidth->ConvertsToLength()) {
|
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 ||
|
2010-08-11 23:32:53 +04:00
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
|
2012-11-21 20:19:37 +04:00
|
|
|
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
|
2007-05-04 03:11:00 +04: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 08:38:33 +03:00
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool originates;
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
|
|
|
styleWidth = &cellFrame->GetStylePosition()->mWidth;
|
2012-11-21 20:19:37 +04:00
|
|
|
if (styleWidth->ConvertsToLength() ||
|
2007-05-04 03:11:00 +04:00
|
|
|
(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);
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 23:32:53 +04:00
|
|
|
// else, for 'auto', '-moz-available', '-moz-fit-content',
|
2012-11-21 20:19:37 +04: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 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
|
2011-04-08 05:04:40 +04:00
|
|
|
FixedTableLayoutStrategy::GetPrefWidth(nsRenderingContext* aRenderingContext,
|
2011-09-29 10:19:26 +04: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 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.
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-04 19:09:53 +03: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 08:38:33 +03:00
|
|
|
/* 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();
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
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
|
|
|
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
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;
|
|
|
|
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
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;
|
2012-11-21 20:19:37 +04:00
|
|
|
if (styleWidth->ConvertsToLength()) {
|
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 ||
|
2010-08-11 23:32:53 +04:00
|
|
|
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
|
2012-11-21 20:19:37 +04:00
|
|
|
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
|
2007-05-04 03:11:00 +04: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 08:38:33 +03:00
|
|
|
|
|
|
|
// The 'table-layout: fixed' algorithm considers only cells
|
|
|
|
// in the first row.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool originates;
|
2012-08-22 19:56:38 +04: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 08:38:33 +03:00
|
|
|
nsTableCellFrame *cellFrame =
|
|
|
|
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
|
|
|
|
if (cellFrame) {
|
|
|
|
styleWidth = &cellFrame->GetStylePosition()->mWidth;
|
2012-11-21 20:19:37 +04:00
|
|
|
if (styleWidth->ConvertsToLength() ||
|
2007-05-04 03:11:00 +04:00
|
|
|
(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 {
|
2010-08-11 23:32:53 +04:00
|
|
|
// 'auto', '-moz-available', '-moz-fit-content', and
|
2012-11-21 20:19:37 +04: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 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));
|
2009-09-16 19:01:36 +04:00
|
|
|
nscoord reduce = NS_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 08:38:33 +03:00
|
|
|
float reduceRatio = float(reduce) / pctTotal;
|
2012-08-22 19:56:38 +04: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 08:38:33 +03: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 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;
|
2012-08-22 19:56:38 +04: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 08:38:33 +03: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-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;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-26 02:22:39 +03: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 19:09:53 +03:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
float(colFrame->GetFinalWidth()) / float(specUndist));
|
2008-11-26 02:22:39 +03: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 19:56:38 +04:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-26 02:22:39 +03: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 19:09:53 +03:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
colFrame->GetPrefPercent() / pctUndist);
|
2008-11-26 02:22:39 +03: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 19:56:38 +04:00
|
|
|
int32_t colsLeft = colCount;
|
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-26 02:22:39 +03: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 19:09:53 +03:00
|
|
|
nscoord toAdd = AllocateUnassigned(unassignedSpace,
|
|
|
|
1.0f / float(colsLeft));
|
2008-11-26 02:22:39 +03: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 08:38:33 +03:00
|
|
|
}
|
2008-12-04 19:09:53 +03: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 08:38:33 +03:00
|
|
|
}
|
2001-01-27 02:44:59 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t col = 0; col < colCount; ++col) {
|
2008-11-28 05:23:52 +03: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 23:56:41 +04:00
|
|
|
}
|
2008-11-28 05:23:52 +03:00
|
|
|
}
|
1998-09-23 06:32:15 +04:00
|
|
|
}
|