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

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

Issue 11316066: Merge 167311 - Print headers and footers with WebKit. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « chrome/renderer/print_web_view_helper_mac.mm ('k') | printing/print_job_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // we make sure the canvas covers the worst case scenario (x2.0 currently). 162 // we make sure the canvas covers the worst case scenario (x2.0 currently).
163 // PrintContext will then set the correct clipping region. 163 // PrintContext will then set the correct clipping region.
164 page_size = gfx::Size( 164 page_size = gfx::Size(
165 static_cast<int>(page_layout_in_points.content_width * 165 static_cast<int>(page_layout_in_points.content_width *
166 params.max_shrink), 166 params.max_shrink),
167 static_cast<int>(page_layout_in_points.content_height * 167 static_cast<int>(page_layout_in_points.content_height *
168 params.max_shrink)); 168 params.max_shrink));
169 } 169 }
170 170
171 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number); 171 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number);
172 float scale_factor = css_scale_factor * webkit_page_shrink_factor;
173
174 gfx::Rect canvas_area =
175 params.display_header_footer ? gfx::Rect(page_size) : content_area;
176
172 SkDevice* device = metafile->StartPageForVectorCanvas( 177 SkDevice* device = metafile->StartPageForVectorCanvas(
173 page_size, content_area, css_scale_factor * webkit_page_shrink_factor); 178 page_size, canvas_area, scale_factor);
174 DCHECK(device); 179 DCHECK(device);
175 // The printPage method may take a reference to the canvas we pass down, so it 180 // The printPage method may take a reference to the canvas we pass down, so it
176 // can't be a stack object. 181 // can't be a stack object.
177 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 182 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
178 canvas->unref(); // SkRefPtr and new both took a reference. 183 canvas->unref(); // SkRefPtr and new both took a reference.
184
179 if (is_preview) { 185 if (is_preview) {
180 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 186 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
181 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); 187 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
182 skia::SetIsPreviewMetafile(*canvas, is_preview); 188 skia::SetIsPreviewMetafile(*canvas, is_preview);
183 } 189 }
184 190
185 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
186
187 if (params.display_header_footer) { 191 if (params.display_header_footer) {
188 // |page_number| is 0-based, so 1 is added. 192 // |page_number| is 0-based, so 1 is added.
189 PrintHeaderAndFooter(canvas.get(), page_number + 1, 193 PrintHeaderAndFooter(canvas.get(), page_number + 1,
190 print_preview_context_.total_page_count(), 194 print_preview_context_.total_page_count(), scale_factor,
191 css_scale_factor * webkit_page_shrink_factor, 195 page_layout_in_points, *header_footer_info_, params);
192 page_layout_in_points, *header_footer_info_, params);
193 } 196 }
194 197
198 float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area,
199 content_area, scale_factor,
200 canvas.get());
201
195 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { 202 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
196 NOTREACHED() << "Printing page " << page_number << " failed."; 203 NOTREACHED() << "Printing page " << page_number << " failed.";
197 } else { 204 } else {
198 // While rendering certain plugins (PDF) to metafile, we might need to 205 // While rendering certain plugins (PDF) to metafile, we might need to
199 // set custom scale factor. Update |actual_shrink| with custom scale 206 // set custom scale factor. Update |actual_shrink| with custom scale
200 // if it is set on canvas. 207 // if it is set on canvas.
201 // TODO(gene): We should revisit this solution for the next versions. 208 // TODO(gene): We should revisit this solution for the next versions.
202 // Consider creating metafile of the right size (or resizable) 209 // Consider creating metafile of the right size (or resizable)
203 // https://code.google.com/p/chromium/issues/detail?id=126037 210 // https://code.google.com/p/chromium/issues/detail?id=126037
204 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( 211 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas(
(...skipping 29 matching lines...) Expand all
234 shared_buf.Unmap(); 241 shared_buf.Unmap();
235 return false; 242 return false;
236 } 243 }
237 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 244 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
238 shared_buf.Unmap(); 245 shared_buf.Unmap();
239 246
240 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, 247 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
241 shared_mem_handle)); 248 shared_mem_handle));
242 return true; 249 return true;
243 } 250 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_mac.mm ('k') | printing/print_job_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698