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" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 !job_settings.GetInteger(kSettingColor, &color) || | 117 !job_settings.GetInteger(kSettingColor, &color) || |
118 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || | 118 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || |
119 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || | 119 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || |
120 !job_settings.GetInteger(kSettingCopies, &copies) || | 120 !job_settings.GetInteger(kSettingCopies, &copies) || |
121 !job_settings.GetString(kSettingDeviceName, &device_name) || | 121 !job_settings.GetString(kSettingDeviceName, &device_name) || |
122 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog)) { | 122 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog)) { |
123 return OnError(); | 123 return OnError(); |
124 } | 124 } |
125 | 125 |
126 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); | 126 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); |
| 127 bool open_pdf_in_preview = job_settings.HasKey(kSettingOpenPDFInPreview); |
127 | 128 |
128 if (!print_to_pdf && !print_to_cloud && !is_cloud_dialog) { | 129 if (!print_to_pdf && !print_to_cloud && !is_cloud_dialog) { |
129 if (!SetPrinter(device_name)) | 130 if (!SetPrinter(device_name)) |
130 return OnError(); | 131 return OnError(); |
131 | 132 |
132 if (!SetCopiesInPrintSettings(copies)) | 133 if (!SetCopiesInPrintSettings(copies)) |
133 return OnError(); | 134 return OnError(); |
134 | 135 |
135 if (!SetCollateInPrintSettings(collate)) | 136 if (!SetCollateInPrintSettings(collate)) |
136 return OnError(); | 137 return OnError(); |
137 | 138 |
138 if (!SetDuplexModeInPrintSettings( | 139 if (!SetDuplexModeInPrintSettings( |
139 static_cast<DuplexMode>(duplex_mode))) { | 140 static_cast<DuplexMode>(duplex_mode))) { |
140 return OnError(); | 141 return OnError(); |
141 } | 142 } |
142 | 143 |
143 if (!SetOutputColor(color)) | 144 if (!SetOutputColor(color)) |
144 return OnError(); | 145 return OnError(); |
145 } | 146 } |
| 147 if (open_pdf_in_preview) { |
| 148 if (!SetPrintPreviewJob()) |
| 149 return OnError(); |
| 150 } |
| 151 |
146 if (!UpdatePageFormatWithPaperInfo()) | 152 if (!UpdatePageFormatWithPaperInfo()) |
147 return OnError(); | 153 return OnError(); |
148 | 154 |
149 if (!SetOrientationIsLandscape(landscape)) | 155 if (!SetOrientationIsLandscape(landscape)) |
150 return OnError(); | 156 return OnError(); |
151 | 157 |
152 [print_info_.get() updateFromPMPrintSettings]; | 158 [print_info_.get() updateFromPMPrintSettings]; |
153 | 159 |
154 InitPrintSettingsFromPrintInfo(ranges); | 160 InitPrintSettingsFromPrintInfo(ranges); |
155 return OK; | 161 return OK; |
156 } | 162 } |
157 | 163 |
| 164 bool PrintingContextMac::SetPrintPreviewJob() { |
| 165 PMPrintSession print_session = |
| 166 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); |
| 167 PMPrintSettings print_settings = |
| 168 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
| 169 return PMSessionSetDestination( |
| 170 print_session, print_settings, kPMDestinationPreview, |
| 171 NULL, NULL) == noErr; |
| 172 } |
| 173 |
158 void PrintingContextMac::InitPrintSettingsFromPrintInfo( | 174 void PrintingContextMac::InitPrintSettingsFromPrintInfo( |
159 const PageRanges& ranges) { | 175 const PageRanges& ranges) { |
160 PMPrintSession print_session = | 176 PMPrintSession print_session = |
161 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); | 177 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); |
162 PMPageFormat page_format = | 178 PMPageFormat page_format = |
163 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); | 179 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); |
164 PMPrinter printer; | 180 PMPrinter printer; |
165 PMSessionGetCurrentPrinter(print_session, &printer); | 181 PMSessionGetCurrentPrinter(print_session, &printer); |
166 PrintSettingsInitializerMac::InitPrintSettings( | 182 PrintSettingsInitializerMac::InitPrintSettings( |
167 printer, page_format, ranges, false, &settings_); | 183 printer, page_format, ranges, false, &settings_); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 void PrintingContextMac::ReleaseContext() { | 489 void PrintingContextMac::ReleaseContext() { |
474 print_info_.reset(); | 490 print_info_.reset(); |
475 context_ = NULL; | 491 context_ = NULL; |
476 } | 492 } |
477 | 493 |
478 gfx::NativeDrawingContext PrintingContextMac::context() const { | 494 gfx::NativeDrawingContext PrintingContextMac::context() const { |
479 return context_; | 495 return context_; |
480 } | 496 } |
481 | 497 |
482 } // namespace printing | 498 } // namespace printing |
OLD | NEW |