| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276 | 5 // TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276 |
| 6 | 6 |
| 7 #include "android_webview/renderer/print_web_view_helper.h" | 7 #include "android_webview/renderer/print_web_view_helper.h" |
| 8 | 8 |
| 9 #include "android_webview/common/print_messages.h" | 9 #include "android_webview/common/print_messages.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.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 "printing/pdf_metafile_skia.h" | 15 #include "printing/pdf_metafile_skia.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/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 20 | 19 |
| 21 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 20 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 22 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
| 23 #else | 22 #else |
| 24 #include "base/file_descriptor_posix.h" | 23 #include "base/file_descriptor_posix.h" |
| 25 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 24 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 26 | 25 |
| 27 namespace printing { | 26 namespace printing { |
| 28 | 27 |
| 29 using blink::WebFrame; | 28 using blink::WebFrame; |
| 30 | 29 |
| 31 bool PrintWebViewHelper::RenderPreviewPage( | 30 bool PrintWebViewHelper::RenderPreviewPage( |
| 32 int page_number, | 31 int page_number, |
| 33 const PrintMsg_Print_Params& print_params) { | 32 const PrintMsg_Print_Params& print_params) { |
| 34 PrintMsg_PrintPage_Params page_params; | 33 PrintMsg_PrintPage_Params page_params; |
| 35 page_params.params = print_params; | 34 page_params.params = print_params; |
| 36 page_params.page_number = page_number; | 35 page_params.page_number = page_number; |
| 37 scoped_ptr<Metafile> draft_metafile; | 36 scoped_ptr<PdfMetafileSkia> draft_metafile; |
| 38 Metafile* initial_render_metafile = print_preview_context_.metafile(); | 37 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
| 39 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 38 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
| 40 draft_metafile.reset(new PdfMetafileSkia); | 39 draft_metafile.reset(new PdfMetafileSkia); |
| 41 initial_render_metafile = draft_metafile.get(); | 40 initial_render_metafile = draft_metafile.get(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 base::TimeTicks begin_time = base::TimeTicks::Now(); | 43 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 45 PrintPageInternal(page_params, | 44 PrintPageInternal(page_params, |
| 46 print_preview_context_.GetPrintCanvasSize(), | 45 print_preview_context_.GetPrintCanvasSize(), |
| 47 print_preview_context_.prepared_frame(), | 46 print_preview_context_.prepared_frame(), |
| 48 initial_render_metafile); | 47 initial_render_metafile); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 printed_page_params.metafile_data_handle.fd = -1; | 146 printed_page_params.metafile_data_handle.fd = -1; |
| 148 } | 147 } |
| 149 return true; | 148 return true; |
| 150 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 149 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 151 } | 150 } |
| 152 | 151 |
| 153 void PrintWebViewHelper::PrintPageInternal( | 152 void PrintWebViewHelper::PrintPageInternal( |
| 154 const PrintMsg_PrintPage_Params& params, | 153 const PrintMsg_PrintPage_Params& params, |
| 155 const gfx::Size& canvas_size, | 154 const gfx::Size& canvas_size, |
| 156 WebFrame* frame, | 155 WebFrame* frame, |
| 157 Metafile* metafile) { | 156 PdfMetafileSkia* metafile) { |
| 158 PageSizeMargins page_layout_in_points; | 157 PageSizeMargins page_layout_in_points; |
| 159 double scale_factor = 1.0f; | 158 double scale_factor = 1.0f; |
| 160 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 159 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 161 ignore_css_margins_, &scale_factor, | 160 ignore_css_margins_, &scale_factor, |
| 162 &page_layout_in_points); | 161 &page_layout_in_points); |
| 163 gfx::Size page_size; | 162 gfx::Size page_size; |
| 164 gfx::Rect content_area; | 163 gfx::Rect content_area; |
| 165 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 164 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 166 &content_area); | 165 &content_area); |
| 167 gfx::Rect canvas_area = | 166 gfx::Rect canvas_area = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 191 } | 190 } |
| 192 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 191 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
| 193 scale_factor, canvas.get()); | 192 scale_factor, canvas.get()); |
| 194 | 193 |
| 195 // Done printing. Close the device context to retrieve the compiled metafile. | 194 // Done printing. Close the device context to retrieve the compiled metafile. |
| 196 if (!metafile->FinishPage()) | 195 if (!metafile->FinishPage()) |
| 197 NOTREACHED() << "metafile failed"; | 196 NOTREACHED() << "metafile failed"; |
| 198 } | 197 } |
| 199 | 198 |
| 200 } // namespace printing | 199 } // namespace printing |
| OLD | NEW |