| 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 14 matching lines...) Expand all Loading... |
| 25 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 25 PrintingContextMac::PrintingContextMac(const std::string& app_locale) |
| 26 : PrintingContext(app_locale), | 26 : PrintingContext(app_locale), |
| 27 print_info_([[NSPrintInfo sharedPrintInfo] copy]), | 27 print_info_([[NSPrintInfo sharedPrintInfo] copy]), |
| 28 context_(NULL) { | 28 context_(NULL) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 PrintingContextMac::~PrintingContextMac() { | 31 PrintingContextMac::~PrintingContextMac() { |
| 32 ReleaseContext(); | 32 ReleaseContext(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, | 35 void PrintingContextMac::AskUserForSettings( |
| 36 int max_pages, | 36 gfx::NativeView parent_view, |
| 37 bool has_selection, | 37 int max_pages, |
| 38 PrintSettingsCallback* callback) { | 38 bool has_selection, |
| 39 const PrintSettingsCallback& callback) { |
| 39 // Third-party print drivers seem to be an area prone to raising exceptions. | 40 // Third-party print drivers seem to be an area prone to raising exceptions. |
| 40 // This will allow exceptions to be raised, but does not handle them. The | 41 // This will allow exceptions to be raised, but does not handle them. The |
| 41 // NSPrintPanel appears to have appropriate NSException handlers. | 42 // NSPrintPanel appears to have appropriate NSException handlers. |
| 42 base::mac::ScopedNSExceptionEnabler enabler; | 43 base::mac::ScopedNSExceptionEnabler enabler; |
| 43 | 44 |
| 44 // Exceptions can also happen when the NSPrintPanel is being | 45 // Exceptions can also happen when the NSPrintPanel is being |
| 45 // deallocated, so it must be autoreleased within this scope. | 46 // deallocated, so it must be autoreleased within this scope. |
| 46 base::mac::ScopedNSAutoreleasePool pool; | 47 base::mac::ScopedNSAutoreleasePool pool; |
| 47 | 48 |
| 48 DCHECK([NSThread isMainThread]); | 49 DCHECK([NSThread isMainThread]); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 73 [printInfo updateFromPMPrintSettings]; | 74 [printInfo updateFromPMPrintSettings]; |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window. | 78 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window. |
| 78 // Will require restructuring the PrintingContext API to use a callback. | 79 // Will require restructuring the PrintingContext API to use a callback. |
| 79 NSInteger selection = [panel runModalWithPrintInfo:printInfo]; | 80 NSInteger selection = [panel runModalWithPrintInfo:printInfo]; |
| 80 if (selection == NSOKButton) { | 81 if (selection == NSOKButton) { |
| 81 print_info_.reset([[panel printInfo] retain]); | 82 print_info_.reset([[panel printInfo] retain]); |
| 82 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); | 83 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); |
| 83 callback->Run(OK); | 84 callback.Run(OK); |
| 84 } else { | 85 } else { |
| 85 callback->Run(CANCEL); | 86 callback.Run(CANCEL); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 PrintingContext::Result PrintingContextMac::UseDefaultSettings() { | 90 PrintingContext::Result PrintingContextMac::UseDefaultSettings() { |
| 90 DCHECK(!in_print_job_); | 91 DCHECK(!in_print_job_); |
| 91 | 92 |
| 92 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); | 93 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); |
| 93 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); | 94 InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo()); |
| 94 | 95 |
| 95 return OK; | 96 return OK; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 void PrintingContextMac::ReleaseContext() { | 490 void PrintingContextMac::ReleaseContext() { |
| 490 print_info_.reset(); | 491 print_info_.reset(); |
| 491 context_ = NULL; | 492 context_ = NULL; |
| 492 } | 493 } |
| 493 | 494 |
| 494 gfx::NativeDrawingContext PrintingContextMac::context() const { | 495 gfx::NativeDrawingContext PrintingContextMac::context() const { |
| 495 return context_; | 496 return context_; |
| 496 } | 497 } |
| 497 | 498 |
| 498 } // namespace printing | 499 } // namespace printing |
| OLD | NEW |