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 #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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "chrome/common/print_messages.h" | 12 #include "chrome/common/print_messages.h" |
13 #include "printing/metafile.h" | 13 #include "printing/metafile.h" |
14 #include "printing/metafile_impl.h" | |
15 #include "printing/metafile_skia_wrapper.h" | 14 #include "printing/metafile_skia_wrapper.h" |
16 #include "printing/page_size_margins.h" | 15 #include "printing/page_size_margins.h" |
17 #include "skia/ext/platform_device.h" | 16 #include "skia/ext/platform_device.h" |
18 #include "skia/ext/vector_canvas.h" | 17 #include "skia/ext/vector_canvas.h" |
19 #include "third_party/WebKit/public/platform/WebCanvas.h" | 18 #include "third_party/WebKit/public/platform/WebCanvas.h" |
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
21 | 20 |
22 namespace printing { | 21 namespace printing { |
23 | 22 |
24 using blink::WebFrame; | 23 using blink::WebFrame; |
25 | 24 |
26 void PrintWebViewHelper::PrintPageInternal( | 25 void PrintWebViewHelper::PrintPageInternal( |
27 const PrintMsg_PrintPage_Params& params, | 26 const PrintMsg_PrintPage_Params& params, |
28 const gfx::Size& canvas_size, | 27 const gfx::Size& canvas_size, |
29 WebFrame* frame) { | 28 WebFrame* frame) { |
30 NativeMetafile metafile; | 29 PdfMetafileSkia metafile; |
31 if (!metafile.Init()) | 30 if (!metafile.Init()) |
32 return; | 31 return; |
33 | 32 |
34 int page_number = params.page_number; | 33 int page_number = params.page_number; |
35 gfx::Size page_size_in_dpi; | 34 gfx::Size page_size_in_dpi; |
36 gfx::Rect content_area_in_dpi; | 35 gfx::Rect content_area_in_dpi; |
37 RenderPage(print_pages_params_->params, page_number, frame, false, &metafile, | 36 RenderPage(print_pages_params_->params, page_number, frame, false, &metafile, |
38 &page_size_in_dpi, &content_area_in_dpi); | 37 &page_size_in_dpi, &content_area_in_dpi); |
39 metafile.FinishDocument(); | 38 metafile.FinishDocument(); |
40 | 39 |
(...skipping 17 matching lines...) Expand all Loading... |
58 int page_number, | 57 int page_number, |
59 const PrintMsg_Print_Params& print_params) { | 58 const PrintMsg_Print_Params& print_params) { |
60 PrintMsg_Print_Params printParams = print_params; | 59 PrintMsg_Print_Params printParams = print_params; |
61 scoped_ptr<Metafile> draft_metafile; | 60 scoped_ptr<Metafile> draft_metafile; |
62 Metafile* initial_render_metafile = print_preview_context_.metafile(); | 61 Metafile* initial_render_metafile = print_preview_context_.metafile(); |
63 | 62 |
64 bool render_to_draft = print_preview_context_.IsModifiable() && | 63 bool render_to_draft = print_preview_context_.IsModifiable() && |
65 is_print_ready_metafile_sent_; | 64 is_print_ready_metafile_sent_; |
66 | 65 |
67 if (render_to_draft) { | 66 if (render_to_draft) { |
68 draft_metafile.reset(new PreviewMetafile()); | 67 draft_metafile.reset(new PdfMetafileSkia()); |
69 if (!draft_metafile->Init()) { | 68 if (!draft_metafile->Init()) { |
70 print_preview_context_.set_error( | 69 print_preview_context_.set_error( |
71 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); | 70 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); |
72 LOG(ERROR) << "Draft PreviewMetafile Init failed"; | 71 LOG(ERROR) << "Draft PdfMetafileSkia Init failed"; |
73 return false; | 72 return false; |
74 } | 73 } |
75 initial_render_metafile = draft_metafile.get(); | 74 initial_render_metafile = draft_metafile.get(); |
76 } | 75 } |
77 | 76 |
78 base::TimeTicks begin_time = base::TimeTicks::Now(); | 77 base::TimeTicks begin_time = base::TimeTicks::Now(); |
79 gfx::Size page_size; | 78 gfx::Size page_size; |
80 RenderPage(printParams, page_number, print_preview_context_.prepared_frame(), | 79 RenderPage(printParams, page_number, print_preview_context_.prepared_frame(), |
81 true, initial_render_metafile, &page_size, NULL); | 80 true, initial_render_metafile, &page_size, NULL); |
82 print_preview_context_.RenderedPreviewPage( | 81 print_preview_context_.RenderedPreviewPage( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 140 } |
142 RenderPageContent(frame, page_number, canvas_area, content_area, | 141 RenderPageContent(frame, page_number, canvas_area, content_area, |
143 scale_factor, canvas_ptr); | 142 scale_factor, canvas_ptr); |
144 } | 143 } |
145 | 144 |
146 // Done printing. Close the device context to retrieve the compiled metafile. | 145 // Done printing. Close the device context to retrieve the compiled metafile. |
147 metafile->FinishPage(); | 146 metafile->FinishPage(); |
148 } | 147 } |
149 | 148 |
150 } // namespace printing | 149 } // namespace printing |
OLD | NEW |