Index: chrome/renderer/print_web_view_helper_win.cc |
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc |
index 94b622ff96eaa848ecfb147e0514ea92e5ef3e72..2780267920412c348aea4a4698e7aa7a1befe61a 100644 |
--- a/chrome/renderer/print_web_view_helper_win.cc |
+++ b/chrome/renderer/print_web_view_helper_win.cc |
@@ -63,6 +63,22 @@ int CALLBACK EnhMetaFileProc(HDC dc, |
return 1; // Continue enumeration |
} |
+gfx::Size PrintWebViewHelper::GetUpdatedPageSizeForRendering( |
+ const ViewMsg_Print_Params& params, WebFrame* frame, int page_number) { |
Lei Zhang
2011/01/26 08:06:52
Have you considered putting this code in RenderPag
kmadhusu
2011/01/26 18:08:29
Moved this code to RenderPage().
|
+ double content_width_in_points; |
+ double content_height_in_points; |
+ GetPageSizeAndMarginsInPoints(frame, page_number, params, |
+ &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, |
+ NULL); |
+ |
+ // Since WebKit extends the page width depending on the magical scale factor |
+ // we make sure the canvas covers the worst case scenario (x2.0 currently). |
+ // PrintContext will then set the correct clipping region. |
+ return gfx::Size( |
+ static_cast<int>(content_width_in_points * params.max_shrink), |
+ static_cast<int>(content_height_in_points * params.max_shrink)); |
+} |
+ |
void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
const gfx::Size& canvas_size, |
WebFrame* frame) { |
@@ -75,22 +91,12 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
int page_number = params.page_number; |
- double content_width_in_points; |
- double content_height_in_points; |
- GetPageSizeAndMarginsInPoints(frame, page_number, params.params, |
- &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, |
- NULL); |
- |
// Calculate the dpi adjustment. |
float scale_factor = static_cast<float>(params.params.desired_dpi / |
params.params.dpi); |
- // Since WebKit extends the page width depending on the magical |scale_factor| |
- // we make sure the canvas covers the worst case scenario (x2.0 currently). |
- // PrintContext will then set the correct clipping region. |
- gfx::Size page_size( |
- static_cast<int>(content_width_in_points * params.params.max_shrink), |
- static_cast<int>(content_height_in_points * params.params.max_shrink)); |
+ gfx::Size page_size = GetUpdatedPageSizeForRendering(params.params, frame, |
+ page_number); |
// Render page for printing. |
RenderPage(page_size, &scale_factor, page_number, frame, &metafile, |
@@ -129,6 +135,79 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
} |
} |
+void PrintWebViewHelper::CreatePreviewDocument( |
+ const ViewMsg_PrintPages_Params& params, WebFrame* frame, |
+ ViewHostMsg_DidPreviewDocument_Params* print_params) { |
+ int page_count = 0; |
+ ViewMsg_Print_Params printParams = params.params; |
Lei Zhang
2011/01/26 08:06:52
You still use params.params in several places belo
Lei Zhang
2011/01/26 08:06:52
Having both |print_params| and |printParams| is co
kmadhusu
2011/01/26 18:08:29
Renamed |print_params| to |preview_params|.
kmadhusu
2011/01/26 18:08:29
To get the expected page count, |printParams| val
|
+ UpdatePrintableSizeInPrintParameters(frame, NULL, &printParams); |
+ PrepareFrameAndViewForPrint prep_frame_view(printParams, frame, NULL, |
+ frame->view()); |
+ page_count = prep_frame_view.GetExpectedPageCount(); |
+ if (!page_count) |
+ return; |
+ |
+ // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
+ // single page metafile. For print preview, we need a metafile with multiple |
+ // pages. |
+ // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
+ // PDF backend" work is completed for windows, make changes to replace this |
+ // EMF with PDF metafile. |
+ // http://code.google.com/p/chromium/issues/detail?id=62889 |
+ scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); |
+ metafile->CreateDc(NULL, NULL); |
+ DCHECK(metafile->hdc()); |
+ skia::PlatformDevice::InitializeDC(metafile->hdc()); |
+ |
+ gfx::Size page_size = GetUpdatedPageSizeForRendering(printParams, frame, |
Lei Zhang
2011/01/26 08:06:52
The third argument to GetUpdatedPageSizeForRenderi
kmadhusu
2011/01/26 18:08:29
Fixed.
|
+ page_count); |
+ float scale_factor; |
Lei Zhang
2011/01/26 08:06:52
declare this in the scope in which it is used.
kmadhusu
2011/01/26 18:08:29
Done.
|
+ |
+ // Calculate the dpi adjustment. |
+ float shrink = static_cast<float>(params.params.desired_dpi / |
Lei Zhang
2011/01/26 08:06:52
but I thought you wanted to get rid of variables n
kmadhusu
2011/01/26 18:08:29
Yeah. Since I am using |scale_factor| variable wit
|
+ params.params.dpi); |
+ |
+ if (params.pages.empty()) { |
+ for (int i = 0; i < page_count; ++i) { |
+ scale_factor = shrink; |
+ RenderPage(page_size, &scale_factor, i, frame, &metafile, |
+ params.params.supports_alpha_blend); |
+ } |
+ } else { |
+ for (size_t i = 0; i < params.pages.size(); ++i) { |
+ if (params.pages[i] >= page_count) |
+ break; |
+ scale_factor = shrink; |
+ RenderPage(page_size, &scale_factor, static_cast<int>(params.pages[i]), |
+ frame, &metafile, params.params.supports_alpha_blend); |
+ } |
+ } |
+ |
+ // Close the device context to retrieve the compiled metafile. |
+ if (!metafile->CloseDc()) |
+ NOTREACHED(); |
+ |
+ // Get the size of the compiled metafile. |
+ uint32 buf_size = metafile->GetDataSize(); |
+ DCHECK_GT(buf_size, 128u); |
+ |
+ print_params->document_cookie = params.params.document_cookie; |
+ print_params->data_size = 0; |
+ print_params->metafile_data_handle = NULL; |
+ |
+ if (CopyMetafileDataToSharedMem(metafile.get(), |
+ &(print_params->metafile_data_handle))) { |
+ print_params->data_size = buf_size; |
+ } |
+ metafile->CloseEmf(); |
+ if (!Send(new ViewHostMsg_DuplicateSection( |
+ routing_id(), |
+ print_params->metafile_data_handle, |
+ &print_params->metafile_data_handle))) { |
+ NOTREACHED() << "Send message failed."; |
+ } |
+} |
+ |
void PrintWebViewHelper::RenderPage( |
const gfx::Size& page_size, float* scale_factor, int page_number, |
WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile, |