| 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 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
| 77 int sequence_number = -1; | 77 int sequence_number = -1; |
| 78 base::FileDescriptor fd; | 78 base::FileDescriptor fd; |
| 79 | 79 |
| 80 // Ask the browser to open a file for us. | 80 // Ask the browser to open a file for us. |
| 81 if (!Send(new ViewHostMsg_AllocateTempFileForPrinting(&fd, | 81 if (!Send(new ViewHostMsg_AllocateTempFileForPrinting(&fd, |
| 82 &sequence_number))) { | 82 &sequence_number))) { |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 if (!metafile->SaveTo(fd)) | 85 if (!metafile->SaveToFD(fd)) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 // Tell the browser we've finished writing the file. | 88 // Tell the browser we've finished writing the file. |
| 89 Send(new ViewHostMsg_TempFileForPrintingWritten(sequence_number)); | 89 Send(new ViewHostMsg_TempFileForPrintingWritten(sequence_number)); |
| 90 #else | 90 #else |
| 91 ViewHostMsg_DidPrintPage_Params printed_page_params; | 91 ViewHostMsg_DidPrintPage_Params printed_page_params; |
| 92 printed_page_params.data_size = 0; | 92 printed_page_params.data_size = 0; |
| 93 printed_page_params.document_cookie = params.params.document_cookie; | 93 printed_page_params.document_cookie = params.params.document_cookie; |
| 94 | 94 |
| 95 base::SharedMemoryHandle shared_mem_handle; | 95 base::SharedMemoryHandle shared_mem_handle; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 GetPageSizeAndMarginsInPoints(frame, | 205 GetPageSizeAndMarginsInPoints(frame, |
| 206 params.page_number, | 206 params.page_number, |
| 207 params.params, | 207 params.params, |
| 208 &content_width_in_points, | 208 &content_width_in_points, |
| 209 &content_height_in_points, | 209 &content_height_in_points, |
| 210 &margin_top_in_points, | 210 &margin_top_in_points, |
| 211 &margin_right_in_points, | 211 &margin_right_in_points, |
| 212 &margin_bottom_in_points, | 212 &margin_bottom_in_points, |
| 213 &margin_left_in_points); | 213 &margin_left_in_points); |
| 214 | 214 |
| 215 gfx::Size page_size(static_cast<int>(content_width_in_points), |
| 216 static_cast<int>(content_height_in_points)); |
| 217 |
| 215 cairo_t* cairo_context = | 218 cairo_t* cairo_context = |
| 216 metafile->StartPage(content_width_in_points, | 219 metafile->StartPage(page_size, |
| 217 content_height_in_points, | |
| 218 margin_top_in_points, | 220 margin_top_in_points, |
| 219 margin_right_in_points, | 221 margin_right_in_points, |
| 220 margin_bottom_in_points, | 222 margin_bottom_in_points, |
| 221 margin_left_in_points); | 223 margin_left_in_points); |
| 222 if (!cairo_context) | 224 if (!cairo_context) |
| 223 return; | 225 return; |
| 224 | 226 |
| 225 canvas->reset(new skia::VectorCanvas(cairo_context, | 227 canvas->reset(new skia::VectorCanvas(cairo_context, |
| 226 canvas_size.width(), | 228 canvas_size.width(), |
| 227 canvas_size.height())); | 229 canvas_size.height())); |
| 228 frame->printPage(params.page_number, canvas->get()); | 230 frame->printPage(params.page_number, canvas->get()); |
| 229 | 231 |
| 230 // TODO(myhuang): We should handle transformation for paper margins. | 232 // TODO(myhuang): We should handle transformation for paper margins. |
| 231 // TODO(myhuang): We should render the header and the footer. | 233 // TODO(myhuang): We should render the header and the footer. |
| 232 | 234 |
| 233 // Done printing. Close the device context to retrieve the compiled metafile. | 235 // Done printing. Close the device context to retrieve the compiled metafile. |
| 234 if (!metafile->FinishPage()) | 236 if (!metafile->FinishPage()) |
| 235 NOTREACHED() << "metafile failed"; | 237 NOTREACHED() << "metafile failed"; |
| 236 } | 238 } |
| OLD | NEW |