Avoid bad relayout roots inside pagination.

We were already preventing this from happening when inside multicol, but
it turns out that we need it for printing as well.

It is actually (at least currently) possible for the print layout to be
updated after initial layout for pagination but before painting
(printing) it. Accessibility may trigger this via Document::
AddAXContext(), which may be called at such an inconvenient time, and it
may trigger a style recalc, and thus layout. Due to crbug.com/452672, it
may also happen inside a window.matchMedia("print") listener.

Bug: 1507840
Change-Id: I213efc610c2b57fc3beceef99e5c52c8655bc483
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5093875
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1234192}
diff --git a/css/css-page/crashtests/match-media-listener-relayout-inside-fixed-size-overflow-hidden-print.html b/css/css-page/crashtests/match-media-listener-relayout-inside-fixed-size-overflow-hidden-print.html
new file mode 100644
index 0000000..77f9dc3
--- /dev/null
+++ b/css/css-page/crashtests/match-media-listener-relayout-inside-fixed-size-overflow-hidden-print.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
+<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1507840">
+<div style="position:relative; overflow:hidden; width:100px; height:100px;">
+  <div style="position:absolute; width:100px; height:100px; background:green;">
+    <div id="trouble"></div>
+  </div>
+</div>
+<script>
+  var mediaQuery = window.matchMedia("print");
+  mediaQuery.addListener(function() {
+    trouble.style.width = "100px";
+  });
+</script>