0

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
This commit is contained in:
kmadhusu@chromium.org
2011-06-03 19:27:00 +00:00
parent fbad4d4fcf
commit 4274861a82
2 changed files with 18 additions and 12 deletions

@ -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);

@ -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(