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