diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-03 19:27:00 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-03 19:27:00 +0000 |
commit | 4274861a828d85d3360d70f54bc3017f87f17502 (patch) | |
tree | fff45251ea587c644155e7771dfa0f61fd022d08 /printing | |
parent | fbad4d4fcf28dde00602157b691848db5d5791ae (diff) | |
download | chromium_src-4274861a828d85d3360d70f54bc3017f87f17502.zip chromium_src-4274861a828d85d3360d70f54bc3017f87f17502.tar.gz chromium_src-4274861a828d85d3360d70f54bc3017f87f17502.tar.bz2 |
PrintPreview: Modified PrintingContextMac code to use the copy of sharedPrintInfo object.
BUG=82739
TEST=Please refer to bug report.
Review URL: http://codereview.chromium.org/7074051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/printing_context_mac.h | 12 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 18 |
2 files changed, 18 insertions, 12 deletions
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h index 84a5c05..af6f9f6 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -42,12 +42,16 @@ class PrintingContextMac : public PrintingContext { virtual gfx::NativeDrawingContext context() const; private: - // Read the settings from the given NSPrintInfo (and cache it for later use). - void ParsePrintInfo(NSPrintInfo* print_info); - - // Initializes PrintSettings from native print info object. + // Initializes PrintSettings from |print_info_|. This must be called + // after changes to |print_info_| in order for the changes to take effect in + // printing. + // This function ignores the page range information specified in the print + // info object and use |ranges| instead. void InitPrintSettingsFromPrintInfo(const PageRanges& ranges); + // Returns the set of page ranges constructed from |print_info_|. + PageRanges GetPageRangesFromPrintInfo(); + // Updates |print_info_| to use the given printer. // Returns true if the printer was set else returns false. bool SetPrinter(const std::string& device_name); diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index 599fa78..fa97793 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -27,6 +27,7 @@ PrintingContext* PrintingContext::Create(const std::string& app_locale) { PrintingContextMac::PrintingContextMac(const std::string& app_locale) : PrintingContext(app_locale), + print_info_([[NSPrintInfo sharedPrintInfo] copy]), context_(NULL) { } @@ -57,7 +58,7 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, // adding a new custom view to the panel on 10.5; 10.6 has // NSPrintPanelShowsPrintSelection). NSPrintPanel* panel = [NSPrintPanel printPanel]; - NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo]; + NSPrintInfo* printInfo = print_info_.get(); NSPrintPanelOptions options = [panel options]; options |= NSPrintPanelShowsPaperSize; @@ -80,7 +81,8 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, // Will require restructuring the PrintingContext API to use a callback. NSInteger selection = [panel runModalWithPrintInfo:printInfo]; if (selection == NSOKButton) { - ParsePrintInfo([panel printInfo]); + print_info_.reset([[panel printInfo] retain]); + InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); callback->Run(OK); } else { callback->Run(CANCEL); @@ -90,7 +92,8 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, PrintingContext::Result PrintingContextMac::UseDefaultSettings() { DCHECK(!in_print_job_); - ParsePrintInfo([NSPrintInfo sharedPrintInfo]); + print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); + InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); return OK; } @@ -99,7 +102,8 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( const DictionaryValue& job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); - ResetSettings(); + // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start + // with a clean slate. print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); bool collate; @@ -250,9 +254,7 @@ bool PrintingContextMac::SetOutputIsColor(bool color) { false) == noErr; } -void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { - ResetSettings(); - print_info_.reset([print_info retain]); +PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { PageRanges page_ranges; NSDictionary* print_info_dict = [print_info_.get() dictionary]; if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { @@ -261,7 +263,7 @@ void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; page_ranges.push_back(range); } - InitPrintSettingsFromPrintInfo(page_ranges); + return page_ranges; } PrintingContext::Result PrintingContextMac::InitWithSettings( |