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 15 matching lines...) Expand all Loading... | |
| 26 #include "printing/units.h" | 26 #include "printing/units.h" |
| 27 #include "third_party/skia/include/core/SkRect.h" | 27 #include "third_party/skia/include/core/SkRect.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintScalingOption .h" | |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" |
| 38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" |
| 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/gfx/rect.h" | 42 #include "ui/gfx/rect.h" |
| 42 #include "webkit/glue/webpreferences.h" | 43 #include "webkit/glue/webpreferences.h" |
| 43 | 44 |
| 44 #if defined(OS_POSIX) | 45 #if defined(OS_POSIX) |
| 45 #include "base/process_util.h" | 46 #include "base/process_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 65 using base::mac::ScopedCFTypeRef; | 66 using base::mac::ScopedCFTypeRef; |
| 66 #endif | 67 #endif |
| 67 using printing::ConvertPixelsToPoint; | 68 using printing::ConvertPixelsToPoint; |
| 68 using printing::ConvertPixelsToPointDouble; | 69 using printing::ConvertPixelsToPointDouble; |
| 69 using printing::ConvertPointsToPixelDouble; | 70 using printing::ConvertPointsToPixelDouble; |
| 70 using printing::ConvertUnit; | 71 using printing::ConvertUnit; |
| 71 using printing::ConvertUnitDouble; | 72 using printing::ConvertUnitDouble; |
| 72 using printing::GetHeaderFooterSegmentWidth; | 73 using printing::GetHeaderFooterSegmentWidth; |
| 73 using printing::PageSizeMargins; | 74 using printing::PageSizeMargins; |
| 74 using WebKit::WebConsoleMessage; | 75 using WebKit::WebConsoleMessage; |
| 75 using WebKit::WebDocument; | 76 using WebKit::WebDocument; |
|
darin (slow to review)
2012/05/17 19:13:03
nit: add more 'using WebKit::WebFoo' here to avoid
kmadhusu
2012/05/17 20:16:29
Done.
| |
| 76 using WebKit::WebElement; | 77 using WebKit::WebElement; |
| 77 using WebKit::WebFrame; | 78 using WebKit::WebFrame; |
| 78 using WebKit::WebNode; | 79 using WebKit::WebNode; |
| 79 using WebKit::WebPlugin; | 80 using WebKit::WebPlugin; |
| 80 using WebKit::WebPluginDocument; | 81 using WebKit::WebPluginDocument; |
| 81 using WebKit::WebSize; | 82 using WebKit::WebSize; |
| 82 using WebKit::WebString; | 83 using WebKit::WebString; |
| 83 using WebKit::WebURLRequest; | 84 using WebKit::WebURLRequest; |
| 84 using WebKit::WebView; | 85 using WebKit::WebView; |
| 85 | 86 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 const PrintMsg_PrintPages_Params& oldParams, | 131 const PrintMsg_PrintPages_Params& oldParams, |
| 131 const PrintMsg_PrintPages_Params& newParams) { | 132 const PrintMsg_PrintPages_Params& newParams) { |
| 132 return PageLayoutIsEqual(oldParams, newParams) && | 133 return PageLayoutIsEqual(oldParams, newParams) && |
| 133 oldParams.params.max_shrink == newParams.params.max_shrink && | 134 oldParams.params.max_shrink == newParams.params.max_shrink && |
| 134 oldParams.params.min_shrink == newParams.params.min_shrink && | 135 oldParams.params.min_shrink == newParams.params.min_shrink && |
| 135 oldParams.params.selection_only == newParams.params.selection_only && | 136 oldParams.params.selection_only == newParams.params.selection_only && |
| 136 oldParams.params.supports_alpha_blend == | 137 oldParams.params.supports_alpha_blend == |
| 137 newParams.params.supports_alpha_blend && | 138 newParams.params.supports_alpha_blend && |
| 138 oldParams.pages.size() == newParams.pages.size() && | 139 oldParams.pages.size() == newParams.pages.size() && |
| 139 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && | 140 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && |
| 140 oldParams.params.fit_to_paper_size == | 141 oldParams.params.print_scaling_option == |
| 141 newParams.params.fit_to_paper_size && | 142 newParams.params.print_scaling_option && |
| 142 oldParams.params.display_header_footer == | 143 oldParams.params.display_header_footer == |
| 143 newParams.params.display_header_footer && | 144 newParams.params.display_header_footer && |
| 144 oldParams.params.date == newParams.params.date && | 145 oldParams.params.date == newParams.params.date && |
| 145 oldParams.params.title == newParams.params.title && | 146 oldParams.params.title == newParams.params.title && |
| 146 oldParams.params.url == newParams.params.url && | 147 oldParams.params.url == newParams.params.url && |
| 147 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 148 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
| 148 newParams.pages.begin()); | 149 newParams.pages.begin()); |
| 149 } | 150 } |
| 150 | 151 |
| 151 PrintMsg_Print_Params GetCssPrintParams( | 152 PrintMsg_Print_Params GetCssPrintParams( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 // Swap the |width| and |height| values. | 300 // Swap the |width| and |height| values. |
| 300 page_params->page_size.SetSize(page_params->page_size.height(), | 301 page_params->page_size.SetSize(page_params->page_size.height(), |
| 301 page_params->page_size.width()); | 302 page_params->page_size.width()); |
| 302 page_params->content_size.SetSize(page_params->content_size.height(), | 303 page_params->content_size.SetSize(page_params->content_size.height(), |
| 303 page_params->content_size.width()); | 304 page_params->content_size.width()); |
| 304 page_params->printable_area.set_size( | 305 page_params->printable_area.set_size( |
| 305 gfx::Size(page_params->printable_area.height(), | 306 gfx::Size(page_params->printable_area.height(), |
| 306 page_params->printable_area.width())); | 307 page_params->printable_area.width())); |
| 307 } | 308 } |
| 308 | 309 |
| 309 void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params, | 310 void ComputeWebKitPrintParamsInDesiredDpi( |
| 310 gfx::Size* result) { | 311 const PrintMsg_Print_Params& print_params, |
| 312 WebKit::WebPrintParams* webkit_print_params) { | |
| 311 int dpi = GetDPI(&print_params); | 313 int dpi = GetDPI(&print_params); |
| 312 result->set_width(ConvertUnit(print_params.content_size.width(), dpi, | 314 webkit_print_params->printerDPI = dpi; |
| 313 print_params.desired_dpi)); | 315 webkit_print_params->printScalingOption = print_params.print_scaling_option; |
| 314 | 316 |
| 315 result->set_height(ConvertUnit(print_params.content_size.height(), dpi, | 317 webkit_print_params->printContentArea.width = |
| 316 print_params.desired_dpi)); | 318 ConvertUnit(print_params.content_size.width(), dpi, |
| 319 print_params.desired_dpi); | |
| 320 webkit_print_params->printContentArea.height = | |
| 321 ConvertUnit(print_params.content_size.height(), dpi, | |
| 322 print_params.desired_dpi); | |
| 323 | |
| 324 webkit_print_params->printableArea.x = | |
| 325 ConvertUnit(print_params.printable_area.x(), dpi, | |
| 326 print_params.desired_dpi); | |
| 327 webkit_print_params->printableArea.y = | |
| 328 ConvertUnit(print_params.printable_area.y(), dpi, | |
| 329 print_params.desired_dpi); | |
| 330 webkit_print_params->printableArea.width = | |
| 331 ConvertUnit(print_params.printable_area.width(), dpi, | |
| 332 print_params.desired_dpi); | |
| 333 webkit_print_params->printableArea.height = | |
| 334 ConvertUnit(print_params.printable_area.height(), | |
| 335 dpi, print_params.desired_dpi); | |
| 336 | |
| 337 webkit_print_params->paperSize.width = | |
| 338 ConvertUnit(print_params.page_size.width(), dpi, | |
| 339 print_params.desired_dpi); | |
| 340 webkit_print_params->paperSize.height = | |
| 341 ConvertUnit(print_params.page_size.height(), dpi, | |
| 342 print_params.desired_dpi); | |
| 317 } | 343 } |
| 318 | 344 |
| 319 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { | 345 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { |
| 320 if (!node.isNull()) | 346 if (!node.isNull()) |
| 321 return true; | 347 return true; |
| 322 if (!frame->document().isPluginDocument()) | 348 if (!frame->document().isPluginDocument()) |
| 323 return false; | 349 return false; |
| 324 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); | 350 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); |
| 325 return plugin && plugin->supportsPaginatedPrint(); | 351 return plugin && plugin->supportsPaginatedPrint(); |
| 326 } | 352 } |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 #endif | 698 #endif |
| 673 } | 699 } |
| 674 | 700 |
| 675 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 701 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 676 const PrintMsg_Print_Params& print_params, | 702 const PrintMsg_Print_Params& print_params, |
| 677 WebFrame* frame, | 703 WebFrame* frame, |
| 678 const WebNode& node) | 704 const WebNode& node) |
| 679 : frame_(frame), | 705 : frame_(frame), |
| 680 node_to_print_(node), | 706 node_to_print_(node), |
| 681 web_view_(frame->view()), | 707 web_view_(frame->view()), |
| 682 dpi_(static_cast<int>(print_params.dpi)), | |
| 683 expected_pages_count_(0), | 708 expected_pages_count_(0), |
| 684 use_browser_overlays_(true), | 709 use_browser_overlays_(true), |
| 685 finished_(false) { | 710 finished_(false) { |
| 686 gfx::Size canvas_size; | 711 WebKit::WebPrintParams webkit_print_params; |
| 687 CalculatePrintCanvasSize(print_params, &canvas_size); | 712 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 688 | 713 |
| 689 if (WebFrame* web_frame = web_view_->mainFrame()) | 714 if (WebFrame* web_frame = web_view_->mainFrame()) |
| 690 prev_scroll_offset_ = web_frame->scrollOffset(); | 715 prev_scroll_offset_ = web_frame->scrollOffset(); |
| 691 prev_view_size_ = web_view_->size(); | 716 prev_view_size_ = web_view_->size(); |
| 692 | 717 |
| 693 StartPrinting(canvas_size); | 718 StartPrinting(webkit_print_params); |
| 694 } | 719 } |
| 695 | 720 |
| 696 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 721 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 697 FinishPrinting(); | 722 FinishPrinting(); |
| 698 } | 723 } |
| 699 | 724 |
| 700 void PrepareFrameAndViewForPrint::UpdatePrintParams( | 725 void PrepareFrameAndViewForPrint::UpdatePrintParams( |
| 701 const PrintMsg_Print_Params& print_params) { | 726 const PrintMsg_Print_Params& print_params) { |
| 702 DCHECK(!finished_); | 727 DCHECK(!finished_); |
| 703 gfx::Size canvas_size; | 728 WebKit::WebPrintParams webkit_print_params; |
| 704 CalculatePrintCanvasSize(print_params, &canvas_size); | 729 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 705 if (canvas_size == print_canvas_size_) | 730 |
| 731 if (webkit_print_params.printContentArea == | |
| 732 web_print_params_.printContentArea && | |
| 733 webkit_print_params.printableArea == web_print_params_.printableArea && | |
| 734 webkit_print_params.paperSize == web_print_params_.paperSize && | |
| 735 webkit_print_params.printScalingOption == | |
| 736 web_print_params_.printScalingOption) { | |
| 706 return; | 737 return; |
| 738 } | |
| 707 | 739 |
| 708 frame_->printEnd(); | 740 frame_->printEnd(); |
| 709 dpi_ = static_cast<int>(print_params.dpi); | 741 StartPrinting(webkit_print_params); |
| 710 StartPrinting(canvas_size); | |
| 711 } | 742 } |
| 712 | 743 |
| 713 void PrepareFrameAndViewForPrint::StartPrinting( | 744 void PrepareFrameAndViewForPrint::StartPrinting( |
| 714 const gfx::Size& print_canvas_size) { | 745 const WebKit::WebPrintParams& webkit_print_params) { |
| 715 print_canvas_size_ = print_canvas_size; | 746 web_print_params_ = webkit_print_params; |
| 716 | 747 |
| 717 // Layout page according to printer page size. Since WebKit shrinks the | 748 // Layout page according to printer page size. Since WebKit shrinks the |
| 718 // size of the page automatically (from 125% to 200%) we trick it to | 749 // size of the page automatically (from 125% to 200%) we trick it to |
| 719 // think the page is 125% larger so the size of the page is correct for | 750 // think the page is 125% larger so the size of the page is correct for |
| 720 // minimum (default) scaling. | 751 // minimum (default) scaling. |
| 721 // This is important for sites that try to fill the page. | 752 // This is important for sites that try to fill the page. |
| 722 gfx::Size print_layout_size(print_canvas_size_); | 753 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
| 754 web_print_params_.printContentArea.height); | |
| 723 print_layout_size.set_height(static_cast<int>( | 755 print_layout_size.set_height(static_cast<int>( |
| 724 static_cast<double>(print_layout_size.height()) * 1.25)); | 756 static_cast<double>(print_layout_size.height()) * 1.25)); |
| 725 | 757 |
| 726 web_view_->resize(print_layout_size); | 758 web_view_->resize(print_layout_size); |
| 727 | 759 |
| 728 expected_pages_count_ = frame_->printBegin(print_canvas_size_, node_to_print_, | 760 expected_pages_count_ = frame_->printBegin(web_print_params_, |
| 729 dpi_, &use_browser_overlays_); | 761 node_to_print_, |
| 762 &use_browser_overlays_); | |
| 730 } | 763 } |
| 731 | 764 |
| 732 void PrepareFrameAndViewForPrint::FinishPrinting() { | 765 void PrepareFrameAndViewForPrint::FinishPrinting() { |
| 733 if (!finished_) { | 766 if (!finished_) { |
| 734 finished_ = true; | 767 finished_ = true; |
| 735 frame_->printEnd(); | 768 frame_->printEnd(); |
| 736 web_view_->resize(prev_view_size_); | 769 web_view_->resize(prev_view_size_); |
| 737 if (WebFrame* web_frame = web_view_->mainFrame()) | 770 if (WebFrame* web_frame = web_view_->mainFrame()) |
| 738 web_frame->setScrollOffset(prev_scroll_offset_); | 771 web_frame->setScrollOffset(prev_scroll_offset_); |
| 739 } | 772 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 } | 934 } |
| 902 | 935 |
| 903 bool PrintWebViewHelper::IsPrintToPdfRequested( | 936 bool PrintWebViewHelper::IsPrintToPdfRequested( |
| 904 const DictionaryValue& job_settings) { | 937 const DictionaryValue& job_settings) { |
| 905 bool print_to_pdf = false; | 938 bool print_to_pdf = false; |
| 906 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) | 939 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) |
| 907 NOTREACHED(); | 940 NOTREACHED(); |
| 908 return print_to_pdf; | 941 return print_to_pdf; |
| 909 } | 942 } |
| 910 | 943 |
| 911 bool PrintWebViewHelper::IsFitToPaperSizeRequested( | 944 WebKit::WebPrintScalingOption PrintWebViewHelper::GetPrintScalingOption( |
| 912 bool source_is_html, const DictionaryValue& job_settings, | 945 bool source_is_html, const DictionaryValue& job_settings, |
| 913 const PrintMsg_Print_Params& params) { | 946 const PrintMsg_Print_Params& params) { |
| 914 DCHECK(!print_for_preview_); | 947 DCHECK(!print_for_preview_); |
| 915 | 948 |
| 916 // Do not fit to paper size when the user is saving the print contents as pdf. | |
| 917 if (params.print_to_pdf) | 949 if (params.print_to_pdf) |
| 918 return false; | 950 return WebKit::WebPrintScalingOptionSourceSize; |
| 919 | 951 |
| 920 if (!source_is_html) { | 952 if (!source_is_html) { |
| 921 if (!FitToPageEnabled(job_settings)) | 953 if (!FitToPageEnabled(job_settings)) |
| 922 return false; | 954 return WebKit::WebPrintScalingOptionNone; |
| 923 | 955 |
| 924 // Get the print scaling option for the initiator renderer pdf. | 956 bool no_plugin_scaling = |
| 925 bool print_scaling_disabled_for_plugin = | |
| 926 print_preview_context_.frame()->isPrintScalingDisabledForPlugin( | 957 print_preview_context_.frame()->isPrintScalingDisabledForPlugin( |
| 927 print_preview_context_.node()); | 958 print_preview_context_.node()); |
| 928 | 959 |
| 929 // If this is the first preview request, UI doesn't know about the print | 960 if (params.is_first_request && no_plugin_scaling) |
| 930 // scaling option of the plugin. Therefore, check the print scaling option | 961 return WebKit::WebPrintScalingOptionNone; |
| 931 // and update the print params accordingly. | |
| 932 // | |
| 933 // If this is not the first preview request, update print params based on | |
| 934 // preview job settings. | |
| 935 if (params.is_first_request && print_scaling_disabled_for_plugin) | |
| 936 return false; | |
| 937 } | 962 } |
| 938 return true; | 963 return WebKit::WebPrintScalingOptionFitToPrintableArea; |
| 939 } | 964 } |
| 940 | 965 |
| 941 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 966 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| 942 DCHECK(is_preview_enabled_); | 967 DCHECK(is_preview_enabled_); |
| 943 print_preview_context_.OnPrintPreview(); | 968 print_preview_context_.OnPrintPreview(); |
| 944 | 969 |
| 945 if (!UpdatePrintSettings(print_preview_context_.frame(), | 970 if (!UpdatePrintSettings(print_preview_context_.frame(), |
| 946 print_preview_context_.node(), settings)) { | 971 print_preview_context_.node(), settings)) { |
| 947 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { | 972 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { |
| 948 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 973 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 // static - Not anonymous so that platform implementations can use it. | 1347 // static - Not anonymous so that platform implementations can use it. |
| 1323 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1348 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
| 1324 WebFrame* frame, | 1349 WebFrame* frame, |
| 1325 int page_index, | 1350 int page_index, |
| 1326 const PrintMsg_Print_Params& page_params, | 1351 const PrintMsg_Print_Params& page_params, |
| 1327 bool ignore_css_margins, | 1352 bool ignore_css_margins, |
| 1328 double* scale_factor, | 1353 double* scale_factor, |
| 1329 PageSizeMargins* page_layout_in_points) { | 1354 PageSizeMargins* page_layout_in_points) { |
| 1330 PrintMsg_Print_Params params = CalculatePrintParamsForCss( | 1355 PrintMsg_Print_Params params = CalculatePrintParamsForCss( |
| 1331 frame, page_index, page_params, ignore_css_margins, | 1356 frame, page_index, page_params, ignore_css_margins, |
| 1332 page_params.fit_to_paper_size, scale_factor); | 1357 page_params.print_scaling_option == |
| 1358 WebKit::WebPrintScalingOptionFitToPrintableArea, | |
| 1359 scale_factor); | |
| 1333 CalculatePageLayoutFromPrintParams(params, page_layout_in_points); | 1360 CalculatePageLayoutFromPrintParams(params, page_layout_in_points); |
| 1334 } | 1361 } |
| 1335 | 1362 |
| 1336 // static - Not anonymous so that platform implementations can use it. | 1363 // static - Not anonymous so that platform implementations can use it. |
| 1337 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( | 1364 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( |
| 1338 WebFrame* frame, | 1365 WebFrame* frame, |
| 1339 const WebNode& node, | 1366 const WebNode& node, |
| 1340 PrepareFrameAndViewForPrint* prepare, | 1367 PrepareFrameAndViewForPrint* prepare, |
| 1341 const PrintMsg_Print_Params& params, | 1368 const PrintMsg_Print_Params& params, |
| 1342 bool ignore_css_margins) { | 1369 bool ignore_css_margins) { |
| 1343 if (PrintingNodeOrPdfFrame(frame, node)) | 1370 if (PrintingNodeOrPdfFrame(frame, node)) |
| 1344 return; | 1371 return; |
| 1372 bool fit_to_page = ignore_css_margins && | |
| 1373 params.print_scaling_option == | |
| 1374 WebKit::WebPrintScalingOptionFitToPrintableArea; | |
| 1345 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( | 1375 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( |
| 1346 frame, 0, params, ignore_css_margins, | 1376 frame, 0, params, ignore_css_margins, fit_to_page, NULL); |
| 1347 ignore_css_margins && params.fit_to_paper_size, NULL); | |
| 1348 prepare->UpdatePrintParams(print_params); | 1377 prepare->UpdatePrintParams(print_params); |
| 1349 } | 1378 } |
| 1350 | 1379 |
| 1351 bool PrintWebViewHelper::InitPrintSettings() { | 1380 bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) { |
| 1352 PrintMsg_PrintPages_Params settings; | 1381 PrintMsg_PrintPages_Params settings; |
| 1353 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1382 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
| 1354 &settings.params)); | 1383 &settings.params)); |
| 1355 // Check if the printer returned any settings, if the settings is empty, we | 1384 // Check if the printer returned any settings, if the settings is empty, we |
| 1356 // can safely assume there are no printer drivers configured. So we safely | 1385 // can safely assume there are no printer drivers configured. So we safely |
| 1357 // terminate. | 1386 // terminate. |
| 1358 bool result = true; | 1387 bool result = true; |
| 1359 if (!PrintMsg_Print_Params_IsValid(settings.params)) | 1388 if (!PrintMsg_Print_Params_IsValid(settings.params)) |
| 1360 result = false; | 1389 result = false; |
| 1361 | 1390 |
| 1362 if (result && | 1391 if (result && |
| 1363 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { | 1392 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { |
| 1364 // Invalid print page settings. | 1393 // Invalid print page settings. |
| 1365 NOTREACHED(); | 1394 NOTREACHED(); |
| 1366 result = false; | 1395 result = false; |
| 1367 } | 1396 } |
| 1368 | 1397 |
| 1369 // Reset to default values. | 1398 // Reset to default values. |
| 1370 ignore_css_margins_ = false; | 1399 ignore_css_margins_ = false; |
| 1371 settings.params.fit_to_paper_size = true; | |
| 1372 settings.pages.clear(); | 1400 settings.pages.clear(); |
| 1373 | 1401 |
| 1402 settings.params.print_scaling_option = | |
| 1403 WebKit::WebPrintScalingOptionSourceSize; | |
| 1404 if (fit_to_paper_size) { | |
| 1405 settings.params.print_scaling_option = | |
| 1406 WebKit::WebPrintScalingOptionFitToPrintableArea; | |
| 1407 } | |
| 1408 | |
| 1374 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1409 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1375 return result; | 1410 return result; |
| 1376 } | 1411 } |
| 1377 | 1412 |
| 1378 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( | 1413 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
| 1379 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1414 WebKit::WebFrame* frame, const WebKit::WebNode& node, |
| 1380 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { | 1415 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { |
| 1381 DCHECK(frame); | 1416 DCHECK(frame); |
| 1382 if (!InitPrintSettings()) { | 1417 |
| 1418 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | |
| 1419 if (!InitPrintSettings(fit_to_paper_size)) { | |
| 1383 notify_browser_of_print_failure_ = false; | 1420 notify_browser_of_print_failure_ = false; |
| 1384 render_view()->RunModalAlertDialog( | 1421 render_view()->RunModalAlertDialog( |
| 1385 frame, | 1422 frame, |
| 1386 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1423 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1387 return false; | 1424 return false; |
| 1388 } | 1425 } |
| 1389 | 1426 |
| 1390 DCHECK(!prepare->get()); | 1427 DCHECK(!prepare->get()); |
| 1391 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 1428 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
| 1392 frame, node)); | 1429 frame, node)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1469 !job_settings->GetInteger(printing::kPreviewRequestID, | 1506 !job_settings->GetInteger(printing::kPreviewRequestID, |
| 1470 &(settings.params.preview_request_id)) || | 1507 &(settings.params.preview_request_id)) || |
| 1471 !job_settings->GetBoolean(printing::kIsFirstRequest, | 1508 !job_settings->GetBoolean(printing::kIsFirstRequest, |
| 1472 &(settings.params.is_first_request))) { | 1509 &(settings.params.is_first_request))) { |
| 1473 NOTREACHED(); | 1510 NOTREACHED(); |
| 1474 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1511 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
| 1475 return false; | 1512 return false; |
| 1476 } | 1513 } |
| 1477 | 1514 |
| 1478 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); | 1515 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); |
| 1479 settings.params.fit_to_paper_size = IsFitToPaperSizeRequested( | 1516 UpdateFrameMarginsCssInfo(*job_settings); |
| 1517 settings.params.print_scaling_option = GetPrintScalingOption( | |
| 1480 source_is_html, *job_settings, settings.params); | 1518 source_is_html, *job_settings, settings.params); |
| 1481 UpdateFrameMarginsCssInfo(*job_settings); | |
| 1482 | 1519 |
| 1483 // Header/Footer: Set |header_footer_info_|. | 1520 // Header/Footer: Set |header_footer_info_|. |
| 1484 if (settings.params.display_header_footer) { | 1521 if (settings.params.display_header_footer) { |
| 1485 header_footer_info_.reset(new DictionaryValue()); | 1522 header_footer_info_.reset(new DictionaryValue()); |
| 1486 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, | 1523 header_footer_info_->SetString(printing::kSettingHeaderFooterDate, |
| 1487 settings.params.date); | 1524 settings.params.date); |
| 1488 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, | 1525 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, |
| 1489 settings.params.url); | 1526 settings.params.url); |
| 1490 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, | 1527 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, |
| 1491 settings.params.title); | 1528 settings.params.title); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1514 params.expected_pages_count = expected_pages_count; | 1551 params.expected_pages_count = expected_pages_count; |
| 1515 printing::MarginType margin_type = printing::DEFAULT_MARGINS; | 1552 printing::MarginType margin_type = printing::DEFAULT_MARGINS; |
| 1516 if (PrintingNodeOrPdfFrame(frame, node)) | 1553 if (PrintingNodeOrPdfFrame(frame, node)) |
| 1517 margin_type = GetMarginsForPdf(frame, node); | 1554 margin_type = GetMarginsForPdf(frame, node); |
| 1518 params.margin_type = margin_type; | 1555 params.margin_type = margin_type; |
| 1519 | 1556 |
| 1520 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1557 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
| 1521 | 1558 |
| 1522 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the | 1559 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the |
| 1523 // value before and restore it afterwards. | 1560 // value before and restore it afterwards. |
| 1524 bool fit_to_paper_size = print_pages_params_->params.fit_to_paper_size; | 1561 WebKit::WebPrintScalingOption scaling_option = |
| 1562 print_pages_params_->params.print_scaling_option; | |
| 1525 | 1563 |
| 1526 print_pages_params_.reset(); | 1564 print_pages_params_.reset(); |
| 1527 IPC::SyncMessage* msg = | 1565 IPC::SyncMessage* msg = |
| 1528 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); | 1566 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); |
| 1529 msg->EnableMessagePumping(); | 1567 msg->EnableMessagePumping(); |
| 1530 Send(msg); | 1568 Send(msg); |
| 1531 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); | 1569 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); |
| 1532 | 1570 |
| 1533 print_pages_params_->params.fit_to_paper_size = fit_to_paper_size; | 1571 print_pages_params_->params.print_scaling_option = scaling_option; |
| 1534 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1572 return (print_settings.params.dpi && print_settings.params.document_cookie); |
| 1535 } | 1573 } |
| 1536 | 1574 |
| 1537 bool PrintWebViewHelper::RenderPagesForPrint( | 1575 bool PrintWebViewHelper::RenderPagesForPrint( |
| 1538 WebKit::WebFrame* frame, | 1576 WebKit::WebFrame* frame, |
| 1539 const WebKit::WebNode& node) { | 1577 const WebKit::WebNode& node) { |
| 1540 if (print_pages_params_->params.selection_only) | 1578 if (print_pages_params_->params.selection_only) |
| 1541 return CopyAndPrint(frame); | 1579 return CopyAndPrint(frame); |
| 1542 return PrintPages(frame, node); | 1580 return PrintPages(frame, node); |
| 1543 } | 1581 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1909 const PrintMsg_Print_Params& | 1947 const PrintMsg_Print_Params& |
| 1910 PrintWebViewHelper::PrintPreviewContext::print_params() const { | 1948 PrintWebViewHelper::PrintPreviewContext::print_params() const { |
| 1911 DCHECK(state_ != UNINITIALIZED); | 1949 DCHECK(state_ != UNINITIALIZED); |
| 1912 return *print_params_; | 1950 return *print_params_; |
| 1913 } | 1951 } |
| 1914 | 1952 |
| 1915 int PrintWebViewHelper::PrintPreviewContext::last_error() const { | 1953 int PrintWebViewHelper::PrintPreviewContext::last_error() const { |
| 1916 return error_; | 1954 return error_; |
| 1917 } | 1955 } |
| 1918 | 1956 |
| 1919 const gfx::Size& | 1957 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1920 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | |
| 1921 DCHECK(IsRendering()); | 1958 DCHECK(IsRendering()); |
| 1922 return prep_frame_view_->GetPrintCanvasSize(); | 1959 return prep_frame_view_->GetPrintCanvasSize(); |
| 1923 } | 1960 } |
| 1924 | 1961 |
| 1925 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1962 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1926 prep_frame_view_.reset(); | 1963 prep_frame_view_.reset(); |
| 1927 metafile_.reset(); | 1964 metafile_.reset(); |
| 1928 pages_to_render_.clear(); | 1965 pages_to_render_.clear(); |
| 1929 error_ = PREVIEW_ERROR_NONE; | 1966 error_ = PREVIEW_ERROR_NONE; |
| 1930 } | 1967 } |
| OLD | NEW |