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

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: changed header_footer_info to scoped_ptr and some style changes. 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 true,
37 print_preview_context_.metafile()); 38 print_preview_context_.metafile());
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;
(...skipping 94 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, false, metafile);
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, false, metafile);
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,
172 bool is_preview,
171 printing::Metafile* metafile) { 173 printing::Metafile* metafile) {
172 PageSizeMargins page_layout_in_points; 174 PageSizeMargins page_layout_in_points;
173 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, 175 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params,
174 &page_layout_in_points); 176 &page_layout_in_points);
175 177
176 gfx::Size page_size( 178 gfx::Size page_size(
177 page_layout_in_points.content_width + 179 page_layout_in_points.content_width +
178 page_layout_in_points.margin_right + 180 page_layout_in_points.margin_right +
179 page_layout_in_points.margin_left, 181 page_layout_in_points.margin_left,
180 page_layout_in_points.content_height + 182 page_layout_in_points.content_height +
181 page_layout_in_points.margin_top + 183 page_layout_in_points.margin_top +
182 page_layout_in_points.margin_bottom); 184 page_layout_in_points.margin_bottom);
183 gfx::Rect content_area(page_layout_in_points.margin_left, 185 gfx::Rect content_area(page_layout_in_points.margin_left,
184 page_layout_in_points.margin_top, 186 page_layout_in_points.margin_top,
185 page_layout_in_points.content_width, 187 page_layout_in_points.content_width,
186 page_layout_in_points.content_height); 188 page_layout_in_points.content_height);
187 189
188 SkDevice* device = metafile->StartPageForVectorCanvas( 190 SkDevice* device = metafile->StartPageForVectorCanvas(
189 params.page_number, page_size, content_area, 1.0f); 191 params.page_number, page_size, content_area, 1.0f);
190 if (!device) 192 if (!device)
191 return; 193 return;
192 194
193 // 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
194 // can't be a stack object. 196 // can't be a stack object.
195 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 197 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
196 canvas->unref(); // SkRefPtr and new both took a reference. 198 canvas->unref(); // SkRefPtr and new both took a reference.
197 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); 199 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile);
198 frame->printPage(params.page_number, canvas.get()); 200 frame->printPage(params.page_number, canvas.get());
199 201
200 // TODO(myhuang): We should render the header and the footer. 202 if (is_preview && params.params.display_header_footer) {
203 // |page_number| is 0-based, so 1 is added.
204 // The scale factor on Linux is 1.
205 PrintHeaderAndFooter(device, *canvas, params.page_number + 1,
206 print_preview_context_.total_page_count(), 1,
207 page_layout_in_points, header_footer_info_.get());
208 }
201 209
202 // Done printing. Close the device context to retrieve the compiled metafile. 210 // Done printing. Close the device context to retrieve the compiled metafile.
203 if (!metafile->FinishPage()) 211 if (!metafile->FinishPage())
204 NOTREACHED() << "metafile failed"; 212 NOTREACHED() << "metafile failed";
205 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698