diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 05:19:41 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 05:19:41 +0000 |
commit | 576f9964c7ab5b355a3f02164066119d96e00463 (patch) | |
tree | 2d2e3a80c16827eb5db91534d793f71b33ffc00c /chrome/renderer/print_web_view_helper_mac.mm | |
parent | e94c69f6b25f93e7d2b97766686a487777eec88f (diff) | |
download | chromium_src-576f9964c7ab5b355a3f02164066119d96e00463.zip chromium_src-576f9964c7ab5b355a3f02164066119d96e00463.tar.gz chromium_src-576f9964c7ab5b355a3f02164066119d96e00463.tar.bz2 |
Print preview page selection should not require a rerendering of draft pages.
On page selection, regenerate the complete document with the selection, but preserve the existing draft pages and simply display a subset of them.
Added a new param |clear all preview data| to |PrintHostMsg_DidGetPreviewPageCount|.
BUG=84383
TEST=print preview works after code changes.
Review URL: http://codereview.chromium.org/7647010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98926 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.mm | 90 |
1 files changed, 54 insertions, 36 deletions
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm index f64a0bf..2048920 100644 --- a/chrome/renderer/print_web_view_helper_mac.mm +++ b/chrome/renderer/print_web_view_helper_mac.mm @@ -67,19 +67,30 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { printParams.printable_size.width(), printParams.printable_size.height()); + scoped_ptr<printing::Metafile> draft_metafile; printing::Metafile* initial_render_metafile = print_preview_context_.metafile(); - scoped_ptr<printing::PreviewMetafile> draft_metafile; -#if !defined(USE_SKIA) - if (print_preview_context_.IsModifiable()) { - draft_metafile.reset(new printing::PreviewMetafile); + +#if defined(USE_SKIA) + bool render_to_draft = print_preview_context_.IsModifiable() && + is_print_ready_metafile_sent_; +#else + // If the page needs to be in both draft metafile and print ready metafile, + // we should always render to the draft metafile first and then copy that + // into the print ready metafile because CG does not allow us to do it in + // the other order. + bool render_to_draft = print_preview_context_.IsModifiable() && + print_preview_context_.generate_draft_pages(); +#endif + + if (render_to_draft) { + draft_metafile.reset(new printing::PreviewMetafile()); if (!draft_metafile->Init()) { LOG(ERROR) << "Draft PreviewMetafile Init failed"; return false; } initial_render_metafile = draft_metafile.get(); } -#endif base::TimeTicks begin_time = base::TimeTicks::Now(); RenderPage(printParams.page_size, content_area, scale_factor, page_number, @@ -87,38 +98,44 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { print_preview_context_.RenderedPreviewPage( base::TimeTicks::Now() - begin_time); - if (print_preview_context_.IsModifiable()) { -#if defined(USE_SKIA) - DCHECK(!draft_metafile.get()); - draft_metafile.reset( - print_preview_context_.metafile()->GetMetafileForCurrentPage()); -#else + if (draft_metafile.get()) { draft_metafile->FinishDocument(); - - // With CG, we rendered into a new metafile so we could get it as a draft - // document. Now we need to add it to complete document. But the document - // has already been scaled and adjusted for margins, so do a 1:1 drawing. - printing::Metafile* complete_metafile = print_preview_context_.metafile(); - bool success = complete_metafile->StartPage( - printParams.page_size, gfx::Rect(printParams.page_size), 1.0); - DCHECK(success); - // StartPage unconditionally flips the content over, flip it back since it - // was already flipped in |draft_metafile|. - CGContextTranslateCTM(complete_metafile->context(), 0, - printParams.page_size.height()); - CGContextScaleCTM(complete_metafile->context(), 1.0, -1.0); - - draft_metafile->RenderPage(1, - complete_metafile->context(), - draft_metafile->GetPageBounds(1).ToCGRect(), - false /* shrink_to_fit */, - false /* stretch_to_fit */, - true /* center_horizontally */, - true /* center_vertically */); - complete_metafile->FinishPage(); +#if !defined(USE_SKIA) + if (!is_print_ready_metafile_sent_) { + // With CG, we rendered into a new metafile so we could get it as a draft + // document. Now we need to add it to print ready document. But the + // document has already been scaled and adjusted for margins, so do a 1:1 + // 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); + 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()); + CGContextScaleCTM(print_ready_metafile->context(), 1.0, -1.0); + draft_metafile->RenderPage(1, + print_ready_metafile->context(), + draft_metafile->GetPageBounds(1).ToCGRect(), + false /* shrink_to_fit */, + false /* stretch_to_fit */, + true /* center_horizontally */, + true /* center_vertically */); + print_ready_metafile->FinishPage(); + } +#endif + } else { +#if defined(USE_SKIA) + if (print_preview_context_.IsModifiable() && + print_preview_context_.generate_draft_pages()) { + DCHECK(!draft_metafile.get()); + draft_metafile.reset( + print_preview_context_.metafile()->GetMetafileForCurrentPage()); + } #endif } - return PreviewPageRendered(page_number, draft_metafile.get()); } @@ -136,8 +153,9 @@ void PrintWebViewHelper::RenderPage( SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); canvas->unref(); // SkRefPtr and new both took a reference. - WebKit::WebCanvas* canvas_ptr = canvas.get(); - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas_ptr, metafile); + printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); + printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(), + is_print_ready_metafile_sent_); #else bool success = metafile->StartPage(page_size, content_area, scale_factor); DCHECK(success); |