| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title); | 75 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title); |
| 76 [printInfo updateFromPMPrintSettings]; | 76 [printInfo updateFromPMPrintSettings]; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window. | 80 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window. |
| 81 // Will require restructuring the PrintingContext API to use a callback. | 81 // Will require restructuring the PrintingContext API to use a callback. |
| 82 NSInteger selection = [panel runModalWithPrintInfo:printInfo]; | 82 NSInteger selection = [panel runModalWithPrintInfo:printInfo]; |
| 83 if (selection == NSOKButton) { | 83 if (selection == NSOKButton) { |
| 84 print_info_.reset([[panel printInfo] retain]); | 84 print_info_.reset([[panel printInfo] retain]); |
| 85 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); | 85 DictionaryValue header_footer_info; |
| 86 header_footer_info.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| 87 false); |
| 88 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo(), |
| 89 header_footer_info); |
| 86 callback->Run(OK); | 90 callback->Run(OK); |
| 87 } else { | 91 } else { |
| 88 callback->Run(CANCEL); | 92 callback->Run(CANCEL); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 | 95 |
| 92 PrintingContext::Result PrintingContextMac::UseDefaultSettings() { | 96 PrintingContext::Result PrintingContextMac::UseDefaultSettings() { |
| 93 DCHECK(!in_print_job_); | 97 DCHECK(!in_print_job_); |
| 94 | 98 |
| 95 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); | 99 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); |
| 96 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); | 100 DictionaryValue header_footer_info; |
| 101 header_footer_info.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| 102 false); |
| 103 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo(), |
| 104 header_footer_info); |
| 97 | 105 |
| 98 return OK; | 106 return OK; |
| 99 } | 107 } |
| 100 | 108 |
| 101 PrintingContext::Result PrintingContextMac::UpdatePrintSettings( | 109 PrintingContext::Result PrintingContextMac::UpdatePrintSettings( |
| 102 const DictionaryValue& job_settings, const PageRanges& ranges) { | 110 const DictionaryValue& job_settings, const PageRanges& ranges) { |
| 103 DCHECK(!in_print_job_); | 111 DCHECK(!in_print_job_); |
| 104 | 112 |
| 105 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start | 113 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start |
| 106 // with a clean slate. | 114 // with a clean slate. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 151 |
| 144 if (!SetOutputIsColor(color)) | 152 if (!SetOutputIsColor(color)) |
| 145 return OnError(); | 153 return OnError(); |
| 146 } | 154 } |
| 147 | 155 |
| 148 if (!SetOrientationIsLandscape(landscape)) | 156 if (!SetOrientationIsLandscape(landscape)) |
| 149 return OnError(); | 157 return OnError(); |
| 150 | 158 |
| 151 [print_info_.get() updateFromPMPrintSettings]; | 159 [print_info_.get() updateFromPMPrintSettings]; |
| 152 | 160 |
| 153 InitPrintSettingsFromPrintInfo(ranges); | 161 bool display_header_footer; |
| 162 // Getting Header and Footer settings. |
| 163 if (!job_settings.GetBoolean(printing::kSettingHeaderFooterEnabled, |
| 164 &display_header_footer)) { |
| 165 NOTREACHED(); |
| 166 } |
| 167 DictionaryValue header_footer_info; |
| 168 header_footer_info.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| 169 display_header_footer); |
| 170 if (display_header_footer) { |
| 171 string16 title; |
| 172 std::string url; |
| 173 if (!job_settings.GetString(printing::kSettingHeaderFooterTitle, &title) || |
| 174 !job_settings.GetString(printing::kSettingHeaderFooterURL, &url)) { |
| 175 NOTREACHED(); |
| 176 } |
| 177 header_footer_info.SetString(printing::kSettingHeaderFooterURL, url); |
| 178 header_footer_info.SetString(printing::kSettingHeaderFooterTitle, title); |
| 179 } |
| 180 |
| 181 InitPrintSettingsFromPrintInfo(ranges, header_footer_info); |
| 154 return OK; | 182 return OK; |
| 155 } | 183 } |
| 156 | 184 |
| 157 void PrintingContextMac::InitPrintSettingsFromPrintInfo( | 185 void PrintingContextMac::InitPrintSettingsFromPrintInfo( |
| 158 const PageRanges& ranges) { | 186 const PageRanges& ranges, |
| 187 const DictionaryValue& header_footer_info) { |
| 159 PMPrintSession print_session = | 188 PMPrintSession print_session = |
| 160 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); | 189 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); |
| 161 PMPageFormat page_format = | 190 PMPageFormat page_format = |
| 162 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); | 191 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); |
| 163 PMPrinter printer; | 192 PMPrinter printer; |
| 164 PMSessionGetCurrentPrinter(print_session, &printer); | 193 PMSessionGetCurrentPrinter(print_session, &printer); |
| 165 PrintSettingsInitializerMac::InitPrintSettings( | 194 PrintSettingsInitializerMac::InitPrintSettings( |
| 166 printer, page_format, ranges, false, &settings_); | 195 printer, page_format, ranges, false, &settings_); |
| 167 } | 196 } |
| 168 | 197 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 void PrintingContextMac::ReleaseContext() { | 399 void PrintingContextMac::ReleaseContext() { |
| 371 print_info_.reset(); | 400 print_info_.reset(); |
| 372 context_ = NULL; | 401 context_ = NULL; |
| 373 } | 402 } |
| 374 | 403 |
| 375 gfx::NativeDrawingContext PrintingContextMac::context() const { | 404 gfx::NativeDrawingContext PrintingContextMac::context() const { |
| 376 return context_; | 405 return context_; |
| 377 } | 406 } |
| 378 | 407 |
| 379 } // namespace printing | 408 } // namespace printing |
| OLD | NEW |