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 "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 preview_params.expected_pages_count = | 860 preview_params.expected_pages_count = |
861 print_preview_context_.total_page_count(); | 861 print_preview_context_.total_page_count(); |
862 preview_params.modifiable = print_preview_context_.IsModifiable(); | 862 preview_params.modifiable = print_preview_context_.IsModifiable(); |
863 preview_params.preview_request_id = | 863 preview_params.preview_request_id = |
864 print_pages_params_->params.preview_request_id; | 864 print_pages_params_->params.preview_request_id; |
865 | 865 |
866 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), | 866 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), |
867 preview_params)); | 867 preview_params)); |
868 return; | 868 return; |
869 } | 869 } |
870 | |
871 // If we are previewing a pdf and the print scaling is disabled, send a | |
872 // message to browser. | |
873 if (!print_preview_context_.IsModifiable() && | |
874 print_pages_params_->params.is_first_request && | |
875 print_preview_context_.frame()->isPrintScalingDisabledForPlugin( | |
876 print_preview_context_.node())) { | |
877 Send(new PrintHostMsg_PrintPreviewScalingDisabled(routing_id())); | |
878 } | |
879 | |
870 // Always clear |old_print_pages_params_| before rendering the pages. | 880 // Always clear |old_print_pages_params_| before rendering the pages. |
871 old_print_pages_params_.reset(); | 881 old_print_pages_params_.reset(); |
872 is_print_ready_metafile_sent_ = false; | 882 is_print_ready_metafile_sent_ = false; |
873 | 883 |
874 // PDF printer device supports alpha blending. | 884 // PDF printer device supports alpha blending. |
875 print_pages_params_->params.supports_alpha_blend = true; | 885 print_pages_params_->params.supports_alpha_blend = true; |
876 | 886 |
877 bool generate_draft_pages = false; | 887 bool generate_draft_pages = false; |
878 if (!settings.GetBoolean(printing::kSettingGenerateDraftData, | 888 if (!settings.GetBoolean(printing::kSettingGenerateDraftData, |
879 &generate_draft_pages)) { | 889 &generate_draft_pages)) { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 } | 1313 } |
1304 } else { | 1314 } else { |
1305 source_is_html = !PrintingNodeOrPdfFrame(frame, node); | 1315 source_is_html = !PrintingNodeOrPdfFrame(frame, node); |
1306 } | 1316 } |
1307 | 1317 |
1308 if (print_for_preview_ || !source_is_html) { | 1318 if (print_for_preview_ || !source_is_html) { |
1309 modified_job_settings.MergeDictionary(job_settings); | 1319 modified_job_settings.MergeDictionary(job_settings); |
1310 modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, | 1320 modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, |
1311 false); | 1321 false); |
1312 | 1322 |
1313 // - On Windows, we don't add a margin until we turn it into an EMF when | |
Lei Zhang
2012/04/26 00:19:51
Is this change related to this CL?
kmadhusu
2012/04/26 22:18:51
Yes.
| |
1314 // printing for print preview (We could add it in the plugin). | |
1315 // - On Mac with Skia, we don't add a margin until we send it to the printer | |
1316 // using the CG PDF class (We could add it in the plugin). | |
1317 // - On Mac with CG, we can add a margin when generating the preview. | |
1318 // - On Linux, we never add a margin (We Could add it in the plugin). | |
1319 #if defined(OS_MACOSX) && !defined(USE_SKIA) | |
1320 bool get_margins_from_pdf = !source_is_html && !print_for_preview_; | |
1321 #elif defined(OS_WIN) || defined(OS_MACOSX) | |
1322 bool get_margins_from_pdf = !source_is_html && print_for_preview_; | |
1323 #else | |
1324 bool get_margins_from_pdf = false; | |
1325 #endif | |
1326 | |
1327 printing::MarginType margin_type = printing::NO_MARGINS; | 1323 printing::MarginType margin_type = printing::NO_MARGINS; |
1328 if (get_margins_from_pdf) | |
1329 margin_type = GetMarginsForPdf(frame, node); | |
1330 modified_job_settings.SetInteger(printing::kSettingMarginsType, | 1324 modified_job_settings.SetInteger(printing::kSettingMarginsType, |
1331 margin_type); | 1325 margin_type); |
1332 job_settings = &modified_job_settings; | 1326 job_settings = &modified_job_settings; |
1333 } | 1327 } |
1334 | 1328 |
1335 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when | 1329 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when |
1336 // possible. | 1330 // possible. |
1337 int cookie = print_pages_params_.get() ? | 1331 int cookie = print_pages_params_.get() ? |
1338 print_pages_params_->params.document_cookie : 0; | 1332 print_pages_params_->params.document_cookie : 0; |
1339 PrintMsg_PrintPages_Params settings; | 1333 PrintMsg_PrintPages_Params settings; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 !job_settings->GetBoolean(printing::kIsFirstRequest, | 1368 !job_settings->GetBoolean(printing::kIsFirstRequest, |
1375 &(settings.params.is_first_request))) { | 1369 &(settings.params.is_first_request))) { |
1376 NOTREACHED(); | 1370 NOTREACHED(); |
1377 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1371 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
1378 return false; | 1372 return false; |
1379 } | 1373 } |
1380 | 1374 |
1381 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); | 1375 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); |
1382 UpdateFrameMarginsCssInfo(*job_settings); | 1376 UpdateFrameMarginsCssInfo(*job_settings); |
1383 | 1377 |
1384 // Fit to paper size. | 1378 // Fit to page |
1385 settings.params.fit_to_paper_size = source_is_html && | 1379 // TODO(kmadhusu): Update this code. |
Lei Zhang
2012/04/26 00:19:51
I would move this into its own method with a clear
kmadhusu
2012/04/26 22:18:51
Done.
| |
1386 !IsPrintToPdfRequested(*job_settings); | 1380 settings.params.fit_to_paper_size = true; |
1381 if (print_for_preview_ || settings.params.print_to_pdf) { | |
1382 settings.params.fit_to_paper_size = false; | |
1383 } else if (!source_is_html) { | |
1384 bool fit_to_paper_size = false; | |
1385 if (!job_settings->GetBoolean(printing::kSettingFitToPageEnabled, | |
1386 &(fit_to_paper_size))) { | |
1387 NOTREACHED(); | |
1388 } | |
1389 if ((settings.params.is_first_request && | |
1390 frame->isPrintScalingDisabledForPlugin( | |
1391 print_preview_context_.node())) || | |
1392 !fit_to_paper_size) { | |
1393 settings.params.fit_to_paper_size = false; | |
1394 } | |
1395 } | |
1387 | 1396 |
1388 // Header/Footer: Set |header_footer_info_|. | 1397 // Header/Footer: Set |header_footer_info_|. |
1389 if (settings.params.display_header_footer) { | 1398 if (settings.params.display_header_footer) { |
1390 header_footer_info_.reset(new DictionaryValue()); | 1399 header_footer_info_.reset(new DictionaryValue()); |
1391 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, | 1400 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, |
1392 settings.params.date); | 1401 settings.params.date); |
1393 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, | 1402 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, |
1394 settings.params.url); | 1403 settings.params.url); |
1395 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, | 1404 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, |
1396 settings.params.title); | 1405 settings.params.title); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1820 DCHECK(IsRendering()); | 1829 DCHECK(IsRendering()); |
1821 return prep_frame_view_->GetPrintCanvasSize(); | 1830 return prep_frame_view_->GetPrintCanvasSize(); |
1822 } | 1831 } |
1823 | 1832 |
1824 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1833 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1825 prep_frame_view_.reset(); | 1834 prep_frame_view_.reset(); |
1826 metafile_.reset(); | 1835 metafile_.reset(); |
1827 pages_to_render_.clear(); | 1836 pages_to_render_.clear(); |
1828 error_ = PREVIEW_ERROR_NONE; | 1837 error_ = PREVIEW_ERROR_NONE; |
1829 } | 1838 } |
OLD | NEW |