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

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

Issue 11359020: Print headers and footers with WebKit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linux 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/file_descriptor_posix.h" 7 #include "base/file_descriptor_posix.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 printing::Metafile* metafile) { 185 printing::Metafile* metafile) {
186 printing::PageSizeMargins page_layout_in_points; 186 printing::PageSizeMargins page_layout_in_points;
187 double scale_factor = 1.0f; 187 double scale_factor = 1.0f;
188 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, 188 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
189 ignore_css_margins_, &scale_factor, 189 ignore_css_margins_, &scale_factor,
190 &page_layout_in_points); 190 &page_layout_in_points);
191 gfx::Size page_size; 191 gfx::Size page_size;
192 gfx::Rect content_area; 192 gfx::Rect content_area;
193 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, 193 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
194 &content_area); 194 &content_area);
195 SkDevice* device = metafile->StartPageForVectorCanvas( 195 gfx::Rect canvas_area =
196 page_size, content_area, scale_factor); 196 params.params.display_header_footer ? gfx::Rect(page_size) : content_area;
197
198 SkDevice* device = metafile->StartPageForVectorCanvas(page_size, canvas_area,
199 scale_factor);
197 if (!device) 200 if (!device)
198 return; 201 return;
199 202
200 // The printPage method take a reference to the canvas we pass down, so it 203 // The printPage method take a reference to the canvas we pass down, so it
201 // can't be a stack object. 204 // can't be a stack object.
202 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 205 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
203 canvas->unref(); // SkRefPtr and new both took a reference. 206 canvas->unref(); // SkRefPtr and new both took a reference.
204 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 207 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
205 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); 208 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
206 frame->printPage(params.page_number, canvas.get());
207 209
208 if (params.params.display_header_footer) { 210 if (params.params.display_header_footer) {
209 // |page_number| is 0-based, so 1 is added. 211 // |page_number| is 0-based, so 1 is added.
210 // The scale factor on Linux is 1. 212 // TODO(vitalybuka) : why does it work only with 1.25?
211 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, 213 PrintHeaderAndFooter(canvas.get(), params.page_number + 1,
212 print_preview_context_.total_page_count(), 214 print_preview_context_.total_page_count(),
213 scale_factor, page_layout_in_points, 215 scale_factor/1.25,
Alexei Svitkine (slow) 2012/11/10 16:52:13 Nit: spaces around the /.
Vitaly Buka (NO REVIEWS) 2012/11/12 08:20:52 Done.
214 *header_footer_info_, params.params); 216 page_layout_in_points, *header_footer_info_,
217 params.params);
215 } 218 }
219 RenderPageContent(frame, params.page_number, canvas_area, content_area,
220 scale_factor, canvas.get());
216 221
217 // Done printing. Close the device context to retrieve the compiled metafile. 222 // Done printing. Close the device context to retrieve the compiled metafile.
218 if (!metafile->FinishPage()) 223 if (!metafile->FinishPage())
219 NOTREACHED() << "metafile failed"; 224 NOTREACHED() << "metafile failed";
220 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698