Bug 939896 part 8: Make FlexLine store the sums of its items' hypothetical inner & outer main sizes. r=mats

This commit is contained in:
Daniel Holbert 2013-11-26 10:27:52 -08:00
parent cdcd202b78
commit d03b23db36

View File

@ -525,10 +525,26 @@ protected:
class FlexLine { class FlexLine {
public: public:
FlexLine() FlexLine()
: mLineCrossSize(0), : mTotalInnerHypotheticalMainSize(0),
mTotalOuterHypotheticalMainSize(0),
mLineCrossSize(0),
mBaselineOffsetFromCrossStart(nscoord_MIN) mBaselineOffsetFromCrossStart(nscoord_MIN)
{} {}
// Returns the sum of our FlexItems' outer hypothetical main sizes.
// ("outer" = margin-box, and "hypothetical" = before flexing)
nscoord GetTotalOuterHypotheticalMainSize() const {
return mTotalOuterHypotheticalMainSize;
}
// Adds a new FlexItem's hypothetical main sizes to our totals.
// (Should only be called when a FlexItem is being appended to this line.)
void AddToMainSizeTotals(nscoord aItemInnerHypotheticalMainSize,
nscoord aItemOuterHypotheticalMainSize) {
mTotalInnerHypotheticalMainSize += aItemInnerHypotheticalMainSize;
mTotalOuterHypotheticalMainSize += aItemOuterHypotheticalMainSize;
}
// Computes the cross-size and baseline position of this FlexLine, based on // Computes the cross-size and baseline position of this FlexLine, based on
// its FlexItems. // its FlexItems.
void ComputeCrossSizeAndBaseline(const FlexboxAxisTracker& aAxisTracker); void ComputeCrossSizeAndBaseline(const FlexboxAxisTracker& aAxisTracker);
@ -565,25 +581,12 @@ public:
nsTArray<FlexItem> mItems; // Array of the flex items in this flex line. nsTArray<FlexItem> mItems; // Array of the flex items in this flex line.
private: private:
nscoord mTotalInnerHypotheticalMainSize;
nscoord mTotalOuterHypotheticalMainSize;
nscoord mLineCrossSize; nscoord mLineCrossSize;
nscoord mBaselineOffsetFromCrossStart; nscoord mBaselineOffsetFromCrossStart;
}; };
// Helper function to calculate the sum of our flex items'
// margin-box main sizes.
static nscoord
SumFlexItemMarginBoxMainSizes(const FlexboxAxisTracker& aAxisTracker,
const nsTArray<FlexItem>& aItems)
{
nscoord sum = 0;
for (uint32_t i = 0; i < aItems.Length(); ++i) {
const FlexItem& item = aItems[i];
sum += item.GetMainSize() +
item.GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
}
return sum;
}
// Helper-function to find the first non-anonymous-box descendent of aFrame. // Helper-function to find the first non-anonymous-box descendent of aFrame.
static nsIFrame* static nsIFrame*
GetFirstNonAnonBoxDescendant(nsIFrame* aFrame) GetFirstNonAnonBoxDescendant(nsIFrame* aFrame)
@ -2028,6 +2031,16 @@ nsFlexContainerFrame::GenerateFlexItems(
nsresult rv = ResolveFlexItemMaxContentSizing(aPresContext, *item, nsresult rv = ResolveFlexItemMaxContentSizing(aPresContext, *item,
aReflowState, aAxisTracker); aReflowState, aAxisTracker);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nscoord itemInnerHypotheticalMainSize = item->GetMainSize();
nscoord itemOuterHypotheticalMainSize = item->GetMainSize() +
item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
// XXXdholbert When we support multi-line, we'll check here if this item's
// outerHypotheticalMainSize takes us past the end of our line's available
// space. If so, we'll create a new FlexLine and shift the item there.
aFlexLine.AddToMainSizeTotals(itemInnerHypotheticalMainSize,
itemOuterHypotheticalMainSize);
} }
return NS_OK; return NS_OK;
@ -2068,8 +2081,7 @@ nsFlexContainerFrame::ComputeFlexContainerMainSize(
// continuation or splitting children, so "amount of height required by // continuation or splitting children, so "amount of height required by
// our children" is just the sum of our children's heights. // our children" is just the sum of our children's heights.
NS_FRAME_SET_INCOMPLETE(aStatus); NS_FRAME_SET_INCOMPLETE(aStatus);
nscoord sumOfChildHeights = nscoord sumOfChildHeights = aLine.GetTotalOuterHypotheticalMainSize();
SumFlexItemMarginBoxMainSizes(aAxisTracker, aLine.mItems);
if (sumOfChildHeights <= aAvailableHeightForContent) { if (sumOfChildHeights <= aAvailableHeightForContent) {
return aAvailableHeightForContent; return aAvailableHeightForContent;
} }
@ -2081,8 +2093,7 @@ nsFlexContainerFrame::ComputeFlexContainerMainSize(
// sizes (their outer heights), clamped to our computed min/max main-size // sizes (their outer heights), clamped to our computed min/max main-size
// properties (min-height & max-height). // properties (min-height & max-height).
// XXXdholbert Handle constrained-aAvailableHeightForContent case here. // XXXdholbert Handle constrained-aAvailableHeightForContent case here.
nscoord sumOfChildHeights = nscoord sumOfChildHeights = aLine.GetTotalOuterHypotheticalMainSize();
SumFlexItemMarginBoxMainSizes(aAxisTracker, aLine.mItems);
return NS_CSS_MINMAX(sumOfChildHeights, return NS_CSS_MINMAX(sumOfChildHeights,
aReflowState.mComputedMinHeight, aReflowState.mComputedMinHeight,
aReflowState.mComputedMaxHeight); aReflowState.mComputedMaxHeight);