Index: chrome/renderer/print_web_view_helper.cc |
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc |
index 499b1fd09270125e78d39fe1e8117b9f0dd49485..d616c3b1abab8bb74e975762298eb50383012bd4 100644 |
--- a/chrome/renderer/print_web_view_helper.cc |
+++ b/chrome/renderer/print_web_view_helper.cc |
@@ -109,6 +109,7 @@ bool PrintMsg_Print_Params_IsEmpty(const PrintMsg_Print_Params& params) { |
bool PageLayoutIsEqual(const PrintMsg_PrintPages_Params& oldParams, |
const PrintMsg_PrintPages_Params& newParams) { |
return oldParams.params.content_size == newParams.params.content_size && |
+ oldParams.params.printable_area == newParams.params.printable_area && |
oldParams.params.page_size == newParams.params.page_size && |
oldParams.params.margin_top == newParams.params.margin_top && |
oldParams.params.margin_left == newParams.params.margin_left && |
@@ -126,6 +127,7 @@ bool PrintMsg_Print_Params_IsEqual( |
oldParams.params.supports_alpha_blend == |
newParams.params.supports_alpha_blend && |
oldParams.pages.size() == newParams.pages.size() && |
+ oldParams.params.print_to_pdf == newParams.params.print_to_pdf && |
oldParams.params.display_header_footer == |
newParams.params.display_header_footer && |
oldParams.params.date == newParams.params.date && |
@@ -135,6 +137,165 @@ bool PrintMsg_Print_Params_IsEqual( |
newParams.pages.begin()); |
} |
+void GetPageCssParams( |
vandebo (ex-Chrome)
2012/01/03 21:55:12
nit: GetCssPrintParams ?
nit: return the page_css_
kmadhusu
2012/01/04 16:55:35
Done.
PrintMsg_Print_Params GetCssPageParams(...)
|
+ WebFrame* frame, |
+ int page_index, |
+ const PrintMsg_Print_Params& default_params, |
+ PrintMsg_Print_Params* page_css_params) { |
+ int dpi = GetDPI(&default_params); |
+ WebSize page_size_in_pixels( |
+ ConvertUnit(default_params.page_size.width(), |
+ dpi, printing::kPixelsPerInch), |
+ ConvertUnit(default_params.page_size.height(), |
+ dpi, printing::kPixelsPerInch)); |
+ int margin_top_in_pixels = ConvertUnit( |
+ default_params.margin_top, |
+ dpi, printing::kPixelsPerInch); |
+ int margin_right_in_pixels = ConvertUnit( |
+ default_params.page_size.width() - |
+ default_params.content_size.width() - default_params.margin_left, |
+ dpi, printing::kPixelsPerInch); |
+ int margin_bottom_in_pixels = ConvertUnit( |
+ default_params.page_size.height() - |
+ default_params.content_size.height() - default_params.margin_top, |
+ dpi, printing::kPixelsPerInch); |
+ int margin_left_in_pixels = ConvertUnit( |
+ default_params.margin_left, |
+ dpi, printing::kPixelsPerInch); |
+ |
+ if (frame) { |
+ frame->pageSizeAndMarginsInPixels(page_index, |
+ page_size_in_pixels, |
+ margin_top_in_pixels, |
+ margin_right_in_pixels, |
+ margin_bottom_in_pixels, |
+ margin_left_in_pixels); |
+ } |
+ |
+ int 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 - |
+ margin_top_in_pixels - margin_bottom_in_pixels; |
+ |
+ // Invalid page size and/or margins. We just use the default setting. |
+ if (new_content_width < 1 || new_content_height < 1) { |
+ CHECK(frame != NULL); |
+ GetPageCssParams(NULL, page_index, default_params, page_css_params); |
+ return; |
+ } |
+ |
+ page_css_params->content_size = gfx::Size( |
+ static_cast<int>(ConvertUnit(new_content_width, |
+ printing::kPixelsPerInch, dpi)), |
+ static_cast<int>(ConvertUnit(new_content_height, |
+ printing::kPixelsPerInch, dpi))); |
+ |
+ page_css_params->page_size = gfx::Size( |
+ static_cast<int>(ConvertUnit(page_size_in_pixels.width, |
+ printing::kPixelsPerInch, dpi)), |
+ static_cast<int>(ConvertUnit(page_size_in_pixels.height, |
+ printing::kPixelsPerInch, dpi))); |
+ |
+ page_css_params->margin_top = |
+ static_cast<int>(ConvertUnit(margin_top_in_pixels, |
+ printing::kPixelsPerInch, dpi)); |
+ |
+ page_css_params->margin_left = |
+ static_cast<int>(ConvertUnit(margin_left_in_pixels, |
+ printing::kPixelsPerInch, dpi)); |
+} |
+ |
+void IgnoreCssMarginsAndUpdateParams( |
+ const PrintMsg_Print_Params& default_params, |
+ bool fit_to_page, |
+ PrintMsg_Print_Params* page_css_params) { |
+ page_css_params->margin_top = default_params.margin_top; |
+ page_css_params->margin_left = default_params.margin_left; |
+ |
+ // Since we are ignoring the margins, the css page size is no longer |
+ // valid. |
+ if (fit_to_page) { |
+ page_css_params->content_size = default_params.content_size; |
+ page_css_params->page_size = default_params.page_size; |
+ } else { |
+ int default_margin_right= default_params.page_size.width() - |
+ default_params.content_size.width() - default_params.margin_left; |
+ int default_margin_bottom = default_params.page_size.height() - |
+ default_params.content_size.height() - default_params.margin_top; |
+ page_css_params->content_size = gfx::Size( |
vandebo (ex-Chrome)
2012/01/03 21:55:12
Is the value calculated here just default_params.c
kmadhusu
2012/01/04 16:55:35
No. page_css_params->page_size != default_params.p
|
+ page_css_params->page_size.width() - page_css_params->margin_left - |
+ default_margin_right, |
+ page_css_params->page_size.height() - page_css_params->margin_top - |
+ default_margin_bottom); |
+ } |
+} |
+ |
+void UpdateCssParamsToFitPaperSize( |
vandebo (ex-Chrome)
2012/01/03 21:55:12
double/*scale_factor*/ FitPrintParamsToPage(const
kmadhusu
2012/01/04 16:55:35
Done.
|
+ const PrintMsg_Print_Params& default_params, |
+ PrintMsg_Print_Params* page_css_params, |
+ double* scale_factor) { |
+ double content_width = (double)page_css_params->content_size.width(); |
vandebo (ex-Chrome)
2012/01/03 21:55:12
I don't think a cast is needed, but if it is, use
kmadhusu
2012/01/04 16:55:35
Done. (double) => static_cast<double>()
|
+ double content_height = (double)page_css_params->content_size.height(); |
+ int default_page_size_height = default_params.page_size.height(); |
vandebo (ex-Chrome)
2012/01/03 21:55:12
It looks like you don't need the variables introdu
kmadhusu
2012/01/04 16:55:35
Removed |margin_top| and |margin_left|.
|new_page_
|
+ int default_page_size_width = default_params.page_size.width(); |
+ int new_page_box_height = page_css_params->page_size.height(); |
+ int new_page_box_width = page_css_params->page_size.width(); |
+ int margin_top = page_css_params->margin_top; |
+ int margin_left = page_css_params->margin_left; |
+ |
+ if (default_params.page_size != page_css_params->page_size) { |
vandebo (ex-Chrome)
2012/01/03 21:55:12
negate this and push it up to the top:
if (default
kmadhusu
2012/01/04 16:55:35
Done.
|
+ double factor = 1.0f; |
+ if (default_page_size_width < new_page_box_width || |
+ default_page_size_height < new_page_box_height) { |
+ double ratio_width = (double) default_params.printable_area.width() / |
+ new_page_box_width; |
+ double ratio_height = (double) default_params.printable_area.height() / |
+ new_page_box_height; |
+ factor = ratio_width < ratio_height ? ratio_width : ratio_height; |
+ if (scale_factor) |
+ *scale_factor = factor; |
+ |
+ content_width *= factor; |
+ content_height *= factor; |
+ } |
+ page_css_params->margin_top = static_cast<int>( |
+ (default_page_size_height - new_page_box_height * factor)/2 + |
+ (margin_top * factor)); |
+ page_css_params->margin_left = static_cast<int>( |
+ (default_page_size_width - new_page_box_width * factor)/2 + |
+ (margin_left * factor)); |
+ page_css_params->content_size = gfx::Size( |
+ static_cast<int>(content_width), static_cast<int>(content_height)); |
+ page_css_params->page_size = default_params.page_size; |
+ } |
+} |
+ |
+void CalculatePageLayoutFromCssParams( |
vandebo (ex-Chrome)
2012/01/03 21:55:12
CalculatePageLayoutFromPrintParams (this isn't CSS
kmadhusu
2012/01/04 16:55:35
Done.
|
+ const PrintMsg_Print_Params& page_css_params, |
+ PageSizeMargins* page_layout_in_points) { |
+ int dpi = GetDPI(&page_css_params); |
+ int content_width = page_css_params.content_size.width(); |
+ int content_height = page_css_params.content_size.height(); |
+ |
+ int margin_bottom = page_css_params.page_size.height() - |
+ content_height - page_css_params.margin_top; |
+ int margin_right = page_css_params.page_size.width() - |
+ content_width - page_css_params.margin_left; |
+ |
+ page_layout_in_points->content_width = ConvertUnit( |
+ content_width, dpi, printing::kPointsPerInch); |
+ page_layout_in_points->content_height = ConvertUnit( |
+ content_height, dpi, printing::kPointsPerInch); |
+ page_layout_in_points->margin_top = ConvertUnit( |
+ page_css_params.margin_top, dpi, printing::kPointsPerInch); |
+ page_layout_in_points->margin_right = ConvertUnit( |
+ margin_right, dpi, printing::kPointsPerInch); |
+ page_layout_in_points->margin_bottom = ConvertUnit( |
+ margin_bottom, dpi, printing::kPointsPerInch); |
+ page_layout_in_points->margin_left = ConvertUnit( |
+ page_css_params.margin_left, dpi, printing::kPointsPerInch); |
+} |
+ |
void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params, |
gfx::Size* result) { |
int dpi = GetDPI(&print_params); |
@@ -152,6 +313,19 @@ bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { |
return mime == "application/pdf"; |
} |
+bool PrintingFrameHasPageSizeStyle(WebFrame* frame, int total_page_count) { |
+ if (!frame) |
+ return false; |
+ bool frame_has_custom_page_size_style = false; |
+ for (int i = 0; i < total_page_count; ++i) { |
+ if (frame->hasCustomPageSizeStyle(i)) { |
+ frame_has_custom_page_size_style = true; |
+ break; |
+ } |
+ } |
+ return frame_has_custom_page_size_style; |
+} |
+ |
printing::MarginType GetMarginsForPdf(WebFrame* frame, const WebNode& node) { |
if (frame->isPrintScalingDisabledForPlugin(node)) |
return printing::NO_MARGINS; |
@@ -440,6 +614,8 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
print_web_view_(NULL), |
is_preview_enabled_(switches::IsPrintPreviewEnabled()), |
is_print_ready_metafile_sent_(false), |
+ ignore_css_margins_(false), |
+ fit_to_page_(true), |
user_cancelled_scripted_print_count_(0), |
notify_browser_of_print_failure_(true) { |
} |
@@ -560,6 +736,39 @@ void PrintWebViewHelper::OnPrintForSystemDialog() { |
Print(frame, print_preview_context_.node()); |
} |
+void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
+ const printing::PageSizeMargins& page_layout_in_points, |
+ gfx::Size* page_size, |
+ gfx::Rect* content_area) { |
+ *page_size = gfx::Size( |
+ page_layout_in_points.content_width + |
+ page_layout_in_points.margin_right + |
+ page_layout_in_points.margin_left, |
+ page_layout_in_points.content_height + |
+ page_layout_in_points.margin_top + |
+ page_layout_in_points.margin_bottom); |
+ *content_area = gfx::Rect(page_layout_in_points.margin_left, |
+ page_layout_in_points.margin_top, |
+ page_layout_in_points.content_width, |
+ page_layout_in_points.content_height); |
+} |
+ |
+void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
+ const DictionaryValue& settings) { |
+ int margins_type = 0; |
+ if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) |
+ margins_type = printing::DEFAULT_MARGINS; |
+ ignore_css_margins_ = margins_type != printing::DEFAULT_MARGINS; |
+} |
+ |
+bool PrintWebViewHelper::IsPrintToPdfRequested( |
+ const DictionaryValue& job_settings) { |
+ bool print_to_pdf = false; |
+ if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) |
+ NOTREACHED(); |
+ return print_to_pdf; |
+} |
+ |
void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
DCHECK(is_preview_enabled_); |
print_preview_context_.OnPrintPreview(); |
@@ -620,8 +829,26 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
bool PrintWebViewHelper::CreatePreviewDocument() { |
PrintMsg_Print_Params print_params = print_pages_params_->params; |
const std::vector<int>& pages = print_pages_params_->pages; |
- if (!print_preview_context_.CreatePreviewDocument(&print_params, pages)) |
+ if (!print_preview_context_.CreatePreviewDocument( |
+ &print_params, pages, ignore_css_margins_, |
vandebo (ex-Chrome)
2012/01/03 21:55:12
nit: don't need to indent four - will fit equally
kmadhusu
2012/01/04 16:55:35
Done.
|
+ fit_to_page_)) { |
return false; |
+ } |
+ |
+ PageSizeMargins default_page_layout; |
+ ComputePageLayout(print_preview_context_.frame(), 0, print_params, |
+ ignore_css_margins_, fit_to_page_, NULL, |
+ &default_page_layout); |
+ if (!old_print_pages_params_.get() || |
+ !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { |
+ bool has_page_size_style = PrintingFrameHasPageSizeStyle( |
+ print_preview_context_.frame(), |
+ print_preview_context_.total_page_count()); |
+ // Margins: Send default page layout to browser process. |
+ Send(new PrintHostMsg_DidGetDefaultPageLayout( |
+ routing_id(), default_page_layout, has_page_size_style)); |
+ } |
+ |
PrintHostMsg_DidGetPreviewPageCount_Params params; |
params.page_count = print_preview_context_.total_page_count(); |
params.is_modifiable = print_preview_context_.IsModifiable(); |
@@ -841,8 +1068,9 @@ bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, |
const WebNode& node) { |
PrintMsg_Print_Params print_params = params.params; |
PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); |
- UpdatePrintableSizeInPrintParameters(frame, node, &prep_frame_view, |
- &print_params); |
+ UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, |
+ print_params, ignore_css_margins_, |
+ fit_to_page_); |
int page_count = prep_frame_view.GetExpectedPageCount(); |
if (!page_count) |
@@ -878,90 +1106,51 @@ void PrintWebViewHelper::didStopLoading() { |
} |
// static - Not anonymous so that platform implementations can use it. |
-void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( |
+void PrintWebViewHelper::ComputePageLayout( |
WebFrame* frame, |
int page_index, |
const PrintMsg_Print_Params& default_params, |
+ bool ignore_css_margins, |
+ bool fit_to_page, |
+ double* scale_factor, |
PageSizeMargins* page_layout_in_points) { |
- int dpi = GetDPI(&default_params); |
- |
- WebSize page_size_in_pixels( |
- ConvertUnit(default_params.page_size.width(), |
- dpi, printing::kPixelsPerInch), |
- ConvertUnit(default_params.page_size.height(), |
- dpi, printing::kPixelsPerInch)); |
- int margin_top_in_pixels = ConvertUnit( |
- default_params.margin_top, |
- dpi, printing::kPixelsPerInch); |
- int margin_right_in_pixels = ConvertUnit( |
- default_params.page_size.width() - |
- default_params.content_size.width() - default_params.margin_left, |
- dpi, printing::kPixelsPerInch); |
- int margin_bottom_in_pixels = ConvertUnit( |
- default_params.page_size.height() - |
- default_params.content_size.height() - default_params.margin_top, |
- dpi, printing::kPixelsPerInch); |
- int margin_left_in_pixels = ConvertUnit( |
- default_params.margin_left, |
- dpi, printing::kPixelsPerInch); |
- |
- if (frame) { |
- frame->pageSizeAndMarginsInPixels(page_index, |
- page_size_in_pixels, |
- margin_top_in_pixels, |
- margin_right_in_pixels, |
- margin_bottom_in_pixels, |
- margin_left_in_pixels); |
+ PrintMsg_Print_Params page_css_params = default_params; |
vandebo (ex-Chrome)
2012/01/03 21:55:12
I don't think we need to copy it here, since GetPa
vandebo (ex-Chrome)
2012/01/03 21:55:12
Instead of calling it page_css_params (which is on
kmadhusu
2012/01/04 16:55:35
Done. page_css_params => params
kmadhusu
2012/01/04 16:55:35
GetPageCssParams only fills "page_size, content_si
|
+ GetPageCssParams(frame, page_index, default_params, &page_css_params); |
vandebo (ex-Chrome)
2012/01/03 21:55:12
Is it correct that we don't need to call this if i
kmadhusu
2012/01/04 16:55:35
Done.
|
+ if (ignore_css_margins) { |
+ IgnoreCssMarginsAndUpdateParams(default_params, fit_to_page, |
vandebo (ex-Chrome)
2012/01/03 21:55:12
nit: I'd probably put the contents of this method
kmadhusu
2012/01/04 16:55:35
Done.
|
+ &page_css_params); |
} |
- page_layout_in_points->content_width = |
- ConvertPixelsToPoint(page_size_in_pixels.width - |
- margin_left_in_pixels - |
- margin_right_in_pixels); |
- page_layout_in_points->content_height = |
- ConvertPixelsToPoint(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. |
- if (page_layout_in_points->content_width < 1.0 || |
- page_layout_in_points->content_height < 1.0) { |
- CHECK(frame != NULL); |
- GetPageSizeAndMarginsInPoints(NULL, page_index, default_params, |
- page_layout_in_points); |
- return; |
+ if (fit_to_page) { |
+ UpdateCssParamsToFitPaperSize(default_params, &page_css_params, |
+ scale_factor); |
} |
- |
- page_layout_in_points->margin_top = |
- ConvertPixelsToPointDouble(margin_top_in_pixels); |
- page_layout_in_points->margin_right = |
- ConvertPixelsToPointDouble(margin_right_in_pixels); |
- page_layout_in_points->margin_bottom = |
- ConvertPixelsToPointDouble(margin_bottom_in_pixels); |
- page_layout_in_points->margin_left = |
- ConvertPixelsToPointDouble(margin_left_in_pixels); |
+ CalculatePageLayoutFromCssParams(page_css_params, page_layout_in_points); |
} |
// static - Not anonymous so that platform implementations can use it. |
-void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( |
+void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( |
WebFrame* frame, |
const WebNode& node, |
PrepareFrameAndViewForPrint* prepare, |
- PrintMsg_Print_Params* params) { |
+ const PrintMsg_Print_Params& params, |
+ bool ignore_css_margins, |
+ bool fit_to_page) { |
if (PrintingNodeOrPdfFrame(frame, node)) |
return; |
PageSizeMargins page_layout_in_points; |
- PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, |
- &page_layout_in_points); |
- int dpi = GetDPI(params); |
- params->content_size = gfx::Size( |
+ PrintMsg_Print_Params current_params = params; |
+ PrintWebViewHelper::ComputePageLayout(frame, 0, current_params, |
vandebo (ex-Chrome)
2012/01/03 21:55:12
It seems that this caller of ComputePageLayout act
kmadhusu
2012/01/04 16:55:35
ComputePageLayout is divided into two different fu
|
+ ignore_css_margins, ignore_css_margins && fit_to_page, NULL, |
+ &page_layout_in_points); |
+ int dpi = GetDPI(¤t_params); |
+ current_params.content_size = gfx::Size( |
static_cast<int>(ConvertUnitDouble( |
page_layout_in_points.content_width, |
printing::kPointsPerInch, dpi)), |
static_cast<int>(ConvertUnitDouble( |
page_layout_in_points.content_height, |
printing::kPointsPerInch, dpi))); |
- |
double page_width_in_points = |
page_layout_in_points.content_width + |
page_layout_in_points.margin_left + |
@@ -971,18 +1160,17 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( |
page_layout_in_points.margin_top + |
page_layout_in_points.margin_bottom; |
- params->page_size = gfx::Size( |
+ current_params.page_size = gfx::Size( |
static_cast<int>(ConvertUnitDouble( |
page_width_in_points, printing::kPointsPerInch, dpi)), |
static_cast<int>(ConvertUnitDouble( |
page_height_in_points, printing::kPointsPerInch, dpi))); |
- |
- params->margin_top = static_cast<int>(ConvertUnitDouble( |
- page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); |
- params->margin_left = static_cast<int>(ConvertUnitDouble( |
+ current_params.margin_top = |
+ static_cast<int>(ConvertUnitDouble( |
+ page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); |
+ current_params.margin_left = static_cast<int>(ConvertUnitDouble( |
page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); |
- |
- prepare->UpdatePrintParams(*params); |
+ prepare->UpdatePrintParams(current_params); |
} |
bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, |
@@ -990,6 +1178,10 @@ bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, |
DCHECK(frame); |
PrintMsg_PrintPages_Params settings; |
+ // Reset to default values. |
+ ignore_css_margins_ = false; |
+ fit_to_page_ = true; |
+ |
Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
&settings.params)); |
// Check if the printer returned any settings, if the settings is empty, we |
@@ -1025,8 +1217,9 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
DCHECK(!prepare->get()); |
prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
frame, node)); |
- UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), |
- &print_pages_params_->params); |
+ UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), |
+ print_pages_params_->params, |
+ ignore_css_margins_, fit_to_page_); |
Send(new PrintHostMsg_DidGetDocumentCookie( |
routing_id(), print_pages_params_->params.document_cookie)); |
return true; |
@@ -1127,15 +1320,9 @@ bool PrintWebViewHelper::UpdatePrintSettings( |
return false; |
} |
- // Margins: Send default page layout to browser process. |
- PageSizeMargins default_page_layout; |
- GetPageSizeAndMarginsInPoints(NULL, -1, settings.params, |
- &default_page_layout); |
- if (!old_print_pages_params_.get() || |
- !PageLayoutIsEqual(*old_print_pages_params_, settings)) { |
- Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), |
- default_page_layout)); |
- } |
+ settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); |
+ UpdateFrameMarginsCssInfo(*job_settings); |
+ fit_to_page_ = source_is_html && !IsPrintToPdfRequested(*job_settings); |
// Header/Footer: Set |header_footer_info_|. |
if (settings.params.display_header_footer) { |
@@ -1373,7 +1560,9 @@ void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { |
bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
PrintMsg_Print_Params* print_params, |
- const std::vector<int>& pages) { |
+ const std::vector<int>& pages, |
+ bool ignore_css_margins, |
+ bool fit_to_page) { |
DCHECK_EQ(INITIALIZED, state_); |
state_ = RENDERING; |
@@ -1387,8 +1576,9 @@ bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
// Need to make sure old object gets destroyed first. |
prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), |
node())); |
- UpdatePrintableSizeInPrintParameters(frame_, node_, |
- prep_frame_view_.get(), print_params); |
+ UpdateFrameAndViewFromCssPageLayout(frame_, node_, |
+ prep_frame_view_.get(), *print_params, |
+ ignore_css_margins, fit_to_page); |
print_params_.reset(new PrintMsg_Print_Params(*print_params)); |