| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/print_web_view_helper.h" | 5 #include "chrome/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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const gfx::Size& canvas_size, | 29 const gfx::Size& canvas_size, |
| 30 WebFrame* frame) { | 30 WebFrame* frame) { |
| 31 printing::NativeMetafile metafile; | 31 printing::NativeMetafile metafile; |
| 32 if (!metafile.Init()) | 32 if (!metafile.Init()) |
| 33 return; | 33 return; |
| 34 | 34 |
| 35 float scale_factor = frame->getPrintPageShrink(params.page_number); | 35 float scale_factor = frame->getPrintPageShrink(params.page_number); |
| 36 int page_number = params.page_number; | 36 int page_number = params.page_number; |
| 37 | 37 |
| 38 // Render page for printing. | 38 // Render page for printing. |
| 39 gfx::Rect content_area(params.params.printable_size); | 39 gfx::Rect content_area(params.params.content_size); |
| 40 RenderPage(params.params.printable_size, content_area, scale_factor, | 40 RenderPage(params.params.content_size, content_area, scale_factor, |
| 41 page_number, frame, false, &metafile); | 41 page_number, frame, false, &metafile); |
| 42 metafile.FinishDocument(); | 42 metafile.FinishDocument(); |
| 43 | 43 |
| 44 PrintHostMsg_DidPrintPage_Params page_params; | 44 PrintHostMsg_DidPrintPage_Params page_params; |
| 45 page_params.data_size = metafile.GetDataSize(); | 45 page_params.data_size = metafile.GetDataSize(); |
| 46 page_params.page_number = page_number; | 46 page_params.page_number = page_number; |
| 47 page_params.document_cookie = params.params.document_cookie; | 47 page_params.document_cookie = params.params.document_cookie; |
| 48 page_params.actual_shrink = scale_factor; | 48 page_params.actual_shrink = scale_factor; |
| 49 page_params.page_size = params.params.page_size; | 49 page_params.page_size = params.params.page_size; |
| 50 page_params.content_area = gfx::Rect(params.params.margin_left, | 50 page_params.content_area = gfx::Rect(params.params.margin_left, |
| 51 params.params.margin_top, | 51 params.params.margin_top, |
| 52 params.params.printable_size.width(), | 52 params.params.content_size.width(), |
| 53 params.params.printable_size.height()); | 53 params.params.content_size.height()); |
| 54 | 54 |
| 55 // Ask the browser to create the shared memory for us. | 55 // Ask the browser to create the shared memory for us. |
| 56 if (!CopyMetafileDataToSharedMem(&metafile, | 56 if (!CopyMetafileDataToSharedMem(&metafile, |
| 57 &(page_params.metafile_data_handle))) { | 57 &(page_params.metafile_data_handle))) { |
| 58 page_params.data_size = 0; | 58 page_params.data_size = 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); | 61 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool PrintWebViewHelper::RenderPreviewPage(int page_number) { | 64 bool PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| 65 float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); | 65 float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); |
| 66 PrintMsg_Print_Params printParams = print_preview_context_.print_params(); | 66 PrintMsg_Print_Params printParams = print_preview_context_.print_params(); |
| 67 gfx::Rect content_area(printParams.margin_left, printParams.margin_top, | 67 gfx::Rect content_area(printParams.margin_left, printParams.margin_top, |
| 68 printParams.printable_size.width(), | 68 printParams.content_size.width(), |
| 69 printParams.printable_size.height()); | 69 printParams.content_size.height()); |
| 70 | 70 |
| 71 scoped_ptr<printing::Metafile> draft_metafile; | 71 scoped_ptr<printing::Metafile> draft_metafile; |
| 72 printing::Metafile* initial_render_metafile = | 72 printing::Metafile* initial_render_metafile = |
| 73 print_preview_context_.metafile(); | 73 print_preview_context_.metafile(); |
| 74 | 74 |
| 75 #if defined(USE_SKIA) | 75 #if defined(USE_SKIA) |
| 76 bool render_to_draft = print_preview_context_.IsModifiable() && | 76 bool render_to_draft = print_preview_context_.IsModifiable() && |
| 77 is_print_ready_metafile_sent_; | 77 is_print_ready_metafile_sent_; |
| 78 #else | 78 #else |
| 79 // If the page needs to be in both draft metafile and print ready metafile, | 79 // If the page needs to be in both draft metafile and print ready metafile, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 print_preview_context_.total_page_count(), | 199 print_preview_context_.total_page_count(), |
| 200 scale_factor, page_layout_in_points, | 200 scale_factor, page_layout_in_points, |
| 201 *header_footer_info_); | 201 *header_footer_info_); |
| 202 } | 202 } |
| 203 #endif // defined(USE_SKIA) | 203 #endif // defined(USE_SKIA) |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Done printing. Close the device context to retrieve the compiled metafile. | 206 // Done printing. Close the device context to retrieve the compiled metafile. |
| 207 metafile->FinishPage(); | 207 metafile->FinishPage(); |
| 208 } | 208 } |
| OLD | NEW |