diff --git a/layout/html/table/src/nsTableFrame.cpp b/layout/html/table/src/nsTableFrame.cpp
index 403450bf38d..b98c7963522 100644
--- a/layout/html/table/src/nsTableFrame.cpp
+++ b/layout/html/table/src/nsTableFrame.cpp
@@ -162,12 +162,14 @@ nsTableFrame::nsTableFrame()
: nsHTMLContainerFrame(),
mCellMap(nsnull),
mTableLayoutStrategy(nsnull),
- mPercentBasisForRows(0)
+ mPercentBasisForRows(0),
+ mPreferredWidth(0)
{
mBits.mColumnWidthsSet = PR_FALSE;
mBits.mColumnWidthsValid = PR_FALSE;
mBits.mFirstPassValid = PR_FALSE;
mBits.mIsInvariantWidth = PR_FALSE;
+ mBits.mMaximumWidthValid = PR_FALSE;
// XXX We really shouldn't do this, but if we don't then we'll have a
// problem with the tree control...
#if 0
@@ -1646,40 +1648,43 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext,
// See if the pass1 maximum width is no longer valid because one of the
// cell maximum widths changed
- if (isAutoOrPctWidth && !IsMaximumWidthValid()) {
- // Initialize the strategy and have it compute the natural size of
- // the table
- mTableLayoutStrategy->Initialize(aPresContext, nsnull, NS_UNCONSTRAINEDSIZE, aReflowState);
-
- // Now the maximum width is valid
- mBits.mMaximumWidthValid = PR_TRUE;
-
- // Initializing the table layout strategy assigns preliminary column
- // widths. We can't leave the column widths this way, and so we need to
- // balance the column widths to get them back to what we had previously.
- // XXX It would be nice to have a cleaner way to calculate the updated
- // maximum width
- BalanceColumnWidths(aPresContext, aReflowState,
- nsSize(aReflowState.availableWidth, aReflowState.availableHeight),
- aDesiredSize.maxElementSize);
- }
-
if (isAutoOrPctWidth) {
- // Ask the strategy for the natural width of the content area
- aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxWidth();
+ if (!IsMaximumWidthValid()) {
+ // Initialize the strategy and have it compute the natural size of
+ // the table
+ mTableLayoutStrategy->Initialize(aPresContext, nsnull, NS_UNCONSTRAINEDSIZE, aReflowState);
+
+ // Ask the strategy for the natural width of the content area
+ aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxWidth();
- // Add in space for border
- nsMargin border;
- GetTableBorder (border); // this gets the max border value at every edge
- aDesiredSize.mMaximumWidth += border.left + border.right;
+ // Add in space for border
+ nsMargin border;
+ GetTableBorder (border); // this gets the max border value at every edge
+ aDesiredSize.mMaximumWidth += border.left + border.right;
- // Add in space for padding
- aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left +
- aReflowState.mComputedPadding.right;
+ // Add in space for padding
+ aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left +
+ aReflowState.mComputedPadding.right;
+ SetPreferredWidth(aDesiredSize.mMaximumWidth); // cache the value
+
+ // Initializing the table layout strategy assigns preliminary column
+ // widths. We can't leave the column widths this way, and so we need to
+ // balance the column widths to get them back to what we had previously.
+ // XXX It would be nice to have a cleaner way to calculate the updated
+ // maximum width
+ BalanceColumnWidths(aPresContext, aReflowState,
+ nsSize(aReflowState.availableWidth, aReflowState.availableHeight),
+ aDesiredSize.maxElementSize);
+ // Now the maximum width is valid
+ mBits.mMaximumWidthValid = PR_TRUE;
+ } else {
+ aDesiredSize.mMaximumWidth = GetPreferredWidth();
+ }
} else {
// We're not auto width so the natural width is the same as the desired width
aDesiredSize.mMaximumWidth = aDesiredSize.width;
+ SetPreferredWidth(aDesiredSize.mMaximumWidth); // cache the value
}
}
diff --git a/layout/html/table/src/nsTableFrame.h b/layout/html/table/src/nsTableFrame.h
index d4724dfd978..667b50148a8 100644
--- a/layout/html/table/src/nsTableFrame.h
+++ b/layout/html/table/src/nsTableFrame.h
@@ -817,6 +817,9 @@ public: /* ----- Cell Map public methods ----- */
nscoord GetPercentBasisForRows();
+ nscoord GetPreferredWidth() const;
+ void SetPreferredWidth(nscoord aWidth);
+
/*---------------- nsITableLayout methods ------------------------*/
/** Get the cell and associated data for a table cell from the frame's cellmap */
@@ -862,13 +865,14 @@ protected:
int : 26; // unused
} mBits;
- nsTableCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
- nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
- nsFrameList mColGroups; // the list of colgroup frames
+ nsTableCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
+ nsITableLayoutStrategy* mTableLayoutStrategy;// the layout strategy for this frame
+ nsFrameList mColGroups; // the list of colgroup frames
- nsTableBorderCollapser* mBorderCollapser; // one list of border segments for each side of the table frame
- // used only for the collapsing border model
- nscoord mPercentBasisForRows;
+ nsTableBorderCollapser* mBorderCollapser; // one list of border segments for each side of the table frame
+ // used only for the collapsing border model
+ nscoord mPercentBasisForRows;
+ nscoord mPreferredWidth;
};
@@ -904,6 +908,17 @@ inline nsVoidArray& nsTableFrame::GetColCache()
return mColFrames;
}
+inline nscoord nsTableFrame::GetPreferredWidth() const
+{
+ return mPreferredWidth;
+}
+
+inline void nsTableFrame::SetPreferredWidth(nscoord aWidth)
+{
+ mPreferredWidth = aWidth;
+}
+
+
enum nsTableIteration {
eTableLTR = 0,
eTableRTL = 1,
diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp
index 403450bf38d..b98c7963522 100644
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -162,12 +162,14 @@ nsTableFrame::nsTableFrame()
: nsHTMLContainerFrame(),
mCellMap(nsnull),
mTableLayoutStrategy(nsnull),
- mPercentBasisForRows(0)
+ mPercentBasisForRows(0),
+ mPreferredWidth(0)
{
mBits.mColumnWidthsSet = PR_FALSE;
mBits.mColumnWidthsValid = PR_FALSE;
mBits.mFirstPassValid = PR_FALSE;
mBits.mIsInvariantWidth = PR_FALSE;
+ mBits.mMaximumWidthValid = PR_FALSE;
// XXX We really shouldn't do this, but if we don't then we'll have a
// problem with the tree control...
#if 0
@@ -1646,40 +1648,43 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext,
// See if the pass1 maximum width is no longer valid because one of the
// cell maximum widths changed
- if (isAutoOrPctWidth && !IsMaximumWidthValid()) {
- // Initialize the strategy and have it compute the natural size of
- // the table
- mTableLayoutStrategy->Initialize(aPresContext, nsnull, NS_UNCONSTRAINEDSIZE, aReflowState);
-
- // Now the maximum width is valid
- mBits.mMaximumWidthValid = PR_TRUE;
-
- // Initializing the table layout strategy assigns preliminary column
- // widths. We can't leave the column widths this way, and so we need to
- // balance the column widths to get them back to what we had previously.
- // XXX It would be nice to have a cleaner way to calculate the updated
- // maximum width
- BalanceColumnWidths(aPresContext, aReflowState,
- nsSize(aReflowState.availableWidth, aReflowState.availableHeight),
- aDesiredSize.maxElementSize);
- }
-
if (isAutoOrPctWidth) {
- // Ask the strategy for the natural width of the content area
- aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxWidth();
+ if (!IsMaximumWidthValid()) {
+ // Initialize the strategy and have it compute the natural size of
+ // the table
+ mTableLayoutStrategy->Initialize(aPresContext, nsnull, NS_UNCONSTRAINEDSIZE, aReflowState);
+
+ // Ask the strategy for the natural width of the content area
+ aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxWidth();
- // Add in space for border
- nsMargin border;
- GetTableBorder (border); // this gets the max border value at every edge
- aDesiredSize.mMaximumWidth += border.left + border.right;
+ // Add in space for border
+ nsMargin border;
+ GetTableBorder (border); // this gets the max border value at every edge
+ aDesiredSize.mMaximumWidth += border.left + border.right;
- // Add in space for padding
- aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left +
- aReflowState.mComputedPadding.right;
+ // Add in space for padding
+ aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left +
+ aReflowState.mComputedPadding.right;
+ SetPreferredWidth(aDesiredSize.mMaximumWidth); // cache the value
+
+ // Initializing the table layout strategy assigns preliminary column
+ // widths. We can't leave the column widths this way, and so we need to
+ // balance the column widths to get them back to what we had previously.
+ // XXX It would be nice to have a cleaner way to calculate the updated
+ // maximum width
+ BalanceColumnWidths(aPresContext, aReflowState,
+ nsSize(aReflowState.availableWidth, aReflowState.availableHeight),
+ aDesiredSize.maxElementSize);
+ // Now the maximum width is valid
+ mBits.mMaximumWidthValid = PR_TRUE;
+ } else {
+ aDesiredSize.mMaximumWidth = GetPreferredWidth();
+ }
} else {
// We're not auto width so the natural width is the same as the desired width
aDesiredSize.mMaximumWidth = aDesiredSize.width;
+ SetPreferredWidth(aDesiredSize.mMaximumWidth); // cache the value
}
}
diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h
index d4724dfd978..667b50148a8 100644
--- a/layout/tables/nsTableFrame.h
+++ b/layout/tables/nsTableFrame.h
@@ -817,6 +817,9 @@ public: /* ----- Cell Map public methods ----- */
nscoord GetPercentBasisForRows();
+ nscoord GetPreferredWidth() const;
+ void SetPreferredWidth(nscoord aWidth);
+
/*---------------- nsITableLayout methods ------------------------*/
/** Get the cell and associated data for a table cell from the frame's cellmap */
@@ -862,13 +865,14 @@ protected:
int : 26; // unused
} mBits;
- nsTableCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
- nsITableLayoutStrategy * mTableLayoutStrategy; // the layout strategy for this frame
- nsFrameList mColGroups; // the list of colgroup frames
+ nsTableCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
+ nsITableLayoutStrategy* mTableLayoutStrategy;// the layout strategy for this frame
+ nsFrameList mColGroups; // the list of colgroup frames
- nsTableBorderCollapser* mBorderCollapser; // one list of border segments for each side of the table frame
- // used only for the collapsing border model
- nscoord mPercentBasisForRows;
+ nsTableBorderCollapser* mBorderCollapser; // one list of border segments for each side of the table frame
+ // used only for the collapsing border model
+ nscoord mPercentBasisForRows;
+ nscoord mPreferredWidth;
};
@@ -904,6 +908,17 @@ inline nsVoidArray& nsTableFrame::GetColCache()
return mColFrames;
}
+inline nscoord nsTableFrame::GetPreferredWidth() const
+{
+ return mPreferredWidth;
+}
+
+inline void nsTableFrame::SetPreferredWidth(nscoord aWidth)
+{
+ mPreferredWidth = aWidth;
+}
+
+
enum nsTableIteration {
eTableLTR = 0,
eTableRTL = 1,