diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 14:37:48 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 14:37:48 +0000 |
commit | 60c671ca9dc52bb7c6a0bac0773d526d9060e87a (patch) | |
tree | 24885879abfe576ff8fa1f1b70a3cee3a8b69623 /chrome/renderer/print_web_view_helper_win.cc | |
parent | fb630c1cdb74e955d343272a1c9b6ac2968e3a0c (diff) | |
download | chromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.zip chromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.tar.gz chromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.tar.bz2 |
Pass printing result to the browser.
The resulting PDF file will now be passed to the browser and be saved as "chromium_printing_test.pdf" under current directory.
BUG=9847
TEST=printing on linux should now generate chromium_printing_test.pdf in download directory. Printing on Windows should still work.
Patch contributed by minyu.huang@gmail.com
Review URL: http://codereview.chromium.org/172115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper_win.cc')
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 625a66d..dba857e 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -11,6 +11,7 @@ #include "chrome/renderer/render_view.h" #include "grit/generated_resources.h" #include "printing/native_metafile.h" +#include "skia/ext/vector_canvas.h" #include "webkit/api/public/WebConsoleMessage.h" #include "webkit/api/public/WebFrame.h" @@ -18,8 +19,6 @@ using WebKit::WebConsoleMessage; using WebKit::WebFrame; using WebKit::WebString; -#include "skia/ext/vector_canvas.h" - void PrintWebViewHelper::Print(WebFrame* frame, bool script_initiated) { const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 2 * 60; // 2 Minutes. @@ -149,6 +148,33 @@ void PrintWebViewHelper::Print(WebFrame* frame, bool script_initiated) { DidFinishPrinting(user_cancelled_print); } +void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, + WebFrame* frame) { + PrepareFrameAndViewForPrint prep_frame_view(params.params, + frame, + frame->view()); + int page_count = prep_frame_view.GetExpectedPageCount(); + + Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(), + params.params.document_cookie, + page_count)); + if (page_count) { + ViewMsg_PrintPage_Params page_params; + page_params.params = params.params; + if (params.pages.empty()) { + for (int i = 0; i < page_count; ++i) { + page_params.page_number = i; + PrintPage(page_params, prep_frame_view.GetPrintCanvasSize(), frame); + } + } else { + for (size_t i = 0; i < params.pages.size(); ++i) { + page_params.page_number = params.pages[i]; + PrintPage(page_params, prep_frame_view.GetPrintCanvasSize(), frame); + } + } + } +} + void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame) { @@ -177,7 +203,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, skia::PlatformCanvas canvas(size_x, size_y, true); canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); float webkit_shrink = frame->PrintPage(params.page_number, &canvas); - if (shrink <= 0) { + if (shrink <= 0 || webkit_shrink <= 0) { NOTREACHED() << "Printing page " << params.page_number << " failed."; } else { // Update the dpi adjustment with the "page shrink" calculated in webkit. @@ -204,7 +230,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, // 100% GDI based. skia::VectorCanvas canvas(hdc, size_x, size_y); float webkit_shrink = frame->printPage(params.page_number, &canvas); - if (shrink <= 0) { + if (shrink <= 0 || webkit_shrink <= 0) { NOTREACHED() << "Printing page " << params.page_number << " failed."; } else { // Update the dpi adjustment with the "page shrink" calculated in webkit. |