Bug 939901 part 3.5: Honor "page-break-before" and "page-break-after" as flex line breaking requests. r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 05 Dec 2013 10:57:51 -0800
changeset 173749 7ffb0aa5121f477c712b18387c9daeaefc096b69
parent 173748 54a3dd704f9ae304638f92f6215ff5e6a23de9f0
child 173750 79a76a1dce4ec13dcd45f6b63dfcb08f4ec74140
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs939901
milestone28.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 939901 part 3.5: Honor "page-break-before" and "page-break-after" as flex line breaking requests. r=mats
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -1984,22 +1984,25 @@ nsFlexContainerFrame::GenerateFlexLines(
   const nsHTMLReflowState& aReflowState,
   nscoord aContentBoxMainSize,
   nscoord aAvailableHeightForContent,
   const FlexboxAxisTracker& aAxisTracker,
   nsTArray<FlexLine>& aLines)
 {
   MOZ_ASSERT(aLines.IsEmpty(), "Expecting outparam to start out empty");
 
+  const bool isSingleLine =
+    NS_STYLE_FLEX_WRAP_NOWRAP == aReflowState.mStylePosition->mFlexWrap;
+
   // We have at least one FlexLine. Even an empty flex container has a single
   // (empty) flex line.
   FlexLine* curLine = aLines.AppendElement();
 
   nscoord wrapThreshold;
-  if (NS_STYLE_FLEX_WRAP_NOWRAP == aReflowState.mStylePosition->mFlexWrap) {
+  if (isSingleLine) {
     // Not wrapping. Set threshold to sentinel value that tells us not to wrap.
     wrapThreshold = NS_UNCONSTRAINEDSIZE;
 
     // Optimization: We know all items will end up in the first line, so we can
     // pre-allocate space for them.
     curLine->mItems.SetCapacity(mFrames.GetLength());
   } else {
     // Wrapping! Set wrap threshold to flex container's content-box main-size.
@@ -2021,18 +2024,26 @@ nsFlexContainerFrame::GenerateFlexLines(
     // (before we run off the end of the page)
     if (!IsAxisHorizontal(aAxisTracker.GetMainAxis()) &&
         aAvailableHeightForContent != NS_UNCONSTRAINEDSIZE) {
       wrapThreshold = std::min(wrapThreshold, aAvailableHeightForContent);
     }
   }
 
   for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
+    nsIFrame* childFrame = e.get();
+
+    // Honor "page-break-before", if we're multi-line and this line isn't empty:
+    if (!isSingleLine && !curLine->mItems.IsEmpty() &&
+        childFrame->StyleDisplay()->mBreakBefore) {
+      curLine = aLines.AppendElement();
+    }
+
     FlexItem* item = curLine->mItems.AppendElement(
-                       GenerateFlexItemForChild(aPresContext, e.get(),
+                       GenerateFlexItemForChild(aPresContext, childFrame,
                                                 aReflowState, aAxisTracker));
 
     nsresult rv = ResolveFlexItemMaxContentSizing(aPresContext, *item,
                                                   aReflowState, aAxisTracker);
     NS_ENSURE_SUCCESS(rv,rv);
     nscoord itemInnerHypotheticalMainSize = item->GetMainSize();
     nscoord itemOuterHypotheticalMainSize = item->GetMainSize() +
       item->GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
@@ -2059,16 +2070,22 @@ nsFlexContainerFrame::GenerateFlexLines(
       // Copy item into cur line:
       curLine->mItems.AppendElement(itemToCopy);
       // ...and remove the old copy in prev line:
       prevLine.mItems.RemoveElementAt(itemIdxInPrevLine);
     }
 
     curLine->AddToMainSizeTotals(itemInnerHypotheticalMainSize,
                                  itemOuterHypotheticalMainSize);
+
+    // Honor "page-break-after", if we're multi-line and have more children:
+    if (!isSingleLine && childFrame->GetNextSibling() &&
+        childFrame->StyleDisplay()->mBreakAfter) {
+      curLine = aLines.AppendElement();
+    }
   }
 
   return NS_OK;
 }
 
 // Retrieves the content-box main-size of our flex container from the
 // reflow state (specifically, the main-size of *this continuation* of the
 // flex container).