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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, | 70 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
71 const gfx::Size& canvas_size, | 71 const gfx::Size& canvas_size, |
72 WebFrame* frame) { | 72 WebFrame* frame) { |
73 // Generate a memory-based metafile. It will use the current screen's DPI. | 73 // Generate a memory-based metafile. It will use the current screen's DPI. |
74 // Each metafile contains a single page. | 74 // Each metafile contains a single page. |
75 scoped_ptr<printing::NativeMetafile> metafile( | 75 scoped_ptr<printing::NativeMetafile> metafile( |
76 printing::NativeMetafileFactory::Create()); | 76 printing::NativeMetafileFactory::Create()); |
77 metafile->CreateDc(NULL, NULL); | 77 metafile->Init(); |
78 DCHECK(metafile->context()); | 78 DCHECK(metafile->context()); |
79 skia::PlatformDevice::InitializeDC(metafile->context()); | 79 skia::PlatformDevice::InitializeDC(metafile->context()); |
80 | 80 |
81 int page_number = params.page_number; | 81 int page_number = params.page_number; |
82 | 82 |
83 // Calculate the dpi adjustment. | 83 // Calculate the dpi adjustment. |
84 float scale_factor = static_cast<float>(params.params.desired_dpi / | 84 float scale_factor = static_cast<float>(params.params.desired_dpi / |
85 params.params.dpi); | 85 params.params.dpi); |
86 | 86 |
87 // Render page for printing. | 87 // Render page for printing. |
(...skipping 16 matching lines...) Expand all Loading... |
104 page_params.page_size = params.params.page_size; | 104 page_params.page_size = params.params.page_size; |
105 page_params.content_area = gfx::Rect(params.params.margin_left, | 105 page_params.content_area = gfx::Rect(params.params.margin_left, |
106 params.params.margin_top, params.params.printable_size.width(), | 106 params.params.margin_top, params.params.printable_size.width(), |
107 params.params.printable_size.height()); | 107 params.params.printable_size.height()); |
108 page_params.has_visible_overlays = frame->isPageBoxVisible(page_number); | 108 page_params.has_visible_overlays = frame->isPageBoxVisible(page_number); |
109 | 109 |
110 if (!CopyMetafileDataToSharedMem(metafile.get(), | 110 if (!CopyMetafileDataToSharedMem(metafile.get(), |
111 &(page_params.metafile_data_handle))) { | 111 &(page_params.metafile_data_handle))) { |
112 page_params.data_size = 0; | 112 page_params.data_size = 0; |
113 } | 113 } |
114 metafile->CloseEmf(); | |
115 if (!Send(new ViewHostMsg_DuplicateSection( | 114 if (!Send(new ViewHostMsg_DuplicateSection( |
116 routing_id(), | 115 routing_id(), |
117 page_params.metafile_data_handle, | 116 page_params.metafile_data_handle, |
118 &page_params.metafile_data_handle))) { | 117 &page_params.metafile_data_handle))) { |
119 NOTREACHED() << "Send message failed."; | 118 NOTREACHED() << "Send message failed."; |
120 } | 119 } |
121 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); | 120 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); |
122 } | 121 } |
123 | 122 |
124 void PrintWebViewHelper::CreatePreviewDocument( | 123 void PrintWebViewHelper::CreatePreviewDocument( |
(...skipping 10 matching lines...) Expand all Loading... |
135 | 134 |
136 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of | 135 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
137 // single page metafile. For print preview, we need a metafile with multiple | 136 // single page metafile. For print preview, we need a metafile with multiple |
138 // pages. | 137 // pages. |
139 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia | 138 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
140 // PDF backend" work is completed for windows, make changes to replace this | 139 // PDF backend" work is completed for windows, make changes to replace this |
141 // EMF with PDF metafile. | 140 // EMF with PDF metafile. |
142 // http://code.google.com/p/chromium/issues/detail?id=62889 | 141 // http://code.google.com/p/chromium/issues/detail?id=62889 |
143 scoped_ptr<printing::NativeMetafile> metafile( | 142 scoped_ptr<printing::NativeMetafile> metafile( |
144 printing::NativeMetafileFactory::Create()); | 143 printing::NativeMetafileFactory::Create()); |
145 metafile->CreateDc(NULL, NULL); | 144 metafile->Init(); |
146 DCHECK(metafile->context()); | 145 DCHECK(metafile->context()); |
147 skia::PlatformDevice::InitializeDC(metafile->context()); | 146 skia::PlatformDevice::InitializeDC(metafile->context()); |
148 | 147 |
149 // Calculate the dpi adjustment. | 148 // Calculate the dpi adjustment. |
150 float shrink = static_cast<float>(params.params.desired_dpi / | 149 float shrink = static_cast<float>(params.params.desired_dpi / |
151 params.params.dpi); | 150 params.params.dpi); |
152 | 151 |
153 if (params.pages.empty()) { | 152 if (params.pages.empty()) { |
154 for (int i = 0; i < page_count; ++i) { | 153 for (int i = 0; i < page_count; ++i) { |
155 float scale_factor = shrink; | 154 float scale_factor = shrink; |
(...skipping 21 matching lines...) Expand all Loading... |
177 preview_params.document_cookie = params.params.document_cookie; | 176 preview_params.document_cookie = params.params.document_cookie; |
178 preview_params.data_size = buf_size; | 177 preview_params.data_size = buf_size; |
179 preview_params.metafile_data_handle = NULL; | 178 preview_params.metafile_data_handle = NULL; |
180 preview_params.expected_pages_count = page_count; | 179 preview_params.expected_pages_count = page_count; |
181 | 180 |
182 if (!CopyMetafileDataToSharedMem(metafile.get(), | 181 if (!CopyMetafileDataToSharedMem(metafile.get(), |
183 &(preview_params.metafile_data_handle))) { | 182 &(preview_params.metafile_data_handle))) { |
184 preview_params.data_size = 0; | 183 preview_params.data_size = 0; |
185 preview_params.expected_pages_count = 0; | 184 preview_params.expected_pages_count = 0; |
186 } | 185 } |
187 metafile->CloseEmf(); | |
188 if (!Send(new ViewHostMsg_DuplicateSection( | 186 if (!Send(new ViewHostMsg_DuplicateSection( |
189 routing_id(), | 187 routing_id(), |
190 preview_params.metafile_data_handle, | 188 preview_params.metafile_data_handle, |
191 &preview_params.metafile_data_handle))) { | 189 &preview_params.metafile_data_handle))) { |
192 NOTREACHED() << "Send message failed."; | 190 NOTREACHED() << "Send message failed."; |
193 } | 191 } |
194 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); | 192 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params)); |
195 } | 193 } |
196 | 194 |
197 void PrintWebViewHelper::RenderPage( | 195 void PrintWebViewHelper::RenderPage( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 HBITMAP hbitmap = CreateDIBSection( | 254 HBITMAP hbitmap = CreateDIBSection( |
257 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); | 255 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); |
258 if (!hbitmap) | 256 if (!hbitmap) |
259 NOTREACHED() << "Raster bitmap creation for printing failed"; | 257 NOTREACHED() << "Raster bitmap creation for printing failed"; |
260 | 258 |
261 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); | 259 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); |
262 RECT rect = {0, 0, width, height }; | 260 RECT rect = {0, 0, width, height }; |
263 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); | 261 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); |
264 FillRect(bitmap_dc, &rect, whiteBrush); | 262 FillRect(bitmap_dc, &rect, whiteBrush); |
265 | 263 |
266 metafile2->CreateDc(NULL, NULL); | 264 metafile2->Init(); |
267 HDC hdc = metafile2->context(); | 265 HDC hdc = metafile2->context(); |
268 DCHECK(hdc); | 266 DCHECK(hdc); |
269 skia::PlatformDevice::InitializeDC(hdc); | 267 skia::PlatformDevice::InitializeDC(hdc); |
270 | 268 |
271 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); | 269 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); |
272 // Process the old metafile, placing all non-AlphaBlend calls into the | 270 // Process the old metafile, placing all non-AlphaBlend calls into the |
273 // new metafile, and copying the results of all the AlphaBlend calls | 271 // new metafile, and copying the results of all the AlphaBlend calls |
274 // from the bitmap DC. | 272 // from the bitmap DC. |
275 EnumEnhMetaFile(hdc, | 273 EnumEnhMetaFile(hdc, |
276 (*metafile)->emf(), | 274 (*metafile)->emf(), |
(...skipping 29 matching lines...) Expand all Loading... |
306 // Copy the bits into shared memory. | 304 // Copy the bits into shared memory. |
307 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 305 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
308 NOTREACHED() << "GetData() failed"; | 306 NOTREACHED() << "GetData() failed"; |
309 shared_buf.Unmap(); | 307 shared_buf.Unmap(); |
310 return false; | 308 return false; |
311 } | 309 } |
312 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 310 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
313 shared_buf.Unmap(); | 311 shared_buf.Unmap(); |
314 return true; | 312 return true; |
315 } | 313 } |
OLD | NEW |