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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/common/render_messages_params.h" | 10 #include "chrome/common/render_messages_params.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, | 67 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
68 const gfx::Size& canvas_size, | 68 const gfx::Size& canvas_size, |
69 WebFrame* frame) { | 69 WebFrame* frame) { |
70 // Generate a memory-based metafile. It will use the current screen's DPI. | 70 // Generate a memory-based metafile. It will use the current screen's DPI. |
71 // Each metafile contains a single page. | 71 // Each metafile contains a single page. |
72 scoped_ptr<printing::NativeMetafile> metafile( | 72 scoped_ptr<printing::NativeMetafile> metafile( |
73 printing::NativeMetafileFactory::CreateMetafile()); | 73 printing::NativeMetafileFactory::CreateMetafile()); |
74 metafile->CreateDc(NULL, NULL); | 74 metafile->Init(); |
75 DCHECK(metafile->context()); | 75 DCHECK(metafile->context()); |
76 skia::PlatformDevice::InitializeDC(metafile->context()); | 76 skia::PlatformDevice::InitializeDC(metafile->context()); |
77 | 77 |
78 int page_number = params.page_number; | 78 int page_number = params.page_number; |
79 | 79 |
80 // Calculate the dpi adjustment. | 80 // Calculate the dpi adjustment. |
81 float scale_factor = static_cast<float>(params.params.desired_dpi / | 81 float scale_factor = static_cast<float>(params.params.desired_dpi / |
82 params.params.dpi); | 82 params.params.dpi); |
83 | 83 |
84 // Render page for printing. | 84 // Render page for printing. |
(...skipping 16 matching lines...) Expand all Loading... |
101 page_params.page_size = params.params.page_size; | 101 page_params.page_size = params.params.page_size; |
102 page_params.content_area = gfx::Rect(params.params.margin_left, | 102 page_params.content_area = gfx::Rect(params.params.margin_left, |
103 params.params.margin_top, params.params.printable_size.width(), | 103 params.params.margin_top, params.params.printable_size.width(), |
104 params.params.printable_size.height()); | 104 params.params.printable_size.height()); |
105 page_params.has_visible_overlays = frame->isPageBoxVisible(page_number); | 105 page_params.has_visible_overlays = frame->isPageBoxVisible(page_number); |
106 | 106 |
107 if (!CopyMetafileDataToSharedMem(metafile.get(), | 107 if (!CopyMetafileDataToSharedMem(metafile.get(), |
108 &(page_params.metafile_data_handle))) { | 108 &(page_params.metafile_data_handle))) { |
109 page_params.data_size = 0; | 109 page_params.data_size = 0; |
110 } | 110 } |
111 metafile->CloseEmf(); | |
112 if (!Send(new ViewHostMsg_DuplicateSection( | 111 if (!Send(new ViewHostMsg_DuplicateSection( |
113 routing_id(), | 112 routing_id(), |
114 page_params.metafile_data_handle, | 113 page_params.metafile_data_handle, |
115 &page_params.metafile_data_handle))) { | 114 &page_params.metafile_data_handle))) { |
116 NOTREACHED() << "Send message failed."; | 115 NOTREACHED() << "Send message failed."; |
117 } | 116 } |
118 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); | 117 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); |
119 } | 118 } |
120 | 119 |
121 void PrintWebViewHelper::CreatePreviewDocument( | 120 void PrintWebViewHelper::CreatePreviewDocument( |
(...skipping 10 matching lines...) Expand all Loading... |
132 | 131 |
133 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of | 132 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
134 // single page metafile. For print preview, we need a metafile with multiple | 133 // single page metafile. For print preview, we need a metafile with multiple |
135 // pages. | 134 // pages. |
136 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia | 135 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
137 // PDF backend" work is completed for windows, make changes to replace this | 136 // PDF backend" work is completed for windows, make changes to replace this |
138 // EMF with PDF metafile. | 137 // EMF with PDF metafile. |
139 // http://code.google.com/p/chromium/issues/detail?id=62889 | 138 // http://code.google.com/p/chromium/issues/detail?id=62889 |
140 scoped_ptr<printing::NativeMetafile> metafile( | 139 scoped_ptr<printing::NativeMetafile> metafile( |
141 printing::NativeMetafileFactory::CreateMetafile()); | 140 printing::NativeMetafileFactory::CreateMetafile()); |
142 metafile->CreateDc(NULL, NULL); | 141 metafile->Init(); |
143 DCHECK(metafile->context()); | 142 DCHECK(metafile->context()); |
144 skia::PlatformDevice::InitializeDC(metafile->context()); | 143 skia::PlatformDevice::InitializeDC(metafile->context()); |
145 | 144 |
146 // Calculate the dpi adjustment. | 145 // Calculate the dpi adjustment. |
147 float shrink = static_cast<float>(params.params.desired_dpi / | 146 float shrink = static_cast<float>(params.params.desired_dpi / |
148 params.params.dpi); | 147 params.params.dpi); |
149 | 148 |
150 if (params.pages.empty()) { | 149 if (params.pages.empty()) { |
151 for (int i = 0; i < page_count; ++i) { | 150 for (int i = 0; i < page_count; ++i) { |
152 float scale_factor = shrink; | 151 float scale_factor = shrink; |
(...skipping 21 matching lines...) Expand all Loading... |
174 preview_params.document_cookie = params.params.document_cookie; | 173 preview_params.document_cookie = params.params.document_cookie; |
175 preview_params.data_size = buf_size; | 174 preview_params.data_size = buf_size; |
176 preview_params.metafile_data_handle = NULL; | 175 preview_params.metafile_data_handle = NULL; |
177 preview_params.expected_pages_count = page_count; | 176 preview_params.expected_pages_count = page_count; |
178 | 177 |
179 if (!CopyMetafileDataToSharedMem(metafile.get(), | 178 if (!CopyMetafileDataToSharedMem(metafile.get(), |
180 &(preview_params.metafile_data_handle))) { | 179 &(preview_params.metafile_data_handle))) { |
181 preview_params.data_size = 0; | 180 preview_params.data_size = 0; |
182 preview_params.expected_pages_count = 0; | 181 preview_params.expected_pages_count = 0; |
183 } | 182 } |
184 metafile->CloseEmf(); | |
185 if (!Send(new ViewHostMsg_DuplicateSection( | 183 if (!Send(new ViewHostMsg_DuplicateSection( |
186 routing_id(), | 184 routing_id(), |
187 preview_params.metafile_data_handle, | 185 preview_params.metafile_data_handle, |
188 &preview_params.metafile_data_handle))) { | 186 &preview_params.metafile_data_handle))) { |
189 NOTREACHED() << "Send message failed."; | 187 NOTREACHED() << "Send message failed."; |
190 } | 188 } |
191 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); | 189 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); |
192 } | 190 } |
193 | 191 |
194 void PrintWebViewHelper::RenderPage( | 192 void PrintWebViewHelper::RenderPage( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 HBITMAP hbitmap = CreateDIBSection( | 280 HBITMAP hbitmap = CreateDIBSection( |
283 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); | 281 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); |
284 if (!hbitmap) | 282 if (!hbitmap) |
285 NOTREACHED() << "Raster bitmap creation for printing failed"; | 283 NOTREACHED() << "Raster bitmap creation for printing failed"; |
286 | 284 |
287 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); | 285 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); |
288 RECT rect = {0, 0, width, height }; | 286 RECT rect = {0, 0, width, height }; |
289 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); | 287 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); |
290 FillRect(bitmap_dc, &rect, whiteBrush); | 288 FillRect(bitmap_dc, &rect, whiteBrush); |
291 | 289 |
292 metafile2->CreateDc(NULL, NULL); | 290 metafile2->Init(); |
293 HDC hdc = metafile2->context(); | 291 HDC hdc = metafile2->context(); |
294 DCHECK(hdc); | 292 DCHECK(hdc); |
295 skia::PlatformDevice::InitializeDC(hdc); | 293 skia::PlatformDevice::InitializeDC(hdc); |
296 | 294 |
297 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); | 295 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); |
298 // Process the old metafile, placing all non-AlphaBlend calls into the | 296 // Process the old metafile, placing all non-AlphaBlend calls into the |
299 // new metafile, and copying the results of all the AlphaBlend calls | 297 // new metafile, and copying the results of all the AlphaBlend calls |
300 // from the bitmap DC. | 298 // from the bitmap DC. |
301 EnumEnhMetaFile(hdc, | 299 EnumEnhMetaFile(hdc, |
302 (*metafile)->emf(), | 300 (*metafile)->emf(), |
(...skipping 29 matching lines...) Expand all Loading... |
332 // Copy the bits into shared memory. | 330 // Copy the bits into shared memory. |
333 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 331 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
334 NOTREACHED() << "GetData() failed"; | 332 NOTREACHED() << "GetData() failed"; |
335 shared_buf.Unmap(); | 333 shared_buf.Unmap(); |
336 return false; | 334 return false; |
337 } | 335 } |
338 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 336 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
339 shared_buf.Unmap(); | 337 shared_buf.Unmap(); |
340 return true; | 338 return true; |
341 } | 339 } |
OLD | NEW |