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 #import <iomanip> | 10 #import <iomanip> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 best_matching_paper = paper; | 61 best_matching_paper = paper; |
62 best_match = difference; | 62 best_match = difference; |
63 } | 63 } |
64 } | 64 } |
65 return best_matching_paper; | 65 return best_matching_paper; |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 // static | 70 // static |
71 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 71 scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { |
72 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); | 72 return make_scoped_ptr<PrintingContext>(new PrintingContextMac(delegate)); |
73 } | 73 } |
74 | 74 |
75 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 75 PrintingContextMac::PrintingContextMac(Delegate* delegate) |
76 : PrintingContext(app_locale), | 76 : PrintingContext(delegate), |
77 print_info_([[NSPrintInfo sharedPrintInfo] copy]), | 77 print_info_([[NSPrintInfo sharedPrintInfo] copy]), |
78 context_(NULL) { | 78 context_(NULL) { |
79 } | 79 } |
80 | 80 |
81 PrintingContextMac::~PrintingContextMac() { | 81 PrintingContextMac::~PrintingContextMac() { |
82 ReleaseContext(); | 82 ReleaseContext(); |
83 } | 83 } |
84 | 84 |
85 void PrintingContextMac::AskUserForSettings( | 85 void PrintingContextMac::AskUserForSettings( |
86 gfx::NativeView parent_view, | |
87 int max_pages, | 86 int max_pages, |
88 bool has_selection, | 87 bool has_selection, |
89 const PrintSettingsCallback& callback) { | 88 const PrintSettingsCallback& callback) { |
90 // Third-party print drivers seem to be an area prone to raising exceptions. | 89 // Third-party print drivers seem to be an area prone to raising exceptions. |
91 // This will allow exceptions to be raised, but does not handle them. The | 90 // This will allow exceptions to be raised, but does not handle them. The |
92 // NSPrintPanel appears to have appropriate NSException handlers. | 91 // NSPrintPanel appears to have appropriate NSException handlers. |
93 base::mac::ScopedNSExceptionEnabler enabler; | 92 base::mac::ScopedNSExceptionEnabler enabler; |
94 | 93 |
95 // Exceptions can also happen when the NSPrintPanel is being | 94 // Exceptions can also happen when the NSPrintPanel is being |
96 // deallocated, so it must be autoreleased within this scope. | 95 // deallocated, so it must be autoreleased within this scope. |
(...skipping 11 matching lines...) Expand all Loading... |
108 NSPrintPanel* panel = [NSPrintPanel printPanel]; | 107 NSPrintPanel* panel = [NSPrintPanel printPanel]; |
109 NSPrintInfo* printInfo = print_info_.get(); | 108 NSPrintInfo* printInfo = print_info_.get(); |
110 | 109 |
111 NSPrintPanelOptions options = [panel options]; | 110 NSPrintPanelOptions options = [panel options]; |
112 options |= NSPrintPanelShowsPaperSize; | 111 options |= NSPrintPanelShowsPaperSize; |
113 options |= NSPrintPanelShowsOrientation; | 112 options |= NSPrintPanelShowsOrientation; |
114 options |= NSPrintPanelShowsScaling; | 113 options |= NSPrintPanelShowsScaling; |
115 [panel setOptions:options]; | 114 [panel setOptions:options]; |
116 | 115 |
117 // Set the print job title text. | 116 // Set the print job title text. |
| 117 gfx::NativeView parent_view = delegate_->GetParentView(); |
118 if (parent_view) { | 118 if (parent_view) { |
119 NSString* job_title = [[parent_view window] title]; | 119 NSString* job_title = [[parent_view window] title]; |
120 if (job_title) { | 120 if (job_title) { |
121 PMPrintSettings printSettings = | 121 PMPrintSettings printSettings = |
122 (PMPrintSettings)[printInfo PMPrintSettings]; | 122 (PMPrintSettings)[printInfo PMPrintSettings]; |
123 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title); | 123 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title); |
124 [printInfo updateFromPMPrintSettings]; | 124 [printInfo updateFromPMPrintSettings]; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 void PrintingContextMac::ReleaseContext() { | 516 void PrintingContextMac::ReleaseContext() { |
517 print_info_.reset(); | 517 print_info_.reset(); |
518 context_ = NULL; | 518 context_ = NULL; |
519 } | 519 } |
520 | 520 |
521 gfx::NativeDrawingContext PrintingContextMac::context() const { | 521 gfx::NativeDrawingContext PrintingContextMac::context() const { |
522 return context_; | 522 return context_; |
523 } | 523 } |
524 | 524 |
525 } // namespace printing | 525 } // namespace printing |
OLD | NEW |