Bug 885424 part 4: Refactor ComputeFlexContainerMainSize to have a clearer horizontal case vs. vertical case. r=dbaron

This commit is contained in:
Daniel Holbert 2013-07-11 16:47:03 -07:00
parent fcbc026824
commit 48e5024923

View File

@ -1957,35 +1957,31 @@ nsFlexContainerFrame::ComputeFlexContainerMainSize(
const FlexboxAxisTracker& aAxisTracker, const FlexboxAxisTracker& aAxisTracker,
const nsTArray<FlexItem>& aItems) const nsTArray<FlexItem>& aItems)
{ {
// If we've got a finite computed main-size, use that. if (IsAxisHorizontal(aAxisTracker.GetMainAxis())) {
nscoord mainSize = // Horizontal case is easy -- our main size is our computed width
aAxisTracker.GetMainComponent(nsSize(aReflowState.ComputedWidth(), // (which is already resolved).
aReflowState.ComputedHeight())); return aReflowState.ComputedWidth();
if (mainSize != NS_UNCONSTRAINEDSIZE) {
return mainSize;
} }
NS_WARN_IF_FALSE(!IsAxisHorizontal(aAxisTracker.GetMainAxis()), // Vertical case, with non-auto-height:
"Computed width should always be constrained, so horizontal " if (aReflowState.ComputedHeight() != NS_AUTOHEIGHT) {
"flex containers should have a constrained main-size"); return aReflowState.ComputedHeight();
}
// Otherwise, use the sum of our items' hypothetical main sizes, clamped // Vertical case, with auto-height:
// to our computed min/max main-size properties. // Resolve auto-height to the sum of our items' hypothetical outer main
mainSize = 0; // sizes (their outer heights), clamped to our computed min/max main-size
// properties (min-height & max-height).
nscoord sumOfChildHeights = 0;
for (uint32_t i = 0; i < aItems.Length(); ++i) { for (uint32_t i = 0; i < aItems.Length(); ++i) {
mainSize += sumOfChildHeights +=
aItems[i].GetMainSize() + aItems[i].GetMainSize() +
aItems[i].GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis()); aItems[i].GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
} }
nscoord minMainSize = return NS_CSS_MINMAX(sumOfChildHeights,
aAxisTracker.GetMainComponent(nsSize(aReflowState.mComputedMinWidth, aReflowState.mComputedMinHeight,
aReflowState.mComputedMinHeight)); aReflowState.mComputedMaxHeight);
nscoord maxMainSize =
aAxisTracker.GetMainComponent(nsSize(aReflowState.mComputedMaxWidth,
aReflowState.mComputedMaxHeight));
return NS_CSS_MINMAX(mainSize, minMainSize, maxMainSize);
} }
void void