diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-23 16:35:12 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-23 16:35:12 +0000 |
commit | 36fbeee2a032e2ffcad31aa0d4207a9b06ad93e8 (patch) | |
tree | 2e1e47ed8762baafedf32c481a2bd792ec9fbd43 /printing | |
parent | f62c70c2a15b30a693bca560c2e9b75332854d64 (diff) | |
download | chromium_src-36fbeee2a032e2ffcad31aa0d4207a9b06ad93e8.zip chromium_src-36fbeee2a032e2ffcad31aa0d4207a9b06ad93e8.tar.gz chromium_src-36fbeee2a032e2ffcad31aa0d4207a9b06ad93e8.tar.bz2 |
PrintPreview: Added a helper function 'SetPrinter' in printing/printing_context_mac.h
BUG=76123
TEST=Preview printing works after code changes.
Review URL: http://codereview.chromium.org/6708074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79135 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/printing_context_mac.h | 4 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h index 78b85c0..870c380 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -47,6 +47,10 @@ class PrintingContextMac : public PrintingContext { // Initializes PrintSettings from native print info object. void InitPrintSettingsFromPrintInfo(const PageRanges& ranges); + // Updates |print_info_| to use the given printer. + // Returns true if the printer was set else returns false. + bool SetPrinter(const std::string& printer_name); + // The native print info object. scoped_nsobject<NSPrintInfo> print_info_; diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index a5d9b33..47ccb72 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -95,18 +95,9 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( if (!job_settings.GetString("printerName", &printer_name)) return OnError(); - NSString* new_printer_name = base::SysUTF8ToNSString(printer_name); - if (!new_printer_name) + if (!SetPrinter(printer_name)) return OnError(); - if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) { - NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name]; - if (new_printer == nil) - return OnError(); - - [print_info_.get() setPrinter:new_printer]; - } - InitPrintSettingsFromPrintInfo(ranges); return OK; } @@ -123,6 +114,21 @@ void PrintingContextMac::InitPrintSettingsFromPrintInfo( printer, page_format, ranges, false, &settings_); } +bool PrintingContextMac::SetPrinter(const std::string& printer_name) { + NSString* new_printer_name = base::SysUTF8ToNSString(printer_name); + if (!new_printer_name) + return false; + + if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) { + NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name]; + if (new_printer == nil) + return false; + + [print_info_.get() setPrinter:new_printer]; + } + return true; +} + void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { ResetSettings(); print_info_.reset([print_info retain]); |