diff --git a/layout/tables/nsTableWrapperFrame.cpp b/layout/tables/nsTableWrapperFrame.cpp index 14d79a208c31..e44652a73309 100644 --- a/layout/tables/nsTableWrapperFrame.cpp +++ b/layout/tables/nsTableWrapperFrame.cpp @@ -951,9 +951,12 @@ nsTableWrapperFrame::Reflow(nsPresContext* aPresContext, captionRI->ComputedLogicalMargin().ConvertTo(wm, captionWM); // Now that we know the bsize of the caption, reduce the available bsize // for the table frame if we are bsize constrained and the caption is above - // or below the inner table. - if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize()) { + // or below the inner table. Also reduce the CB size that we store for + // our children in case we're a grid item, by the same amount. + LogicalSize* cbSize = Properties().Get(GridItemCBSizeProperty()); + if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize() || cbSize) { nscoord captionBSize = 0; + nscoord captionISize = 0; switch (captionSide) { case NS_STYLE_CAPTION_SIDE_TOP: case NS_STYLE_CAPTION_SIDE_BOTTOM: @@ -961,9 +964,27 @@ nsTableWrapperFrame::Reflow(nsPresContext* aPresContext, case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: captionBSize = captionSize.BSize(wm) + captionMargin.BStartEnd(wm); break; + case NS_STYLE_CAPTION_SIDE_LEFT: + case NS_STYLE_CAPTION_SIDE_RIGHT: + captionISize = captionSize.ISize(wm) + captionMargin.IStartEnd(wm); + break; + } + if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize()) { + innerRI->AvailableBSize() = + std::max(0, innerRI->AvailableBSize() - captionBSize); + } + if (cbSize) { + // Shrink the CB size by the size reserved for the caption. + LogicalSize oldCBSize = *cbSize; + cbSize->ISize(wm) = std::max(0, cbSize->ISize(wm) - captionISize); + cbSize->BSize(wm) = std::max(0, cbSize->BSize(wm) - captionBSize); + if (oldCBSize != *cbSize) { + // Reset the inner table's ReflowInput to stretch it to the new size. + innerRI.reset(); + OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, + innerRI, aOuterRI.ComputedSize(wm).ISize(wm)); + } } - innerRI->AvailableBSize() = - std::max(0, innerRI->AvailableBSize() - captionBSize); } }