Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10022)

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 7822014: Fix the print preview regression bug caused by r98926. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored the code as per comments. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/print_web_view_helper.cc
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 36726eee4667e71193e7de272e489219da218c46..f0d82c9fa1f6896c32bcc7d07eb966f83a8cb1df 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -702,19 +702,31 @@ bool PrintWebViewHelper::CreatePreviewDocument() {
if (CheckForCancel())
return false;
- int page_number;
- while ((page_number = print_preview_context_.GetNextPageNumber()) >= 0) {
+ while (!print_preview_context_.IsFinalPageRendered()) {
kmadhusu 2011/09/01 18:40:20 GetNextPageNumber() function needs to be called wh
+ int page_number = print_preview_context_.GetNextPageNumber();
+ DCHECK(page_number >= 0);
if (!RenderPreviewPage(page_number))
return false;
+
if (CheckForCancel())
return false;
+
+ // AllPagesRendered() will be called only once i.e., after rendering the
vandebo (ex-Chrome) 2011/09/01 18:53:56 I wouldn't include the second part of this comment
kmadhusu 2011/09/01 20:07:14 Done..
+ // required pages. This code is here because if we are previewing a PDF
+ // file, we need to invoke PrepareFrameAndViewForPrint::FinishPrinting()
+ // before calling PreviewMetafile::FinishDocument().
+ //
+ // This function call ordering is not required if we are previewing a
+ // normal html page. We can invoke PreviewMetafile::FinishDocument() as
+ // soon as the print ready doucment is available.
+ if (print_preview_context_.IsFinalPageRendered())
+ print_preview_context_.AllPagesRendered();
+
if (print_preview_context_.IsLastPageOfPrintReadyMetafile()) {
vandebo (ex-Chrome) 2011/09/01 18:53:56 To help enforce the comment, you can add a DCHECK
kmadhusu 2011/09/01 20:07:14 Done.
- // Finished generating preview. Finalize the document.
if (!FinalizePrintReadyDocument())
return false;
}
}
- print_preview_context_.AllPagesRendered();
print_preview_context_.Finished();
return true;
}
@@ -1470,6 +1482,10 @@ bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile()
return current_page_index_ == print_ready_metafile_page_count_;
}
+bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const {
+ return (size_t)current_page_index_ == pages_to_render_.size();
vandebo (ex-Chrome) 2011/09/01 18:53:56 static_cast<size_t>
kmadhusu 2011/09/01 20:07:14 Done.
+}
+
void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages(
bool generate_draft_pages) {
generate_draft_pages_ = generate_draft_pages;
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698