Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Unified Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2116283002: Don't let rounding prematurely influence document size when printing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@620456-2
Patch Set: bug 467579 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | printing/units.h » ('j') | third_party/WebKit/public/web/WebFrame.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/printing/renderer/print_web_view_helper.cc
diff --git a/components/printing/renderer/print_web_view_helper.cc b/components/printing/renderer/print_web_view_helper.cc
index fa79d1a2714353a0a665ff0e7f4c77d78738f0ea..3b030fd654ab1817b8e5084c07a5880b43897dda 100644
--- a/components/printing/renderer/print_web_view_helper.cc
+++ b/components/printing/renderer/print_web_view_helper.cc
@@ -126,9 +126,9 @@ PrintMsg_Print_Params GetCssPrintParams(
PrintMsg_Print_Params page_css_params = page_params;
int dpi = GetDPI(&page_params);
- blink::WebSize page_size_in_pixels(
- ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch),
- ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch));
+ blink::WebFloatSize page_size_in_pixels(
+ ConvertUnitDouble(page_params.page_size.width(), dpi, kPixelsPerInch),
+ ConvertUnitDouble(page_params.page_size.height(), dpi, kPixelsPerInch));
int margin_top_in_pixels =
ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch);
int margin_right_in_pixels = ConvertUnit(
@@ -143,8 +143,6 @@ PrintMsg_Print_Params GetCssPrintParams(
page_params.margin_left,
dpi, kPixelsPerInch);
- blink::WebSize original_page_size_in_pixels = page_size_in_pixels;
-
if (frame) {
frame->pageSizeAndMarginsInPixels(page_index,
page_size_in_pixels,
@@ -154,9 +152,9 @@ PrintMsg_Print_Params GetCssPrintParams(
margin_left_in_pixels);
}
- int new_content_width = page_size_in_pixels.width -
+ float new_content_width = page_size_in_pixels.width -
margin_left_in_pixels - margin_right_in_pixels;
- int new_content_height = page_size_in_pixels.height -
+ float new_content_height = page_size_in_pixels.height -
margin_top_in_pixels - margin_bottom_in_pixels;
// Invalid page size and/or margins. We just use the default setting.
@@ -166,20 +164,14 @@ PrintMsg_Print_Params GetCssPrintParams(
return page_css_params;
}
+ page_css_params.page_size =
+ gfx::Size(ConvertUnit(page_size_in_pixels.width,
+ kPixelsPerInch, dpi),
+ ConvertUnit(page_size_in_pixels.height,
Lei Zhang 2016/07/06 18:26:45 Just run: clang-format -i -style=Chromium $file, a
+ kPixelsPerInch, dpi));
page_css_params.content_size =
gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi),
- ConvertUnit(new_content_height, kPixelsPerInch, dpi));
-
- if (original_page_size_in_pixels != page_size_in_pixels) {
- page_css_params.page_size =
- gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi),
- ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi));
- } else {
- // Printing frame doesn't have any page size css. Pixels to dpi conversion
- // causes rounding off errors. Therefore use the default page size values
- // directly.
- page_css_params.page_size = page_params.page_size;
- }
+ ConvertUnit(new_content_height, kPixelsPerInch, dpi));
page_css_params.margin_top =
ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi);
« no previous file with comments | « no previous file | printing/units.h » ('j') | third_party/WebKit/public/web/WebFrame.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698