| 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/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 "components/printing/common/print_messages.h" | 12 #include "components/printing/common/print_messages.h" |
| 13 #include "printing/metafile_skia_wrapper.h" | 13 #include "printing/metafile_skia_wrapper.h" |
| 14 #include "printing/page_size_margins.h" | 14 #include "printing/page_size_margins.h" |
| 15 #include "third_party/WebKit/public/platform/WebCanvas.h" | 15 #include "third_party/WebKit/public/platform/WebCanvas.h" |
| 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 | 18 |
| 19 namespace printing { | 19 namespace printing { |
| 20 | 20 |
| 21 #if defined(ENABLE_BASIC_PRINTING) | 21 #if defined(ENABLE_BASIC_PRINTING) |
| 22 bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame, | 22 bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame, |
| 23 int page_count) { | 23 int page_count) { |
| 24 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 24 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
| 25 const PrintMsg_Print_Params& print_params = params.params; | 25 const PrintMsg_Print_Params& print_params = params.params; |
| 26 | 26 |
| 27 std::vector<int> printed_pages = GetPrintedPages(params, page_count); | 27 std::vector<int> printed_pages = GetPrintedPages(params, page_count); |
| 28 if (printed_pages.empty()) | 28 if (printed_pages.empty()) |
| 29 return false; | 29 return false; |
| 30 | 30 |
| 31 PrintMsg_PrintPage_Params page_params; | 31 PrintMsg_PrintPage_Params page_params; |
| 32 page_params.params = print_params; | 32 page_params.params = print_params; |
| 33 for (int page_number : printed_pages) { | 33 for (int page_number : printed_pages) { |
| 34 page_params.page_number = page_number; | 34 page_params.page_number = page_number; |
| 35 PrintPageInternal(page_params, frame); | 35 PrintPageInternal(page_params, frame); |
| 36 } | 36 } |
| 37 return true; | 37 return true; |
| 38 } | 38 } |
| 39 #endif // defined(ENABLE_BASIC_PRINTING) | 39 #endif // defined(ENABLE_BASIC_PRINTING) |
| 40 | 40 |
| 41 void PrintWebViewHelper::PrintPageInternal( | 41 void PrintWebViewHelper::PrintPageInternal( |
| 42 const PrintMsg_PrintPage_Params& params, | 42 const PrintMsg_PrintPage_Params& params, |
| 43 blink::WebFrame* frame) { | 43 blink::WebLocalFrame* frame) { |
| 44 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); | 44 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); |
| 45 CHECK(metafile.Init()); | 45 CHECK(metafile.Init()); |
| 46 | 46 |
| 47 int page_number = params.page_number; | 47 int page_number = params.page_number; |
| 48 gfx::Size page_size_in_dpi; | 48 gfx::Size page_size_in_dpi; |
| 49 gfx::Rect content_area_in_dpi; | 49 gfx::Rect content_area_in_dpi; |
| 50 RenderPage(print_pages_params_->params, page_number, frame, false, &metafile, | 50 RenderPage(print_pages_params_->params, page_number, frame, false, &metafile, |
| 51 &page_size_in_dpi, &content_area_in_dpi); | 51 &page_size_in_dpi, &content_area_in_dpi); |
| 52 metafile.FinishDocument(); | 52 metafile.FinishDocument(); |
| 53 | 53 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 print_preview_context_.metafile()->GetMetafileForCurrentPage( | 102 print_preview_context_.metafile()->GetMetafileForCurrentPage( |
| 103 PDF_SKIA_DOCUMENT_TYPE); | 103 PDF_SKIA_DOCUMENT_TYPE); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 return PreviewPageRendered(page_number, draft_metafile.get()); | 106 return PreviewPageRendered(page_number, draft_metafile.get()); |
| 107 } | 107 } |
| 108 #endif // defined(ENABLE_PRINT_PREVIEW) | 108 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 109 | 109 |
| 110 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, | 110 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, |
| 111 int page_number, | 111 int page_number, |
| 112 blink::WebFrame* frame, | 112 blink::WebLocalFrame* frame, |
| 113 bool is_preview, | 113 bool is_preview, |
| 114 PdfMetafileSkia* metafile, | 114 PdfMetafileSkia* metafile, |
| 115 gfx::Size* page_size, | 115 gfx::Size* page_size, |
| 116 gfx::Rect* content_rect) { | 116 gfx::Rect* content_rect) { |
| 117 double scale_factor = 1.0f; | 117 double scale_factor = 1.0f; |
| 118 double webkit_shrink_factor = frame->getPrintPageShrink(page_number); | 118 double webkit_shrink_factor = frame->getPrintPageShrink(page_number); |
| 119 PageSizeMargins page_layout_in_points; | 119 PageSizeMargins page_layout_in_points; |
| 120 gfx::Rect content_area; | 120 gfx::Rect content_area; |
| 121 | 121 |
| 122 ComputePageLayoutInPointsForCss(frame, page_number, params, | 122 ComputePageLayoutInPointsForCss(frame, page_number, params, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 150 #endif // defined(ENABLE_PRINT_PREVIEW) | 150 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 151 RenderPageContent(frame, page_number, canvas_area, content_area, | 151 RenderPageContent(frame, page_number, canvas_area, content_area, |
| 152 scale_factor, static_cast<blink::WebCanvas*>(canvas)); | 152 scale_factor, static_cast<blink::WebCanvas*>(canvas)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Done printing. Close the device context to retrieve the compiled metafile. | 155 // Done printing. Close the device context to retrieve the compiled metafile. |
| 156 metafile->FinishPage(); | 156 metafile->FinishPage(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace printing | 159 } // namespace printing |
| OLD | NEW |