Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 7019013: Removal of dependencies on PlatformDevice classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing comments. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void PrintWebViewHelper::PrintPageInternal( 73 void PrintWebViewHelper::PrintPageInternal(
74 const PrintMsg_PrintPage_Params& params, 74 const PrintMsg_PrintPage_Params& params,
75 const gfx::Size& canvas_size, 75 const gfx::Size& canvas_size,
76 WebFrame* frame) { 76 WebFrame* frame) {
77 // Generate a memory-based metafile. It will use the current screen's DPI. 77 // Generate a memory-based metafile. It will use the current screen's DPI.
78 // Each metafile contains a single page. 78 // Each metafile contains a single page.
79 scoped_ptr<Metafile> metafile(new printing::NativeMetafile); 79 scoped_ptr<Metafile> metafile(new printing::NativeMetafile);
80 metafile->Init(); 80 metafile->Init();
81 DCHECK(metafile->context()); 81 DCHECK(metafile->context());
82 skia::PlatformDevice::InitializeDC(metafile->context()); 82 skia::InitializeDC(metafile->context());
83 83
84 int page_number = params.page_number; 84 int page_number = params.page_number;
85 85
86 // Calculate the dpi adjustment. 86 // Calculate the dpi adjustment.
87 float scale_factor = static_cast<float>(params.params.desired_dpi / 87 float scale_factor = static_cast<float>(params.params.desired_dpi /
88 params.params.dpi); 88 params.params.dpi);
89 89
90 // Render page for printing. 90 // Render page for printing.
91 RenderPage(params.params, &scale_factor, page_number, false, frame, 91 RenderPage(params.params, &scale_factor, page_number, false, frame,
92 &metafile); 92 &metafile);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // PrintContext will then set the correct clipping region. 213 // PrintContext will then set the correct clipping region.
214 width = static_cast<int>(content_width_in_points * params.max_shrink); 214 width = static_cast<int>(content_width_in_points * params.max_shrink);
215 height = static_cast<int>(content_height_in_points * params.max_shrink); 215 height = static_cast<int>(content_height_in_points * params.max_shrink);
216 } 216 }
217 217
218 gfx::Size page_size(width, height); 218 gfx::Size page_size(width, height);
219 gfx::Rect content_area(static_cast<int>(margin_left_in_points), 219 gfx::Rect content_area(static_cast<int>(margin_left_in_points),
220 static_cast<int>(margin_top_in_points), 220 static_cast<int>(margin_top_in_points),
221 static_cast<int>(content_width_in_points), 221 static_cast<int>(content_width_in_points),
222 static_cast<int>(content_height_in_points)); 222 static_cast<int>(content_height_in_points));
223 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( 223 SkDevice* device = (*metafile)->StartPageForVectorCanvas(
224 page_size, content_area, frame->getPrintPageShrink(page_number)); 224 page_size, content_area, frame->getPrintPageShrink(page_number));
225 DCHECK(device); 225 DCHECK(device);
226 skia::VectorCanvas canvas(device); 226 skia::VectorCanvas canvas(device);
227 227
228 float webkit_scale_factor = frame->printPage(page_number, &canvas); 228 float webkit_scale_factor = frame->printPage(page_number, &canvas);
229 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 229 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
230 NOTREACHED() << "Printing page " << page_number << " failed."; 230 NOTREACHED() << "Printing page " << page_number << " failed.";
231 } else { 231 } else {
232 // Update the dpi adjustment with the "page |scale_factor|" calculated in 232 // Update the dpi adjustment with the "page |scale_factor|" calculated in
233 // webkit. 233 // webkit.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); 269 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
270 RECT rect = {0, 0, width, height }; 270 RECT rect = {0, 0, width, height };
271 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); 271 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
272 FillRect(bitmap_dc, &rect, whiteBrush); 272 FillRect(bitmap_dc, &rect, whiteBrush);
273 273
274 scoped_ptr<Metafile> metafile2(new printing::NativeMetafile); 274 scoped_ptr<Metafile> metafile2(new printing::NativeMetafile);
275 metafile2->Init(); 275 metafile2->Init();
276 HDC hdc = metafile2->context(); 276 HDC hdc = metafile2->context();
277 DCHECK(hdc); 277 DCHECK(hdc);
278 skia::PlatformDevice::InitializeDC(hdc); 278 skia::InitializeDC(hdc);
279 279
280 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); 280 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
281 // Process the old metafile, placing all non-AlphaBlend calls into the 281 // Process the old metafile, placing all non-AlphaBlend calls into the
282 // new metafile, and copying the results of all the AlphaBlend calls 282 // new metafile, and copying the results of all the AlphaBlend calls
283 // from the bitmap DC. 283 // from the bitmap DC.
284 EnumEnhMetaFile(hdc, 284 EnumEnhMetaFile(hdc,
285 (*metafile)->emf(), 285 (*metafile)->emf(),
286 EnhMetaFileProc, 286 EnhMetaFileProc,
287 &bitmap_dc, 287 &bitmap_dc,
288 &metafile_bounds); 288 &metafile_bounds);
(...skipping 26 matching lines...) Expand all
315 // Copy the bits into shared memory. 315 // Copy the bits into shared memory.
316 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 316 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
317 NOTREACHED() << "GetData() failed"; 317 NOTREACHED() << "GetData() failed";
318 shared_buf.Unmap(); 318 shared_buf.Unmap();
319 return false; 319 return false;
320 } 320 }
321 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 321 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
322 shared_buf.Unmap(); 322 shared_buf.Unmap();
323 return true; 323 return true;
324 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698