Only block container children support pagination struts.

Removed partial support for pagination struts on table captions, since it
didn't work too well (caused inconsistent layout and also overlap with the
table section that followed). Instead, set a strut on the content inside the
caption (first line, for instance), just like we already do for table cells.

We had a check to avoid setting pagination struts on table cells, but there was
no similar check for table captions. Replaced the check with examining the
containing block. We may only set a pagination strut on a block if its
containing block is a block container (LayoutBlockFlow). This automatically
fixes similar issues with flexboxes and possible other layout modes too.

BUG=329421
R=jchaffraix@chromium.org,leviw@chromium.org

Review URL: https://codereview.chromium.org/1360753002

git-svn-id: svn://svn.chromium.org/blink/trunk@202648 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary-expected.html b/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary-expected.html
new file mode 100644
index 0000000..81a1d86
--- /dev/null
+++ b/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary-expected.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<p>Check that a flexbox that starts at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below.</p>
+<div style="margin-left:50%;">PASS</div>
diff --git a/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary.html b/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary.html
new file mode 100644
index 0000000..0cfa42b
--- /dev/null
+++ b/LayoutTests/fast/multicol/flexbox-starts-at-column-boundary.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<p>Check that a flexbox that starts at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below.</p>
+<div style="-webkit-columns:2; -webkit-column-gap:0; column-fill:auto; height:90px;">
+    <div style="height:80px;"></div>
+    <div style="display:flex;">
+        <div>PA</div><div>SS</div>
+    </div>
+</div>
diff --git a/LayoutTests/fast/multicol/table-caption-and-cells-expected.html b/LayoutTests/fast/multicol/table-caption-and-cells-expected.html
new file mode 100644
index 0000000..206b8f0
--- /dev/null
+++ b/LayoutTests/fast/multicol/table-caption-and-cells-expected.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<p>Check that a table caption at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below, fully visible and unbroken.</p>
+<div style="margin-left:50%; width:10em; line-height:2em; text-align:center;">
+    PASS<br>
+    <div style="height:2em; background:black;"></div>
+</div>
diff --git a/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width-expected.html b/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width-expected.html
new file mode 100644
index 0000000..21f9fe4
--- /dev/null
+++ b/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width-expected.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<p>Check that a table caption at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below, fully visible and unbroken.</p>
+<div style="margin-left:15em; width:10em; line-height:2em; text-align:center;">
+    PASS<br>
+    <div style="height:2em; background:black;"></div>
+</div>
diff --git a/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width.html b/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width.html
new file mode 100644
index 0000000..ba1da9d
--- /dev/null
+++ b/LayoutTests/fast/multicol/table-caption-and-cells-fixed-width.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<p>Check that a table caption at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below, fully visible and unbroken.</p>
+<div style="-webkit-columns:2; -webkit-column-gap:0; column-fill:auto; line-height:2em; width:30em; height:9em;">
+    <div style="height:8em;"></div>
+    <table style="height:2em; width:10em; background:black;" cellspacing="0" cellpadding="0">
+        <caption>PASS</caption>
+        <tr>
+            <td></td>
+        </tr>
+    </table>
+</div>
diff --git a/LayoutTests/fast/multicol/table-caption-and-cells.html b/LayoutTests/fast/multicol/table-caption-and-cells.html
new file mode 100644
index 0000000..0f3f6ed
--- /dev/null
+++ b/LayoutTests/fast/multicol/table-caption-and-cells.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<p>Check that a table caption at a column boundary is properly pushed to the next column.</p>
+<p>The word "PASS" should be seen below, fully visible and unbroken.</p>
+<div style="-webkit-columns:2; -webkit-column-gap:0; column-fill:auto; line-height:2em; height:9em;">
+    <div style="height:8em;"></div>
+    <table style="width:10em; height:2em; background:black;" cellspacing="0" cellpadding="0">
+        <caption>PASS</caption>
+        <tr>
+            <td></td>
+        </tr>
+    </table>
+</div>
diff --git a/Source/core/layout/LayoutBlockFlow.cpp b/Source/core/layout/LayoutBlockFlow.cpp
index a4cb56f..73f871a 100644
--- a/Source/core/layout/LayoutBlockFlow.cpp
+++ b/Source/core/layout/LayoutBlockFlow.cpp
@@ -781,9 +781,16 @@
         if (totalLogicalHeight < pageLogicalHeightAtNewOffset)
             wantsStrutOnBlock = true;
     }
-    // If we want to break before the block, one final check is needed, since some block object
-    // types cannot handle struts.
-    return wantsStrutOnBlock && !block.isOutOfFlowPositioned() && !block.isTableCell();
+    // The block needs to be contained by a LayoutBlockFlow (and not by e.g. a flexbox or a table
+    // (which would be the case for table cell or table caption)). The reason for this limitation is
+    // simply that LayoutBlockFlow child layout code is the only place where we pick up the struts
+    // and handle them. We handle floats and regular in-flow children, and that's all. We could
+    // handle this in other layout modes as well (and even for out-of-flow children), but currently
+    // we don't.
+    if (!wantsStrutOnBlock || block.isOutOfFlowPositioned())
+        return false;
+    LayoutBlock* containingBlock = block.containingBlock();
+    return containingBlock && containingBlock->isLayoutBlockFlow();
 }
 
 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, LayoutUnit& delta)
diff --git a/Source/core/layout/LayoutTable.cpp b/Source/core/layout/LayoutTable.cpp
index 7c2d93c..484a745 100644
--- a/Source/core/layout/LayoutTable.cpp
+++ b/Source/core/layout/LayoutTable.cpp
@@ -372,10 +372,6 @@
     }
     // Apply the margins to the location now that they are definitely available from layout
     LayoutUnit captionLogicalTop = collapsedMarginBeforeForChild(caption) + logicalHeight();
-    if (view()->layoutState()->isPaginated()) {
-        captionLogicalTop += caption.paginationStrut();
-        caption.setPaginationStrut(0);
-    }
     caption.setLogicalLocation(LayoutPoint(caption.marginStart(), captionLogicalTop));
 
     if (!selfNeedsLayout())