summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/print_web_view_helper_mac.mm
diff options
context:
space:
mode:
authoraayushkumar@chromium.org <aayushkumar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 20:21:28 +0000
committeraayushkumar@chromium.org <aayushkumar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 20:21:28 +0000
commit151b4f24d0746185e5254b251db88041aba257be (patch)
tree52aeccf1b9b1adcba2bf5bc9dc4936206dc01fe7 /chrome/renderer/print_web_view_helper_mac.mm
parent0b7ae67ae0d301bd909cc96e98eccbce97357bcd (diff)
downloadchromium_src-151b4f24d0746185e5254b251db88041aba257be.zip
chromium_src-151b4f24d0746185e5254b251db88041aba257be.tar.gz
chromium_src-151b4f24d0746185e5254b251db88041aba257be.tar.bz2
Added Headers and Footers support for Core Graphics on Mac
BUG=67514 TEST=In the preview tab, note added options for printing headers and footers. Toggle with the checkbox and ensure that the correct headers and footers are displayed. Review URL: http://codereview.chromium.org/7544006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper_mac.mm')
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm38
1 files changed, 27 insertions, 11 deletions
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index b6d28cb..3e5051f 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -135,8 +135,8 @@ void PrintWebViewHelper::RenderPage(
SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
canvas->unref(); // SkRefPtr and new both took a reference.
- WebKit::WebCanvas* canvasPtr = canvas.get();
- printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvasPtr, metafile);
+ WebKit::WebCanvas* canvas_ptr = canvas.get();
+ printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas_ptr, metafile);
#else
bool success = metafile->StartPage(page_size, content_area, scale_factor);
DCHECK(success);
@@ -145,18 +145,34 @@ void PrintWebViewHelper::RenderPage(
// certain that there are no lingering references.
base::mac::ScopedNSAutoreleasePool pool;
CGContextRef cgContext = metafile->context();
- CGContextRef canvasPtr = cgContext;
+ CGContextRef canvas_ptr = cgContext;
#endif
- frame->printPage(page_number, canvasPtr);
+
+ PageSizeMargins page_layout_in_points;
+ GetPageSizeAndMarginsInPoints(frame, page_number,
+ print_pages_params_->params,
+ &page_layout_in_points);
+
+#if !defined(USE_SKIA)
+ // For CoreGraphics, print in the margins before printing in the content
+ // area so that we don't spill over. Webkit draws a white background in the
+ // content area and this acts as a clip.
+ // TODO(aayushkumar): Combine the calls to PrintHeaderAndFooter once we
+ // can draw in the margins safely in Skia in any order.
+ if (print_pages_params_->params.display_header_footer) {
+ PrintHeaderAndFooter(canvas_ptr, page_number + 1,
+ print_preview_context_.total_page_count(),
+ scale_factor, page_layout_in_points,
+ *header_footer_info_);
+ }
+#endif // !USE_SKIA
+
+ frame->printPage(page_number, canvas_ptr);
+
#if defined(USE_SKIA)
- const PrintMsg_Print_Params& printParams =
- print_preview_context_.print_params();
- if (printParams.display_header_footer) {
- PageSizeMargins page_layout_in_points;
- GetPageSizeAndMarginsInPoints(frame, page_number, printParams,
- &page_layout_in_points);
+ if (print_pages_params_->params.display_header_footer) {
// |page_number| is 0-based, so 1 is added.
- PrintHeaderAndFooter(device, canvas.get(), page_number + 1,
+ PrintHeaderAndFooter(canvas_ptr, page_number + 1,
print_preview_context_.total_page_count(),
scale_factor, page_layout_in_points,
*header_footer_info_);