diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 01:58:22 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 01:58:22 +0000 |
commit | 06cb23886ba8f1eec7e6ad3217a76051b9079579 (patch) | |
tree | 6759a1f24d2715d9ad23a87dda2482fc58b318c8 | |
parent | 4724e4139b6e7c1d48acee1b788ab0c1598a9406 (diff) | |
download | chromium_src-06cb23886ba8f1eec7e6ad3217a76051b9079579.zip chromium_src-06cb23886ba8f1eec7e6ad3217a76051b9079579.tar.gz chromium_src-06cb23886ba8f1eec7e6ad3217a76051b9079579.tar.bz2 |
Print Preview: Print the entire page range since the preview only contains the user selected pages.
BUG=none
TEST=Only a 3 page PDF, select page 3, print.
Review URL: http://codereview.chromium.org/6895015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82767 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/printing/print_job_worker.cc | 25 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler.cc | 11 | ||||
-rw-r--r-- | printing/print_job_constants.cc | 9 | ||||
-rw-r--r-- | printing/print_job_constants.h | 3 |
4 files changed, 34 insertions, 14 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index fb38d47..1d0fc4f 100644 --- a/chrome/browser/printing/print_job_worker.cc +++ b/chrome/browser/printing/print_job_worker.cc @@ -10,6 +10,7 @@ #include "chrome/browser/printing/print_job.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" +#include "printing/print_job_constants.h" #include "printing/printed_document.h" #include "printing/printed_page.h" @@ -112,19 +113,23 @@ void PrintJobWorker::UpdatePrintSettings( // Create new PageRanges based on |new_settings|. PageRanges new_ranges; ListValue* page_range_array; - if (new_settings->GetList("pageRange", &page_range_array)) { + if (new_settings->GetList(kSettingPageRange, &page_range_array)) { for (size_t index = 0; index < page_range_array->GetSize(); ++index) { DictionaryValue* dict; - if (page_range_array->GetDictionary(index, &dict)) { - PageRange range; - if (dict->GetInteger("from", &range.from) && - dict->GetInteger("to", &range.to)) { - // Page numbers are 0-based. - range.from--; - range.to--; - new_ranges.push_back(range); - } + if (!page_range_array->GetDictionary(index, &dict)) + continue; + + PageRange range; + if (!dict->GetInteger(kSettingPageRangeFrom, &range.from) || + !dict->GetInteger(kSettingPageRangeTo, &range.to)) { + continue; } + + // Page numbers are 1-based in the dictionary. + // Page numbers are 0-based for the printing context. + range.from--; + range.to--; + new_ranges.push_back(range); } } PrintingContext::Result result = diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc index ee62440..9867cb7 100644 --- a/chrome/browser/ui/webui/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview_handler.cc @@ -289,6 +289,9 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { SelectFile(default_filename); } else { + // The PDF being printed contains only the pages that the user selected, + // so ignore the page range and print all pages. + settings->Remove(printing::kSettingPageRange, NULL); RenderViewHost* rvh = web_ui_->GetRenderViewHost(); rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); } @@ -358,10 +361,10 @@ void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { void PrintPreviewHandler::FileSelected(const FilePath& path, int index, void* params) { PrintPreviewUIHTMLSource::PrintPreviewData data; - PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_); - pp_ui->html_source()->GetPrintPreviewData(&data); - DCHECK(data.first != NULL); - DCHECK(data.second > 0); + PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); + print_preview_ui->html_source()->GetPrintPreviewData(&data); + DCHECK(data.first); + DCHECK_GT(data.second, 0U); printing::PreviewMetafile* metafile = new printing::PreviewMetafile; metafile->InitFromData(data.first->memory(), data.second); diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc index 21a0199..82f9adf 100644 --- a/printing/print_job_constants.cc +++ b/printing/print_job_constants.cc @@ -21,6 +21,15 @@ const char kSettingDuplexMode[] = "duplex"; // Page orientation: true for landscape, false for portrait. const char kSettingLandscape[] = "landscape"; +// A page range. +const char kSettingPageRange[] = "pageRange"; + +// The first page of a page range. (1-based) +const char kSettingPageRangeFrom[] = "from"; + +// The last page of a page range. (1-based) +const char kSettingPageRangeTo[] = "to"; + // Printer name. const char kSettingPrinterName[] = "printerName"; diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h index ec8ca8c..1005ca3 100644 --- a/printing/print_job_constants.h +++ b/printing/print_job_constants.h @@ -12,6 +12,9 @@ extern const char kSettingColor[]; extern const char kSettingCopies[]; extern const char kSettingDuplexMode[]; extern const char kSettingLandscape[]; +extern const char kSettingPageRange[]; +extern const char kSettingPageRangeFrom[]; +extern const char kSettingPageRangeTo[]; extern const char kSettingPrinterName[]; extern const char kSettingPrintToPDF[]; |