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/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/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/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "base/win/scoped_gdi_object.h" | 11 #include "base/win/scoped_gdi_object.h" |
12 #include "base/win/scoped_hdc.h" | 12 #include "base/win/scoped_hdc.h" |
13 #include "base/win/scoped_select_object.h" | 13 #include "base/win/scoped_select_object.h" |
14 #include "chrome/common/print_messages.h" | 14 #include "chrome/common/print_messages.h" |
15 #include "printing/metafile.h" | 15 #include "printing/metafile.h" |
16 #include "printing/metafile_impl.h" | |
17 #include "printing/metafile_skia_wrapper.h" | 16 #include "printing/metafile_skia_wrapper.h" |
18 #include "printing/page_size_margins.h" | 17 #include "printing/page_size_margins.h" |
| 18 #include "printing/pdf_metafile_skia.h" |
19 #include "printing/units.h" | 19 #include "printing/units.h" |
20 #include "skia/ext/platform_device.h" | 20 #include "skia/ext/platform_device.h" |
21 #include "skia/ext/refptr.h" | 21 #include "skia/ext/refptr.h" |
22 #include "skia/ext/vector_canvas.h" | 22 #include "skia/ext/vector_canvas.h" |
23 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
24 #include "ui/gfx/gdi_util.h" | 24 #include "ui/gfx/gdi_util.h" |
25 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
27 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
28 | 28 |
29 namespace printing { | 29 namespace printing { |
30 | 30 |
31 using blink::WebFrame; | 31 using blink::WebFrame; |
32 | 32 |
33 void PrintWebViewHelper::PrintPageInternal( | 33 void PrintWebViewHelper::PrintPageInternal( |
34 const PrintMsg_PrintPage_Params& params, | 34 const PrintMsg_PrintPage_Params& params, |
35 const gfx::Size& canvas_size, | 35 const gfx::Size& canvas_size, |
36 WebFrame* frame) { | 36 WebFrame* frame) { |
37 // Generate a memory-based metafile. It will use the current screen's DPI. | 37 // Generate a memory-based metafile. It will use the current screen's DPI. |
38 // Each metafile contains a single page. | 38 // Each metafile contains a single page. |
39 scoped_ptr<NativeMetafile> metafile(new NativeMetafile); | 39 scoped_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia); |
40 metafile->Init(); | 40 metafile->Init(); |
41 DCHECK(metafile->context()); | 41 DCHECK(metafile->context()); |
42 skia::InitializeDC(metafile->context()); | 42 skia::InitializeDC(metafile->context()); |
43 | 43 |
44 int page_number = params.page_number; | 44 int page_number = params.page_number; |
45 | 45 |
46 // Calculate the dpi adjustment. | 46 // Calculate the dpi adjustment. |
47 // Browser will render context using desired_dpi, so we need to calculate | 47 // Browser will render context using desired_dpi, so we need to calculate |
48 // adjustment factor to play content on the printer DC later during the | 48 // adjustment factor to play content on the printer DC later during the |
49 // actual printing. | 49 // actual printing. |
50 double actual_shrink = static_cast<float>(params.params.desired_dpi / | 50 double actual_shrink = static_cast<float>(params.params.desired_dpi / |
51 params.params.dpi); | 51 params.params.dpi); |
52 gfx::Size page_size_in_dpi; | 52 gfx::Size page_size_in_dpi; |
53 gfx::Rect content_area_in_dpi; | 53 gfx::Rect content_area_in_dpi; |
54 | 54 |
55 // Render page for printing. | 55 // Render page for printing. |
56 RenderPage(params.params, page_number, frame, false, metafile.get(), | 56 RenderPage(params.params, page_number, frame, false, metafile.get(), |
57 &actual_shrink, &page_size_in_dpi, &content_area_in_dpi); | 57 &actual_shrink, &page_size_in_dpi, &content_area_in_dpi); |
58 | 58 |
59 // Close the device context to retrieve the compiled metafile. | 59 // Close the device context to retrieve the compiled metafile. |
60 if (!metafile->FinishDocument()) | 60 if (!metafile->FinishDocument()) |
61 NOTREACHED(); | 61 NOTREACHED(); |
62 | 62 |
63 if (!params.params.supports_alpha_blend && metafile->IsAlphaBlendUsed()) { | 63 if (!params.params.supports_alpha_blend && metafile->IsAlphaBlendUsed()) { |
64 scoped_ptr<NativeMetafile> raster_metafile( | 64 scoped_ptr<PdfMetafileSkia> raster_metafile( |
65 metafile->RasterizeAlphaBlend()); | 65 metafile->RasterizeAlphaBlend()); |
66 if (raster_metafile.get()) | 66 if (raster_metafile.get()) |
67 metafile.swap(raster_metafile); | 67 metafile.swap(raster_metafile); |
68 } | 68 } |
69 | 69 |
70 // Get the size of the compiled metafile. | 70 // Get the size of the compiled metafile. |
71 uint32 buf_size = metafile->GetDataSize(); | 71 uint32 buf_size = metafile->GetDataSize(); |
72 DCHECK_GT(buf_size, 128u); | 72 DCHECK_GT(buf_size, 128u); |
73 | 73 |
74 PrintHostMsg_DidPrintPage_Params page_params; | 74 PrintHostMsg_DidPrintPage_Params page_params; |
(...skipping 16 matching lines...) Expand all Loading... |
91 bool PrintWebViewHelper::RenderPreviewPage( | 91 bool PrintWebViewHelper::RenderPreviewPage( |
92 int page_number, | 92 int page_number, |
93 const PrintMsg_Print_Params& print_params) { | 93 const PrintMsg_Print_Params& print_params) { |
94 // Calculate the dpi adjustment. | 94 // Calculate the dpi adjustment. |
95 double actual_shrink = static_cast<float>(print_params.desired_dpi / | 95 double actual_shrink = static_cast<float>(print_params.desired_dpi / |
96 print_params.dpi); | 96 print_params.dpi); |
97 scoped_ptr<Metafile> draft_metafile; | 97 scoped_ptr<Metafile> draft_metafile; |
98 Metafile* initial_render_metafile = print_preview_context_.metafile(); | 98 Metafile* initial_render_metafile = print_preview_context_.metafile(); |
99 | 99 |
100 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 100 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
101 draft_metafile.reset(new PreviewMetafile); | 101 draft_metafile.reset(new PdfMetafileSkia); |
102 initial_render_metafile = draft_metafile.get(); | 102 initial_render_metafile = draft_metafile.get(); |
103 } | 103 } |
104 | 104 |
105 base::TimeTicks begin_time = base::TimeTicks::Now(); | 105 base::TimeTicks begin_time = base::TimeTicks::Now(); |
106 RenderPage(print_params, page_number, print_preview_context_.prepared_frame(), | 106 RenderPage(print_params, page_number, print_preview_context_.prepared_frame(), |
107 true, initial_render_metafile, &actual_shrink, NULL, NULL); | 107 true, initial_render_metafile, &actual_shrink, NULL, NULL); |
108 print_preview_context_.RenderedPreviewPage( | 108 print_preview_context_.RenderedPreviewPage( |
109 base::TimeTicks::Now() - begin_time); | 109 base::TimeTicks::Now() - begin_time); |
110 | 110 |
111 if (draft_metafile.get()) { | 111 if (draft_metafile.get()) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 241 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
242 shared_buf.Unmap(); | 242 shared_buf.Unmap(); |
243 | 243 |
244 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 244 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
245 shared_mem_handle)); | 245 shared_mem_handle)); |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 } // namespace printing | 249 } // namespace printing |
OLD | NEW |