diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp
index f71fb1d4949..3a10ed6f75d 100644
--- a/mozilla/layout/html/table/src/nsTableFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableFrame.cpp
@@ -1108,7 +1108,10 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext,
// assign table width
SetTableWidth(aPresContext);
- aStatus = ResizeReflowPass2(aPresContext, aDesiredSize, aReflowState, 0, 0);
+ // Constrain our reflow width to the computed table width
+ nsReflowState reflowState(aReflowState);
+ reflowState.maxSize.width = mRect.width;
+ aStatus = ResizeReflowPass2(aPresContext, aDesiredSize, reflowState, 0, 0);
if (gsTiming) {
PRIntervalTime endTime = PR_IntervalNow();
diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp
index d3fd003968b..b5066b01690 100644
--- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp
@@ -188,9 +188,6 @@ nsresult nsTableOuterFrame::RecoverState(OuterTableReflowState& aState,
aState.innerTableMaxSize.width = innerTableSize.width;
aState.innerTableMaxSize.height = aState.reflowState.maxSize.height;
- // The available space is the width of the inner table
- aState.availSize.width = aState.innerTableMaxSize.width;
-
return NS_OK;
}
@@ -293,8 +290,11 @@ nsresult nsTableOuterFrame::IncrementalReflow(nsIPresContext* aPresContext,
aState.y += topMargin;
kidFrame->WillReflow(*aPresContext);
kidFrame->MoveTo(kidMargin.left, aState.y);
- nsReflowState kidReflowState(kidFrame, aState.reflowState, kidFrame == mInnerTableFrame ?
- aState.innerTableMaxSize : aState.availSize);
+ nsReflowState kidReflowState(kidFrame, aState.reflowState, aState.availSize);
+ if (kidFrame != mInnerTableFrame) {
+ // Reflow captions to the width of the inner table
+ kidReflowState.maxSize.width = aState.innerTableMaxSize.width;
+ }
mInnerTableFrame->SetReflowPass(nsTableFrame::kPASS_INCREMENTAL);
aStatus = ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState,
pKidMaxElementSize, aState);
diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp
index 52b6d4e2c68..a785d46433d 100644
--- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp
+++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp
@@ -1081,17 +1081,39 @@ nsTableRowFrame::Reflow(nsIPresContext* aPresContext,
nsSize kidMaxElementSize;
nsReflowMetrics desiredSize(&kidMaxElementSize);
// XXX Correctly compute the available height...
- nsSize availSpace(NS_UNCONSTRAINEDSIZE, aReflowState.maxSize.height);
+ nsSize availSpace(aReflowState.maxSize);
nsReflowState kidReflowState(kidFrame, aReflowState, availSpace);
kidFrame->WillReflow(*aPresContext);
+
+ // XXX Unfortunately we need to reflow the child several times.
+ // The first time is for the incremental reflow command. We can't pass in
+ // a max width of NS_UNCONSTRAINEDSIZE, because the max width must match
+ // the width of the previous reflow...
aStatus = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
- // Update the cell layout data
- nsCellLayoutData *kidLayoutData = new nsCellLayoutData((nsTableCellFrame *)kidFrame,
- &desiredSize, &kidMaxElementSize);
- ((nsTableCellFrame *)kidFrame)->SetCellLayoutData(kidLayoutData);
- // XXX The equivalent of incrementally updating the column cache
- state.tableFrame->SetCellLayoutData(aPresContext, kidLayoutData, (nsTableCellFrame*)kidFrame);
+ // Now do the regular pass 1 reflow and gather the max width and max element
+ // size.
+ // XXX It would be nice if we could skip this step and the next step if the
+ // column width isn't dependent on the max cell width...
+ kidReflowState.reason = eReflowReason_Resize;
+ kidReflowState.reflowCommand = nsnull;
+ kidReflowState.maxSize.width = NS_UNCONSTRAINEDSIZE;
+ aStatus = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
+
+ // Update the cell layout data. Note that we need to do this for both
+ // the data the cell maintains AND the data the table maintains...
+ nsCellLayoutData *kidLayoutData = ((nsTableCellFrame *)kidFrame)->GetCellLayoutData();
+
+ kidLayoutData->SetDesiredSize(&desiredSize);
+ kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
+
+ kidLayoutData = state.tableFrame->GetCellLayoutData((nsTableCellFrame*)kidFrame);
+ kidLayoutData->SetDesiredSize(&desiredSize);
+ kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
+
+ // Now reflow the cell again this time constraining the width
+ // XXX Skip this for the time being, because the table code is going to
+ // reflow the entire table anyway...
// XXX Compute desired size...
diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp
index f71fb1d4949..3a10ed6f75d 100644
--- a/mozilla/layout/tables/nsTableFrame.cpp
+++ b/mozilla/layout/tables/nsTableFrame.cpp
@@ -1108,7 +1108,10 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext,
// assign table width
SetTableWidth(aPresContext);
- aStatus = ResizeReflowPass2(aPresContext, aDesiredSize, aReflowState, 0, 0);
+ // Constrain our reflow width to the computed table width
+ nsReflowState reflowState(aReflowState);
+ reflowState.maxSize.width = mRect.width;
+ aStatus = ResizeReflowPass2(aPresContext, aDesiredSize, reflowState, 0, 0);
if (gsTiming) {
PRIntervalTime endTime = PR_IntervalNow();
diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp
index d3fd003968b..b5066b01690 100644
--- a/mozilla/layout/tables/nsTableOuterFrame.cpp
+++ b/mozilla/layout/tables/nsTableOuterFrame.cpp
@@ -188,9 +188,6 @@ nsresult nsTableOuterFrame::RecoverState(OuterTableReflowState& aState,
aState.innerTableMaxSize.width = innerTableSize.width;
aState.innerTableMaxSize.height = aState.reflowState.maxSize.height;
- // The available space is the width of the inner table
- aState.availSize.width = aState.innerTableMaxSize.width;
-
return NS_OK;
}
@@ -293,8 +290,11 @@ nsresult nsTableOuterFrame::IncrementalReflow(nsIPresContext* aPresContext,
aState.y += topMargin;
kidFrame->WillReflow(*aPresContext);
kidFrame->MoveTo(kidMargin.left, aState.y);
- nsReflowState kidReflowState(kidFrame, aState.reflowState, kidFrame == mInnerTableFrame ?
- aState.innerTableMaxSize : aState.availSize);
+ nsReflowState kidReflowState(kidFrame, aState.reflowState, aState.availSize);
+ if (kidFrame != mInnerTableFrame) {
+ // Reflow captions to the width of the inner table
+ kidReflowState.maxSize.width = aState.innerTableMaxSize.width;
+ }
mInnerTableFrame->SetReflowPass(nsTableFrame::kPASS_INCREMENTAL);
aStatus = ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState,
pKidMaxElementSize, aState);
diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp
index 52b6d4e2c68..a785d46433d 100644
--- a/mozilla/layout/tables/nsTableRowFrame.cpp
+++ b/mozilla/layout/tables/nsTableRowFrame.cpp
@@ -1081,17 +1081,39 @@ nsTableRowFrame::Reflow(nsIPresContext* aPresContext,
nsSize kidMaxElementSize;
nsReflowMetrics desiredSize(&kidMaxElementSize);
// XXX Correctly compute the available height...
- nsSize availSpace(NS_UNCONSTRAINEDSIZE, aReflowState.maxSize.height);
+ nsSize availSpace(aReflowState.maxSize);
nsReflowState kidReflowState(kidFrame, aReflowState, availSpace);
kidFrame->WillReflow(*aPresContext);
+
+ // XXX Unfortunately we need to reflow the child several times.
+ // The first time is for the incremental reflow command. We can't pass in
+ // a max width of NS_UNCONSTRAINEDSIZE, because the max width must match
+ // the width of the previous reflow...
aStatus = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
- // Update the cell layout data
- nsCellLayoutData *kidLayoutData = new nsCellLayoutData((nsTableCellFrame *)kidFrame,
- &desiredSize, &kidMaxElementSize);
- ((nsTableCellFrame *)kidFrame)->SetCellLayoutData(kidLayoutData);
- // XXX The equivalent of incrementally updating the column cache
- state.tableFrame->SetCellLayoutData(aPresContext, kidLayoutData, (nsTableCellFrame*)kidFrame);
+ // Now do the regular pass 1 reflow and gather the max width and max element
+ // size.
+ // XXX It would be nice if we could skip this step and the next step if the
+ // column width isn't dependent on the max cell width...
+ kidReflowState.reason = eReflowReason_Resize;
+ kidReflowState.reflowCommand = nsnull;
+ kidReflowState.maxSize.width = NS_UNCONSTRAINEDSIZE;
+ aStatus = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState);
+
+ // Update the cell layout data. Note that we need to do this for both
+ // the data the cell maintains AND the data the table maintains...
+ nsCellLayoutData *kidLayoutData = ((nsTableCellFrame *)kidFrame)->GetCellLayoutData();
+
+ kidLayoutData->SetDesiredSize(&desiredSize);
+ kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
+
+ kidLayoutData = state.tableFrame->GetCellLayoutData((nsTableCellFrame*)kidFrame);
+ kidLayoutData->SetDesiredSize(&desiredSize);
+ kidLayoutData->SetMaxElementSize(&kidMaxElementSize);
+
+ // Now reflow the cell again this time constraining the width
+ // XXX Skip this for the time being, because the table code is going to
+ // reflow the entire table anyway...
// XXX Compute desired size...