Chromium Code Reviews| Index: chrome/renderer/print_web_view_helper_mac.mm |
| diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm |
| index 1700f669af18fc4a068f1e166c7aececcd6b1ffb..47210f9a63bfaf88f2d40991b8a7d57f15bdc4b6 100644 |
| --- a/chrome/renderer/print_web_view_helper_mac.mm |
| +++ b/chrome/renderer/print_web_view_helper_mac.mm |
| @@ -32,13 +32,38 @@ void PrintWebViewHelper::PrintPageInternal( |
| if (!metafile.Init()) |
| return; |
| - float scale_factor = frame->getPrintPageShrink(params.page_number); |
| + double scale_factor = frame->getPrintPageShrink(params.page_number); |
| int page_number = params.page_number; |
| // Render page for printing. |
| + printing::PageSizeMargins page_layout_in_points; |
| + gfx::Size page_size(params.params.printable_size); |
| gfx::Rect content_area(params.params.printable_size); |
| - RenderPage(params.params.printable_size, content_area, scale_factor, |
| - page_number, frame, false, &metafile); |
| + |
| +#if defined(USE_SKIA) |
|
vandebo (ex-Chrome)
2011/12/04 22:20:34
I thought that the mac-skia flow was already diffe
kmadhusu
2011/12/05 09:06:54
In the mac-cg workflow, we are doing some scaling
|
| + GetPageSizeAndMarginsInPoints(print_preview_context_.frame(), page_number, |
| + print_pages_params_->params, |
| + ignore_frame_margins_css_, fit_to_page_, |
| + &scale_factor, &page_layout_in_points); |
| + page_size = gfx::Size( |
|
vandebo (ex-Chrome)
2011/12/04 22:20:34
Will this calculation of page_size come out to the
kmadhusu
2011/12/05 09:06:54
When source is html (with a special margin & size
|
| + page_layout_in_points.content_width + |
| + page_layout_in_points.margin_right + |
| + page_layout_in_points.margin_left, |
| + page_layout_in_points.content_height + |
| + page_layout_in_points.margin_top + |
| + page_layout_in_points.margin_bottom); |
| + content_area = gfx::Rect(page_layout_in_points.margin_left, |
| + page_layout_in_points.margin_top, |
| + page_layout_in_points.content_width, |
| + page_layout_in_points.content_height); |
| +#else |
| + GetPageSizeAndMarginsInPoints(print_preview_context_.frame(), page_number, |
| + print_pages_params_->params, false, false, NULL, |
| + &page_layout_in_points); |
| +#endif |
| + |
| + RenderPage(page_size, content_area, scale_factor, page_number, frame, false, |
| + &metafile, page_layout_in_points); |
| metafile.FinishDocument(); |
| PrintHostMsg_DidPrintPage_Params page_params; |
| @@ -46,11 +71,8 @@ void PrintWebViewHelper::PrintPageInternal( |
| page_params.page_number = page_number; |
| page_params.document_cookie = params.params.document_cookie; |
| page_params.actual_shrink = scale_factor; |
| - page_params.page_size = params.params.page_size; |
| - page_params.content_area = gfx::Rect(params.params.margin_left, |
| - params.params.margin_top, |
| - params.params.printable_size.width(), |
| - params.params.printable_size.height()); |
| + page_params.page_size = page_size; |
| + page_params.content_area = content_area; |
| // Ask the browser to create the shared memory for us. |
| if (!CopyMetafileDataToSharedMem(&metafile, |
| @@ -62,12 +84,37 @@ void PrintWebViewHelper::PrintPageInternal( |
| } |
| bool PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| - float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); |
| + double scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); |
| PrintMsg_Print_Params printParams = print_preview_context_.print_params(); |
| + printing::PageSizeMargins page_layout_in_points; |
| + gfx::Size page_size(printParams.page_size); |
| gfx::Rect content_area(printParams.margin_left, printParams.margin_top, |
| printParams.printable_size.width(), |
| printParams.printable_size.height()); |
| +#if defined(USE_SKIA) |
|
vandebo (ex-Chrome)
2011/12/04 22:20:34
Should this get pulled out into a common function?
kmadhusu
2011/12/05 09:06:54
I created a helper function to update the page siz
|
| +// scale_factor = 1.0f; |
|
vandebo (ex-Chrome)
2011/12/04 22:20:34
extra
kmadhusu
2011/12/05 09:06:54
Removed.
|
| + GetPageSizeAndMarginsInPoints(print_preview_context_.frame(), page_number, |
| + print_pages_params_->params, |
| + ignore_frame_margins_css_, fit_to_page_, |
| + &scale_factor, &page_layout_in_points); |
| + page_size = gfx::Size( |
| + page_layout_in_points.content_width + |
| + page_layout_in_points.margin_right + |
| + page_layout_in_points.margin_left, |
| + page_layout_in_points.content_height + |
| + page_layout_in_points.margin_top + |
| + page_layout_in_points.margin_bottom); |
| + content_area = gfx::Rect(page_layout_in_points.margin_left, |
| + page_layout_in_points.margin_top, |
| + page_layout_in_points.content_width, |
| + page_layout_in_points.content_height); |
| +#else |
| + GetPageSizeAndMarginsInPoints(print_preview_context_.frame(), page_number, |
| + print_pages_params_->params, false, false, NULL, |
| + &page_layout_in_points); |
| +#endif |
| + |
| scoped_ptr<printing::Metafile> draft_metafile; |
| printing::Metafile* initial_render_metafile = |
| print_preview_context_.metafile(); |
| @@ -96,8 +143,9 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| } |
| base::TimeTicks begin_time = base::TimeTicks::Now(); |
| - RenderPage(printParams.page_size, content_area, scale_factor, page_number, |
| - print_preview_context_.frame(), true, initial_render_metafile); |
| + RenderPage(page_size, content_area, scale_factor, page_number, |
| + print_preview_context_.frame(), true, initial_render_metafile, |
| + page_layout_in_points); |
| print_preview_context_.RenderedPreviewPage( |
| base::TimeTicks::Now() - begin_time); |
| @@ -111,13 +159,13 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| // drawing. |
| printing::Metafile* print_ready_metafile = |
| print_preview_context_.metafile(); |
| - bool success = print_ready_metafile->StartPage( |
| - printParams.page_size, gfx::Rect(printParams.page_size), 1.0); |
| + bool success = print_ready_metafile->StartPage(page_size, |
| + gfx::Rect(page_size), 1.0); |
| DCHECK(success); |
| // StartPage unconditionally flips the content over, flip it back since it |
| // was already flipped in |draft_metafile|. |
| CGContextTranslateCTM(print_ready_metafile->context(), 0, |
| - printParams.page_size.height()); |
| + page_size.height()); |
| CGContextScaleCTM(print_ready_metafile->context(), 1.0, -1.0); |
| draft_metafile->RenderPage(1, |
| print_ready_metafile->context(), |
| @@ -144,8 +192,9 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| void PrintWebViewHelper::RenderPage( |
| const gfx::Size& page_size, const gfx::Rect& content_area, |
| - const float& scale_factor, int page_number, WebFrame* frame, |
| - bool is_preview, printing::Metafile* metafile) { |
| + const double& scale_factor, int page_number, WebFrame* frame, |
| + bool is_preview, printing::Metafile* metafile, |
| + printing::PageSizeMargins page_layout_in_points) { |
| { |
| #if defined(USE_SKIA) |
| @@ -171,11 +220,6 @@ void PrintWebViewHelper::RenderPage( |
| CGContextRef canvas_ptr = cgContext; |
| #endif |
| - printing::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 |