Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: printing/printing_context_mac.mm

Issue 478183005: Added PrintingContext::Delegate to get parent view handle and application locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wed Aug 20 16:46:22 PDT 2014 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 CHECK(delegate);
73 return make_scoped_ptr(new PrintingContextMac(delegate));
73 } 74 }
74 75
75 PrintingContextMac::PrintingContextMac(const std::string& app_locale) 76 PrintingContextMac::PrintingContextMac(Delegate* delegate)
76 : PrintingContext(app_locale), 77 : PrintingContext(delegate),
77 print_info_([[NSPrintInfo sharedPrintInfo] copy]), 78 print_info_([[NSPrintInfo sharedPrintInfo] copy]),
78 context_(NULL) { 79 context_(NULL) {
79 } 80 }
80 81
81 PrintingContextMac::~PrintingContextMac() { 82 PrintingContextMac::~PrintingContextMac() {
82 ReleaseContext(); 83 ReleaseContext();
83 } 84 }
84 85
85 void PrintingContextMac::AskUserForSettings( 86 void PrintingContextMac::AskUserForSettings(
86 gfx::NativeView parent_view,
87 int max_pages, 87 int max_pages,
88 bool has_selection, 88 bool has_selection,
89 const PrintSettingsCallback& callback) { 89 const PrintSettingsCallback& callback) {
90 // Third-party print drivers seem to be an area prone to raising exceptions. 90 // 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 91 // This will allow exceptions to be raised, but does not handle them. The
92 // NSPrintPanel appears to have appropriate NSException handlers. 92 // NSPrintPanel appears to have appropriate NSException handlers.
93 base::mac::ScopedNSExceptionEnabler enabler; 93 base::mac::ScopedNSExceptionEnabler enabler;
94 94
95 // Exceptions can also happen when the NSPrintPanel is being 95 // Exceptions can also happen when the NSPrintPanel is being
96 // deallocated, so it must be autoreleased within this scope. 96 // deallocated, so it must be autoreleased within this scope.
(...skipping 11 matching lines...) Expand all
108 NSPrintPanel* panel = [NSPrintPanel printPanel]; 108 NSPrintPanel* panel = [NSPrintPanel printPanel];
109 NSPrintInfo* printInfo = print_info_.get(); 109 NSPrintInfo* printInfo = print_info_.get();
110 110
111 NSPrintPanelOptions options = [panel options]; 111 NSPrintPanelOptions options = [panel options];
112 options |= NSPrintPanelShowsPaperSize; 112 options |= NSPrintPanelShowsPaperSize;
113 options |= NSPrintPanelShowsOrientation; 113 options |= NSPrintPanelShowsOrientation;
114 options |= NSPrintPanelShowsScaling; 114 options |= NSPrintPanelShowsScaling;
115 [panel setOptions:options]; 115 [panel setOptions:options];
116 116
117 // Set the print job title text. 117 // Set the print job title text.
118 gfx::NativeView parent_view = delegate_->GetParentView();
118 if (parent_view) { 119 if (parent_view) {
119 NSString* job_title = [[parent_view window] title]; 120 NSString* job_title = [[parent_view window] title];
120 if (job_title) { 121 if (job_title) {
121 PMPrintSettings printSettings = 122 PMPrintSettings printSettings =
122 (PMPrintSettings)[printInfo PMPrintSettings]; 123 (PMPrintSettings)[printInfo PMPrintSettings];
123 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title); 124 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title);
124 [printInfo updateFromPMPrintSettings]; 125 [printInfo updateFromPMPrintSettings];
125 } 126 }
126 } 127 }
127 128
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 void PrintingContextMac::ReleaseContext() { 517 void PrintingContextMac::ReleaseContext() {
517 print_info_.reset(); 518 print_info_.reset();
518 context_ = NULL; 519 context_ = NULL;
519 } 520 }
520 521
521 gfx::NativeDrawingContext PrintingContextMac::context() const { 522 gfx::NativeDrawingContext PrintingContextMac::context() const {
522 return context_; 523 return context_;
523 } 524 }
524 525
525 } // namespace printing 526 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698