[GridFragmentation] Position items based on their row position.

Previously we'd decide if a grid-item should be placed in the current
fragmentainer based on their global position.

This was ok - but a better strategy is to try and keep them with their
row. This wasn't initially important, but as break avoidance is row
based, when we try to shift a row to a subsequent fragmentainer we'll
potentially end up with an item which has already been placed.

This has the side-effect that a grid-item with a negative block-start
margin, may be placed above the start fragmentainer edge - which seems
ok.

I added this as a tentative testcase.

Bug: 614667
Change-Id: I65486307fd72f8e5f8cb7f87ebce66c5569deedf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3276728
Reviewed-by: Morten Stenshorne <mstensho@chromium.org>
Reviewed-by: Alison Maher <almaher@microsoft.com>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#941176}
diff --git a/css/css-break/grid/grid-item-fragmentation-026.html b/css/css-break/grid/grid-item-fragmentation-026.html
new file mode 100644
index 0000000..9f4be08
--- /dev/null
+++ b/css/css-break/grid/grid-item-fragmentation-026.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-grid-1/#pagination">
+<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
+<title>Tests that grid-items with a block-start margin will get pushed into the next fragmentainer.</title>
+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
+<div style="width: 100px; height: 100px; columns: 2; column-gap: 0; background: red;">
+  <div style="display: grid; grid-template: 100px 100px / 50px; grid-template-areas: 'a' 'b'">
+    <div style="background: green; grid-area: a; margin-top: 100px; height: 100px;"></div>
+    <div style="background: green; grid-area: a; height: 100px; "></div>
+  </div>
+</div>
diff --git a/css/css-break/grid/grid-item-fragmentation-027.tentative.html b/css/css-break/grid/grid-item-fragmentation-027.tentative.html
new file mode 100644
index 0000000..c0270db
--- /dev/null
+++ b/css/css-break/grid/grid-item-fragmentation-027.tentative.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-grid-1/#pagination">
+<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
+<title>Tests that grid-items with a negative margin are placed relative to their row (instead of fragmenting earlier).</title>
+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
+<div style="background: red; width: 100px; height: 100px; display: flow-root;">
+  <div style="margin-top: 10px; height: 90px; columns: 2; column-gap: 0;">
+    <div style="display: grid; grid-template: 90px 90px / 50px;">
+      <div>
+        <div style="background: green; margin-top: -10px; height: 100px;"></div>
+      </div>
+      <div style="background: green; margin-top: -10px; height: 100px;"></div>
+    </div>
+  </div>
+</div>