Bug 939896 part 4: Move PositionItemInCrossAxis to live on FlexLine, and make it position all the line's items. r=mats

This commit is contained in:
Daniel Holbert 2013-11-26 10:27:52 -08:00
parent 038b8568d7
commit bb73dce218
2 changed files with 26 additions and 39 deletions

View File

@ -550,6 +550,9 @@ public:
return mBaselineOffsetFromCrossStart; return mBaselineOffsetFromCrossStart;
} }
void PositionItemsInCrossAxis(nscoord aLineStartPosition,
const FlexboxAxisTracker& aAxisTracker);
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:
@ -2265,30 +2268,32 @@ nsFlexContainerFrame::SizeItemInCrossAxis(
} }
void void
nsFlexContainerFrame::PositionItemInCrossAxis( FlexLine::PositionItemsInCrossAxis(nscoord aLineStartPosition,
nscoord aLineStartPosition, const FlexboxAxisTracker& aAxisTracker)
SingleLineCrossAxisPositionTracker& aLineCrossAxisPosnTracker,
FlexLine& aLine,
FlexItem& aItem)
{ {
MOZ_ASSERT(aLineCrossAxisPosnTracker.GetPosition() == 0, SingleLineCrossAxisPositionTracker lineCrossAxisPosnTracker(aAxisTracker);
"per-line cross-axis position tracker wasn't correctly reset");
aLineCrossAxisPosnTracker.ResolveAutoMarginsInCrossAxis(aLine, aItem); for (uint32_t i = 0; i < mItems.Length(); ++i) {
FlexItem& item = mItems[i];
// First, stretch the item's cross size (if appropriate), and resolve any
// auto margins in this axis.
item.ResolveStretchedCrossSize(mLineCrossSize, aAxisTracker);
lineCrossAxisPosnTracker.ResolveAutoMarginsInCrossAxis(*this, item);
// Compute the cross-axis position of this item // Compute the cross-axis position of this item
nscoord itemCrossBorderBoxSize = nscoord itemCrossBorderBoxSize =
aItem.GetCrossSize() + item.GetCrossSize() +
aItem.GetBorderPaddingSizeInAxis(aLineCrossAxisPosnTracker.GetAxis()); item.GetBorderPaddingSizeInAxis(aAxisTracker.GetCrossAxis());
aLineCrossAxisPosnTracker.EnterAlignPackingSpace(aLine, aItem); lineCrossAxisPosnTracker.EnterAlignPackingSpace(*this, item);
aLineCrossAxisPosnTracker.EnterMargin(aItem.GetMargin()); lineCrossAxisPosnTracker.EnterMargin(item.GetMargin());
aLineCrossAxisPosnTracker.EnterChildFrame(itemCrossBorderBoxSize); lineCrossAxisPosnTracker.EnterChildFrame(itemCrossBorderBoxSize);
aItem.SetCrossPosition(aLineStartPosition + item.SetCrossPosition(aLineStartPosition +
aLineCrossAxisPosnTracker.GetPosition()); lineCrossAxisPosnTracker.GetPosition());
// Back out to cross-axis edge of the line. // Back out to cross-axis edge of the line.
aLineCrossAxisPosnTracker.ResetPosition(); lineCrossAxisPosnTracker.ResetPosition();
}
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -2446,20 +2451,8 @@ nsFlexContainerFrame::Reflow(nsPresContext* aPresContext,
// Cross-Axis Alignment - Flexbox spec section 9.6 // Cross-Axis Alignment - Flexbox spec section 9.6
// =============================================== // ===============================================
// Set up state for cross-axis-positioning of children _within_ a single line.PositionItemsInCrossAxis(crossAxisPosnTracker.GetPosition(),
// flex line. axisTracker);
SingleLineCrossAxisPositionTracker lineCrossAxisPosnTracker(axisTracker);
for (uint32_t i = 0; i < line.mItems.Length(); ++i) {
// Resolve stretched cross-size, if appropriate
nscoord lineCrossSize = line.GetLineCrossSize();
line.mItems[i].ResolveStretchedCrossSize(lineCrossSize, axisTracker);
// ...and position.
PositionItemInCrossAxis(crossAxisPosnTracker.GetPosition(),
lineCrossAxisPosnTracker,
line,
line.mItems[i]);
}
// Before giving each child a final reflow, calculate the origin of the // Before giving each child a final reflow, calculate the origin of the
// flex container's content box (with respect to its border-box), so that // flex container's content box (with respect to its border-box), so that

View File

@ -126,12 +126,6 @@ protected:
nsHTMLReflowState& aChildReflowState, nsHTMLReflowState& aChildReflowState,
FlexItem& aItem); FlexItem& aItem);
void PositionItemInCrossAxis(
nscoord aLineStartPosition,
SingleLineCrossAxisPositionTracker& aLineCrossAxisPosnTracker,
FlexLine& aLine,
FlexItem& aItem);
bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
// to satisfy their 'order' values? // to satisfy their 'order' values?
}; };