Bug 1596310 - Clamp negative available size to zero and ensure page break frames don't apply margins. r=TYLin
authorMats Palmgren <mats@mozilla.com>
Mon, 18 Nov 2019 20:36:52 +0000
changeset 502468 c1d9e657897e5e7ef32227d8a0c8c7dfc9d13de6
parent 502467 975df36124a5bc2fbaf43c9ec0bdc3b93048d49c
child 502469 5a76ddcb1ac13213e905126cf8e5136ee3b7f6f1
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTYLin
bugs1596310
milestone72.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 1596310 - Clamp negative available size to zero and ensure page break frames don't apply margins. r=TYLin Differential Revision: https://phabricator.services.mozilla.com/D53040
layout/generic/crashtests/1596310.html
layout/generic/crashtests/crashtests.list
layout/generic/nsBlockFrame.cpp
layout/generic/nsBlockReflowContext.cpp
layout/reftests/pagination/1596310-ref.html
layout/reftests/pagination/1596310.html
layout/reftests/pagination/reftest.list
new file mode 100644
--- /dev/null
+++ b/layout/generic/crashtests/1596310.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html class="reftest-paged">
+<head>
+  <style>
+@page { size:5in 3in; margin:0; }
+html,body { padding:0; margin:0; height:100%; }
+div {
+  margin-bottom: 1em;
+  height: 100%;
+  page-break-after: always;
+}
+</style>
+</head>
+<body>
+  <div>A</div>
+</body>
+</html>
--- a/layout/generic/crashtests/crashtests.list
+++ b/layout/generic/crashtests/crashtests.list
@@ -742,8 +742,9 @@ load 1571460.html
 pref(layout.css.column-span.enabled,true) load 1571598.html
 pref(layout.css.column-span.enabled,true) load 1571897.html
 pref(layout.css.column-span.enabled,true) load 1572901.html
 pref(layout.css.column-span.enabled,true) load 1573216.html
 load 1574552.html
 pref(layout.css.column-span.enabled,true) load 1574993.html
 pref(layout.css.column-span.enabled,true) load 1582019.html
 load 1586470.html
+load 1596310.html
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -3302,16 +3302,22 @@ bool nsBlockFrame::IsEmpty() {
     if (!line->IsEmpty()) return false;
   }
 
   return true;
 }
 
 bool nsBlockFrame::ShouldApplyBStartMargin(BlockReflowInput& aState,
                                            nsLineBox* aLine) {
+  if (aLine->mFirstChild->IsPageBreakFrame()) {
+    // A page break frame consumes margins adjacent to it.
+    // https://drafts.csswg.org/css-break/#break-margins
+    return false;
+  }
+
   if (aState.mFlags.mShouldApplyBStartMargin) {
     // Apply short-circuit check to avoid searching the line list
     return true;
   }
 
   if (!aState.IsAdjacentWithTop()) {
     // If we aren't at the start block-coordinate then something of non-zero
     // height must have been placed. Therefore the childs block-start margin
--- a/layout/generic/nsBlockReflowContext.cpp
+++ b/layout/generic/nsBlockReflowContext.cpp
@@ -236,20 +236,22 @@ void nsBlockReflowContext::ReflowBlock(
     printf(" margin => %d, clearance => %d\n", mBStartMargin.get(), aClearance);
 #endif
 
     // Adjust the available size if it's constrained so that the
     // child frame doesn't think it can reflow into its margin area.
     if (mWritingMode.IsOrthogonalTo(mFrame->GetWritingMode())) {
       if (NS_UNCONSTRAINEDSIZE != aFrameRI.AvailableISize()) {
         aFrameRI.AvailableISize() -= mBStartMargin.get() + aClearance;
+        aFrameRI.AvailableISize() = std::max(0, aFrameRI.AvailableISize());
       }
     } else {
       if (NS_UNCONSTRAINEDSIZE != aFrameRI.AvailableBSize()) {
         aFrameRI.AvailableBSize() -= mBStartMargin.get() + aClearance;
+        aFrameRI.AvailableBSize() = std::max(0, aFrameRI.AvailableBSize());
       }
     }
   } else {
     // nsBlockFrame::ReflowBlock might call us multiple times with
     // *different* values of aApplyBStartMargin.
     mBStartMargin.Zero();
   }
 
new file mode 100644
--- /dev/null
+++ b/layout/reftests/pagination/1596310-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html class="reftest-paged">
+<head>
+<style>
+@page { size:5in 3in; margin:0; }
+html,body { padding:0; margin:0; height:100%; }
+div {
+  height:100%;
+  background: black;
+  color: white;
+}
+</style>
+</head>
+<body>
+  <div>A</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/pagination/1596310.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html class="reftest-paged">
+<head>
+<style>
+@page { size:5in 3in; margin:0; }
+html,body { padding:0; margin:0; height:100%; }
+div {
+  margin-bottom: 1in;
+  height: 100%;
+  background: black;
+  color: white;
+  page-break-after: always;
+}
+</style>
+</head>
+<body>
+  <div>A</div>
+</body>
+</html>
--- a/layout/reftests/pagination/reftest.list
+++ b/layout/reftests/pagination/reftest.list
@@ -119,14 +119,15 @@ fuzzy-if(cocoaWidget,0-1,0-5000) == 7450
 == 1404868-1.html 1404868-1-ref.html
 == 1406050-1.html 1406050-1-ref.html
 == 1406291-1.html 1406291-1-ref.html
 == 1409585-1.html 1409585-1-ref.html
 == 1411799-1.html 1411799-1-ref.html
 == 1420528-1.html 1420528-1-ref.html
 pref(layout.css.column-span.enabled,true) == 1420528-1.html 1420528-1-ref.html
 == 1468654-1.html 1468654-1-ref.html
+== 1596310.html 1596310-ref.html
 
 == content-url-element.html image.html
 == content-url-pseudo.html content-url-pseudo-ref.html
 
 == quirks.html quirks-ref.html
 != quirks.html quirks-notref.html