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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame, | 22 bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame, |
23 int page_count) { | 23 int page_count) { |
24 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 24 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
25 const PrintMsg_Print_Params& print_params = params.params; | 25 const PrintMsg_Print_Params& print_params = params.params; |
26 | 26 |
27 std::vector<int> printed_pages = GetPrintedPages(params, page_count); | 27 std::vector<int> printed_pages = GetPrintedPages(params, page_count); |
28 if (printed_pages.empty()) | 28 if (printed_pages.empty()) |
29 return false; | 29 return false; |
30 | 30 |
31 if (delegate_->UseSingleMetafile()) { | 31 if (delegate_->UseSingleMetafile()) { |
32 PrintPagesInternal(print_params, printed_pages, frame); | 32 PrintPagesInternal(print_params, printed_pages, page_count, frame); |
33 return true; | 33 return true; |
34 } | 34 } |
35 | 35 |
36 for (int page_number : printed_pages) | 36 for (int page_number : printed_pages) |
37 PrintPagesInternal(print_params, std::vector<int>{page_number}, frame); | 37 PrintPagesInternal(print_params, std::vector<int>{page_number}, page_count, |
| 38 frame); |
38 return true; | 39 return true; |
39 } | 40 } |
40 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 41 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
41 | 42 |
42 void PrintWebViewHelper::PrintPagesInternal( | 43 void PrintWebViewHelper::PrintPagesInternal( |
43 const PrintMsg_Print_Params& params, | 44 const PrintMsg_Print_Params& params, |
44 const std::vector<int>& printed_pages, | 45 const std::vector<int>& printed_pages, |
| 46 int page_count, |
45 blink::WebLocalFrame* frame) { | 47 blink::WebLocalFrame* frame) { |
46 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); | 48 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); |
47 CHECK(metafile.Init()); | 49 CHECK(metafile.Init()); |
48 | 50 |
49 gfx::Size page_size_in_dpi; | 51 gfx::Size page_size_in_dpi; |
50 gfx::Rect content_area_in_dpi; | 52 gfx::Rect content_area_in_dpi; |
51 for (int page_number : printed_pages) { | 53 for (int page_number : printed_pages) { |
52 RenderPage(params, page_number, frame, false, &metafile, &page_size_in_dpi, | 54 RenderPage(params, page_number, page_count, frame, false, &metafile, |
53 &content_area_in_dpi); | 55 &page_size_in_dpi, &content_area_in_dpi); |
54 } | 56 } |
55 metafile.FinishDocument(); | 57 metafile.FinishDocument(); |
56 | 58 |
57 PrintHostMsg_DidPrintPage_Params page_params; | 59 PrintHostMsg_DidPrintPage_Params page_params; |
58 page_params.data_size = metafile.GetDataSize(); | 60 page_params.data_size = metafile.GetDataSize(); |
59 page_params.document_cookie = params.document_cookie; | 61 page_params.document_cookie = params.document_cookie; |
60 page_params.page_size = page_size_in_dpi; | 62 page_params.page_size = page_size_in_dpi; |
61 page_params.content_area = content_area_in_dpi; | 63 page_params.content_area = content_area_in_dpi; |
62 | 64 |
63 // Ask the browser to create the shared memory for us. | 65 // Ask the browser to create the shared memory for us. |
(...skipping 22 matching lines...) Expand all Loading... |
86 is_print_ready_metafile_sent_; | 88 is_print_ready_metafile_sent_; |
87 | 89 |
88 if (render_to_draft) { | 90 if (render_to_draft) { |
89 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); | 91 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); |
90 CHECK(draft_metafile->Init()); | 92 CHECK(draft_metafile->Init()); |
91 initial_render_metafile = draft_metafile.get(); | 93 initial_render_metafile = draft_metafile.get(); |
92 } | 94 } |
93 | 95 |
94 base::TimeTicks begin_time = base::TimeTicks::Now(); | 96 base::TimeTicks begin_time = base::TimeTicks::Now(); |
95 gfx::Size page_size; | 97 gfx::Size page_size; |
96 RenderPage(printParams, page_number, print_preview_context_.prepared_frame(), | 98 RenderPage(printParams, page_number, |
97 true, initial_render_metafile, &page_size, NULL); | 99 print_preview_context_.total_page_count(), |
| 100 print_preview_context_.prepared_frame(), true, |
| 101 initial_render_metafile, &page_size, NULL); |
98 print_preview_context_.RenderedPreviewPage( | 102 print_preview_context_.RenderedPreviewPage( |
99 base::TimeTicks::Now() - begin_time); | 103 base::TimeTicks::Now() - begin_time); |
100 | 104 |
101 if (draft_metafile.get()) { | 105 if (draft_metafile.get()) { |
102 draft_metafile->FinishDocument(); | 106 draft_metafile->FinishDocument(); |
103 } else { | 107 } else { |
104 if (print_preview_context_.IsModifiable() && | 108 if (print_preview_context_.IsModifiable() && |
105 print_preview_context_.generate_draft_pages()) { | 109 print_preview_context_.generate_draft_pages()) { |
106 DCHECK(!draft_metafile.get()); | 110 DCHECK(!draft_metafile.get()); |
107 draft_metafile = | 111 draft_metafile = |
108 print_preview_context_.metafile()->GetMetafileForCurrentPage( | 112 print_preview_context_.metafile()->GetMetafileForCurrentPage( |
109 PDF_SKIA_DOCUMENT_TYPE); | 113 PDF_SKIA_DOCUMENT_TYPE); |
110 } | 114 } |
111 } | 115 } |
112 return PreviewPageRendered(page_number, draft_metafile.get()); | 116 return PreviewPageRendered(page_number, draft_metafile.get()); |
113 } | 117 } |
114 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 118 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
115 | 119 |
116 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, | 120 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, |
117 int page_number, | 121 int page_number, |
| 122 int page_count, |
118 blink::WebLocalFrame* frame, | 123 blink::WebLocalFrame* frame, |
119 bool is_preview, | 124 bool is_preview, |
120 PdfMetafileSkia* metafile, | 125 PdfMetafileSkia* metafile, |
121 gfx::Size* page_size, | 126 gfx::Size* page_size, |
122 gfx::Rect* content_rect) { | 127 gfx::Rect* content_rect) { |
123 double scale_factor = | 128 double scale_factor = |
124 params.scale_factor >= kEpsilon ? params.scale_factor : 1.0f; | 129 params.scale_factor >= kEpsilon ? params.scale_factor : 1.0f; |
125 double webkit_shrink_factor = frame->GetPrintPageShrink(page_number); | 130 double webkit_shrink_factor = frame->GetPrintPageShrink(page_number); |
126 PageSizeMargins page_layout_in_points; | 131 PageSizeMargins page_layout_in_points; |
127 gfx::Rect content_area; | 132 gfx::Rect content_area; |
(...skipping 12 matching lines...) Expand all Loading... |
140 params.display_header_footer ? gfx::Rect(*page_size) : content_area; | 145 params.display_header_footer ? gfx::Rect(*page_size) : content_area; |
141 | 146 |
142 { | 147 { |
143 cc::PaintCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 148 cc::PaintCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
144 *page_size, canvas_area, scale_factor); | 149 *page_size, canvas_area, scale_factor); |
145 if (!canvas) | 150 if (!canvas) |
146 return; | 151 return; |
147 | 152 |
148 MetafileSkiaWrapper::SetMetafileOnCanvas(canvas, metafile); | 153 MetafileSkiaWrapper::SetMetafileOnCanvas(canvas, metafile); |
149 cc::SetIsPreviewMetafile(canvas, is_preview); | 154 cc::SetIsPreviewMetafile(canvas, is_preview); |
150 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | |
151 if (params.display_header_footer) { | 155 if (params.display_header_footer) { |
152 PrintHeaderAndFooter(static_cast<blink::WebCanvas*>(canvas), | 156 PrintHeaderAndFooter(static_cast<blink::WebCanvas*>(canvas), |
153 page_number + 1, | 157 page_number + 1, page_count, *frame, scale_factor, |
154 print_preview_context_.total_page_count(), *frame, | 158 page_layout_in_points, params); |
155 scale_factor, page_layout_in_points, params); | |
156 } | 159 } |
157 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | |
158 RenderPageContent(frame, page_number, canvas_area, content_area, | 160 RenderPageContent(frame, page_number, canvas_area, content_area, |
159 scale_factor, static_cast<blink::WebCanvas*>(canvas)); | 161 scale_factor, static_cast<blink::WebCanvas*>(canvas)); |
160 } | 162 } |
161 | 163 |
162 // Done printing. Close the device context to retrieve the compiled metafile. | 164 // Done printing. Close the device context to retrieve the compiled metafile. |
163 metafile->FinishPage(); | 165 metafile->FinishPage(); |
164 } | 166 } |
165 | 167 |
166 } // namespace printing | 168 } // namespace printing |
OLD | NEW |