| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void CalculatePageLayoutFromPrintParams( | 227 void CalculatePageLayoutFromPrintParams( |
| 228 const PrintMsg_Print_Params& params, | 228 const PrintMsg_Print_Params& params, |
| 229 double scale_factor, | 229 double scale_factor, |
| 230 PageSizeMargins* page_layout_in_points) { | 230 PageSizeMargins* page_layout_in_points) { |
| 231 bool fit_to_page = IsWebPrintScalingOptionFitToPage(params); | 231 bool fit_to_page = IsWebPrintScalingOptionFitToPage(params); |
| 232 int dpi = GetDPI(¶ms); | 232 int dpi = GetDPI(¶ms); |
| 233 int content_width = params.content_size.width(); | 233 int content_width = params.content_size.width(); |
| 234 int content_height = params.content_size.height(); | 234 int content_height = params.content_size.height(); |
| 235 // Scale the content to its normal size for purpose of computing page layout. | 235 // Scale the content to its normal size for purpose of computing page layout. |
| 236 // Otherwise we will get negative margins. | 236 // Otherwise we will get negative margins. |
| 237 if (scale_factor > 0 && (fit_to_page || params.print_to_pdf)) { | 237 if (scale_factor >= PrintWebViewHelper::kEpsilon && |
| 238 (fit_to_page || params.print_to_pdf)) { |
| 238 content_width = | 239 content_width = |
| 239 static_cast<int>(static_cast<double>(content_width) * scale_factor); | 240 static_cast<int>(static_cast<double>(content_width) * scale_factor); |
| 240 content_height = | 241 content_height = |
| 241 static_cast<int>(static_cast<double>(content_height) * scale_factor); | 242 static_cast<int>(static_cast<double>(content_height) * scale_factor); |
| 242 } | 243 } |
| 243 | 244 |
| 244 int margin_bottom = | 245 int margin_bottom = |
| 245 params.page_size.height() - content_height - params.margin_top; | 246 params.page_size.height() - content_height - params.margin_top; |
| 246 int margin_right = | 247 int margin_right = |
| 247 params.page_size.width() - content_width - params.margin_left; | 248 params.page_size.width() - content_width - params.margin_left; |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 weak_ptr_factory_(this) { | 715 weak_ptr_factory_(this) { |
| 715 PrintMsg_Print_Params print_params = params; | 716 PrintMsg_Print_Params print_params = params; |
| 716 if (!should_print_selection_only_ || | 717 if (!should_print_selection_only_ || |
| 717 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { | 718 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { |
| 718 bool fit_to_page = | 719 bool fit_to_page = |
| 719 ignore_css_margins && IsWebPrintScalingOptionFitToPage(print_params); | 720 ignore_css_margins && IsWebPrintScalingOptionFitToPage(print_params); |
| 720 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); | 721 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); |
| 721 frame->printBegin(web_print_params_, node_to_print_); | 722 frame->printBegin(web_print_params_, node_to_print_); |
| 722 double scale_factor = 1.0f; | 723 double scale_factor = 1.0f; |
| 723 #if defined(ENABLE_PRINT_PREVIEW) | 724 #if defined(ENABLE_PRINT_PREVIEW) |
| 724 if (print_params.scale_factor > 0) | 725 if (print_params.scale_factor >= PrintWebViewHelper::kEpsilon) |
| 725 scale_factor = print_params.scale_factor; | 726 scale_factor = print_params.scale_factor; |
| 726 #endif | 727 #endif |
| 727 print_params = CalculatePrintParamsForCss( | 728 print_params = CalculatePrintParamsForCss( |
| 728 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor); | 729 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor); |
| 729 frame->printEnd(); | 730 frame->printEnd(); |
| 730 } | 731 } |
| 731 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); | 732 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); |
| 732 } | 733 } |
| 733 | 734 |
| 734 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 735 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1226 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1226 const std::vector<int>& pages = print_pages_params_->pages; | 1227 const std::vector<int>& pages = print_pages_params_->pages; |
| 1227 | 1228 |
| 1228 if (!print_preview_context_.CreatePreviewDocument(prep_frame_view_.release(), | 1229 if (!print_preview_context_.CreatePreviewDocument(prep_frame_view_.release(), |
| 1229 pages)) { | 1230 pages)) { |
| 1230 return false; | 1231 return false; |
| 1231 } | 1232 } |
| 1232 | 1233 |
| 1233 PageSizeMargins default_page_layout; | 1234 PageSizeMargins default_page_layout; |
| 1234 double scale_factor = | 1235 double scale_factor = |
| 1235 print_params.scale_factor > 0 ? print_params.scale_factor : 1.0f; | 1236 print_params.scale_factor >= kEpsilon ? print_params.scale_factor : 1.0f; |
| 1236 | 1237 |
| 1237 ComputePageLayoutInPointsForCss(print_preview_context_.prepared_frame(), 0, | 1238 ComputePageLayoutInPointsForCss(print_preview_context_.prepared_frame(), 0, |
| 1238 print_params, ignore_css_margins_, | 1239 print_params, ignore_css_margins_, |
| 1239 &scale_factor, &default_page_layout); | 1240 &scale_factor, &default_page_layout); |
| 1240 bool has_page_size_style = | 1241 bool has_page_size_style = |
| 1241 PrintingFrameHasPageSizeStyle(print_preview_context_.prepared_frame(), | 1242 PrintingFrameHasPageSizeStyle(print_preview_context_.prepared_frame(), |
| 1242 print_preview_context_.total_page_count()); | 1243 print_preview_context_.total_page_count()); |
| 1243 int dpi = GetDPI(&print_params); | 1244 int dpi = GetDPI(&print_params); |
| 1244 | 1245 |
| 1245 gfx::Rect printable_area_in_points( | 1246 gfx::Rect printable_area_in_points( |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 void PrintWebViewHelper::PrintPageInternal( | 1822 void PrintWebViewHelper::PrintPageInternal( |
| 1822 const PrintMsg_PrintPage_Params& params, | 1823 const PrintMsg_PrintPage_Params& params, |
| 1823 blink::WebLocalFrame* frame, | 1824 blink::WebLocalFrame* frame, |
| 1824 PdfMetafileSkia* metafile, | 1825 PdfMetafileSkia* metafile, |
| 1825 gfx::Size* page_size_in_dpi, | 1826 gfx::Size* page_size_in_dpi, |
| 1826 gfx::Rect* content_area_in_dpi) { | 1827 gfx::Rect* content_area_in_dpi) { |
| 1827 PageSizeMargins page_layout_in_points; | 1828 PageSizeMargins page_layout_in_points; |
| 1828 | 1829 |
| 1829 double css_scale_factor = 1.0f; | 1830 double css_scale_factor = 1.0f; |
| 1830 #if defined(ENABLE_PRINT_PREVIEW) | 1831 #if defined(ENABLE_PRINT_PREVIEW) |
| 1831 if (params.params.scale_factor > 0) | 1832 if (params.params.scale_factor >= kEpsilon) |
| 1832 css_scale_factor = params.params.scale_factor; | 1833 css_scale_factor = params.params.scale_factor; |
| 1833 #endif | 1834 #endif |
| 1834 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1835 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 1835 ignore_css_margins_, &css_scale_factor, | 1836 ignore_css_margins_, &css_scale_factor, |
| 1836 &page_layout_in_points); | 1837 &page_layout_in_points); |
| 1837 gfx::Size page_size; | 1838 gfx::Size page_size; |
| 1838 gfx::Rect content_area; | 1839 gfx::Rect content_area; |
| 1839 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 1840 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 1840 &content_area); | 1841 &content_area); |
| 1841 int dpi = static_cast<int>(params.params.dpi); | 1842 int dpi = static_cast<int>(params.params.dpi); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2333 blink::WebConsoleMessage::LevelWarning, message)); | 2334 blink::WebConsoleMessage::LevelWarning, message)); |
| 2334 return false; | 2335 return false; |
| 2335 } | 2336 } |
| 2336 | 2337 |
| 2337 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2338 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2338 // Reset counter on successful print. | 2339 // Reset counter on successful print. |
| 2339 count_ = 0; | 2340 count_ = 0; |
| 2340 } | 2341 } |
| 2341 | 2342 |
| 2342 } // namespace printing | 2343 } // namespace printing |
| OLD | NEW |