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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 // Swap the |width| and |height| values. | 295 // Swap the |width| and |height| values. |
296 page_params->page_size.SetSize(page_params->page_size.height(), | 296 page_params->page_size.SetSize(page_params->page_size.height(), |
297 page_params->page_size.width()); | 297 page_params->page_size.width()); |
298 page_params->content_size.SetSize(page_params->content_size.height(), | 298 page_params->content_size.SetSize(page_params->content_size.height(), |
299 page_params->content_size.width()); | 299 page_params->content_size.width()); |
300 page_params->printable_area.set_size( | 300 page_params->printable_area.set_size( |
301 gfx::Size(page_params->printable_area.height(), | 301 gfx::Size(page_params->printable_area.height(), |
302 page_params->printable_area.width())); | 302 page_params->printable_area.width())); |
303 } | 303 } |
304 | 304 |
305 void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params, | 305 void ComputePrintParamsInDesiredDpi(const PrintMsg_Print_Params& print_params, |
306 gfx::Size* result) { | 306 gfx::Size* content_size, |
307 gfx::Rect* printable_area, | |
308 gfx::Size* paper_size) { | |
307 int dpi = GetDPI(&print_params); | 309 int dpi = GetDPI(&print_params); |
308 result->set_width(ConvertUnit(print_params.content_size.width(), dpi, | 310 content_size->set_width(ConvertUnit(print_params.content_size.width(), dpi, |
309 print_params.desired_dpi)); | 311 print_params.desired_dpi)); |
310 | 312 |
311 result->set_height(ConvertUnit(print_params.content_size.height(), dpi, | 313 content_size->set_height(ConvertUnit(print_params.content_size.height(), dpi, |
312 print_params.desired_dpi)); | 314 print_params.desired_dpi)); |
315 | |
316 printable_area->SetRect(ConvertUnit(print_params.printable_area.x(), dpi, | |
317 print_params.desired_dpi), | |
318 ConvertUnit(print_params.printable_area.y(), dpi, | |
319 print_params.desired_dpi), | |
320 ConvertUnit(print_params.printable_area.width(), dpi, | |
321 print_params.desired_dpi), | |
322 ConvertUnit(print_params.printable_area.height(), dpi, | |
323 print_params.desired_dpi)); | |
324 paper_size->SetSize(ConvertUnit(print_params.page_size.width(), dpi, | |
325 print_params.desired_dpi), | |
326 ConvertUnit(print_params.page_size.height(), dpi, | |
327 print_params.desired_dpi)); | |
313 } | 328 } |
314 | 329 |
315 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { | 330 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { |
316 if (!node.isNull()) | 331 if (!node.isNull()) |
317 return true; | 332 return true; |
318 if (!frame->document().isPluginDocument()) | 333 if (!frame->document().isPluginDocument()) |
319 return false; | 334 return false; |
320 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); | 335 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); |
321 return plugin && plugin->supportsPaginatedPrint(); | 336 return plugin && plugin->supportsPaginatedPrint(); |
322 } | 337 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 } | 608 } |
594 | 609 |
595 #if defined(USE_SKIA) | 610 #if defined(USE_SKIA) |
596 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 611 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
597 #endif | 612 #endif |
598 } | 613 } |
599 | 614 |
600 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 615 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
601 const PrintMsg_Print_Params& print_params, | 616 const PrintMsg_Print_Params& print_params, |
602 WebFrame* frame, | 617 WebFrame* frame, |
603 const WebNode& node) | 618 const WebNode& node, |
619 WebKit::WebPrintScalingOption scaling_option) | |
604 : frame_(frame), | 620 : frame_(frame), |
605 node_to_print_(node), | 621 node_to_print_(node), |
606 web_view_(frame->view()), | 622 web_view_(frame->view()), |
607 dpi_(static_cast<int>(print_params.dpi)), | 623 dpi_(static_cast<int>(print_params.dpi)), |
608 expected_pages_count_(0), | 624 expected_pages_count_(0), |
609 use_browser_overlays_(true), | 625 use_browser_overlays_(true), |
626 print_scaling_option_(scaling_option), | |
610 finished_(false) { | 627 finished_(false) { |
611 gfx::Size canvas_size; | 628 gfx::Size canvas_size; |
612 CalculatePrintCanvasSize(print_params, &canvas_size); | 629 gfx::Rect printable_area; |
630 gfx::Size paper_size; | |
631 ComputePrintParamsInDesiredDpi(print_params, &canvas_size, &printable_area, | |
632 &paper_size); | |
613 | 633 |
614 if (WebFrame* web_frame = web_view_->mainFrame()) | 634 if (WebFrame* web_frame = web_view_->mainFrame()) |
615 prev_scroll_offset_ = web_frame->scrollOffset(); | 635 prev_scroll_offset_ = web_frame->scrollOffset(); |
616 prev_view_size_ = web_view_->size(); | 636 prev_view_size_ = web_view_->size(); |
617 | 637 |
618 StartPrinting(canvas_size); | 638 StartPrinting(canvas_size, printable_area, paper_size); |
619 } | 639 } |
620 | 640 |
621 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 641 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
622 FinishPrinting(); | 642 FinishPrinting(); |
623 } | 643 } |
624 | 644 |
625 void PrepareFrameAndViewForPrint::UpdatePrintParams( | 645 void PrepareFrameAndViewForPrint::UpdatePrintParams( |
626 const PrintMsg_Print_Params& print_params) { | 646 const PrintMsg_Print_Params& print_params) { |
627 DCHECK(!finished_); | 647 DCHECK(!finished_); |
628 gfx::Size canvas_size; | 648 gfx::Size canvas_size; |
629 CalculatePrintCanvasSize(print_params, &canvas_size); | 649 gfx::Rect printable_area; |
630 if (canvas_size == print_canvas_size_) | 650 gfx::Size paper_size; |
651 ComputePrintParamsInDesiredDpi(print_params, &canvas_size, &printable_area, | |
652 &paper_size); | |
653 if (canvas_size == print_canvas_size_ && | |
654 printable_area == printable_area_ && | |
655 paper_size == paper_size_) { | |
631 return; | 656 return; |
657 } | |
632 | 658 |
633 frame_->printEnd(); | 659 frame_->printEnd(); |
634 dpi_ = static_cast<int>(print_params.dpi); | 660 dpi_ = static_cast<int>(print_params.dpi); |
635 StartPrinting(canvas_size); | 661 StartPrinting(canvas_size, printable_area, paper_size); |
636 } | 662 } |
637 | 663 |
638 void PrepareFrameAndViewForPrint::StartPrinting( | 664 void PrepareFrameAndViewForPrint::StartPrinting( |
639 const gfx::Size& print_canvas_size) { | 665 const gfx::Size& print_canvas_size, |
666 const gfx::Rect& printable_area, | |
667 const gfx::Size& paper_size) { | |
640 print_canvas_size_ = print_canvas_size; | 668 print_canvas_size_ = print_canvas_size; |
669 printable_area_ = printable_area; | |
670 paper_size_ = paper_size; | |
641 | 671 |
642 // Layout page according to printer page size. Since WebKit shrinks the | 672 // Layout page according to printer page size. Since WebKit shrinks the |
643 // size of the page automatically (from 125% to 200%) we trick it to | 673 // size of the page automatically (from 125% to 200%) we trick it to |
644 // think the page is 125% larger so the size of the page is correct for | 674 // think the page is 125% larger so the size of the page is correct for |
645 // minimum (default) scaling. | 675 // minimum (default) scaling. |
646 // This is important for sites that try to fill the page. | 676 // This is important for sites that try to fill the page. |
647 gfx::Size print_layout_size(print_canvas_size_); | 677 gfx::Size print_layout_size(print_canvas_size_); |
648 print_layout_size.set_height(static_cast<int>( | 678 print_layout_size.set_height(static_cast<int>( |
649 static_cast<double>(print_layout_size.height()) * 1.25)); | 679 static_cast<double>(print_layout_size.height()) * 1.25)); |
650 | 680 |
651 web_view_->resize(print_layout_size); | 681 web_view_->resize(print_layout_size); |
652 | 682 |
653 expected_pages_count_ = frame_->printBegin(print_canvas_size_, node_to_print_, | 683 expected_pages_count_ = frame_->printBegin(print_canvas_size_, |
654 dpi_, &use_browser_overlays_); | 684 printable_area_, |
685 paper_size_, | |
686 node_to_print_, | |
687 dpi_, | |
688 print_scaling_option_, | |
689 &use_browser_overlays_); | |
655 } | 690 } |
656 | 691 |
657 void PrepareFrameAndViewForPrint::FinishPrinting() { | 692 void PrepareFrameAndViewForPrint::FinishPrinting() { |
658 if (!finished_) { | 693 if (!finished_) { |
659 finished_ = true; | 694 finished_ = true; |
660 frame_->printEnd(); | 695 frame_->printEnd(); |
661 web_view_->resize(prev_view_size_); | 696 web_view_->resize(prev_view_size_); |
662 if (WebFrame* web_frame = web_view_->mainFrame()) | 697 if (WebFrame* web_frame = web_view_->mainFrame()) |
663 web_frame->setScrollOffset(prev_scroll_offset_); | 698 web_frame->setScrollOffset(prev_scroll_offset_); |
664 } | 699 } |
665 } | 700 } |
666 | 701 |
667 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) | 702 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
668 : content::RenderViewObserver(render_view), | 703 : content::RenderViewObserver(render_view), |
669 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 704 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
670 print_web_view_(NULL), | 705 print_web_view_(NULL), |
671 is_preview_enabled_(IsPrintPreviewEnabled()), | 706 is_preview_enabled_(IsPrintPreviewEnabled()), |
672 is_print_ready_metafile_sent_(false), | 707 is_print_ready_metafile_sent_(false), |
673 ignore_css_margins_(false), | 708 ignore_css_margins_(false), |
674 user_cancelled_scripted_print_count_(0), | 709 user_cancelled_scripted_print_count_(0), |
675 is_scripted_printing_blocked_(false), | 710 is_scripted_printing_blocked_(false), |
676 notify_browser_of_print_failure_(true), | 711 notify_browser_of_print_failure_(true), |
677 print_for_preview_(false) { | 712 print_for_preview_(false), |
713 print_scaling_option_(WebKit::WebPrintFitToPrintableArea) { | |
678 } | 714 } |
679 | 715 |
680 PrintWebViewHelper::~PrintWebViewHelper() {} | 716 PrintWebViewHelper::~PrintWebViewHelper() {} |
681 | 717 |
682 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 718 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
683 WebKit::WebFrame* frame) { | 719 WebKit::WebFrame* frame) { |
684 if (is_scripted_printing_blocked_) | 720 if (is_scripted_printing_blocked_) |
685 return false; | 721 return false; |
686 return !IsScriptInitiatedPrintTooFrequent(frame); | 722 return !IsScriptInitiatedPrintTooFrequent(frame); |
687 } | 723 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
887 if (notify_browser_of_print_failure_) | 923 if (notify_browser_of_print_failure_) |
888 LOG(ERROR) << "CreatePreviewDocument failed"; | 924 LOG(ERROR) << "CreatePreviewDocument failed"; |
889 DidFinishPrinting(FAIL_PREVIEW); | 925 DidFinishPrinting(FAIL_PREVIEW); |
890 } | 926 } |
891 } | 927 } |
892 | 928 |
893 bool PrintWebViewHelper::CreatePreviewDocument() { | 929 bool PrintWebViewHelper::CreatePreviewDocument() { |
894 PrintMsg_Print_Params print_params = print_pages_params_->params; | 930 PrintMsg_Print_Params print_params = print_pages_params_->params; |
895 const std::vector<int>& pages = print_pages_params_->pages; | 931 const std::vector<int>& pages = print_pages_params_->pages; |
896 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, | 932 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, |
897 ignore_css_margins_)) { | 933 ignore_css_margins_, |
934 print_scaling_option_)) { | |
898 return false; | 935 return false; |
899 } | 936 } |
900 | 937 |
901 PageSizeMargins default_page_layout; | 938 PageSizeMargins default_page_layout; |
902 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, | 939 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, |
903 print_params, ignore_css_margins_, NULL, | 940 print_params, ignore_css_margins_, NULL, |
904 &default_page_layout); | 941 &default_page_layout); |
905 | 942 |
906 if (!old_print_pages_params_.get() || | 943 if (!old_print_pages_params_.get() || |
907 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { | 944 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 // actual printing. | 1199 // actual printing. |
1163 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); | 1200 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); |
1164 | 1201 |
1165 return true; | 1202 return true; |
1166 } | 1203 } |
1167 | 1204 |
1168 #if defined(OS_MACOSX) || defined(OS_WIN) | 1205 #if defined(OS_MACOSX) || defined(OS_WIN) |
1169 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { | 1206 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { |
1170 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1207 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1171 const PrintMsg_Print_Params& print_params = params.params; | 1208 const PrintMsg_Print_Params& print_params = params.params; |
1172 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); | 1209 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node, |
1210 print_scaling_option_); | |
1173 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, | 1211 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, |
1174 print_params, ignore_css_margins_); | 1212 print_params, ignore_css_margins_); |
1175 | 1213 |
1176 int page_count = prep_frame_view.GetExpectedPageCount(); | 1214 int page_count = prep_frame_view.GetExpectedPageCount(); |
1177 if (!page_count) | 1215 if (!page_count) |
1178 return false; | 1216 return false; |
1179 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 1217 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
1180 print_params.document_cookie, | 1218 print_params.document_cookie, |
1181 page_count)); | 1219 page_count)); |
1182 | 1220 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 const PrintMsg_Print_Params& params, | 1264 const PrintMsg_Print_Params& params, |
1227 bool ignore_css_margins) { | 1265 bool ignore_css_margins) { |
1228 if (PrintingNodeOrPdfFrame(frame, node)) | 1266 if (PrintingNodeOrPdfFrame(frame, node)) |
1229 return; | 1267 return; |
1230 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( | 1268 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( |
1231 frame, 0, params, ignore_css_margins, | 1269 frame, 0, params, ignore_css_margins, |
1232 ignore_css_margins && params.fit_to_paper_size, NULL); | 1270 ignore_css_margins && params.fit_to_paper_size, NULL); |
1233 prepare->UpdatePrintParams(print_params); | 1271 prepare->UpdatePrintParams(print_params); |
1234 } | 1272 } |
1235 | 1273 |
1236 bool PrintWebViewHelper::InitPrintSettings() { | 1274 bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) { |
1237 PrintMsg_PrintPages_Params settings; | 1275 PrintMsg_PrintPages_Params settings; |
1238 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1276 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
1239 &settings.params)); | 1277 &settings.params)); |
1240 // Check if the printer returned any settings, if the settings is empty, we | 1278 // Check if the printer returned any settings, if the settings is empty, we |
1241 // can safely assume there are no printer drivers configured. So we safely | 1279 // can safely assume there are no printer drivers configured. So we safely |
1242 // terminate. | 1280 // terminate. |
1243 bool result = true; | 1281 bool result = true; |
1244 if (!PrintMsg_Print_Params_IsValid(settings.params)) | 1282 if (!PrintMsg_Print_Params_IsValid(settings.params)) |
1245 result = false; | 1283 result = false; |
1246 | 1284 |
1247 if (result && | 1285 if (result && |
1248 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { | 1286 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { |
1249 // Invalid print page settings. | 1287 // Invalid print page settings. |
1250 NOTREACHED(); | 1288 NOTREACHED(); |
1251 result = false; | 1289 result = false; |
1252 } | 1290 } |
1253 | 1291 |
1254 // Reset to default values. | 1292 // Reset to default values. |
1255 ignore_css_margins_ = false; | 1293 ignore_css_margins_ = false; |
1256 settings.params.fit_to_paper_size = true; | |
1257 settings.pages.clear(); | 1294 settings.pages.clear(); |
1295 settings.params.fit_to_paper_size = fit_to_paper_size; | |
1296 | |
1297 // Update the print scaling option. | |
1298 print_scaling_option_ = static_cast<WebKit::WebPrintScalingOption>( | |
vandebo (ex-Chrome)
2012/04/20 23:26:11
This cast is pretty ugly. A conditional or trinar
kmadhusu
2012/04/23 17:39:10
Done... Removed print_scaling_option_ from PrintWe
| |
1299 fit_to_paper_size); | |
1258 | 1300 |
1259 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1301 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
1260 return result; | 1302 return result; |
1261 } | 1303 } |
1262 | 1304 |
1263 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( | 1305 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
1264 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1306 WebKit::WebFrame* frame, const WebKit::WebNode& node, |
1265 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { | 1307 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { |
1266 DCHECK(frame); | 1308 DCHECK(frame); |
1267 if (!InitPrintSettings()) { | 1309 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node) && |
1310 frame->isPrintScalingDisabledForPlugin(node)); | |
1311 if (!InitPrintSettings(fit_to_paper_size)) { | |
1268 notify_browser_of_print_failure_ = false; | 1312 notify_browser_of_print_failure_ = false; |
1269 render_view()->RunModalAlertDialog( | 1313 render_view()->RunModalAlertDialog( |
1270 frame, | 1314 frame, |
1271 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1315 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
1272 return false; | 1316 return false; |
1273 } | 1317 } |
1274 | 1318 |
1275 DCHECK(!prepare->get()); | 1319 DCHECK(!prepare->get()); |
1276 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 1320 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
1277 frame, node)); | 1321 frame, node, |
1322 print_scaling_option_)); | |
1278 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), | 1323 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), |
1279 print_pages_params_->params, | 1324 print_pages_params_->params, |
1280 ignore_css_margins_); | 1325 ignore_css_margins_); |
1281 Send(new PrintHostMsg_DidGetDocumentCookie( | 1326 Send(new PrintHostMsg_DidGetDocumentCookie( |
1282 routing_id(), print_pages_params_->params.document_cookie)); | 1327 routing_id(), print_pages_params_->params.document_cookie)); |
1283 return true; | 1328 return true; |
1284 } | 1329 } |
1285 | 1330 |
1286 bool PrintWebViewHelper::UpdatePrintSettings( | 1331 bool PrintWebViewHelper::UpdatePrintSettings( |
1287 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1332 WebKit::WebFrame* frame, const WebKit::WebNode& node, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 &(settings.params.is_first_request))) { | 1420 &(settings.params.is_first_request))) { |
1376 NOTREACHED(); | 1421 NOTREACHED(); |
1377 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1422 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
1378 return false; | 1423 return false; |
1379 } | 1424 } |
1380 | 1425 |
1381 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); | 1426 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); |
1382 UpdateFrameMarginsCssInfo(*job_settings); | 1427 UpdateFrameMarginsCssInfo(*job_settings); |
1383 | 1428 |
1384 // Fit to paper size. | 1429 // Fit to paper size. |
1385 settings.params.fit_to_paper_size = source_is_html && | 1430 settings.params.fit_to_paper_size = |
vandebo (ex-Chrome)
2012/04/20 23:26:11
At this point, it might be clearer to use an if or
kmadhusu
2012/04/23 17:39:10
Done.
| |
1386 !IsPrintToPdfRequested(*job_settings); | 1431 !(print_for_preview_ || settings.params.print_to_pdf || |
1432 (PrintingNodeOrPdfFrame(frame, node) && | |
1433 frame->isPrintScalingDisabledForPlugin(node))); | |
1434 | |
1435 // Update the print scaling option. | |
1436 print_scaling_option_ = (print_for_preview_ || | |
1437 settings.params.print_to_pdf) ? | |
1438 WebKit::WebPrintActualSize : | |
1439 static_cast<WebKit::WebPrintScalingOption>( | |
1440 settings.params.fit_to_paper_size); | |
1387 | 1441 |
1388 // Header/Footer: Set |header_footer_info_|. | 1442 // Header/Footer: Set |header_footer_info_|. |
1389 if (settings.params.display_header_footer) { | 1443 if (settings.params.display_header_footer) { |
1390 header_footer_info_.reset(new DictionaryValue()); | 1444 header_footer_info_.reset(new DictionaryValue()); |
1391 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, | 1445 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, |
1392 settings.params.date); | 1446 settings.params.date); |
1393 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, | 1447 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, |
1394 settings.params.url); | 1448 settings.params.url); |
1395 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, | 1449 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, |
1396 settings.params.title); | 1450 settings.params.title); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1630 } | 1684 } |
1631 | 1685 |
1632 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { | 1686 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { |
1633 DCHECK_EQ(INITIALIZED, state_); | 1687 DCHECK_EQ(INITIALIZED, state_); |
1634 ClearContext(); | 1688 ClearContext(); |
1635 } | 1689 } |
1636 | 1690 |
1637 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( | 1691 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
1638 PrintMsg_Print_Params* print_params, | 1692 PrintMsg_Print_Params* print_params, |
1639 const std::vector<int>& pages, | 1693 const std::vector<int>& pages, |
1640 bool ignore_css_margins) { | 1694 bool ignore_css_margins, |
1695 WebKit::WebPrintScalingOption print_scaling_option) { | |
1641 DCHECK_EQ(INITIALIZED, state_); | 1696 DCHECK_EQ(INITIALIZED, state_); |
1642 state_ = RENDERING; | 1697 state_ = RENDERING; |
1643 | 1698 |
1644 metafile_.reset(new printing::PreviewMetafile); | 1699 metafile_.reset(new printing::PreviewMetafile); |
1645 if (!metafile_->Init()) { | 1700 if (!metafile_->Init()) { |
1646 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); | 1701 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); |
1647 LOG(ERROR) << "PreviewMetafile Init failed"; | 1702 LOG(ERROR) << "PreviewMetafile Init failed"; |
1648 return false; | 1703 return false; |
1649 } | 1704 } |
1650 | 1705 |
1651 // Need to make sure old object gets destroyed first. | 1706 // Need to make sure old object gets destroyed first. |
1652 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), | 1707 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), |
1653 node())); | 1708 node(), |
1709 print_scaling_option)); | |
1654 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), | 1710 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), |
1655 *print_params, ignore_css_margins); | 1711 *print_params, ignore_css_margins); |
1656 | 1712 |
1657 print_params_.reset(new PrintMsg_Print_Params(*print_params)); | 1713 print_params_.reset(new PrintMsg_Print_Params(*print_params)); |
1658 | 1714 |
1659 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); | 1715 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); |
1660 if (total_page_count_ == 0) { | 1716 if (total_page_count_ == 0) { |
1661 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; | 1717 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; |
1662 set_error(PREVIEW_ERROR_ZERO_PAGES); | 1718 set_error(PREVIEW_ERROR_ZERO_PAGES); |
1663 return false; | 1719 return false; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1820 DCHECK(IsRendering()); | 1876 DCHECK(IsRendering()); |
1821 return prep_frame_view_->GetPrintCanvasSize(); | 1877 return prep_frame_view_->GetPrintCanvasSize(); |
1822 } | 1878 } |
1823 | 1879 |
1824 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1880 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1825 prep_frame_view_.reset(); | 1881 prep_frame_view_.reset(); |
1826 metafile_.reset(); | 1882 metafile_.reset(); |
1827 pages_to_render_.clear(); | 1883 pages_to_render_.clear(); |
1828 error_ = PREVIEW_ERROR_NONE; | 1884 error_ = PREVIEW_ERROR_NONE; |
1829 } | 1885 } |
OLD | NEW |