Skip to content

Commit

Permalink
Printing: Move page size calculation to Blink.
Browse files Browse the repository at this point in the history
This is in preparation for mixed page sizes support (which will be added
in an upcoming CL).

We need to set the correct size for each individual page during layout.
Remove the concept of "*the* page size", since each page can have its
own size. Note, however, that we still need a uniform page size to use
as the initial containing block, which is used to resolve viewport
units, among other things. The spec defines the initial containing block
as the page area size of the first page:
https://www.w3.org/TR/css-page-3/#page-model

As a result of this change, some cleanup in PrintRenderFrameHelper
should be possible (in future CLs). For one, we no longer need to lay
out everything twice, since we lay out with the correct page sizes in
the first layout pass (rather than first using printer defaults, then
read out sizes and pargins specified in @page rules, and then lay out
again with the correct sizes). It should also be possible to untangle
some margin logic in PrintRenderFrameHelper, since Blink now only
applies CSS-specified margins when it should (e.g. not if the user has
chosen their own margins in the print preview UI). Furthermore, there
are redundant fields in WebPrintParams. We no longer need to store a
page size or content area size (since we're providing a
WebPrintPageDescription now).

PrintContext no longer stores a vector of page rectangles. They will
instead be calculated when needed. We only used the rectangles when
printing with Blink, whereas ChromePluginPrintContext was forced to
populate a page_rects_ vector, just so that we could return the correct
number of pages. Since the code for calculating the page rectangles has
been rewritten, especially when it comes to how additional pages caused
by monolithic content is calculated, I added a web test for that, since
it turned out that we didn't have a good test for that particular case.

No behavior changes intended.

Bug: 835358
Change-Id: Ic669071b3e0ac729a467321720e25d6101e7b13f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4725066
Reviewed-by: Chris Harrelson <[email protected]>
Commit-Queue: Morten Stenshorne <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Ian Kilpatrick <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1177868}
  • Loading branch information
mstensho authored and Lightning00Blade committed Dec 11, 2023
1 parent d70657d commit 2f6e6cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions css/printing/monolithic-overflow-022-print-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">
<style>
body {
margin: 0;
}
</style>
<div style="height:350vh; background:cyan;">
There should be four pages.
</div>
12 changes: 12 additions & 0 deletions css/printing/monolithic-overflow-022-print.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">
<link rel="help" href="https://www.w3.org/TR/css-break-3/#possible-breaks">
<link rel="match" href="monolithic-overflow-022-print-ref.html">
<style>
body {
margin: 0;
}
</style>
<div style="contain:size; height:350vh; background:cyan;">
There should be four pages.
</div>

0 comments on commit 2f6e6cc

Please sign in to comment.