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
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 27 Oct 2016 18:56:48 -0700
changeset 319883 ae632144724fc5efae24a32acab2d7d938384123
parent 319882 c565ba669d962165dc90b99f77b0b26d4acb4d92
child 319884 1658a195f669351b5f6caf5dbafdb0b4b12a6c2c
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1313421, 1269045
milestone52.0a1
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
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -832,16 +832,30 @@ public:
 
   const FlexItem* GetFirstItem() const
   {
     MOZ_ASSERT(mItems.isEmpty() == (mNumItems == 0),
                "mNumItems bookkeeping is off");
     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),
                "mNumItems bookkeeping is off");
     return mItems.isEmpty();
   }
 
   uint32_t NumItems() const
@@ -4175,16 +4189,24 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
 
   // Determine flex container's border-box size (used in positioning children):
   LogicalSize logSize =
     aAxisTracker.LogicalSizeFromFlexRelativeSizes(aContentBoxMainSize,
                                                   contentBoxCrossSize);
   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()) {
     for (const FlexItem* item = line->GetFirstItem(); item;
          item = item->getNext()) {
       LogicalPoint framePos = aAxisTracker.LogicalPointFromFlexRelativePoint(
                                item->GetMainPosition(),
                                item->GetCrossPosition(),
@@ -4225,20 +4247,20 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
           }
         }
       }
       if (itemNeedsReflow) {
         ReflowFlexItem(aPresContext, aAxisTracker, aReflowInput,
                        *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();
       }
     }
   }
 
   // Compute flex container's desired size (in its own writing-mode),
   // starting w/ content-box size & growing from there: