summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 17:01:09 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 17:01:09 +0000
commitb1b1492cb7f5d5072ebf85cd138e6933f3837afb (patch)
tree7f73afa247b6418248083a3adda30a8d8285ba18 /chrome
parent83a8d3a4b0066627911ded97dba095abe3110534 (diff)
downloadchromium_src-b1b1492cb7f5d5072ebf85cd138e6933f3837afb.zip
chromium_src-b1b1492cb7f5d5072ebf85cd138e6933f3837afb.tar.gz
chromium_src-b1b1492cb7f5d5072ebf85cd138e6933f3837afb.tar.bz2
Refactor win printing workflow to support print preview.
Made code changes to create a single metafile for the entire printing document. Implemented the following function: 1. CreatePreviewDocument(): Create a single metafile and render all the pages(entire printing document) into the same metafile. Note: Although the structure of PrintPage() function looks similar to CreatePreviewDocument(), merging of these functions is difficult for the following reasons: 1. As of now, we are using EMF metafile to create a preview document. In future we are going to use Skia->PDF metafile. So construction and destruction of the metafile will be different. 2. The message for preview workflow(ViewHostMsg_PagesReadyForPreview) is different from normal printing workflow(ViewHostMsg_DidPrintPage). 3. The param struct which is sent along with the message for preview workflow is different from printing workflow. 4. Finally, the semantics of PrintPage() function is to print a page per metafile which is completely different from the semantics of CreatePreviewDocument() function. Once Skia->Pdf work is completed, Modify CreatePreviewDocument() function to use this PDF metafile. BUG=64121 TEST=printing works after code changes. Review URL: http://codereview.chromium.org/6261025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/renderer/print_web_view_helper.cc4
-rw-r--r--chrome/renderer/print_web_view_helper.h9
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc105
3 files changed, 92 insertions, 26 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 4c7a02e..51b5e73 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -510,12 +510,12 @@ void PrintWebViewHelper::RenderPagesForPreview(WebFrame *frame) {
Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), preview_params));
}
-#if !defined(OS_MACOSX)
+#if defined(OS_LINUX)
void PrintWebViewHelper::CreatePreviewDocument(
const ViewMsg_PrintPages_Params& params,
WebFrame* frame,
ViewHostMsg_DidPreviewDocument_Params* preview_params) {
- // TODO(kmadhusu): Implement this function for windows & linux.
+ // TODO(kmadhusu): Implement this function for linux.
preview_params->document_cookie = params.params.document_cookie;
}
#endif
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 7742df8..f908b47 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -174,6 +174,10 @@ class PrintWebViewHelper : public WebKit::WebViewClient,
// Render the frame for preview.
void RenderPagesForPreview(WebKit::WebFrame* frame);
+
+ // Renders all the pages listed in |params| for preview.
+ // On Success, |preview_params| will have a valid handle to metafile data,
+ // data buffer size and document cookie.
void CreatePreviewDocument(const ViewMsg_PrintPages_Params& params,
WebKit::WebFrame* frame,
ViewHostMsg_DidPreviewDocument_Params* preview_params);
@@ -182,10 +186,9 @@ class PrintWebViewHelper : public WebKit::WebViewClient,
const float& scale_factor, int page_number,
WebKit::WebFrame* frame, printing::NativeMetafile* metafile);
#elif defined(OS_WIN)
- void RenderPage(const gfx::Size& page_size, float* scale_factor,
+ void RenderPage(const ViewMsg_Print_Params& params, float* scale_factor,
int page_number, WebKit::WebFrame* frame,
- scoped_ptr<printing::NativeMetafile>* metafile,
- bool supports_alpha_blend);
+ scoped_ptr<printing::NativeMetafile>* metafile);
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 94b622f..7e6e53d 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -75,26 +75,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));
-
// Render page for printing.
- RenderPage(page_size, &scale_factor, page_number, frame, &metafile,
- params.params.supports_alpha_blend);
+ RenderPage(params.params, &scale_factor, page_number, frame, &metafile);
// Close the device context to retrieve the compiled metafile.
if (!metafile->CloseDc())
@@ -129,15 +115,92 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
}
}
+void PrintWebViewHelper::CreatePreviewDocument(
+ const ViewMsg_PrintPages_Params& params, WebFrame* frame,
+ ViewHostMsg_DidPreviewDocument_Params* preview_params) {
+ int page_count = 0;
+ ViewMsg_Print_Params print_params = params.params;
+ UpdatePrintableSizeInPrintParameters(frame, NULL, &print_params);
+ PrepareFrameAndViewForPrint prep_frame_view(print_params, 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());
+
+ // Calculate the dpi adjustment.
+ float shrink = static_cast<float>(params.params.desired_dpi /
+ params.params.dpi);
+
+ if (params.pages.empty()) {
+ for (int i = 0; i < page_count; ++i) {
+ float scale_factor = shrink;
+ RenderPage(params.params, &scale_factor, i, frame, &metafile);
+ }
+ } else {
+ for (size_t i = 0; i < params.pages.size(); ++i) {
+ if (params.pages[i] >= page_count)
+ break;
+ float scale_factor = shrink;
+ RenderPage(params.params, &scale_factor,
+ static_cast<int>(params.pages[i]), frame, &metafile);
+ }
+ }
+
+ // 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);
+
+ preview_params->document_cookie = params.params.document_cookie;
+ preview_params->data_size = 0;
+ preview_params->metafile_data_handle = NULL;
+
+ if (CopyMetafileDataToSharedMem(metafile.get(),
+ &(preview_params->metafile_data_handle))) {
+ preview_params->data_size = buf_size;
+ }
+ metafile->CloseEmf();
+ if (!Send(new ViewHostMsg_DuplicateSection(
+ routing_id(),
+ preview_params->metafile_data_handle,
+ &preview_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,
- bool supports_alpha_blend) {
+ const ViewMsg_Print_Params& params, float* scale_factor, int page_number,
+ WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
HDC hdc = (*metafile)->hdc();
DCHECK(hdc);
- int width = page_size.width();
- int height = page_size.height();
+ 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.
+ int width = static_cast<int>(content_width_in_points * params.max_shrink);
+ int height = static_cast<int>(content_height_in_points * params.max_shrink);
+
#if 0
// TODO(maruel): This code is kept for testing until the 100% GDI drawing
// code is stable. maruels use this code's output as a reference when the
@@ -186,7 +249,7 @@ void PrintWebViewHelper::RenderPage(
skia::VectorPlatformDevice* platform_device =
static_cast<skia::VectorPlatformDevice*>(canvas.getDevice());
- if (platform_device->alpha_blend_used() && !supports_alpha_blend) {
+ if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
// Close the device context to retrieve the compiled metafile.
if (!(*metafile)->CloseDc())
NOTREACHED();