Bug 991512: Add convenience methods to calculate outer main & cross size of a FlexItem. r=mats

This commit is contained in:
Daniel Holbert 2014-04-03 10:40:12 -07:00
Родитель d474c0c60f
Коммит 2f7de5725c
1 изменённых файлов: 22 добавлений и 20 удалений

Просмотреть файл

@ -316,6 +316,19 @@ public:
nscoord GetCrossSize() const { return mCrossSize; } nscoord GetCrossSize() const { return mCrossSize; }
nscoord GetCrossPosition() const { return mCrossPosn; } 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 // Returns the distance between this FlexItem's baseline and the cross-start
// edge of its margin-box. Used in baseline alignment. // edge of its margin-box. Used in baseline alignment.
// (This function needs to be told what the cross axis is so that it can // (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 // 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 // (i.e. outer cross size), minus the distance from margin-top to baseline
// (already computed above). // (already computed above).
nscoord outerCrossSize = mCrossSize + return GetOuterCrossSize(aCrossAxis) - marginTopToBaseline;
GetMarginBorderPaddingSizeInAxis(aCrossAxis);
return outerCrossSize - marginTopToBaseline;
} }
uint32_t uint32_t
@ -1787,10 +1797,7 @@ MainAxisPositionTracker::
// with the *actual* amount of packing space. // with the *actual* amount of packing space.
for (const FlexItem* item = aLine->GetFirstItem(); item; for (const FlexItem* item = aLine->GetFirstItem(); item;
item = item->getNext()) { item = item->getNext()) {
nscoord itemMarginBoxMainSize = mPackingSpaceRemaining -= item->GetOuterMainSize(mAxis);
item->GetMainSize() +
item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
mPackingSpaceRemaining -= itemMarginBoxMainSize;
mNumAutoMarginsInMainAxis += item->GetNumAutoMarginsInAxis(mAxis); mNumAutoMarginsInMainAxis += item->GetNumAutoMarginsInAxis(mAxis);
} }
@ -2074,8 +2081,8 @@ FlexLine::ComputeCrossSizeAndBaseline(const FlexboxAxisTracker& aAxisTracker)
nscoord crossEndToFurthestBaseline = nscoord_MIN; nscoord crossEndToFurthestBaseline = nscoord_MIN;
nscoord largestOuterCrossSize = 0; nscoord largestOuterCrossSize = 0;
for (const FlexItem* item = mItems.getFirst(); item; item = item->getNext()) { for (const FlexItem* item = mItems.getFirst(); item; item = item->getNext()) {
nscoord curOuterCrossSize = item->GetCrossSize() + nscoord curOuterCrossSize =
item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetCrossAxis()); item->GetOuterCrossSize(aAxisTracker.GetCrossAxis());
if (item->GetAlignSelf() == NS_STYLE_ALIGN_ITEMS_BASELINE && if (item->GetAlignSelf() == NS_STYLE_ALIGN_ITEMS_BASELINE &&
item->GetNumAutoMarginsInAxis(aAxisTracker.GetCrossAxis()) == 0) { item->GetNumAutoMarginsInAxis(aAxisTracker.GetCrossAxis()) == 0) {
@ -2180,7 +2187,7 @@ SingleLineCrossAxisPositionTracker::
// Subtract the space that our item is already occupying, to see how much // Subtract the space that our item is already occupying, to see how much
// space (if any) is available for its auto margins. // space (if any) is available for its auto margins.
nscoord spaceForAutoMargins = aLine.GetLineCrossSize() - nscoord spaceForAutoMargins = aLine.GetLineCrossSize() -
(aItem.GetCrossSize() + aItem.GetMarginBorderPaddingSizeInAxis(mAxis)); aItem.GetOuterCrossSize(mAxis);
if (spaceForAutoMargins <= 0) { if (spaceForAutoMargins <= 0) {
return; // No available space --> nothing to do return; // No available space --> nothing to do
@ -2230,17 +2237,12 @@ SingleLineCrossAxisPositionTracker::
// auto-sized items (which we've already done). // auto-sized items (which we've already done).
break; break;
case NS_STYLE_ALIGN_ITEMS_FLEX_END: case NS_STYLE_ALIGN_ITEMS_FLEX_END:
mPosition += mPosition += aLine.GetLineCrossSize() - aItem.GetOuterCrossSize(mAxis);
aLine.GetLineCrossSize() -
(aItem.GetCrossSize() +
aItem.GetMarginBorderPaddingSizeInAxis(mAxis));
break; break;
case NS_STYLE_ALIGN_ITEMS_CENTER: case NS_STYLE_ALIGN_ITEMS_CENTER:
// Note: If cross-size is odd, the "after" space will get the extra unit. // Note: If cross-size is odd, the "after" space will get the extra unit.
mPosition += mPosition +=
(aLine.GetLineCrossSize() - (aLine.GetLineCrossSize() - aItem.GetOuterCrossSize(mAxis)) / 2;
(aItem.GetCrossSize() +
aItem.GetMarginBorderPaddingSizeInAxis(mAxis))) / 2;
break; break;
case NS_STYLE_ALIGN_ITEMS_BASELINE: { case NS_STYLE_ALIGN_ITEMS_BASELINE: {
nscoord lineBaselineOffset = nscoord lineBaselineOffset =
@ -2419,8 +2421,8 @@ nsFlexContainerFrame::GenerateFlexLines(
} }
nscoord itemInnerHypotheticalMainSize = item->GetMainSize(); nscoord itemInnerHypotheticalMainSize = item->GetMainSize();
nscoord itemOuterHypotheticalMainSize = item->GetMainSize() + nscoord itemOuterHypotheticalMainSize =
item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis()); item->GetOuterMainSize(aAxisTracker.GetMainAxis());
// Check if we need to wrap |item| to a new line // Check if we need to wrap |item| to a new line
// (i.e. check if its outer hypothetical main size pushes our line over // (i.e. check if its outer hypothetical main size pushes our line over