Chromium Code Reviews| 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 b31cd851cfe5213c2219515b3dde4681cd01e5f7..75dc9c21093e7f7f5fd3bb91afb98d0287c186c7 100644 |
| --- a/chrome/renderer/print_web_view_helper.cc |
| +++ b/chrome/renderer/print_web_view_helper.cc |
| @@ -341,6 +341,15 @@ printing::MarginType GetMarginsForPdf(WebFrame* frame, const WebNode& node) { |
| return printing::PRINTABLE_AREA_MARGINS; |
| } |
| +bool FitToPageEnabled(const DictionaryValue& job_settings) { |
| + bool fit_to_paper_size = false; |
| + if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled, |
| + &fit_to_paper_size)) { |
| + NOTREACHED(); |
| + } |
| + return fit_to_paper_size; |
| +} |
| + |
| // Get the (x, y) coordinate from where printing of the current text should |
| // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and |
| // vertical alignment (TOP, BOTTOM). |
| @@ -833,6 +842,43 @@ bool PrintWebViewHelper::IsPrintToPdfRequested( |
| return print_to_pdf; |
| } |
| +void PrintWebViewHelper::UpdateFitToPageInfo( |
| + WebKit::WebFrame* frame, const WebKit::WebNode& node, |
| + const DictionaryValue& job_settings, PrintMsg_PrintPages_Params* settings) { |
| + bool source_is_html = true; |
|
Lei Zhang
2012/04/26 22:57:53
This first bit of logic is the same as PrintWebVie
kmadhusu
2012/04/27 01:28:58
Done.
|
| + if (print_for_preview_) { |
| + if (!job_settings.GetBoolean(printing::kSettingPreviewModifiable, |
| + &source_is_html)) { |
| + NOTREACHED(); |
| + } |
| + } else { |
| + source_is_html = !PrintingNodeOrFrame(frame, node); |
|
Lei Zhang
2012/04/26 22:57:53
I don't think this will compile.
kmadhusu
2012/04/27 01:28:58
oops.. My commit is messed up while resolving a co
|
| + } |
| + |
| + settings->params.fit_to_paper_size = true; |
| + if (print_for_preview_ || settings->params.print_to_pdf) { |
| + // Do not fit to paper size when the user is printing the preview data or |
| + // saving the print contents as pdf. |
| + settings->params.fit_to_paper_size = false; |
| + } else if (!source_is_html) { |
| + // PDF in initiator renderer. Get the print scaling option for the initiator |
| + // renderer pdf. |
| + bool print_scaling_disabled = frame->isPrintScalingDisabledForPlugin(node); |
| + |
| + // If this is the first preview request, UI doesn't know about the print |
| + // scaling option of the plugin. Therefore, check the print scaling option |
| + // and update the print params accordingly. |
| + // |
| + // If this is not the first preview request, update print params based on |
| + // preview job settings. |
| + if ((settings.params.is_first_request && |
| + print_scaling_disabled_for_plugin) || |
| + !FitToPageEnabled(job_settings)) { |
| + settings->params.fit_to_paper_size = false; |
| + } |
| + } |
| +} |
| + |
| void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| DCHECK(is_preview_enabled_); |
| print_preview_context_.OnPrintPreview(); |
| @@ -867,6 +913,16 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| preview_params)); |
| return; |
| } |
| + |
| + // If we are previewing a pdf and the print scaling is disabled, send a |
| + // message to browser. |
| + if (!print_preview_context_.IsModifiable() && |
| + print_pages_params_->params.is_first_request && |
| + print_preview_context_.frame()->isPrintScalingDisabledForPlugin( |
| + print_preview_context_.node())) { |
| + Send(new PrintHostMsg_PrintPreviewScalingDisabled(routing_id())); |
| + } |
| + |
| // Always clear |old_print_pages_params_| before rendering the pages. |
| old_print_pages_params_.reset(); |
| is_print_ready_metafile_sent_ = false; |
| @@ -1310,23 +1366,7 @@ bool PrintWebViewHelper::UpdatePrintSettings( |
| modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| false); |
| - // - On Windows, we don't add a margin until we turn it into an EMF when |
|
Lei Zhang
2012/04/26 22:52:23
BTW, why are we removing this?
kmadhusu
2012/04/27 01:28:58
While printing pdf for print preview, we have alre
Lei Zhang
2012/04/27 04:32:47
Ok, can you also get rid of |margin_type| then?
kmadhusu
2012/05/01 16:43:15
Done.
|
| - // printing for print preview (We could add it in the plugin). |
| - // - On Mac with Skia, we don't add a margin until we send it to the printer |
| - // using the CG PDF class (We could add it in the plugin). |
| - // - On Mac with CG, we can add a margin when generating the preview. |
| - // - On Linux, we never add a margin (We Could add it in the plugin). |
| -#if defined(OS_MACOSX) && !defined(USE_SKIA) |
| - bool get_margins_from_pdf = !source_is_html && !print_for_preview_; |
| -#elif defined(OS_WIN) || defined(OS_MACOSX) |
| - bool get_margins_from_pdf = !source_is_html && print_for_preview_; |
| -#else |
| - bool get_margins_from_pdf = false; |
| -#endif |
| - |
| printing::MarginType margin_type = printing::NO_MARGINS; |
| - if (get_margins_from_pdf) |
| - margin_type = GetMarginsForPdf(frame, node); |
| modified_job_settings.SetInteger(printing::kSettingMarginsType, |
| margin_type); |
| job_settings = &modified_job_settings; |
| @@ -1380,10 +1420,7 @@ bool PrintWebViewHelper::UpdatePrintSettings( |
| settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); |
| UpdateFrameMarginsCssInfo(*job_settings); |
| - |
| - // Fit to paper size. |
| - settings.params.fit_to_paper_size = source_is_html && |
| - !IsPrintToPdfRequested(*job_settings); |
| + UpdateFitToPageInfo(frame, node, job_settings, &settings); |
| // Header/Footer: Set |header_footer_info_|. |
| if (settings.params.display_header_footer) { |