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

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

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Style changes as per Kausalya and Demetrios' comments Created 9 years, 4 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 #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 18 matching lines...) Expand all
29 PrintMsg_PrintPage_Params page_params; 29 PrintMsg_PrintPage_Params page_params;
30 page_params.params = print_preview_context_.print_params(); 30 page_params.params = print_preview_context_.print_params();
31 page_params.page_number = page_number; 31 page_params.page_number = page_number;
32 page_params.page_slot = 32 page_params.page_slot =
33 print_preview_context_.GetPageSlotForPage(page_number); 33 print_preview_context_.GetPageSlotForPage(page_number);
34 34
35 base::TimeTicks begin_time = base::TimeTicks::Now(); 35 base::TimeTicks begin_time = base::TimeTicks::Now();
36 PrintPageInternal(page_params, 36 PrintPageInternal(page_params,
37 print_preview_context_.GetPrintCanvasSize(), 37 print_preview_context_.GetPrintCanvasSize(),
38 print_preview_context_.frame(), 38 print_preview_context_.frame(),
39 true,
39 print_preview_context_.metafile()); 40 print_preview_context_.metafile());
40 41
41 print_preview_context_.RenderedPreviewPage( 42 print_preview_context_.RenderedPreviewPage(
42 base::TimeTicks::Now() - begin_time); 43 base::TimeTicks::Now() - begin_time);
43 printing::Metafile* page_metafile = NULL; 44 printing::Metafile* page_metafile = NULL;
44 if (print_preview_context_.IsModifiable()) { 45 if (print_preview_context_.IsModifiable()) {
45 page_metafile = reinterpret_cast<printing::PreviewMetafile*>( 46 page_metafile = reinterpret_cast<printing::PreviewMetafile*>(
46 print_preview_context_.metafile())->GetMetafileForCurrentPage(); 47 print_preview_context_.metafile())->GetMetafileForCurrentPage();
47 } 48 }
48 PreviewPageRendered(page_number, page_metafile); 49 PreviewPageRendered(page_number, page_metafile);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 base::TimeTicks begin_time = base::TimeTicks::Now(); 157 base::TimeTicks begin_time = base::TimeTicks::Now();
157 base::TimeTicks page_begin_time = begin_time; 158 base::TimeTicks page_begin_time = begin_time;
158 159
159 PrintMsg_PrintPage_Params page_params; 160 PrintMsg_PrintPage_Params page_params;
160 page_params.params = print_params; 161 page_params.params = print_params;
161 const gfx::Size& canvas_size = prepare->GetPrintCanvasSize(); 162 const gfx::Size& canvas_size = prepare->GetPrintCanvasSize();
162 if (params.pages.empty()) { 163 if (params.pages.empty()) {
163 for (int i = 0; i < *page_count; ++i) { 164 for (int i = 0; i < *page_count; ++i) {
164 page_params.page_number = i; 165 page_params.page_number = i;
165 page_params.page_slot = i; 166 page_params.page_slot = i;
166 PrintPageInternal(page_params, canvas_size, frame, metafile); 167 PrintPageInternal(page_params, canvas_size, frame, false, metafile);
vandebo (ex-Chrome) 2011/08/01 21:07:37 Instead of changing the signature of this method,
Aayush Kumar 2011/08/02 00:18:13 Done.
167 } 168 }
168 } else { 169 } else {
169 for (size_t i = 0; i < params.pages.size(); ++i) { 170 for (size_t i = 0; i < params.pages.size(); ++i) {
170 page_params.page_number = params.pages[i]; 171 page_params.page_number = params.pages[i];
171 page_params.page_slot = i; 172 page_params.page_slot = i;
172 PrintPageInternal(page_params, canvas_size, frame, metafile); 173 PrintPageInternal(page_params, canvas_size, frame, false, metafile);
173 } 174 }
174 } 175 }
175 176
176 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time; 177 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time;
177 178
178 prepare->FinishPrinting(); 179 prepare->FinishPrinting();
179 metafile->FinishDocument(); 180 metafile->FinishDocument();
180 return true; 181 return true;
181 } 182 }
182 183
183 void PrintWebViewHelper::PrintPageInternal( 184 void PrintWebViewHelper::PrintPageInternal(
184 const PrintMsg_PrintPage_Params& params, 185 const PrintMsg_PrintPage_Params& params,
185 const gfx::Size& canvas_size, 186 const gfx::Size& canvas_size,
186 WebFrame* frame, 187 WebFrame* frame,
188 bool is_preview,
187 printing::Metafile* metafile) { 189 printing::Metafile* metafile) {
188 PageSizeMargins page_layout_in_points; 190 PageSizeMargins page_layout_in_points;
189 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, 191 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params,
190 &page_layout_in_points); 192 &page_layout_in_points);
191 193
192 gfx::Size page_size( 194 gfx::Size page_size(
193 page_layout_in_points.content_width + 195 page_layout_in_points.content_width +
194 page_layout_in_points.margin_right + 196 page_layout_in_points.margin_right +
195 page_layout_in_points.margin_left, 197 page_layout_in_points.margin_left,
196 page_layout_in_points.content_height + 198 page_layout_in_points.content_height +
197 page_layout_in_points.margin_top + 199 page_layout_in_points.margin_top +
198 page_layout_in_points.margin_bottom); 200 page_layout_in_points.margin_bottom);
199 gfx::Rect content_area(page_layout_in_points.margin_left, 201 gfx::Rect content_area(page_layout_in_points.margin_left,
200 page_layout_in_points.margin_top, 202 page_layout_in_points.margin_top,
201 page_layout_in_points.content_width, 203 page_layout_in_points.content_width,
202 page_layout_in_points.content_height); 204 page_layout_in_points.content_height);
203 205
204 SkDevice* device = metafile->StartPageForVectorCanvas( 206 SkDevice* device = metafile->StartPageForVectorCanvas(
205 params.page_slot, page_size, content_area, 1.0f); 207 params.page_slot, page_size, content_area, 1.0f);
206 if (!device) 208 if (!device)
207 return; 209 return;
208 210
209 // The printPage method take a reference to the canvas we pass down, so it 211 // The printPage method take a reference to the canvas we pass down, so it
210 // can't be a stack object. 212 // can't be a stack object.
211 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 213 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
212 canvas->unref(); // SkRefPtr and new both took a reference. 214 canvas->unref(); // SkRefPtr and new both took a reference.
213 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); 215 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile);
214 frame->printPage(params.page_number, canvas.get()); 216 frame->printPage(params.page_number, canvas.get());
215 217
216 // TODO(myhuang): We should render the header and the footer. 218 if (is_preview && params.params.display_header_footer) {
219 // |page_number| is 0-based, so 1 is added.
220 // The scale factor on Linux is 1.
221 PrintHeaderAndFooter(device, *canvas, params.page_number + 1,
222 print_preview_context_.total_page_count(), 1,
223 page_layout_in_points, *header_footer_info_);
224 }
217 225
218 // Done printing. Close the device context to retrieve the compiled metafile. 226 // Done printing. Close the device context to retrieve the compiled metafile.
219 if (!metafile->FinishPage()) 227 if (!metafile->FinishPage())
220 NOTREACHED() << "metafile failed"; 228 NOTREACHED() << "metafile failed";
221 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698