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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 // PDF printer device supports alpha blending. | 845 // PDF printer device supports alpha blending. |
846 print_pages_params_->params.supports_alpha_blend = true; | 846 print_pages_params_->params.supports_alpha_blend = true; |
847 | 847 |
848 bool generate_draft_pages = false; | 848 bool generate_draft_pages = false; |
849 if (!settings.GetBoolean(printing::kSettingGenerateDraftData, | 849 if (!settings.GetBoolean(printing::kSettingGenerateDraftData, |
850 &generate_draft_pages)) { | 850 &generate_draft_pages)) { |
851 NOTREACHED(); | 851 NOTREACHED(); |
852 } | 852 } |
853 print_preview_context_.set_generate_draft_pages(generate_draft_pages); | 853 print_preview_context_.set_generate_draft_pages(generate_draft_pages); |
854 | 854 |
855 if (CreatePreviewDocument()) { | 855 int margins_type = 0; |
856 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) | |
857 margins_type = printing::DEFAULT_MARGINS; | |
858 | |
859 if (CreatePreviewDocument(margins_type)) { | |
856 DidFinishPrinting(OK); | 860 DidFinishPrinting(OK); |
857 } else { | 861 } else { |
858 if (notify_browser_of_print_failure_) | 862 if (notify_browser_of_print_failure_) |
859 LOG(ERROR) << "CreatePreviewDocument failed"; | 863 LOG(ERROR) << "CreatePreviewDocument failed"; |
860 DidFinishPrinting(FAIL_PREVIEW); | 864 DidFinishPrinting(FAIL_PREVIEW); |
861 } | 865 } |
862 } | 866 } |
863 | 867 |
864 bool PrintWebViewHelper::CreatePreviewDocument() { | 868 bool PrintWebViewHelper::CreatePreviewDocument(int margins_type) { |
865 PrintMsg_Print_Params print_params = print_pages_params_->params; | 869 PrintMsg_Print_Params print_params = print_pages_params_->params; |
866 const std::vector<int>& pages = print_pages_params_->pages; | 870 const std::vector<int>& pages = print_pages_params_->pages; |
867 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, | 871 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, |
868 ignore_css_margins_, | 872 ignore_css_margins_, |
869 fit_to_page_)) { | 873 fit_to_page_)) { |
870 return false; | 874 return false; |
871 } | 875 } |
872 | 876 |
873 PageSizeMargins default_page_layout; | 877 PageSizeMargins default_page_layout; |
874 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, | 878 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, |
875 print_params, ignore_css_margins_, | 879 print_params, ignore_css_margins_, |
876 fit_to_page_, NULL, &default_page_layout); | 880 fit_to_page_, NULL, &default_page_layout); |
881 | |
882 bool preview_is_modifiable = print_preview_context_.IsModifiable(); | |
877 if (!old_print_pages_params_.get() || | 883 if (!old_print_pages_params_.get() || |
878 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { | 884 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { |
879 bool has_page_size_style = PrintingFrameHasPageSizeStyle( | 885 bool has_page_size_style = PrintingFrameHasPageSizeStyle( |
880 print_preview_context_.frame(), | 886 print_preview_context_.frame(), |
881 print_preview_context_.total_page_count()); | 887 print_preview_context_.total_page_count()); |
888 | |
889 bool header_footer_applies = true; | |
vandebo (ex-Chrome)
2012/03/15 21:47:17
It seems like this is solely concerned with the pr
kmadhusu
2012/03/17 00:29:12
Done.
| |
890 if (!preview_is_modifiable || margins_type == printing::NO_MARGINS) { | |
891 header_footer_applies = false; | |
892 } else if (margins_type != printing::PRINTABLE_AREA_MARGINS) { | |
893 #if defined(OS_LINUX) | |
894 header_footer_applies = | |
895 (default_page_layout.margin_top > 0) || | |
896 (default_page_layout.margin_bottom > 0); | |
897 #else | |
898 int dpi = GetDPI(&print_params); | |
899 int non_printable_area_top = ConvertUnit( | |
900 print_pages_params_->params.printable_area.y(), | |
901 dpi, printing::kPointsPerInch); | |
902 int non_printable_area_bottom = ConvertUnit( | |
903 print_pages_params_->params.page_size.height() - | |
904 print_pages_params_->params.printable_area.y() - | |
905 print_pages_params_->params.printable_area.height(), | |
906 dpi, printing::kPointsPerInch); | |
907 header_footer_applies = | |
908 (default_page_layout.margin_top > non_printable_area_top) || | |
909 (default_page_layout.margin_bottom > non_printable_area_bottom); | |
910 #endif | |
911 } | |
882 // Margins: Send default page layout to browser process. | 912 // Margins: Send default page layout to browser process. |
883 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), | 913 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), |
884 default_page_layout, | 914 default_page_layout, |
885 has_page_size_style)); | 915 has_page_size_style, |
916 header_footer_applies)); | |
886 } | 917 } |
887 | 918 |
888 PrintHostMsg_DidGetPreviewPageCount_Params params; | 919 PrintHostMsg_DidGetPreviewPageCount_Params params; |
889 params.page_count = print_preview_context_.total_page_count(); | 920 params.page_count = print_preview_context_.total_page_count(); |
890 params.is_modifiable = print_preview_context_.IsModifiable(); | 921 params.is_modifiable = preview_is_modifiable; |
891 params.document_cookie = print_pages_params_->params.document_cookie; | 922 params.document_cookie = print_pages_params_->params.document_cookie; |
892 params.preview_request_id = print_pages_params_->params.preview_request_id; | 923 params.preview_request_id = print_pages_params_->params.preview_request_id; |
893 params.clear_preview_data = print_preview_context_.generate_draft_pages(); | 924 params.clear_preview_data = print_preview_context_.generate_draft_pages(); |
894 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); | 925 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); |
895 if (CheckForCancel()) | 926 if (CheckForCancel()) |
896 return false; | 927 return false; |
897 | 928 |
898 while (!print_preview_context_.IsFinalPageRendered()) { | 929 while (!print_preview_context_.IsFinalPageRendered()) { |
899 int page_number = print_preview_context_.GetNextPageNumber(); | 930 int page_number = print_preview_context_.GetNextPageNumber(); |
900 DCHECK_GE(page_number, 0); | 931 DCHECK_GE(page_number, 0); |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1775 DCHECK(IsRendering()); | 1806 DCHECK(IsRendering()); |
1776 return prep_frame_view_->GetPrintCanvasSize(); | 1807 return prep_frame_view_->GetPrintCanvasSize(); |
1777 } | 1808 } |
1778 | 1809 |
1779 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1810 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1780 prep_frame_view_.reset(); | 1811 prep_frame_view_.reset(); |
1781 metafile_.reset(); | 1812 metafile_.reset(); |
1782 pages_to_render_.clear(); | 1813 pages_to_render_.clear(); |
1783 error_ = PREVIEW_ERROR_NONE; | 1814 error_ = PREVIEW_ERROR_NONE; |
1784 } | 1815 } |
OLD | NEW |