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

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

Issue 11359020: Print headers and footers with WebKit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/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
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // we make sure the canvas covers the worst case scenario (x2.0 currently). 155 // we make sure the canvas covers the worst case scenario (x2.0 currently).
156 // PrintContext will then set the correct clipping region. 156 // PrintContext will then set the correct clipping region.
157 page_size = gfx::Size( 157 page_size = gfx::Size(
158 static_cast<int>(page_layout_in_points.content_width * 158 static_cast<int>(page_layout_in_points.content_width *
159 params.max_shrink), 159 params.max_shrink),
160 static_cast<int>(page_layout_in_points.content_height * 160 static_cast<int>(page_layout_in_points.content_height *
161 params.max_shrink)); 161 params.max_shrink));
162 } 162 }
163 163
164 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number); 164 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number);
165 float scale_factor = css_scale_factor * webkit_page_shrink_factor;
166
167 gfx::Rect canvas_area =
168 params.display_header_footer ? gfx::Rect(page_size) : content_area;
169
165 SkDevice* device = metafile->StartPageForVectorCanvas( 170 SkDevice* device = metafile->StartPageForVectorCanvas(
166 page_size, content_area, css_scale_factor * webkit_page_shrink_factor); 171 page_size, canvas_area, scale_factor);
167 DCHECK(device); 172 DCHECK(device);
168 // The printPage method may take a reference to the canvas we pass down, so it 173 // The printPage method may take a reference to the canvas we pass down, so it
169 // can't be a stack object. 174 // can't be a stack object.
170 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 175 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
171 canvas->unref(); // SkRefPtr and new both took a reference. 176 canvas->unref(); // SkRefPtr and new both took a reference.
177
178 if (params.display_header_footer) {
179 // |page_number| is 0-based, so 1 is added.
180 PrintHeaderAndFooter(canvas.get(), page_number + 1,
181 print_preview_context_.total_page_count(), scale_factor,
182 page_layout_in_points, *header_footer_info_, params);
183 }
184
185 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor,
186 (content_area.y() - canvas_area.y()) / scale_factor);
172 if (is_preview) { 187 if (is_preview) {
173 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 188 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
174 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); 189 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
175 skia::SetIsPreviewMetafile(*canvas, is_preview); 190 skia::SetIsPreviewMetafile(*canvas, is_preview);
176 } 191 }
177 192
178 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); 193 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
179 194
180 if (params.display_header_footer) {
181 // |page_number| is 0-based, so 1 is added.
182 PrintHeaderAndFooter(canvas.get(), page_number + 1,
183 print_preview_context_.total_page_count(),
184 css_scale_factor * webkit_page_shrink_factor,
185 page_layout_in_points, *header_footer_info_, params);
186 }
187
188 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { 195 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
189 NOTREACHED() << "Printing page " << page_number << " failed."; 196 NOTREACHED() << "Printing page " << page_number << " failed.";
190 } else { 197 } else {
191 // While rendering certain plugins (PDF) to metafile, we might need to 198 // While rendering certain plugins (PDF) to metafile, we might need to
192 // set custom scale factor. Update |actual_shrink| with custom scale 199 // set custom scale factor. Update |actual_shrink| with custom scale
193 // if it is set on canvas. 200 // if it is set on canvas.
194 // TODO(gene): We should revisit this solution for the next versions. 201 // TODO(gene): We should revisit this solution for the next versions.
195 // Consider creating metafile of the right size (or resizable) 202 // Consider creating metafile of the right size (or resizable)
196 // https://code.google.com/p/chromium/issues/detail?id=126037 203 // https://code.google.com/p/chromium/issues/detail?id=126037
197 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( 204 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas(
(...skipping 29 matching lines...) Expand all
227 shared_buf.Unmap(); 234 shared_buf.Unmap();
228 return false; 235 return false;
229 } 236 }
230 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 237 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
231 shared_buf.Unmap(); 238 shared_buf.Unmap();
232 239
233 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, 240 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
234 shared_mem_handle)); 241 shared_mem_handle));
235 return true; 242 return true;
236 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698