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

Side by Side Diff: chrome/renderer/print_web_view_helper_win.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/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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Release since |print_preview_context_| is the real owner. 138 // Release since |print_preview_context_| is the real owner.
139 metafile.release(); 139 metafile.release();
140 print_preview_context_.RenderedPreviewPage( 140 print_preview_context_.RenderedPreviewPage(
141 base::TimeTicks::Now() - begin_time); 141 base::TimeTicks::Now() - begin_time);
142 PreviewPageRendered(page_number); 142 PreviewPageRendered(page_number);
143 } 143 }
144 144
145 void PrintWebViewHelper::RenderPage( 145 void PrintWebViewHelper::RenderPage(
146 const PrintMsg_Print_Params& params, float* scale_factor, int page_number, 146 const PrintMsg_Print_Params& params, float* scale_factor, int page_number,
147 bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) { 147 bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) {
148 double content_width_in_points; 148 PageSizeMargins page_size_margins_in_points =
149 double content_height_in_points; 149 GetPageSizeAndMarginsInPoints(frame, page_number, params);
150 double margin_top_in_points;
151 double margin_left_in_points;
152 GetPageSizeAndMarginsInPoints(frame, page_number, params,
153 &content_width_in_points,
154 &content_height_in_points,
155 &margin_top_in_points, NULL, NULL,
156 &margin_left_in_points);
157 150
158 int width; 151 int width;
159 int height; 152 int height;
160 if (is_preview) { 153 if (is_preview) {
161 int dpi = static_cast<int>(params.dpi); 154 int dpi = static_cast<int>(params.dpi);
162 int desired_dpi = printing::kPointsPerInch; 155 int desired_dpi = printing::kPointsPerInch;
163 width = ConvertUnit(params.page_size.width(), dpi, desired_dpi); 156 width = ConvertUnit(params.page_size.width(), dpi, desired_dpi);
164 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi); 157 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi);
165 } else { 158 } else {
166 // Since WebKit extends the page width depending on the magical scale factor 159 // Since WebKit extends the page width depending on the magical scale factor
167 // we make sure the canvas covers the worst case scenario (x2.0 currently). 160 // we make sure the canvas covers the worst case scenario (x2.0 currently).
168 // PrintContext will then set the correct clipping region. 161 // PrintContext will then set the correct clipping region.
169 width = static_cast<int>(content_width_in_points * params.max_shrink); 162 width = static_cast<int>(page_size_margins_in_points.content_width *
170 height = static_cast<int>(content_height_in_points * params.max_shrink); 163 params.max_shrink);
164 height = static_cast<int>(page_size_margins_in_points.content_height *
165 params.max_shrink);
171 } 166 }
172 167
173 gfx::Size page_size(width, height); 168 gfx::Size page_size(width, height);
174 gfx::Rect content_area(static_cast<int>(margin_left_in_points), 169 gfx::Rect content_area(
175 static_cast<int>(margin_top_in_points), 170 static_cast<int>(page_size_margins_in_points.margin_left),
176 static_cast<int>(content_width_in_points), 171 static_cast<int>(page_size_margins_in_points.margin_top),
177 static_cast<int>(content_height_in_points)); 172 static_cast<int>(page_size_margins_in_points.content_width),
173 static_cast<int>(page_size_margins_in_points.content_height));
178 SkDevice* device = (*metafile)->StartPageForVectorCanvas( 174 SkDevice* device = (*metafile)->StartPageForVectorCanvas(
179 page_size, content_area, frame->getPrintPageShrink(page_number)); 175 page_size, content_area, frame->getPrintPageShrink(page_number));
180 DCHECK(device); 176 DCHECK(device);
181 // The printPage method may take a reference to the canvas we pass down, so it 177 // The printPage method may take a reference to the canvas we pass down, so it
182 // can't be a stack object. 178 // can't be a stack object.
183 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 179 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
184 canvas->unref(); // SkRefPtr and new both took a reference. 180 canvas->unref(); // SkRefPtr and new both took a reference.
185 if (is_preview) { 181 if (is_preview) {
186 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), 182 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(),
187 metafile->get()); 183 metafile->get());
188 } 184 }
189 185
190 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); 186 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
187
188 if (is_preview && params.display_header_footer) {
189 // The page_number count starts from 0, so we add 1.
190 PrintHeaderAndFooter(static_cast<skia::VectorPlatformDeviceSkia*>(device),
191 canvas, page_number + 1,
192 print_preview_context_.total_page_count(),
193 webkit_scale_factor, page_size_margins_in_points,
194 header_footer_info_);
195 }
196
191 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 197 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
192 NOTREACHED() << "Printing page " << page_number << " failed."; 198 NOTREACHED() << "Printing page " << page_number << " failed.";
193 } else { 199 } else {
194 // Update the dpi adjustment with the "page |scale_factor|" calculated in 200 // Update the dpi adjustment with the "page |scale_factor|" calculated in
195 // webkit. 201 // webkit.
196 *scale_factor /= webkit_scale_factor; 202 *scale_factor /= webkit_scale_factor;
197 } 203 }
198 204
199 bool result = (*metafile)->FinishPage(); 205 bool result = (*metafile)->FinishPage();
200 DCHECK(result); 206 DCHECK(result);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Copy the bits into shared memory. 283 // Copy the bits into shared memory.
278 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 284 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
279 NOTREACHED() << "GetData() failed"; 285 NOTREACHED() << "GetData() failed";
280 shared_buf.Unmap(); 286 shared_buf.Unmap();
281 return false; 287 return false;
282 } 288 }
283 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 289 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
284 shared_buf.Unmap(); 290 shared_buf.Unmap();
285 return true; 291 return true;
286 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698