Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "printing/printing_context_mac.h" | 5 #include "printing/printing_context_mac.h" |
| 6 | 6 |
| 7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
| 8 #import <AppKit/AppKit.h> | 8 #import <AppKit/AppKit.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/mac/scoped_nsautorelease_pool.h" | 12 #include "base/mac/scoped_nsautorelease_pool.h" |
| 13 #include "base/mac/scoped_nsexception_enabler.h" | 13 #include "base/mac/scoped_nsexception_enabler.h" |
| 14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "printing/print_settings_initializer_mac.h" | 16 #include "printing/print_settings_initializer_mac.h" |
| 17 | 17 |
| 18 static const CFStringRef kColorModel = CFSTR("ColorModel"); | 18 static const CFStringRef kColorModel = CFSTR("ColorModel"); |
| 19 static const CFStringRef kGrayColor = CFSTR("Gray"); | 19 static const CFStringRef kGrayColor = CFSTR("Gray"); |
| 20 static const CFStringRef kCMYK = CFSTR("CMYK"); | |
| 20 | 21 |
| 21 namespace printing { | 22 namespace printing { |
| 22 | 23 |
| 23 // static | 24 // static |
| 24 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 25 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
| 25 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); | 26 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 29 PrintingContextMac::PrintingContextMac(const std::string& app_locale) |
| 29 : PrintingContext(app_locale), | 30 : PrintingContext(app_locale), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 101 |
| 101 PrintingContext::Result PrintingContextMac::UpdatePrinterSettings( | 102 PrintingContext::Result PrintingContextMac::UpdatePrinterSettings( |
| 102 const DictionaryValue& job_settings, const PageRanges& ranges) { | 103 const DictionaryValue& job_settings, const PageRanges& ranges) { |
| 103 DCHECK(!in_print_job_); | 104 DCHECK(!in_print_job_); |
| 104 | 105 |
| 105 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start | 106 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start |
| 106 // with a clean slate. | 107 // with a clean slate. |
| 107 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); | 108 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); |
| 108 | 109 |
| 109 bool collate; | 110 bool collate; |
| 110 bool color; | 111 int color; |
| 111 bool landscape; | 112 bool landscape; |
| 112 bool print_to_pdf; | 113 bool print_to_pdf; |
| 113 int copies; | 114 int copies; |
| 114 int duplex_mode; | 115 int duplex_mode; |
| 115 std::string device_name; | 116 std::string device_name; |
| 116 | 117 |
| 117 if (!job_settings.GetBoolean(kSettingLandscape, &landscape) || | 118 if (!job_settings.GetBoolean(kSettingLandscape, &landscape) || |
| 118 !job_settings.GetBoolean(kSettingCollate, &collate) || | 119 !job_settings.GetBoolean(kSettingCollate, &collate) || |
| 119 !job_settings.GetBoolean(kSettingColor, &color) || | 120 !job_settings.GetInteger(kSettingColor, &color) || |
| 120 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || | 121 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || |
| 121 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || | 122 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || |
| 122 !job_settings.GetInteger(kSettingCopies, &copies) || | 123 !job_settings.GetInteger(kSettingCopies, &copies) || |
| 123 !job_settings.GetString(kSettingDeviceName, &device_name)) { | 124 !job_settings.GetString(kSettingDeviceName, &device_name)) { |
| 124 return OnError(); | 125 return OnError(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); | 128 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); |
| 128 | 129 |
| 129 if (!print_to_pdf && !print_to_cloud) { | 130 if (!print_to_pdf && !print_to_cloud) { |
| 130 if (!SetPrinter(device_name)) | 131 if (!SetPrinter(device_name)) |
| 131 return OnError(); | 132 return OnError(); |
| 132 | 133 |
| 133 if (!SetCopiesInPrintSettings(copies)) | 134 if (!SetCopiesInPrintSettings(copies)) |
| 134 return OnError(); | 135 return OnError(); |
| 135 | 136 |
| 136 if (!SetCollateInPrintSettings(collate)) | 137 if (!SetCollateInPrintSettings(collate)) |
| 137 return OnError(); | 138 return OnError(); |
| 138 | 139 |
| 139 if (!SetDuplexModeInPrintSettings( | 140 if (!SetDuplexModeInPrintSettings( |
| 140 static_cast<DuplexMode>(duplex_mode))) { | 141 static_cast<DuplexMode>(duplex_mode))) { |
| 141 return OnError(); | 142 return OnError(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 if (!SetOutputIsColor(color)) | 145 if (!SetOutputColor(color)) |
| 145 return OnError(); | 146 return OnError(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 if (!SetOrientationIsLandscape(landscape)) | 149 if (!SetOrientationIsLandscape(landscape)) |
| 149 return OnError(); | 150 return OnError(); |
| 150 | 151 |
| 151 [print_info_.get() updateFromPMPrintSettings]; | 152 [print_info_.get() updateFromPMPrintSettings]; |
| 152 | 153 |
| 153 InitPrintSettingsFromPrintInfo(ranges); | 154 InitPrintSettingsFromPrintInfo(ranges); |
| 154 return OK; | 155 return OK; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 default: | 239 default: |
| 239 duplexSetting = kPMDuplexNone; | 240 duplexSetting = kPMDuplexNone; |
| 240 break; | 241 break; |
| 241 } | 242 } |
| 242 | 243 |
| 243 PMPrintSettings pmPrintSettings = | 244 PMPrintSettings pmPrintSettings = |
| 244 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 245 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
| 245 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; | 246 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; |
| 246 } | 247 } |
| 247 | 248 |
| 248 bool PrintingContextMac::SetOutputIsColor(bool color) { | 249 bool PrintingContextMac::SetOutputColor(int color_mode) { |
| 249 PMPrintSettings pmPrintSettings = | 250 PMPrintSettings pmPrintSettings = |
| 250 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 251 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
| 251 CFStringRef output_color = color ? NULL : kGrayColor; | 252 CFStringRef output_color = NULL; |
|
vandebo (ex-Chrome)
2011/09/02 22:38:18
Setting the color model to NULL is color? That's k
kmadhusu
2011/09/04 01:52:51
If I remember correct, NULL will clear the previou
| |
| 253 if (color_mode == printing::GRAY) | |
| 254 output_color = kGrayColor; | |
| 255 else if (color_mode == printing::CMYK) | |
| 256 output_color = kCMYK; | |
| 252 | 257 |
| 253 return PMPrintSettingsSetValue(pmPrintSettings, | 258 return PMPrintSettingsSetValue(pmPrintSettings, |
| 254 kColorModel, | 259 kColorModel, |
| 255 output_color, | 260 output_color, |
| 256 false) == noErr; | 261 false) == noErr; |
| 257 } | 262 } |
| 258 | 263 |
| 259 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { | 264 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { |
| 260 PageRanges page_ranges; | 265 PageRanges page_ranges; |
| 261 NSDictionary* print_info_dict = [print_info_.get() dictionary]; | 266 NSDictionary* print_info_dict = [print_info_.get() dictionary]; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 void PrintingContextMac::ReleaseContext() { | 375 void PrintingContextMac::ReleaseContext() { |
| 371 print_info_.reset(); | 376 print_info_.reset(); |
| 372 context_ = NULL; | 377 context_ = NULL; |
| 373 } | 378 } |
| 374 | 379 |
| 375 gfx::NativeDrawingContext PrintingContextMac::context() const { | 380 gfx::NativeDrawingContext PrintingContextMac::context() const { |
| 376 return context_; | 381 return context_; |
| 377 } | 382 } |
| 378 | 383 |
| 379 } // namespace printing | 384 } // namespace printing |
| OLD | NEW |