Skip to content

Commit

Permalink
Remove redundant fields from WebPrintParams.
Browse files Browse the repository at this point in the history
paper_size_in_css_pixels can be removed because default_page_description
already contains the page box size.

print_content_area_in_css_pixels can be removed because the page area
can be deduced by subtracting the margins in default_page_description
from the page box size. The page area offset part of this field was
always set to 0,0 in PrintRenderFrameHelper, by the way.

Change-Id: Ib0d32b1089ff0e3e699fafa453f48b1228959c36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4858744
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Derek Schuff <dschuff@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1195892}
  • Loading branch information
mstensho authored and Chromium LUCI CQ committed Sep 13, 2023
1 parent 5b12af3 commit d2ff80e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
9 changes: 0 additions & 9 deletions components/printing/renderer/print_render_frame_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,6 @@ blink::WebPrintParams ComputeWebKitPrintParamsInDesiredDpi(
webkit_print_params.rasterize_pdf = print_params.rasterize_pdf;
webkit_print_params.print_scaling_option = print_params.print_scaling_option;

webkit_print_params.print_content_area_in_css_pixels.set_size(gfx::SizeF(
ConvertUnitFloat(print_params.content_size.width(), dpi, kPixelsPerInch),
ConvertUnitFloat(print_params.content_size.height(), dpi,
kPixelsPerInch)));

webkit_print_params.printable_area_in_css_pixels = gfx::RectF(
ConvertUnitFloat(print_params.printable_area.x(), dpi, kPixelsPerInch),
ConvertUnitFloat(print_params.printable_area.y(), dpi, kPixelsPerInch),
Expand All @@ -381,10 +376,6 @@ blink::WebPrintParams ComputeWebKitPrintParamsInDesiredDpi(
ConvertUnitFloat(print_params.printable_area.height(), dpi,
kPixelsPerInch));

webkit_print_params.paper_size_in_css_pixels = gfx::SizeF(
ConvertUnitFloat(print_params.page_size.width(), dpi, kPixelsPerInch),
ConvertUnitFloat(print_params.page_size.height(), dpi, kPixelsPerInch));

// The following settings is for N-up mode.
webkit_print_params.pages_per_sheet = print_params.pages_per_sheet;

Expand Down
17 changes: 13 additions & 4 deletions content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1609,13 +1609,22 @@ int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) {
return 0;
}

const blink::WebPrintPageDescription& description =
print_params.default_page_description;
gfx::SizeF page_area_size = description.size;
page_area_size.set_width(std::max(0.0f, page_area_size.width() -
description.margin_left -
description.margin_right));
page_area_size.set_height(std::max(0.0f, page_area_size.height() -
description.margin_top -
description.margin_bottom));

PP_PrintSettings_Dev print_settings;
print_settings.printable_area =
CSSPixelsToPoints(print_params.printable_area_in_css_pixels);
print_settings.content_area =
CSSPixelsToPoints(print_params.print_content_area_in_css_pixels);
print_settings.paper_size =
CSSPixelsToPoints(print_params.paper_size_in_css_pixels);
print_settings.content_area.point = PP_Point();
print_settings.content_area.size = CSSPixelsToPoints(page_area_size);
print_settings.paper_size = CSSPixelsToPoints(description.size);
print_settings.dpi = print_params.printer_dpi;
print_settings.orientation = PP_PRINTORIENTATION_NORMAL;
print_settings.grayscale = PP_FALSE;
Expand Down
4 changes: 2 additions & 2 deletions pdf/pdfium/pdfium_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
return nullptr;
}

gfx::Size int_paper_size =
ToFlooredSize(CSSPixelsToPoints(print_params.paper_size_in_css_pixels));
gfx::Size int_paper_size = ToFlooredSize(
CSSPixelsToPoints(print_params.default_page_description.size));
gfx::Rect int_printable_area = ToEnclosedRect(
CSSPixelsToPoints(print_params.printable_area_in_css_pixels));

Expand Down
3 changes: 1 addition & 2 deletions pdf/pdfium/pdfium_print_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ base::FilePath GetReferenceFilePath(base::StringPiece test_filename) {

blink::WebPrintParams GetDefaultPrintParams() {
blink::WebPrintParams params;
params.print_content_area_in_css_pixels = kUSLetterRect;
params.default_page_description.size = kUSLetterSize;
params.printable_area_in_css_pixels = kUSLetterRect;
params.paper_size_in_css_pixels = kUSLetterSize;
params.print_scaling_option = printing::mojom::PrintScalingOption::kNone;
return params;
}
Expand Down
14 changes: 3 additions & 11 deletions third_party/blink/public/web/web_print_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@
namespace blink {

struct WebPrintParams {
// Specifies printable content rect in CSS pixels (a CSS pixel is 1/96 of an
// inch).
gfx::RectF print_content_area_in_css_pixels;

// Specifies the selected printer default printable area details in
// pixels.
// in CSS pixels (a CSS pixel is 1/96 of an inch).
gfx::RectF printable_area_in_css_pixels;

// Specifies the selected printer default paper size in pixels.
gfx::SizeF paper_size_in_css_pixels;

// The page size and margins as provided by the system / user. This will be
// used as a base when handling @page rules, to fill in the blanks (rules may
// provide or omit declarations for the page size and/or any margin side).
// In CSS pixels.
WebPrintPageDescription default_page_description;

// Specifies user selected DPI for printing.
Expand Down Expand Up @@ -81,9 +75,7 @@ struct WebPrintParams {
: WebPrintParams(paper_size, true) {}

WebPrintParams(const gfx::SizeF& paper_size, bool use_printing_layout)
: print_content_area_in_css_pixels(paper_size),
printable_area_in_css_pixels(paper_size),
paper_size_in_css_pixels(paper_size),
: printable_area_in_css_pixels(paper_size),
default_page_description(paper_size),
print_scaling_option(printing::mojom::PrintScalingOption::kSourceSize),
use_printing_layout(use_printing_layout) {}
Expand Down

0 comments on commit d2ff80e

Please sign in to comment.