Skip to content

Commit

Permalink
Properly update the ICB when shrinking print contents.
Browse files Browse the repository at this point in the history
Be more consistent about this. Scaling specified by the print preview UI
was taken into account, but scaling caused by internal page scaling (to
avoid / reduce inline overflow) was not.

The initial containing block isn't used for a lot of things when
printing, since each page defines a containing block. However, for
out-of-flow positioned boxes and things like vw and vh units, it
matters.

(cherry picked from commit 1ee4c82)

Bug: 1485819
Change-Id: I87b37cd5d1154824ca2a0a7c9567298c2c50fd89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4889925
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1201358}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4934590
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Auto-Submit: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/branch-heads/5993@{#1257}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
mstensho authored and Chromium LUCI CQ committed Oct 12, 2023
1 parent c79e925 commit d06ddae
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
13 changes: 7 additions & 6 deletions third_party/blink/renderer/core/frame/local_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3309,9 +3309,10 @@ void LocalFrameView::ForceLayoutForPagination(float maximum_shrink_factor) {

const auto& first_page = To<NGPhysicalBoxFragment>(
*layout_view->GetPhysicalFragment(0)->Children()[0]);
if (const AtomicString& page_name = first_page.PageName()) {
const AtomicString& first_page_name = first_page.PageName();
if (first_page_name) {
PhysicalSize new_size =
layout_view->PageAreaSize(/* page_index */ 0u, page_name);
layout_view->PageAreaSize(/* page_index */ 0u, first_page_name);
if (new_size != initial_containing_block_size) {
// If the first page was named (this isn't something we can detect without
// laying out first), and the size of the first page is different from
Expand Down Expand Up @@ -3362,12 +3363,12 @@ void LocalFrameView::ForceLayoutForPagination(float maximum_shrink_factor) {
// Re-layout and apply the same scale factor to all pages. PageScaleFactor()
// has already been set to honor any scale factor from print settings. That
// has to be included as well.
//
// Note that we deliberately don't set a new initial containing block size
// here. But should we? EdgeHTML does it. Gecko doesn't. WebKit is buggy
// (uses the initial block based on the browser frame size).
layout_view->SetPageScaleFactor(layout_view->PageScaleFactor() *
overall_scale_factor);
PhysicalSize new_size =
layout_view->PageAreaSize(/* page_index */ 0u, first_page_name);
layout_view->SetInitialContainingBlockSizeForPagination(new_size);
frame_->GetDocument()->LayoutViewportWasResized();
layout_view->SetNeedsLayoutAndIntrinsicWidthsRecalcAndFullPaintInvalidation(
layout_invalidation_reason::kPrintingChanged);
frame_->GetDocument()->UpdateStyleAndLayout(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<style>
@page {
size: 300px 200px;
margin: 0;
}
body { margin: 0; }
</style>
<div style="float:right; width:100px; height:100px; background:green;"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!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=1485969">
<link rel="match" href="icb-scaling-001-print-ref.html">
<style>
@page {
size: 300px 200px;
margin: 0;
}
body { margin: 0; }
</style>
<!-- This test assumes that the printing implementation shrinks the content (and
grows the initial containing block) to avoid overflowing content. -->
<div style="width:450px; height:100px;">
<div style="position:fixed; width:150px; height:150px; right:0; top:0; background:green;"></div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<style>
@page {
size: 300px 600px;
margin: 0;
}
body { margin: 0; }
</style>
<div style="margin-left:100px; margin-top:100px; width:150px; height:300px; background:green;"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!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=1485969">
<link rel="match" href="icb-scaling-002-print-ref.html">
<style>
@page {
size: 300px 600px;
margin: 0;
}
body { margin: 0; }
</style>
<!-- This test assumes that the printing implementation shrinks the content (and
grows the initial containing block) to avoid overflowing content. -->
<div style="width:450px; height:100px;">
<div style="position:absolute; left:150px; top:150px; width:50%; height:50%; background:green;"></div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<style>
@page {
size: 300px 600px;
margin: 0;
}
body { margin: 0; }
</style>
<div style="margin-left:100px; margin-top:100px; width:150px; height:300px; background:green;"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!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=1485969">
<link rel="match" href="icb-scaling-003-print-ref.html">
<style>
@page {
size: 300px 600px;
margin: 0;
}
body { margin: 0; }
</style>
<!-- This test assumes that the printing implementation shrinks the content (and
grows the initial containing block) to avoid overflowing content. -->
<div style="width:450px; height:100px;">
<div style="position:absolute; left:150px; top:150px; width:50vw; height:50vh; background:green;"></div>
</div>

0 comments on commit d06ddae

Please sign in to comment.