From 7868ecabafc39bcd917276899742be136cca2ae3 Mon Sep 17 00:00:00 2001 From: "kmadhusu@chromium.org" Date: Sat, 5 Mar 2011 00:12:53 +0000 Subject: (1) Hook up the print button to send the pages to the default printer for printing without displaying a native dialog. (2) Made code changes to accept a print page range from the user and to print only those specified pages. BUG=none TEST=Enable print preview on mac, provide a valid page range and make sure print button in print preview works. Review URL: http://codereview.chromium.org/6533006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77003 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/printing/print_job_worker.cc | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'chrome/browser/printing/print_job_worker.cc') diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index db0c341..3c7f862 100644 --- a/chrome/browser/printing/print_job_worker.cc +++ b/chrome/browser/printing/print_job_worker.cc @@ -5,6 +5,7 @@ #include "chrome/browser/printing/print_job_worker.h" #include "base/message_loop.h" +#include "base/values.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/printing/print_job.h" #include "chrome/common/notification_service.h" @@ -98,6 +99,41 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings, } } +void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) { + DCHECK_EQ(message_loop(), MessageLoop::current()); + + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings, + new_settings)); +} + +void PrintJobWorker::UpdatePrintSettings( + const DictionaryValue* const new_settings) { + // Create new PageRanges based on |new_settings|. + PageRanges new_ranges; + ListValue* page_range_array; + if (new_settings->GetList("pageRange", &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); + } + } + } + } + // We don't update any other print job settings now, so delete |new_settings|. + delete new_settings; + PrintingContext::Result result = + printing_context_->UpdatePrintSettings(new_ranges); + GetSettingsDone(result); +} + void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { // Most PrintingContext functions may start a message loop and process // message recursively, so disable recursive task processing. -- cgit v1.1