| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
| 10 #include "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 gfx::Rect canvas_area = | 175 gfx::Rect canvas_area = |
| 176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
| 177 | 177 |
| 178 float webkit_page_shrink_factor = | 178 float webkit_page_shrink_factor = |
| 179 frame->getPrintPageShrink(params.page_number); | 179 frame->getPrintPageShrink(params.page_number); |
| 180 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 180 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
| 181 | 181 |
| 182 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, | 182 skia::VectorCanvas* canvas = |
| 183 canvas_area, | 183 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); |
| 184 scale_factor); | 184 if (!canvas) |
| 185 if (!device) | |
| 186 return; | 185 return; |
| 187 | 186 |
| 188 // The printPage method take a reference to the canvas we pass down, so it | |
| 189 // can't be a stack object. | |
| 190 skia::RefPtr<skia::VectorCanvas> canvas = | |
| 191 skia::AdoptRef(new skia::VectorCanvas(device)); | |
| 192 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 187 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 193 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 188 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 194 | 189 |
| 195 if (params.params.display_header_footer) { | 190 if (params.params.display_header_footer) { |
| 196 // |page_number| is 0-based, so 1 is added. | 191 // |page_number| is 0-based, so 1 is added. |
| 197 PrintHeaderAndFooter(canvas.get(), | 192 PrintHeaderAndFooter(canvas, params.page_number + 1, |
| 198 params.page_number + 1, | 193 print_preview_context_.total_page_count(), *frame, |
| 199 print_preview_context_.total_page_count(), | 194 scale_factor, page_layout_in_points, params.params); |
| 200 *frame, | |
| 201 scale_factor, | |
| 202 page_layout_in_points, | |
| 203 params.params); | |
| 204 } | 195 } |
| 205 | 196 |
| 206 float webkit_scale_factor = RenderPageContent(frame, | 197 float webkit_scale_factor = |
| 207 params.page_number, | 198 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
| 208 canvas_area, | 199 scale_factor, canvas); |
| 209 content_area, | |
| 210 scale_factor, | |
| 211 canvas.get()); | |
| 212 DCHECK_GT(webkit_scale_factor, 0.0f); | 200 DCHECK_GT(webkit_scale_factor, 0.0f); |
| 213 // Done printing. Close the device context to retrieve the compiled metafile. | 201 // Done printing. Close the canvas to retrieve the compiled metafile. |
| 214 if (!metafile->FinishPage()) | 202 if (!metafile->FinishPage()) |
| 215 NOTREACHED() << "metafile failed"; | 203 NOTREACHED() << "metafile failed"; |
| 216 } | 204 } |
| 217 | 205 |
| 218 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 206 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
| 219 PdfMetafileSkia* metafile, | 207 PdfMetafileSkia* metafile, |
| 220 base::SharedMemoryHandle* shared_mem_handle) { | 208 base::SharedMemoryHandle* shared_mem_handle) { |
| 221 uint32 buf_size = metafile->GetDataSize(); | 209 uint32 buf_size = metafile->GetDataSize(); |
| 222 base::SharedMemory shared_buf; | 210 base::SharedMemory shared_buf; |
| 223 // Allocate a shared memory buffer to hold the generated metafile data. | 211 // Allocate a shared memory buffer to hold the generated metafile data. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 234 } | 222 } |
| 235 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 223 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
| 236 shared_buf.Unmap(); | 224 shared_buf.Unmap(); |
| 237 | 225 |
| 238 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 226 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
| 239 shared_mem_handle)); | 227 shared_mem_handle)); |
| 240 return true; | 228 return true; |
| 241 } | 229 } |
| 242 | 230 |
| 243 } // namespace printing | 231 } // namespace printing |
| OLD | NEW |