Chromium Code Reviews| 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" |
| 11 #include "chrome/renderer/render_view.h" | 11 #include "chrome/renderer/render_view.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "printing/native_metafile.h" | 13 #include "printing/metafile_factory.h" |
| 14 #include "printing/units.h" | 14 #include "printing/units.h" |
| 15 #include "skia/ext/vector_canvas.h" | 15 #include "skia/ext/vector_canvas.h" |
| 16 #include "skia/ext/vector_platform_device.h" | 16 #include "skia/ext/vector_platform_device.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 18 #include "ui/gfx/gdi_util.h" | 18 #include "ui/gfx/gdi_util.h" |
| 19 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 20 | 20 |
| 21 using printing::ConvertUnitDouble; | 21 using printing::ConvertUnitDouble; |
| 22 using printing::kPointsPerInch; | 22 using printing::kPointsPerInch; |
| 23 using WebKit::WebFrame; | 23 using WebKit::WebFrame; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 PlayEnhMetaFileRecord(dc, handle_table, record, num_objects); | 61 PlayEnhMetaFileRecord(dc, handle_table, record, num_objects); |
| 62 } | 62 } |
| 63 return 1; // Continue enumeration | 63 return 1; // Continue enumeration |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, | 66 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
| 67 const gfx::Size& canvas_size, | 67 const gfx::Size& canvas_size, |
| 68 WebFrame* frame) { | 68 WebFrame* frame) { |
| 69 // Generate a memory-based metafile. It will use the current screen's DPI. | 69 // Generate a memory-based metafile. It will use the current screen's DPI. |
| 70 // Each metafile contains a single page. | 70 // Each metafile contains a single page. |
| 71 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 71 scoped_ptr<printing::NativeMetafile> metafile( |
| 72 printing::MetafileFactory::GetMetafile()); | |
|
Avi (use Gerrit)
2011/02/22 17:33:42
For example, this is a pointer without a _ptr nami
dpapad
2011/02/22 18:09:30
Done.
| |
| 72 metafile->CreateDc(NULL, NULL); | 73 metafile->CreateDc(NULL, NULL); |
| 73 DCHECK(metafile->hdc()); | 74 DCHECK(metafile->hdc()); |
| 74 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 75 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
| 75 | 76 |
| 76 int page_number = params.page_number; | 77 int page_number = params.page_number; |
| 77 | 78 |
| 78 // Calculate the dpi adjustment. | 79 // Calculate the dpi adjustment. |
| 79 float scale_factor = static_cast<float>(params.params.desired_dpi / | 80 float scale_factor = static_cast<float>(params.params.desired_dpi / |
| 80 params.params.dpi); | 81 params.params.dpi); |
| 81 | 82 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 if (!page_count) | 128 if (!page_count) |
| 128 return; | 129 return; |
| 129 | 130 |
| 130 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of | 131 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
| 131 // single page metafile. For print preview, we need a metafile with multiple | 132 // single page metafile. For print preview, we need a metafile with multiple |
| 132 // pages. | 133 // pages. |
| 133 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia | 134 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
| 134 // PDF backend" work is completed for windows, make changes to replace this | 135 // PDF backend" work is completed for windows, make changes to replace this |
| 135 // EMF with PDF metafile. | 136 // EMF with PDF metafile. |
| 136 // http://code.google.com/p/chromium/issues/detail?id=62889 | 137 // http://code.google.com/p/chromium/issues/detail?id=62889 |
| 137 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 138 scoped_ptr<printing::NativeMetafile> metafile( |
| 139 printing::MetafileFactory::GetMetafile()); | |
| 138 metafile->CreateDc(NULL, NULL); | 140 metafile->CreateDc(NULL, NULL); |
| 139 DCHECK(metafile->hdc()); | 141 DCHECK(metafile->hdc()); |
| 140 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 142 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
| 141 | 143 |
| 142 // Calculate the dpi adjustment. | 144 // Calculate the dpi adjustment. |
| 143 float shrink = static_cast<float>(params.params.desired_dpi / | 145 float shrink = static_cast<float>(params.params.desired_dpi / |
| 144 params.params.dpi); | 146 params.params.dpi); |
| 145 | 147 |
| 146 if (params.pages.empty()) { | 148 if (params.pages.empty()) { |
| 147 for (int i = 0; i < page_count; ++i) { | 149 for (int i = 0; i < page_count; ++i) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 #endif | 252 #endif |
| 251 | 253 |
| 252 skia::VectorPlatformDevice* platform_device = | 254 skia::VectorPlatformDevice* platform_device = |
| 253 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); | 255 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); |
| 254 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { | 256 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { |
| 255 // Close the device context to retrieve the compiled metafile. | 257 // Close the device context to retrieve the compiled metafile. |
| 256 if (!(*metafile)->CloseDc()) | 258 if (!(*metafile)->CloseDc()) |
| 257 NOTREACHED(); | 259 NOTREACHED(); |
| 258 | 260 |
| 259 scoped_ptr<printing::NativeMetafile> metafile2( | 261 scoped_ptr<printing::NativeMetafile> metafile2( |
| 260 new printing::NativeMetafile); | 262 printing::MetafileFactory::GetMetafile()); |
| 261 // Page used alpha blend, but printer doesn't support it. Rewrite the | 263 // Page used alpha blend, but printer doesn't support it. Rewrite the |
| 262 // metafile and flatten out the transparency. | 264 // metafile and flatten out the transparency. |
| 263 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); | 265 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); |
| 264 if (!bitmap_dc) { | 266 if (!bitmap_dc) { |
| 265 NOTREACHED() << "Bitmap DC creation failed"; | 267 NOTREACHED() << "Bitmap DC creation failed"; |
| 266 } | 268 } |
| 267 SetGraphicsMode(bitmap_dc, GM_ADVANCED); | 269 SetGraphicsMode(bitmap_dc, GM_ADVANCED); |
| 268 void* bits = NULL; | 270 void* bits = NULL; |
| 269 BITMAPINFO hdr; | 271 BITMAPINFO hdr; |
| 270 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); | 272 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 // Copy the bits into shared memory. | 324 // Copy the bits into shared memory. |
| 323 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 325 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
| 324 NOTREACHED() << "GetData() failed"; | 326 NOTREACHED() << "GetData() failed"; |
| 325 shared_buf.Unmap(); | 327 shared_buf.Unmap(); |
| 326 return false; | 328 return false; |
| 327 } | 329 } |
| 328 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 330 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
| 329 shared_buf.Unmap(); | 331 shared_buf.Unmap(); |
| 330 return true; | 332 return true; |
| 331 } | 333 } |
| OLD | NEW |