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

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

Issue 8052020: Revert 103021 - PrintPreview: Printing preview of a PDF on Mac with Skia only previews the last p... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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/mac/scoped_nsautorelease_pool.h" 10 #include "base/mac/scoped_nsautorelease_pool.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "chrome/common/print_messages.h" 12 #include "chrome/common/print_messages.h"
13 #include "printing/metafile.h" 13 #include "printing/metafile.h"
14 #include "printing/metafile_impl.h" 14 #include "printing/metafile_impl.h"
15 #include "printing/page_size_margins.h" 15 #include "printing/page_size_margins.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
17 17
18 #if defined(USE_SKIA) 18 #if defined(USE_SKIA)
19 #include "printing/metafile_skia_wrapper.h" 19 #include "printing/metafile_skia_wrapper.h"
20 #include "skia/ext/platform_device.h"
21 #include "skia/ext/vector_canvas.h" 20 #include "skia/ext/vector_canvas.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
23 #endif 22 #endif
24 23
25 using WebKit::WebFrame; 24 using WebKit::WebFrame;
26 25
27 void PrintWebViewHelper::PrintPageInternal( 26 void PrintWebViewHelper::PrintPageInternal(
28 const PrintMsg_PrintPage_Params& params, 27 const PrintMsg_PrintPage_Params& params,
29 const gfx::Size& canvas_size, 28 const gfx::Size& canvas_size,
30 WebFrame* frame) { 29 WebFrame* frame) {
31 printing::NativeMetafile metafile; 30 printing::NativeMetafile metafile;
32 if (!metafile.Init()) 31 if (!metafile.Init())
33 return; 32 return;
34 33
35 float scale_factor = frame->getPrintPageShrink(params.page_number); 34 float scale_factor = frame->getPrintPageShrink(params.page_number);
36 int page_number = params.page_number; 35 int page_number = params.page_number;
37 36
38 // Render page for printing. 37 // Render page for printing.
39 gfx::Rect content_area(params.params.printable_size); 38 gfx::Rect content_area(params.params.printable_size);
40 RenderPage(params.params.printable_size, content_area, scale_factor, 39 RenderPage(params.params.printable_size, content_area, scale_factor,
41 page_number, frame, false, &metafile); 40 page_number, frame, &metafile);
42 metafile.FinishDocument(); 41 metafile.FinishDocument();
43 42
44 PrintHostMsg_DidPrintPage_Params page_params; 43 PrintHostMsg_DidPrintPage_Params page_params;
45 page_params.data_size = metafile.GetDataSize(); 44 page_params.data_size = metafile.GetDataSize();
46 page_params.page_number = page_number; 45 page_params.page_number = page_number;
47 page_params.document_cookie = params.params.document_cookie; 46 page_params.document_cookie = params.params.document_cookie;
48 page_params.actual_shrink = scale_factor; 47 page_params.actual_shrink = scale_factor;
49 page_params.page_size = params.params.page_size; 48 page_params.page_size = params.params.page_size;
50 page_params.content_area = gfx::Rect(params.params.margin_left, 49 page_params.content_area = gfx::Rect(params.params.margin_left,
51 params.params.margin_top, 50 params.params.margin_top,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 print_preview_context_.set_error( 89 print_preview_context_.set_error(
91 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); 90 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED);
92 LOG(ERROR) << "Draft PreviewMetafile Init failed"; 91 LOG(ERROR) << "Draft PreviewMetafile Init failed";
93 return false; 92 return false;
94 } 93 }
95 initial_render_metafile = draft_metafile.get(); 94 initial_render_metafile = draft_metafile.get();
96 } 95 }
97 96
98 base::TimeTicks begin_time = base::TimeTicks::Now(); 97 base::TimeTicks begin_time = base::TimeTicks::Now();
99 RenderPage(printParams.page_size, content_area, scale_factor, page_number, 98 RenderPage(printParams.page_size, content_area, scale_factor, page_number,
100 print_preview_context_.frame(), true, initial_render_metafile); 99 print_preview_context_.frame(), initial_render_metafile);
101 print_preview_context_.RenderedPreviewPage( 100 print_preview_context_.RenderedPreviewPage(
102 base::TimeTicks::Now() - begin_time); 101 base::TimeTicks::Now() - begin_time);
103 102
104 if (draft_metafile.get()) { 103 if (draft_metafile.get()) {
105 draft_metafile->FinishDocument(); 104 draft_metafile->FinishDocument();
106 #if !defined(USE_SKIA) 105 #if !defined(USE_SKIA)
107 if (!is_print_ready_metafile_sent_) { 106 if (!is_print_ready_metafile_sent_) {
108 // With CG, we rendered into a new metafile so we could get it as a draft 107 // With CG, we rendered into a new metafile so we could get it as a draft
109 // document. Now we need to add it to print ready document. But the 108 // document. Now we need to add it to print ready document. But the
110 // document has already been scaled and adjusted for margins, so do a 1:1 109 // document has already been scaled and adjusted for margins, so do a 1:1
(...skipping 27 matching lines...) Expand all
138 print_preview_context_.metafile()->GetMetafileForCurrentPage()); 137 print_preview_context_.metafile()->GetMetafileForCurrentPage());
139 } 138 }
140 #endif 139 #endif
141 } 140 }
142 return PreviewPageRendered(page_number, draft_metafile.get()); 141 return PreviewPageRendered(page_number, draft_metafile.get());
143 } 142 }
144 143
145 void PrintWebViewHelper::RenderPage( 144 void PrintWebViewHelper::RenderPage(
146 const gfx::Size& page_size, const gfx::Rect& content_area, 145 const gfx::Size& page_size, const gfx::Rect& content_area,
147 const float& scale_factor, int page_number, WebFrame* frame, 146 const float& scale_factor, int page_number, WebFrame* frame,
148 bool is_preview, printing::Metafile* metafile) { 147 printing::Metafile* metafile) {
149 148
150 { 149 {
151 #if defined(USE_SKIA) 150 #if defined(USE_SKIA)
152 SkDevice* device = metafile->StartPageForVectorCanvas( 151 SkDevice* device = metafile->StartPageForVectorCanvas(
153 page_size, content_area, scale_factor); 152 page_size, content_area, scale_factor);
154 if (!device) 153 if (!device)
155 return; 154 return;
156 155
157 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 156 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
158 canvas->unref(); // SkRefPtr and new both took a reference. 157 canvas->unref(); // SkRefPtr and new both took a reference.
159 WebKit::WebCanvas* canvas_ptr = canvas.get(); 158 WebKit::WebCanvas* canvas_ptr = canvas.get();
160 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 159 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile);
161 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); 160 printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(),
162 skia::SetIsPreviewMetafile(*canvas, is_preview); 161 is_print_ready_metafile_sent_);
163 #else 162 #else
164 bool success = metafile->StartPage(page_size, content_area, scale_factor); 163 bool success = metafile->StartPage(page_size, content_area, scale_factor);
165 DCHECK(success); 164 DCHECK(success);
166 // printPage can create autoreleased references to |context|. PDF contexts 165 // printPage can create autoreleased references to |context|. PDF contexts
167 // don't write all their data until they are destroyed, so we need to make 166 // don't write all their data until they are destroyed, so we need to make
168 // certain that there are no lingering references. 167 // certain that there are no lingering references.
169 base::mac::ScopedNSAutoreleasePool pool; 168 base::mac::ScopedNSAutoreleasePool pool;
170 CGContextRef cgContext = metafile->context(); 169 CGContextRef cgContext = metafile->context();
171 CGContextRef canvas_ptr = cgContext; 170 CGContextRef canvas_ptr = cgContext;
172 #endif 171 #endif
(...skipping 26 matching lines...) Expand all
199 print_preview_context_.total_page_count(), 198 print_preview_context_.total_page_count(),
200 scale_factor, page_layout_in_points, 199 scale_factor, page_layout_in_points,
201 *header_footer_info_); 200 *header_footer_info_);
202 } 201 }
203 #endif // defined(USE_SKIA) 202 #endif // defined(USE_SKIA)
204 } 203 }
205 204
206 // Done printing. Close the device context to retrieve the compiled metafile. 205 // Done printing. Close the device context to retrieve the compiled metafile.
207 metafile->FinishPage(); 206 metafile->FinishPage();
208 } 207 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | chrome/renderer/print_web_view_helper_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698