Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 oldParams.pages.size() == newParams.pages.size() && | 102 oldParams.pages.size() == newParams.pages.size() && |
| 103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && | 103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && |
| 104 oldParams.params.print_scaling_option == | 104 oldParams.params.print_scaling_option == |
| 105 newParams.params.print_scaling_option && | 105 newParams.params.print_scaling_option && |
| 106 oldParams.params.display_header_footer == | 106 oldParams.params.display_header_footer == |
| 107 newParams.params.display_header_footer && | 107 newParams.params.display_header_footer && |
| 108 oldParams.params.date == newParams.params.date && | 108 oldParams.params.date == newParams.params.date && |
| 109 oldParams.params.title == newParams.params.title && | 109 oldParams.params.title == newParams.params.title && |
| 110 oldParams.params.url == newParams.params.url && | 110 oldParams.params.url == newParams.params.url && |
| 111 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 111 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
| 112 newParams.pages.begin()); | 112 newParams.pages.begin()) && |
| 113 oldParams.params.should_print_backgrounds == | |
| 114 newParams.params.should_print_backgrounds; | |
| 113 } | 115 } |
| 114 | 116 |
| 115 PrintMsg_Print_Params GetCssPrintParams( | 117 PrintMsg_Print_Params GetCssPrintParams( |
| 116 WebKit::WebFrame* frame, | 118 WebKit::WebFrame* frame, |
| 117 int page_index, | 119 int page_index, |
| 118 const PrintMsg_Print_Params& page_params) { | 120 const PrintMsg_Print_Params& page_params) { |
| 119 PrintMsg_Print_Params page_css_params = page_params; | 121 PrintMsg_Print_Params page_css_params = page_params; |
| 120 int dpi = GetDPI(&page_params); | 122 int dpi = GetDPI(&page_params); |
| 121 | 123 |
| 122 using printing::ConvertUnit; | 124 using printing::ConvertUnit; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 web_print_params_ = webkit_print_params; | 532 web_print_params_ = webkit_print_params; |
| 531 | 533 |
| 532 // Layout page according to printer page size. Since WebKit shrinks the | 534 // Layout page according to printer page size. Since WebKit shrinks the |
| 533 // size of the page automatically (from 125% to 200%) we trick it to | 535 // size of the page automatically (from 125% to 200%) we trick it to |
| 534 // think the page is 125% larger so the size of the page is correct for | 536 // think the page is 125% larger so the size of the page is correct for |
| 535 // minimum (default) scaling. | 537 // minimum (default) scaling. |
| 536 // This is important for sites that try to fill the page. | 538 // This is important for sites that try to fill the page. |
| 537 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 539 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
| 538 web_print_params_.printContentArea.height); | 540 web_print_params_.printContentArea.height); |
| 539 print_layout_size.set_height(static_cast<int>( | 541 print_layout_size.set_height(static_cast<int>( |
| 540 static_cast<double>(print_layout_size.height()) * 1.25)); | 542 static_cast<double>(print_layout_size.height()) * 1.25)); |
|
Vitaly Buka (NO REVIEWS)
2013/01/10 21:16:56
Probably you should set flag here.
PrepareFrameAnd
Toscano
2013/01/10 22:27:25
Done.
| |
| 541 | 543 |
| 542 web_view_->resize(print_layout_size); | 544 web_view_->resize(print_layout_size); |
| 543 | 545 |
| 544 expected_pages_count_ = frame_->printBegin(web_print_params_, | 546 expected_pages_count_ = frame_->printBegin(web_print_params_, |
| 545 node_to_print_, | 547 node_to_print_, |
| 546 &use_browser_overlays_); | 548 &use_browser_overlays_); |
| 547 } | 549 } |
| 548 | 550 |
| 549 void PrepareFrameAndViewForPrint::FinishPrinting() { | 551 void PrepareFrameAndViewForPrint::FinishPrinting() { |
| 550 if (!finished_) { | 552 if (!finished_) { |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1283 job_settings = &modified_job_settings; | 1285 job_settings = &modified_job_settings; |
| 1284 } | 1286 } |
| 1285 | 1287 |
| 1286 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when | 1288 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when |
| 1287 // possible. | 1289 // possible. |
| 1288 int cookie = print_pages_params_.get() ? | 1290 int cookie = print_pages_params_.get() ? |
| 1289 print_pages_params_->params.document_cookie : 0; | 1291 print_pages_params_->params.document_cookie : 0; |
| 1290 PrintMsg_PrintPages_Params settings; | 1292 PrintMsg_PrintPages_Params settings; |
| 1291 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 1293 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 1292 cookie, *job_settings, &settings)); | 1294 cookie, *job_settings, &settings)); |
| 1295 | |
| 1296 // Apply whether to print CSS backgrounds. | |
| 1297 bool shouldPrintBackgrounds = false; | |
| 1298 job_settings->GetBoolean(printing::kSettingShouldPrintBackgrounds, | |
| 1299 &shouldPrintBackgrounds); | |
| 1300 frame->view()->settings()->setShouldPrintBackgrounds(shouldPrintBackgrounds); | |
|
Lei Zhang
2013/01/10 23:30:11
This probably should go into PrintWebViewHelper::P
Toscano
2013/01/11 00:19:23
Hey Lei, I actually moved this to inside of the Pr
| |
| 1301 settings.params.should_print_backgrounds = shouldPrintBackgrounds; | |
| 1302 | |
| 1293 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1303 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1294 | 1304 |
| 1295 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1305 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
| 1296 if (!print_for_preview_) { | 1306 if (!print_for_preview_) { |
| 1297 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1307 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
| 1298 } else { | 1308 } else { |
| 1299 // PrintForPrintPreview | 1309 // PrintForPrintPreview |
| 1300 WebKit::WebFrame* print_frame = NULL; | 1310 WebKit::WebFrame* print_frame = NULL; |
| 1301 // This may not be the right frame, but the alert will be modal, | 1311 // This may not be the right frame, but the alert will be modal, |
| 1302 // therefore it works well enough. | 1312 // therefore it works well enough. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, | 1352 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, |
| 1343 settings.params.url); | 1353 settings.params.url); |
| 1344 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, | 1354 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, |
| 1345 settings.params.title); | 1355 settings.params.title); |
| 1346 } | 1356 } |
| 1347 } | 1357 } |
| 1348 | 1358 |
| 1349 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1359 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1350 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1360 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1351 settings.params.document_cookie)); | 1361 settings.params.document_cookie)); |
| 1362 | |
| 1352 return true; | 1363 return true; |
| 1353 } | 1364 } |
| 1354 | 1365 |
| 1355 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 1366 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 1356 const WebKit::WebNode& node, | 1367 const WebKit::WebNode& node, |
| 1357 int expected_pages_count, | 1368 int expected_pages_count, |
| 1358 bool use_browser_overlays) { | 1369 bool use_browser_overlays) { |
| 1359 PrintHostMsg_ScriptedPrint_Params params; | 1370 PrintHostMsg_ScriptedPrint_Params params; |
| 1360 PrintMsg_PrintPages_Params print_settings; | 1371 PrintMsg_PrintPages_Params print_settings; |
| 1361 | 1372 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1755 DCHECK(IsRendering()); | 1766 DCHECK(IsRendering()); |
| 1756 return prep_frame_view_->GetPrintCanvasSize(); | 1767 return prep_frame_view_->GetPrintCanvasSize(); |
| 1757 } | 1768 } |
| 1758 | 1769 |
| 1759 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1770 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1760 prep_frame_view_.reset(); | 1771 prep_frame_view_.reset(); |
| 1761 metafile_.reset(); | 1772 metafile_.reset(); |
| 1762 pages_to_render_.clear(); | 1773 pages_to_render_.clear(); |
| 1763 error_ = PREVIEW_ERROR_NONE; | 1774 error_ = PREVIEW_ERROR_NONE; |
| 1764 } | 1775 } |
| OLD | NEW |