OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(OS_MACOSX) && !defined(USE_SKIA) | 7 #if defined(OS_MACOSX) && !defined(USE_SKIA) |
8 #include <CoreGraphics/CGContext.h> | 8 #include <CoreGraphics/CGContext.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 WebNode duplicate_node(*node); | 622 WebNode duplicate_node(*node); |
623 Print(frame, &duplicate_node); | 623 Print(frame, &duplicate_node); |
624 } | 624 } |
625 } | 625 } |
626 | 626 |
627 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 627 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
628 DCHECK(is_preview_); | 628 DCHECK(is_preview_); |
629 print_preview_context_.OnPrintPreview(); | 629 print_preview_context_.OnPrintPreview(); |
630 | 630 |
631 if (!InitPrintSettings(print_preview_context_.frame(), | 631 if (!InitPrintSettings(print_preview_context_.frame(), |
632 print_preview_context_.node())) { | 632 print_preview_context_.node(), |
633 NOTREACHED(); | 633 true)) { |
634 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | |
635 routing_id(), | |
kmadhusu
2011/08/26 18:50:40
nit: Fix indentation
arthurhsu
2011/08/29 22:53:16
Done.
| |
636 print_pages_params_->params.document_cookie)); | |
634 return; | 637 return; |
635 } | 638 } |
636 | 639 |
637 if (!UpdatePrintSettings(settings, true)) { | 640 if (!UpdatePrintSettings(settings, true)) { |
638 DidFinishPrinting(FAIL_PREVIEW); | 641 DidFinishPrinting(FAIL_PREVIEW); |
639 return; | 642 return; |
640 } | 643 } |
641 | 644 |
642 if (!print_pages_params_->params.is_first_request && | 645 if (!print_pages_params_->params.is_first_request && |
643 old_print_pages_params_.get() && | 646 old_print_pages_params_.get() && |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 static_cast<int>(ConvertUnitDouble( | 1005 static_cast<int>(ConvertUnitDouble( |
1003 page_height_in_points, printing::kPointsPerInch, dpi))); | 1006 page_height_in_points, printing::kPointsPerInch, dpi))); |
1004 | 1007 |
1005 params->margin_top = static_cast<int>(ConvertUnitDouble( | 1008 params->margin_top = static_cast<int>(ConvertUnitDouble( |
1006 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); | 1009 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); |
1007 params->margin_left = static_cast<int>(ConvertUnitDouble( | 1010 params->margin_left = static_cast<int>(ConvertUnitDouble( |
1008 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); | 1011 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); |
1009 } | 1012 } |
1010 | 1013 |
1011 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, | 1014 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, |
1012 WebKit::WebNode* node) { | 1015 WebKit::WebNode* node, |
1016 bool is_preview) { | |
1013 DCHECK(frame); | 1017 DCHECK(frame); |
1014 PrintMsg_PrintPages_Params settings; | 1018 PrintMsg_PrintPages_Params settings; |
1015 | 1019 |
1016 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1020 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
1017 &settings.params)); | 1021 &settings.params)); |
1018 // Check if the printer returned any settings, if the settings is empty, we | 1022 // Check if the printer returned any settings, if the settings is empty, we |
1019 // can safely assume there are no printer drivers configured. So we safely | 1023 // can safely assume there are no printer drivers configured. So we safely |
1020 // terminate. | 1024 // terminate. |
1025 bool result = true; | |
1021 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | 1026 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { |
1022 render_view()->runModalAlertDialog( | 1027 if (!is_preview) { |
1023 frame, | 1028 render_view()->runModalAlertDialog( |
1024 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); | 1029 frame, |
1025 return false; | 1030 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); |
kmadhusu
2011/08/26 18:50:40
If the printer settings is empty/invalid, we don't
arthurhsu
2011/08/29 22:53:16
Done.
| |
1031 } | |
1032 result = false; | |
1026 } | 1033 } |
1027 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { | 1034 |
1035 if (result && | |
1036 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { | |
1028 // Invalid print page settings. | 1037 // Invalid print page settings. |
1029 NOTREACHED(); | 1038 NOTREACHED(); |
1030 return false; | 1039 result = false; |
1031 } | 1040 } |
1032 | 1041 |
1033 settings.pages.clear(); | 1042 settings.pages.clear(); |
1034 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1043 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
1035 return true; | 1044 return result; |
1036 } | 1045 } |
1037 | 1046 |
1038 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( | 1047 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
1039 WebKit::WebFrame* frame, WebKit::WebNode* node, | 1048 WebKit::WebFrame* frame, WebKit::WebNode* node, |
1040 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { | 1049 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { |
1041 if (!InitPrintSettings(frame, node)) | 1050 if (!InitPrintSettings(frame, node, false)) |
1042 return false; | 1051 return false; |
1043 | 1052 |
1044 DCHECK(!prepare->get()); | 1053 DCHECK(!prepare->get()); |
1045 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 1054 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
1046 frame, node)); | 1055 frame, node)); |
1047 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), | 1056 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), |
1048 &print_pages_params_->params); | 1057 &print_pages_params_->params); |
1049 Send(new PrintHostMsg_DidGetDocumentCookie( | 1058 Send(new PrintHostMsg_DidGetDocumentCookie( |
1050 routing_id(), print_pages_params_->params.document_cookie)); | 1059 routing_id(), print_pages_params_->params.document_cookie)); |
1051 return true; | 1060 return true; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1437 const gfx::Size& | 1446 const gfx::Size& |
1438 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1447 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
1439 return prep_frame_view_->GetPrintCanvasSize(); | 1448 return prep_frame_view_->GetPrintCanvasSize(); |
1440 } | 1449 } |
1441 | 1450 |
1442 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1451 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1443 prep_frame_view_.reset(); | 1452 prep_frame_view_.reset(); |
1444 metafile_.reset(); | 1453 metafile_.reset(); |
1445 pages_to_render_.clear(); | 1454 pages_to_render_.clear(); |
1446 } | 1455 } |
OLD | NEW |