From b76fdcd7b95311286cc18d99e53deb676fe016d2 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Thu, 27 Oct 2016 18:56:48 -0700 Subject: [PATCH] Bug 1313421 part 2: Use flex container's FlexLine linked-list to determine the first flex item, rather than its child-frame list. r=mats This shouldn't change our behavior right now, but it will make a difference after bug 1269045 -- when that bug lands, we'll have nsPlaceholderFrames (which are not flex items) in the child-frame list, which means we can't depend on its first entry being a flex item anymore. MozReview-Commit-ID: KRXYaK8R8bc --- layout/generic/nsFlexContainerFrame.cpp | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp index c1556c6636f8..a30456cf7c14 100644 --- a/layout/generic/nsFlexContainerFrame.cpp +++ b/layout/generic/nsFlexContainerFrame.cpp @@ -837,6 +837,20 @@ public: return mItems.getFirst(); } + FlexItem* GetLastItem() + { + MOZ_ASSERT(mItems.isEmpty() == (mNumItems == 0), + "mNumItems bookkeeping is off"); + return mItems.getLast(); + } + + const FlexItem* GetLastItem() const + { + MOZ_ASSERT(mItems.isEmpty() == (mNumItems == 0), + "mNumItems bookkeeping is off"); + return mItems.getLast(); + } + bool IsEmpty() const { MOZ_ASSERT(mItems.isEmpty() == (mNumItems == 0), @@ -4180,6 +4194,14 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext, logSize += aReflowInput.ComputedLogicalBorderPadding().Size(flexWM); nsSize containerSize = logSize.GetPhysicalSize(flexWM); + // If the flex container has no baseline-aligned items, it will use this item + // (the first item, discounting any under-the-hood reversing that we've done) + // to determine its baseline: + const FlexItem* const firstItem = + aAxisTracker.AreAxesInternallyReversed() + ? lines.getLast()->GetLastItem() + : lines.getFirst()->GetFirstItem(); + // FINAL REFLOW: Give each child frame another chance to reflow, now that // we know its final size and position. for (const FlexLine* line = lines.getFirst(); line; line = line->getNext()) { @@ -4230,10 +4252,10 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext, *item, framePos, containerSize); } - // If this is our first child and we haven't established a baseline for + // 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 baseline as the container's baseline. - if (item->Frame() == mFrames.FirstChild() && + if (item == firstItem && flexContainerAscent == nscoord_MIN) { flexContainerAscent = itemNormalBPos + item->ResolvedAscent(); }