Bug 1298008 Part 2: Make nsFlexContainer update UsedMargin property after final reflow. r=dholbert

MozReview-Commit-ID: HV4uhJqWjfj

--HG--
extra : rebase_source : 8dd4d384ed78dcea6093cb4f86f5a84d03048fa5
This commit is contained in:
Brad Werth 2018-03-08 17:35:47 -08:00
Родитель 69dd600383
Коммит 15154e29fb
1 изменённых файлов: 24 добавлений и 7 удалений

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

@ -553,6 +553,9 @@ public:
bool NeedsMinSizeAutoResolution() const
{ return mNeedsMinSizeAutoResolution; }
bool HasAnyAutoMargin() const
{ return mHasAnyAutoMargin; }
// Indicates whether this item is a "strut" left behind by an element with
// visibility:collapse.
bool IsStrut() const { return mIsStrut; }
@ -858,6 +861,9 @@ protected:
// Does this item need to resolve a min-[width|height]:auto (in main-axis).
bool mNeedsMinSizeAutoResolution;
// Does this item have an auto margin in either main or cross axis?
bool mHasAnyAutoMargin;
uint8_t mAlignSelf; // My "align-self" computed value (with "auto"
// swapped out for parent"s "align-items" value,
// in our constructor).
@ -1816,7 +1822,7 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput,
mIsInlineAxisMainAxis(aAxisTracker.IsRowOriented() !=
aAxisTracker.GetWritingMode().IsOrthogonalTo(mWM))
// mNeedsMinSizeAutoResolution is initialized in CheckForMinSizeAuto()
// mAlignSelf, see below
// mAlignSelf, mHasAnyAutoMargin see below
{
MOZ_ASSERT(mFrame, "expecting a non-null child frame");
MOZ_ASSERT(!mFrame->IsPlaceholderFrame(),
@ -1853,12 +1859,16 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput,
SetFlexBaseSizeAndMainSize(aFlexBaseSize);
CheckForMinSizeAuto(aFlexItemReflowInput, aAxisTracker);
const nsStyleSides& styleMargin =
aFlexItemReflowInput.mStyleMargin->mMargin;
mHasAnyAutoMargin = styleMargin.HasInlineAxisAuto(mWM) ||
styleMargin.HasBlockAxisAuto(mWM);
// Assert that any "auto" margin components are set to 0.
// (We'll resolve them later; until then, we want to treat them as 0-sized.)
#ifdef DEBUG
{
const nsStyleSides& styleMargin =
aFlexItemReflowInput.mStyleMargin->mMargin;
NS_FOR_CSS_SIDES(side) {
if (styleMargin.GetUnit(side) == eStyleUnit_Auto) {
MOZ_ASSERT(GetMarginComponentForSide(side) == 0,
@ -1917,6 +1927,7 @@ FlexItem::FlexItem(nsIFrame* aChildFrame, nscoord aCrossSize,
mIsStrut(true), // (this is the constructor for making struts, after all)
mIsInlineAxisMainAxis(true), // (doesn't matter b/c we're not doing layout)
mNeedsMinSizeAutoResolution(false),
mHasAnyAutoMargin(false),
mAlignSelf(NS_STYLE_ALIGN_FLEX_START)
{
MOZ_ASSERT(mFrame, "expecting a non-null child frame");
@ -4753,6 +4764,16 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,
*item, framePos, containerSize);
}
// If the item has auto margins, and we were tracking the UsedMargin
// property, set the property to the computed margin values.
if (item->HasAnyAutoMargin()) {
nsMargin* propValue =
item->Frame()->GetProperty(nsIFrame::UsedMarginProperty());
if (propValue) {
*propValue = item->GetMargin();
}
}
// If this is our first item and we haven't established a baseline for
// the container yet (i.e. if we don't have 'align-self: baseline' on any
// children), then use this child's first baseline as the container's
@ -4953,10 +4974,6 @@ nsFlexContainerFrame::ReflowFlexItem(nsPresContext* aPresContext,
aItem.Frame()->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
}
// XXXdholbert Might need to actually set the correct margins in the
// reflow state at some point, so that they can be saved on the frame for
// UsedMarginProperty(). Maybe doesn't matter though...?
// If we're overriding the computed width or height, *and* we had an
// earlier "measuring" reflow, then this upcoming reflow needs to be
// treated as a resize.