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

Side by Side Diff: chrome/renderer/print_web_view_helper_mac.mm

Issue 6696076: Adding CreateFromData to NativeMetafileFactory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments, fixing mac unitests. Created 9 years, 9 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 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "chrome/common/print_messages.h" 11 #include "chrome/common/print_messages.h"
12 #include "printing/native_metafile_factory.h" 12 #include "printing/native_metafile_factory.h"
13 #include "printing/native_metafile.h" 13 #include "printing/native_metafile.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 15
16 using WebKit::WebFrame; 16 using WebKit::WebFrame;
17 17
18 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, 18 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params,
19 const gfx::Size& canvas_size, 19 const gfx::Size& canvas_size,
20 WebFrame* frame) { 20 WebFrame* frame) {
21 scoped_ptr<printing::NativeMetafile> metafile( 21 scoped_ptr<printing::NativeMetafile> metafile(
22 printing::NativeMetafileFactory::Create()); 22 printing::NativeMetafileFactory::Create());
23 if (!metafile->Init()) 23 CHECK(metafile.get());
vandebo (ex-Chrome) 2011/03/24 21:21:58 Doing the same thing as before is fine here - retu
dpapad 2011/03/24 22:02:37 Done.
24 return;
25 24
26 float scale_factor = frame->getPrintPageShrink(params.page_number); 25 float scale_factor = frame->getPrintPageShrink(params.page_number);
27 int page_number = params.page_number; 26 int page_number = params.page_number;
28 27
29 // Render page for printing. 28 // Render page for printing.
30 gfx::Point origin(0.0f, 0.0f); 29 gfx::Point origin(0.0f, 0.0f);
31 RenderPage(params.params.printable_size, origin, scale_factor, page_number, 30 RenderPage(params.params.printable_size, origin, scale_factor, page_number,
32 frame, metafile.get()); 31 frame, metafile.get());
33 metafile->FinishDocument(); 32 metafile->FinishDocument();
34 33
(...skipping 25 matching lines...) Expand all
60 59
61 PrepareFrameAndViewForPrint prep_frame_view(printParams, 60 PrepareFrameAndViewForPrint prep_frame_view(printParams,
62 frame, node, frame->view()); 61 frame, node, frame->view());
63 int page_count = prep_frame_view.GetExpectedPageCount(); 62 int page_count = prep_frame_view.GetExpectedPageCount();
64 63
65 if (!page_count) 64 if (!page_count)
66 return; 65 return;
67 66
68 scoped_ptr<printing::NativeMetafile> metafile( 67 scoped_ptr<printing::NativeMetafile> metafile(
69 printing::NativeMetafileFactory::Create()); 68 printing::NativeMetafileFactory::Create());
70 if (!metafile->Init()) 69 CHECK(metafile.get());
vandebo (ex-Chrome) 2011/03/24 21:21:58 And here.
dpapad 2011/03/24 22:02:37 Done.
71 return;
72 70
73 float scale_factor = frame->getPrintPageShrink(0); 71 float scale_factor = frame->getPrintPageShrink(0);
74 gfx::Point origin(printParams.margin_left, printParams.margin_top); 72 gfx::Point origin(printParams.margin_left, printParams.margin_top);
75 if (params.pages.empty()) { 73 if (params.pages.empty()) {
76 for (int i = 0; i < page_count; ++i) { 74 for (int i = 0; i < page_count; ++i) {
77 RenderPage(printParams.page_size, origin, scale_factor, i, frame, 75 RenderPage(printParams.page_size, origin, scale_factor, i, frame,
78 metafile.get()); 76 metafile.get());
79 } 77 }
80 } else { 78 } else {
81 for (size_t i = 0; i < params.pages.size(); ++i) { 79 for (size_t i = 0; i < params.pages.size(); ++i) {
(...skipping 29 matching lines...) Expand all
111 // printPage can create autoreleased references to |context|. PDF contexts 109 // printPage can create autoreleased references to |context|. PDF contexts
112 // don't write all their data until they are destroyed, so we need to make 110 // don't write all their data until they are destroyed, so we need to make
113 // certain that there are no lingering references. 111 // certain that there are no lingering references.
114 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 112 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
115 frame->printPage(page_number, metafile->context()); 113 frame->printPage(page_number, metafile->context());
116 [pool release]; 114 [pool release];
117 115
118 // Done printing. Close the device context to retrieve the compiled metafile. 116 // Done printing. Close the device context to retrieve the compiled metafile.
119 metafile->FinishPage(); 117 metafile->FinishPage();
120 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698