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 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/process_util.h" | 22 #include "base/process_util.h" |
23 #endif // !defined(OS_CHROMEOS) | 23 #endif // !defined(OS_CHROMEOS) |
24 | 24 |
25 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
26 using WebKit::WebNode; | 26 using WebKit::WebNode; |
27 | 27 |
28 void PrintWebViewHelper::RenderPreviewPage(int page_number) { | 28 void PrintWebViewHelper::RenderPreviewPage(int page_number) { |
29 PrintMsg_PrintPage_Params page_params; | 29 PrintMsg_PrintPage_Params page_params; |
30 page_params.params = print_preview_context_.print_params(); | 30 page_params.params = print_preview_context_.print_params(); |
31 page_params.page_number = page_number; | 31 page_params.page_number = page_number; |
32 page_params.page_slot = | |
33 print_preview_context_.GetPageSlotForPage(page_number); | |
34 | 32 |
35 base::TimeTicks begin_time = base::TimeTicks::Now(); | 33 base::TimeTicks begin_time = base::TimeTicks::Now(); |
36 PrintPageInternal(page_params, | 34 PrintPageInternal(page_params, |
37 print_preview_context_.GetPrintCanvasSize(), | 35 print_preview_context_.GetPrintCanvasSize(), |
38 print_preview_context_.frame(), | 36 print_preview_context_.frame(), |
39 print_preview_context_.metafile()); | 37 print_preview_context_.metafile()); |
40 | 38 |
41 print_preview_context_.RenderedPreviewPage( | 39 print_preview_context_.RenderedPreviewPage( |
42 base::TimeTicks::Now() - begin_time); | 40 base::TimeTicks::Now() - begin_time); |
43 printing::Metafile* page_metafile = NULL; | 41 printing::Metafile* page_metafile = NULL; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 153 |
156 base::TimeTicks begin_time = base::TimeTicks::Now(); | 154 base::TimeTicks begin_time = base::TimeTicks::Now(); |
157 base::TimeTicks page_begin_time = begin_time; | 155 base::TimeTicks page_begin_time = begin_time; |
158 | 156 |
159 PrintMsg_PrintPage_Params page_params; | 157 PrintMsg_PrintPage_Params page_params; |
160 page_params.params = print_params; | 158 page_params.params = print_params; |
161 const gfx::Size& canvas_size = prepare->GetPrintCanvasSize(); | 159 const gfx::Size& canvas_size = prepare->GetPrintCanvasSize(); |
162 if (params.pages.empty()) { | 160 if (params.pages.empty()) { |
163 for (int i = 0; i < *page_count; ++i) { | 161 for (int i = 0; i < *page_count; ++i) { |
164 page_params.page_number = i; | 162 page_params.page_number = i; |
165 page_params.page_slot = i; | |
166 PrintPageInternal(page_params, canvas_size, frame, metafile); | 163 PrintPageInternal(page_params, canvas_size, frame, metafile); |
167 } | 164 } |
168 } else { | 165 } else { |
169 for (size_t i = 0; i < params.pages.size(); ++i) { | 166 for (size_t i = 0; i < params.pages.size(); ++i) { |
170 page_params.page_number = params.pages[i]; | 167 page_params.page_number = params.pages[i]; |
171 page_params.page_slot = i; | |
172 PrintPageInternal(page_params, canvas_size, frame, metafile); | 168 PrintPageInternal(page_params, canvas_size, frame, metafile); |
173 } | 169 } |
174 } | 170 } |
175 | 171 |
176 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time; | 172 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time; |
177 | 173 |
178 prepare->FinishPrinting(); | 174 prepare->FinishPrinting(); |
179 metafile->FinishDocument(); | 175 metafile->FinishDocument(); |
180 return true; | 176 return true; |
181 } | 177 } |
(...skipping 13 matching lines...) Expand all Loading... |
195 page_layout_in_points.margin_left, | 191 page_layout_in_points.margin_left, |
196 page_layout_in_points.content_height + | 192 page_layout_in_points.content_height + |
197 page_layout_in_points.margin_top + | 193 page_layout_in_points.margin_top + |
198 page_layout_in_points.margin_bottom); | 194 page_layout_in_points.margin_bottom); |
199 gfx::Rect content_area(page_layout_in_points.margin_left, | 195 gfx::Rect content_area(page_layout_in_points.margin_left, |
200 page_layout_in_points.margin_top, | 196 page_layout_in_points.margin_top, |
201 page_layout_in_points.content_width, | 197 page_layout_in_points.content_width, |
202 page_layout_in_points.content_height); | 198 page_layout_in_points.content_height); |
203 | 199 |
204 SkDevice* device = metafile->StartPageForVectorCanvas( | 200 SkDevice* device = metafile->StartPageForVectorCanvas( |
205 params.page_slot, page_size, content_area, 1.0f); | 201 page_size, content_area, 1.0f); |
206 if (!device) | 202 if (!device) |
207 return; | 203 return; |
208 | 204 |
209 // The printPage method take a reference to the canvas we pass down, so it | 205 // The printPage method take a reference to the canvas we pass down, so it |
210 // can't be a stack object. | 206 // can't be a stack object. |
211 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 207 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
212 canvas->unref(); // SkRefPtr and new both took a reference. | 208 canvas->unref(); // SkRefPtr and new both took a reference. |
213 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); | 209 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); |
214 frame->printPage(params.page_number, canvas.get()); | 210 frame->printPage(params.page_number, canvas.get()); |
215 | 211 |
216 // TODO(myhuang): We should render the header and the footer. | 212 // TODO(myhuang): We should render the header and the footer. |
217 | 213 |
218 // Done printing. Close the device context to retrieve the compiled metafile. | 214 // Done printing. Close the device context to retrieve the compiled metafile. |
219 if (!metafile->FinishPage()) | 215 if (!metafile->FinishPage()) |
220 NOTREACHED() << "metafile failed"; | 216 NOTREACHED() << "metafile failed"; |
221 } | 217 } |
OLD | NEW |