From 2f7de5725c62488ef74d6df5e53a2682e68ddb5d Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Thu, 3 Apr 2014 10:40:12 -0700 Subject: [PATCH] Bug 991512: Add convenience methods to calculate outer main & cross size of a FlexItem. r=mats --- layout/generic/nsFlexContainerFrame.cpp | 42 +++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp index 8e0856aac587..61b35f990a12 100644 --- a/layout/generic/nsFlexContainerFrame.cpp +++ b/layout/generic/nsFlexContainerFrame.cpp @@ -316,6 +316,19 @@ public: nscoord GetCrossSize() const { return mCrossSize; } nscoord GetCrossPosition() const { return mCrossPosn; } + // Convenience methods to compute the main & cross size of our *margin-box*. + // The caller is responsible for telling us the right axis, so that we can + // pull out the appropriate components of our margin/border/padding structs. + nscoord GetOuterMainSize(AxisOrientationType aMainAxis) const + { + return mMainSize + GetMarginBorderPaddingSizeInAxis(aMainAxis); + } + + nscoord GetOuterCrossSize(AxisOrientationType aCrossAxis) const + { + return mCrossSize + GetMarginBorderPaddingSizeInAxis(aCrossAxis); + } + // Returns the distance between this FlexItem's baseline and the cross-start // edge of its margin-box. Used in baseline alignment. // (This function needs to be told what the cross axis is so that it can @@ -1216,10 +1229,7 @@ FlexItem::GetBaselineOffsetFromOuterCrossStart( // margin-bottom edge) to the baseline is just the margin-box cross size // (i.e. outer cross size), minus the distance from margin-top to baseline // (already computed above). - nscoord outerCrossSize = mCrossSize + - GetMarginBorderPaddingSizeInAxis(aCrossAxis); - - return outerCrossSize - marginTopToBaseline; + return GetOuterCrossSize(aCrossAxis) - marginTopToBaseline; } uint32_t @@ -1787,10 +1797,7 @@ MainAxisPositionTracker:: // with the *actual* amount of packing space. for (const FlexItem* item = aLine->GetFirstItem(); item; item = item->getNext()) { - nscoord itemMarginBoxMainSize = - item->GetMainSize() + - item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis()); - mPackingSpaceRemaining -= itemMarginBoxMainSize; + mPackingSpaceRemaining -= item->GetOuterMainSize(mAxis); mNumAutoMarginsInMainAxis += item->GetNumAutoMarginsInAxis(mAxis); } @@ -2074,8 +2081,8 @@ FlexLine::ComputeCrossSizeAndBaseline(const FlexboxAxisTracker& aAxisTracker) nscoord crossEndToFurthestBaseline = nscoord_MIN; nscoord largestOuterCrossSize = 0; for (const FlexItem* item = mItems.getFirst(); item; item = item->getNext()) { - nscoord curOuterCrossSize = item->GetCrossSize() + - item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetCrossAxis()); + nscoord curOuterCrossSize = + item->GetOuterCrossSize(aAxisTracker.GetCrossAxis()); if (item->GetAlignSelf() == NS_STYLE_ALIGN_ITEMS_BASELINE && item->GetNumAutoMarginsInAxis(aAxisTracker.GetCrossAxis()) == 0) { @@ -2180,7 +2187,7 @@ SingleLineCrossAxisPositionTracker:: // Subtract the space that our item is already occupying, to see how much // space (if any) is available for its auto margins. nscoord spaceForAutoMargins = aLine.GetLineCrossSize() - - (aItem.GetCrossSize() + aItem.GetMarginBorderPaddingSizeInAxis(mAxis)); + aItem.GetOuterCrossSize(mAxis); if (spaceForAutoMargins <= 0) { return; // No available space --> nothing to do @@ -2230,17 +2237,12 @@ SingleLineCrossAxisPositionTracker:: // auto-sized items (which we've already done). break; case NS_STYLE_ALIGN_ITEMS_FLEX_END: - mPosition += - aLine.GetLineCrossSize() - - (aItem.GetCrossSize() + - aItem.GetMarginBorderPaddingSizeInAxis(mAxis)); + mPosition += aLine.GetLineCrossSize() - aItem.GetOuterCrossSize(mAxis); break; case NS_STYLE_ALIGN_ITEMS_CENTER: // Note: If cross-size is odd, the "after" space will get the extra unit. mPosition += - (aLine.GetLineCrossSize() - - (aItem.GetCrossSize() + - aItem.GetMarginBorderPaddingSizeInAxis(mAxis))) / 2; + (aLine.GetLineCrossSize() - aItem.GetOuterCrossSize(mAxis)) / 2; break; case NS_STYLE_ALIGN_ITEMS_BASELINE: { nscoord lineBaselineOffset = @@ -2419,8 +2421,8 @@ nsFlexContainerFrame::GenerateFlexLines( } nscoord itemInnerHypotheticalMainSize = item->GetMainSize(); - nscoord itemOuterHypotheticalMainSize = item->GetMainSize() + - item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis()); + nscoord itemOuterHypotheticalMainSize = + item->GetOuterMainSize(aAxisTracker.GetMainAxis()); // Check if we need to wrap |item| to a new line // (i.e. check if its outer hypothetical main size pushes our line over