Bug 1637145 Part 1 - Create a helper method for the code that generates FlexLines and FlexItems for a flex container's next-in-flows. r=dholbert
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 19 May 2020 03:46:46 +0000
changeset 530930 ad89f466d991715dba86eb61630eee7f9761369c
parent 530929 bd3a170fc984a92ff6478480b16e3d8ce9cb2f68
child 530931 dfd3e63d3371eac20a4217369677c1cbe16cce35
push id37434
push userabutkovits@mozilla.com
push dateWed, 20 May 2020 10:05:10 +0000
treeherdermozilla-central@005ef1c25992 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1637145
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1637145 Part 1 - Create a helper method for the code that generates FlexLines and FlexItems for a flex container's next-in-flows. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D75154
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsFlexContainerFrame.h
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -3858,16 +3858,43 @@ void nsFlexContainerFrame::GenerateFlexL
     if (!isSingleLine && childFrame->GetNextSibling() &&
         childFrame->StyleDisplay()->BreakAfter()) {
       curLine = ConstructNewFlexLine();
     }
     itemIdxInContainer++;
   }
 }
 
+void nsFlexContainerFrame::GenerateFlexLines(const SharedFlexData& aData,
+                                             nsTArray<FlexLine>& aLines) {
+  MOZ_ASSERT(GetPrevInFlow(), "This should be called by non-first-in-flows!");
+
+  // Pretend we have only one line and zero main gap size.
+  aLines.AppendElement(FlexLine(0));
+
+  // Construct flex items for this flex container fragment from existing flex
+  // items in SharedFlexData.
+  CSSOrderAwareFrameIterator iter(
+      this, kPrincipalList, CSSOrderAwareFrameIterator::eSkipPlaceholders,
+      CSSOrderAwareFrameIterator::eUnknownOrder, OrderingPropertyForIter(this));
+
+  // FIXME(Bug 1637145): This has worst-case O(n^3) performance.
+  for (; !iter.AtEnd(); iter.Next()) {
+    nsIFrame* const child = *iter;
+    nsIFrame* const childFirstInFlow = child->FirstInFlow();
+    for (const FlexLine& line : aData.mLines) {
+      for (const FlexItem& item : line.Items()) {
+        if (item.Frame() == childFirstInFlow) {
+          aLines[0].Items().AppendElement(item.CloneFor(child));
+        }
+      }
+    }
+  }
+}
+
 // Retrieves the content-box main-size of our flex container from the
 // reflow input (specifically, the main-size of *this continuation* of the
 // flex container).
 nscoord nsFlexContainerFrame::GetMainSizeFromReflowInput(
     const ReflowInput& aReflowInput, const FlexboxAxisTracker& aAxisTracker) {
   if (aAxisTracker.IsRowOriented()) {
     // Row-oriented --> our main axis is the inline axis, so our main size
     // is our inline size (which should already be resolved).
@@ -4255,39 +4282,17 @@ void nsFlexContainerFrame::Reflow(nsPres
                    contentBoxCrossSize, flexContainerAscent,
                    availableBSizeForContent, columnWrapThreshold, lines, struts,
                    placeholders, axisTracker, mainGapSize, crossGapSize,
                    hasLineClampEllipsis, containerInfo);
     }
   } else {
     auto* data = FirstInFlow()->GetProperty(SharedFlexData::Prop());
 
-    // Pretend we have only one line and zero main gap size.
-    lines.AppendElement(FlexLine(0));
-
-    // Construct flex items for this flex container fragment from existing flex
-    // items in SharedFlexData.
-    CSSOrderAwareFrameIterator iter(
-        this, kPrincipalList, CSSOrderAwareFrameIterator::eSkipPlaceholders,
-        CSSOrderAwareFrameIterator::eUnknownOrder,
-        OrderingPropertyForIter(this));
-
-    // FIXME(Bug 1637145): This has worst-case O(n^3) performance.
-    for (; !iter.AtEnd(); iter.Next()) {
-      nsIFrame* const child = *iter;
-      nsIFrame* const childFirstInFlow = child->FirstInFlow();
-      for (const FlexLine& line : data->mLines) {
-        for (const FlexItem& item : line.Items()) {
-          if (item.Frame() == childFirstInFlow) {
-            lines[0].Items().AppendElement(item.CloneFor(child));
-          }
-        }
-      }
-    }
-
+    GenerateFlexLines(*data, lines);
     contentBoxMainSize = data->mContentBoxMainSize;
     contentBoxCrossSize = data->mContentBoxCrossSize;
   }
 
   const LogicalSize contentBoxSize =
       axisTracker.LogicalSizeFromFlexRelativeSizes(contentBoxMainSize,
                                                    contentBoxCrossSize);
   const nscoord consumedBSize = ConsumedBSize(wm);
--- a/layout/generic/nsFlexContainerFrame.h
+++ b/layout/generic/nsFlexContainerFrame.h
@@ -415,16 +415,24 @@ class nsFlexContainerFrame final : publi
                          nscoord aContentBoxMainSize,
                          nscoord aColumnWrapThreshold,
                          const nsTArray<StrutInfo>& aStruts,
                          const FlexboxAxisTracker& aAxisTracker,
                          nscoord aMainGapSize, bool aHasLineClampEllipsis,
                          nsTArray<nsIFrame*>& aPlaceholders,
                          nsTArray<FlexLine>& aLines);
 
+  /**
+   * This method creates FlexLines and FlexItems for children in flex
+   * container's next-in-flows by using the SharedFlexData stored in flex
+   * container's first-in-flow. Returns FlexLines in the outparam |aLines|.
+   */
+  void GenerateFlexLines(const SharedFlexData& aData,
+                         nsTArray<FlexLine>& aLines);
+
   nscoord GetMainSizeFromReflowInput(const ReflowInput& aReflowInput,
                                      const FlexboxAxisTracker& aAxisTracker);
 
   /**
    * Resolves the content-box main-size of a flex container frame,
    * primarily based on:
    * - the "tentative" main size, taken from the reflow input ("tentative"
    *    because it may be unconstrained or may run off the page).