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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 Send(new PrintHostMsg_DuplicateSection(routing_id(), | 207 Send(new PrintHostMsg_DuplicateSection(routing_id(), |
208 preview_params.metafile_data_handle, | 208 preview_params.metafile_data_handle, |
209 &preview_params.metafile_data_handle)); | 209 &preview_params.metafile_data_handle)); |
210 Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params)); | 210 Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params)); |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 void PrintWebViewHelper::RenderPage( | 214 void PrintWebViewHelper::RenderPage( |
215 const PrintMsg_Print_Params& params, float* scale_factor, int page_number, | 215 const PrintMsg_Print_Params& params, float* scale_factor, int page_number, |
216 bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) { | 216 bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) { |
217 double content_width_in_points; | 217 GetPageSizeAndMarginsInPoints(frame, page_number, params); |
218 double content_height_in_points; | |
219 double margin_top_in_points; | |
220 double margin_left_in_points; | |
221 GetPageSizeAndMarginsInPoints(frame, page_number, params, | |
222 &content_width_in_points, | |
223 &content_height_in_points, | |
224 &margin_top_in_points, NULL, NULL, | |
225 &margin_left_in_points); | |
226 | 218 |
227 int width; | 219 int width; |
228 int height; | 220 int height; |
229 if (is_preview) { | 221 if (is_preview) { |
230 int dpi = static_cast<int>(params.dpi); | 222 int dpi = static_cast<int>(params.dpi); |
231 int desired_dpi = printing::kPointsPerInch; | 223 int desired_dpi = printing::kPointsPerInch; |
232 width = ConvertUnit(params.page_size.width(), dpi, desired_dpi); | 224 width = ConvertUnit(params.page_size.width(), dpi, desired_dpi); |
233 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi); | 225 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi); |
234 } else { | 226 } else { |
235 // Since WebKit extends the page width depending on the magical scale factor | 227 // Since WebKit extends the page width depending on the magical scale factor |
(...skipping 14 matching lines...) Expand all Loading... | |
250 // The printPage method may take a reference to the canvas we pass down, so it | 242 // The printPage method may take a reference to the canvas we pass down, so it |
251 // can't be a stack object. | 243 // can't be a stack object. |
252 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 244 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
253 canvas->unref(); // SkRefPtr and new both took a reference. | 245 canvas->unref(); // SkRefPtr and new both took a reference. |
254 if (is_preview) { | 246 if (is_preview) { |
255 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), | 247 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), |
256 metafile->get()); | 248 metafile->get()); |
257 } | 249 } |
258 | 250 |
259 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); | 251 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); |
252 | |
253 if (is_preview && params.header_footer) { | |
254 // The page_number count starts from '0', so, we add by '1'. | |
255 PrintHeaderAndFooter(device, canvas, page_number+1, preview_page_count_, | |
kmadhusu
2011/07/14 01:50:15
nit: add space before and after '+'.
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
256 webkit_scale_factor); | |
257 } | |
258 | |
260 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 259 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
261 NOTREACHED() << "Printing page " << page_number << " failed."; | 260 NOTREACHED() << "Printing page " << page_number << " failed."; |
262 } else { | 261 } else { |
263 // Update the dpi adjustment with the "page |scale_factor|" calculated in | 262 // Update the dpi adjustment with the "page |scale_factor|" calculated in |
264 // webkit. | 263 // webkit. |
265 *scale_factor /= webkit_scale_factor; | 264 *scale_factor /= webkit_scale_factor; |
266 } | 265 } |
267 | 266 |
268 bool result = (*metafile)->FinishPage(); | 267 bool result = (*metafile)->FinishPage(); |
269 DCHECK(result); | 268 DCHECK(result); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 // Copy the bits into shared memory. | 345 // Copy the bits into shared memory. |
347 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 346 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
348 NOTREACHED() << "GetData() failed"; | 347 NOTREACHED() << "GetData() failed"; |
349 shared_buf.Unmap(); | 348 shared_buf.Unmap(); |
350 return false; | 349 return false; |
351 } | 350 } |
352 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 351 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
353 shared_buf.Unmap(); | 352 shared_buf.Unmap(); |
354 return true; | 353 return true; |
355 } | 354 } |
OLD | NEW |