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

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 demetrios comments Created 9 years, 5 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 16 matching lines...) Expand all
27 27
28 void PrintWebViewHelper::RenderPreviewPage(int page_number) { 28 void PrintWebViewHelper::RenderPreviewPage(int page_number) {
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 32
33 base::TimeTicks begin_time = base::TimeTicks::Now(); 33 base::TimeTicks begin_time = base::TimeTicks::Now();
34 PrintPageInternal(page_params, 34 PrintPageInternal(page_params,
35 print_preview_context_.GetPrintCanvasSize(), 35 print_preview_context_.GetPrintCanvasSize(),
36 print_preview_context_.frame(), 36 print_preview_context_.frame(),
37 print_preview_context_.metafile()); 37 print_preview_context_.metafile(),
38 true);
38 print_preview_context_.RenderedPreviewPage( 39 print_preview_context_.RenderedPreviewPage(
39 base::TimeTicks::Now() - begin_time); 40 base::TimeTicks::Now() - begin_time);
40 PreviewPageRendered(page_number); 41 PreviewPageRendered(page_number);
41 } 42 }
42 43
43 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, 44 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
44 WebFrame* frame, 45 WebFrame* frame,
45 WebNode* node) { 46 WebNode* node) {
46 printing::NativeMetafile metafile; 47 printing::NativeMetafile metafile;
47 if (!metafile.Init()) 48 if (!metafile.Init())
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 142
142 base::TimeTicks begin_time = base::TimeTicks::Now(); 143 base::TimeTicks begin_time = base::TimeTicks::Now();
143 base::TimeTicks page_begin_time = begin_time; 144 base::TimeTicks page_begin_time = begin_time;
144 145
145 PrintMsg_PrintPage_Params page_params; 146 PrintMsg_PrintPage_Params page_params;
146 page_params.params = printParams; 147 page_params.params = printParams;
147 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); 148 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize();
148 if (params.pages.empty()) { 149 if (params.pages.empty()) {
149 for (int i = 0; i < *page_count; ++i) { 150 for (int i = 0; i < *page_count; ++i) {
150 page_params.page_number = i; 151 page_params.page_number = i;
151 PrintPageInternal(page_params, canvas_size, frame, metafile); 152 PrintPageInternal(page_params, canvas_size, frame, metafile, false);
152 } 153 }
153 } else { 154 } else {
154 for (size_t i = 0; i < params.pages.size(); ++i) { 155 for (size_t i = 0; i < params.pages.size(); ++i) {
155 page_params.page_number = params.pages[i]; 156 page_params.page_number = params.pages[i];
156 PrintPageInternal(page_params, canvas_size, frame, metafile); 157 PrintPageInternal(page_params, canvas_size, frame, metafile, false);
157 } 158 }
158 } 159 }
159 160
160 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time; 161 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time;
161 162
162 prep_frame_view.FinishPrinting(); 163 prep_frame_view.FinishPrinting();
163 metafile->FinishDocument(); 164 metafile->FinishDocument();
164 return true; 165 return true;
165 } 166 }
166 167
167 void PrintWebViewHelper::PrintPageInternal( 168 void PrintWebViewHelper::PrintPageInternal(
168 const PrintMsg_PrintPage_Params& params, 169 const PrintMsg_PrintPage_Params& params,
169 const gfx::Size& canvas_size, 170 const gfx::Size& canvas_size,
170 WebFrame* frame, 171 WebFrame* frame,
171 printing::Metafile* metafile) { 172 printing::Metafile* metafile,
172 double content_width_in_points; 173 bool is_preview) {
173 double content_height_in_points; 174 PageSizeMargins page_size_margins_in_points =
174 double margin_top_in_points; 175 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params);
175 double margin_right_in_points;
176 double margin_bottom_in_points;
177 double margin_left_in_points;
178 GetPageSizeAndMarginsInPoints(frame,
179 params.page_number,
180 params.params,
181 &content_width_in_points,
182 &content_height_in_points,
183 &margin_top_in_points,
184 &margin_right_in_points,
185 &margin_bottom_in_points,
186 &margin_left_in_points);
187 176
188 gfx::Size page_size( 177 gfx::Size page_size(
189 content_width_in_points + margin_right_in_points + 178 page_size_margins_in_points.content_width +
190 margin_left_in_points, 179 page_size_margins_in_points.margin_right +
191 content_height_in_points + margin_top_in_points + 180 page_size_margins_in_points.margin_left,
192 margin_bottom_in_points); 181 page_size_margins_in_points.content_height +
193 gfx::Rect content_area(margin_left_in_points, margin_top_in_points, 182 page_size_margins_in_points.margin_top +
194 content_width_in_points, content_height_in_points); 183 page_size_margins_in_points.margin_bottom);
184
185 gfx::Rect content_area(page_size_margins_in_points.margin_left,
186 page_size_margins_in_points.margin_top,
187 page_size_margins_in_points.content_width,
188 page_size_margins_in_points.content_height);
195 189
196 SkDevice* device = metafile->StartPageForVectorCanvas( 190 SkDevice* device = metafile->StartPageForVectorCanvas(
197 page_size, content_area, 1.0f); 191 page_size, content_area, 1.0f);
198 if (!device) 192 if (!device)
199 return; 193 return;
200 194
201 // The printPage method take a reference to the canvas we pass down, so it 195 // The printPage method take a reference to the canvas we pass down, so it
202 // can't be a stack object. 196 // can't be a stack object.
203 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 197 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
204 canvas->unref(); // SkRefPtr and new both took a reference. 198 canvas->unref(); // SkRefPtr and new both took a reference.
205 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); 199 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile);
200
206 frame->printPage(params.page_number, canvas.get()); 201 frame->printPage(params.page_number, canvas.get());
207 202
208 // TODO(myhuang): We should render the header and the footer. 203 if (is_preview && params.params.display_header_footer) {
204 // The page_number count starts from 0, so we add 1.
205 // The scale factor on Linux is 1.
206 PrintHeaderAndFooter(static_cast<skia::VectorPlatformDeviceSkia*>(device),
207 canvas, params.page_number + 1,
208 print_preview_context_.total_page_count(), 1,
209 page_size_margins_in_points, header_footer_info_);
210 }
209 211
210 // Done printing. Close the device context to retrieve the compiled metafile. 212 // Done printing. Close the device context to retrieve the compiled metafile.
211 if (!metafile->FinishPage()) 213 if (!metafile->FinishPage())
212 NOTREACHED() << "metafile failed"; 214 NOTREACHED() << "metafile failed";
213 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698