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" | |
14 #include "printing/metafile_skia_wrapper.h" | 13 #include "printing/metafile_skia_wrapper.h" |
15 #include "printing/page_size_margins.h" | 14 #include "printing/page_size_margins.h" |
16 #include "skia/ext/platform_device.h" | 15 #include "skia/ext/platform_device.h" |
17 #include "skia/ext/vector_canvas.h" | 16 #include "skia/ext/vector_canvas.h" |
18 #include "third_party/WebKit/public/platform/WebCanvas.h" | 17 #include "third_party/WebKit/public/platform/WebCanvas.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 | 19 |
21 namespace printing { | 20 namespace printing { |
22 | 21 |
23 using blink::WebFrame; | 22 using blink::WebFrame; |
(...skipping 26 matching lines...) Expand all Loading... |
50 page_params.data_size = 0; | 49 page_params.data_size = 0; |
51 } | 50 } |
52 | 51 |
53 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); | 52 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); |
54 } | 53 } |
55 | 54 |
56 bool PrintWebViewHelper::RenderPreviewPage( | 55 bool PrintWebViewHelper::RenderPreviewPage( |
57 int page_number, | 56 int page_number, |
58 const PrintMsg_Print_Params& print_params) { | 57 const PrintMsg_Print_Params& print_params) { |
59 PrintMsg_Print_Params printParams = print_params; | 58 PrintMsg_Print_Params printParams = print_params; |
60 scoped_ptr<Metafile> draft_metafile; | 59 scoped_ptr<PdfMetafileSkia> draft_metafile; |
61 Metafile* initial_render_metafile = print_preview_context_.metafile(); | 60 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
62 | 61 |
63 bool render_to_draft = print_preview_context_.IsModifiable() && | 62 bool render_to_draft = print_preview_context_.IsModifiable() && |
64 is_print_ready_metafile_sent_; | 63 is_print_ready_metafile_sent_; |
65 | 64 |
66 if (render_to_draft) { | 65 if (render_to_draft) { |
67 draft_metafile.reset(new PdfMetafileSkia()); | 66 draft_metafile.reset(new PdfMetafileSkia()); |
68 if (!draft_metafile->Init()) { | 67 if (!draft_metafile->Init()) { |
69 print_preview_context_.set_error( | 68 print_preview_context_.set_error( |
70 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); | 69 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); |
71 LOG(ERROR) << "Draft PdfMetafileSkia Init failed"; | 70 LOG(ERROR) << "Draft PdfMetafileSkia Init failed"; |
(...skipping 15 matching lines...) Expand all Loading... |
87 if (print_preview_context_.IsModifiable() && | 86 if (print_preview_context_.IsModifiable() && |
88 print_preview_context_.generate_draft_pages()) { | 87 print_preview_context_.generate_draft_pages()) { |
89 DCHECK(!draft_metafile.get()); | 88 DCHECK(!draft_metafile.get()); |
90 draft_metafile.reset( | 89 draft_metafile.reset( |
91 print_preview_context_.metafile()->GetMetafileForCurrentPage()); | 90 print_preview_context_.metafile()->GetMetafileForCurrentPage()); |
92 } | 91 } |
93 } | 92 } |
94 return PreviewPageRendered(page_number, draft_metafile.get()); | 93 return PreviewPageRendered(page_number, draft_metafile.get()); |
95 } | 94 } |
96 | 95 |
97 void PrintWebViewHelper::RenderPage( | 96 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, |
98 const PrintMsg_Print_Params& params, int page_number, WebFrame* frame, | 97 int page_number, |
99 bool is_preview, Metafile* metafile, gfx::Size* page_size, | 98 WebFrame* frame, |
100 gfx::Rect* content_rect) { | 99 bool is_preview, |
| 100 PdfMetafileSkia* metafile, |
| 101 gfx::Size* page_size, |
| 102 gfx::Rect* content_rect) { |
101 double scale_factor = 1.0f; | 103 double scale_factor = 1.0f; |
102 double webkit_shrink_factor = frame->getPrintPageShrink(page_number); | 104 double webkit_shrink_factor = frame->getPrintPageShrink(page_number); |
103 PageSizeMargins page_layout_in_points; | 105 PageSizeMargins page_layout_in_points; |
104 gfx::Rect content_area; | 106 gfx::Rect content_area; |
105 | 107 |
106 ComputePageLayoutInPointsForCss(frame, page_number, params, | 108 ComputePageLayoutInPointsForCss(frame, page_number, params, |
107 ignore_css_margins_, &scale_factor, | 109 ignore_css_margins_, &scale_factor, |
108 &page_layout_in_points); | 110 &page_layout_in_points); |
109 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, | 111 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, |
110 &content_area); | 112 &content_area); |
(...skipping 29 matching lines...) Expand all Loading... |
140 } | 142 } |
141 RenderPageContent(frame, page_number, canvas_area, content_area, | 143 RenderPageContent(frame, page_number, canvas_area, content_area, |
142 scale_factor, canvas_ptr); | 144 scale_factor, canvas_ptr); |
143 } | 145 } |
144 | 146 |
145 // Done printing. Close the device context to retrieve the compiled metafile. | 147 // Done printing. Close the device context to retrieve the compiled metafile. |
146 metafile->FinishPage(); | 148 metafile->FinishPage(); |
147 } | 149 } |
148 | 150 |
149 } // namespace printing | 151 } // namespace printing |
OLD | NEW |