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

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: Updated as per Chris' 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"
11 #include "chrome/common/print_messages.h" 11 #include "chrome/common/print_messages.h"
12 #include "printing/metafile.h" 12 #include "printing/metafile.h"
13 #include "printing/metafile_impl.h" 13 #include "printing/metafile_impl.h"
14 #include "printing/metafile_skia_wrapper.h" 14 #include "printing/metafile_skia_wrapper.h"
15 #include "printing/units.h" 15 #include "printing/units.h"
16 #include "skia/ext/vector_canvas.h" 16 #include "skia/ext/vector_canvas.h"
17 #include "skia/ext/vector_platform_device_emf_win.h" 17 #include "skia/ext/vector_platform_device_emf_win.h"
18 #include "skia/ext/vector_platform_device_skia.h"
18 #include "third_party/skia/include/core/SkRefCnt.h" 19 #include "third_party/skia/include/core/SkRefCnt.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
20 #include "ui/gfx/gdi_util.h" 21 #include "ui/gfx/gdi_util.h"
21 #include "ui/gfx/point.h" 22 #include "ui/gfx/point.h"
22 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 25
25 using printing::ConvertUnit; 26 using printing::ConvertUnit;
26 using printing::ConvertUnitDouble; 27 using printing::ConvertUnitDouble;
27 using printing::kPointsPerInch; 28 using printing::kPointsPerInch;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // The printPage method may take a reference to the canvas we pass down, so it 179 // The printPage method may take a reference to the canvas we pass down, so it
179 // can't be a stack object. 180 // can't be a stack object.
180 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 181 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
181 canvas->unref(); // SkRefPtr and new both took a reference. 182 canvas->unref(); // SkRefPtr and new both took a reference.
182 if (is_preview) { 183 if (is_preview) {
183 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), 184 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(),
184 metafile->get()); 185 metafile->get());
185 } 186 }
186 187
187 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); 188 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
189
190 if (is_preview && params.display_header_footer) {
191 // |page_number| is 0-based, so 1 is added.
192 PrintHeaderAndFooter(static_cast<skia::VectorPlatformDeviceSkia*>(device),
vandebo (ex-Chrome) 2011/07/26 06:11:37 I didn't realize that doing the casting outside th
Aayush Kumar 2011/07/26 07:37:33 Done.
193 *canvas, page_number + 1,
194 print_preview_context_.total_page_count(),
195 webkit_scale_factor, page_layout_in_points,
196 header_footer_info_);
197 }
198
188 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 199 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
189 NOTREACHED() << "Printing page " << page_number << " failed."; 200 NOTREACHED() << "Printing page " << page_number << " failed.";
190 } else { 201 } else {
191 // Update the dpi adjustment with the "page |scale_factor|" calculated in 202 // Update the dpi adjustment with the "page |scale_factor|" calculated in
192 // webkit. 203 // webkit.
193 *scale_factor /= webkit_scale_factor; 204 *scale_factor /= webkit_scale_factor;
194 } 205 }
195 206
196 bool result = (*metafile)->FinishPage(); 207 bool result = (*metafile)->FinishPage();
197 DCHECK(result); 208 DCHECK(result);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Copy the bits into shared memory. 285 // Copy the bits into shared memory.
275 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 286 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
276 NOTREACHED() << "GetData() failed"; 287 NOTREACHED() << "GetData() failed";
277 shared_buf.Unmap(); 288 shared_buf.Unmap();
278 return false; 289 return false;
279 } 290 }
280 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 291 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
281 shared_buf.Unmap(); 292 shared_buf.Unmap();
282 return true; 293 return true;
283 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698