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

Side by Side Diff: printing/printing_context_mac.mm

Issue 46623002: Move settings setup for PDF and cloud print into single location in PrintingContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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>
11 #import <numeric> 11 #import <numeric>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/mac/scoped_cftyperef.h" 14 #include "base/mac/scoped_cftyperef.h"
15 #include "base/mac/scoped_nsautorelease_pool.h" 15 #include "base/mac/scoped_nsautorelease_pool.h"
16 #include "base/mac/scoped_nsexception_enabler.h" 16 #include "base/mac/scoped_nsexception_enabler.h"
17 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "printing/print_settings_initializer_mac.h" 20 #include "printing/print_settings_initializer_mac.h"
21 #include "printing/units.h"
21 22
22 namespace printing { 23 namespace printing {
23 24
24 namespace { 25 namespace {
25 26
26 // Return true if PPD name of paper is equal. 27 // Return true if PPD name of paper is equal.
27 bool IsPaperNameEqual(const PMPaper& paper1, const PMPaper& paper2) { 28 bool IsPaperNameEqual(const PMPaper& paper1, const PMPaper& paper2) {
28 CFStringRef name1 = NULL; 29 CFStringRef name1 = NULL;
29 CFStringRef name2 = NULL; 30 CFStringRef name2 = NULL;
30 return (PMPaperGetPPDPaperName(paper1, &name1) == noErr) && 31 return (PMPaperGetPPDPaperName(paper1, &name1) == noErr) &&
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (selection == NSOKButton) { 100 if (selection == NSOKButton) {
100 print_info_.reset([[panel printInfo] retain]); 101 print_info_.reset([[panel printInfo] retain]);
101 settings_.set_ranges(GetPageRangesFromPrintInfo()); 102 settings_.set_ranges(GetPageRangesFromPrintInfo());
102 InitPrintSettingsFromPrintInfo(); 103 InitPrintSettingsFromPrintInfo();
103 callback.Run(OK); 104 callback.Run(OK);
104 } else { 105 } else {
105 callback.Run(CANCEL); 106 callback.Run(CANCEL);
106 } 107 }
107 } 108 }
108 109
110 gfx::Size PrintingContextMac::GetPdfPaperSizeDeviceUnits() {
111 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start
112 // with a clean slate.
113 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]);
114 UpdatePageFormatWithPaperInfo();
115
116 PMPageFormat page_format =
117 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]);
118 PMRect paper_rect;
119 PMGetAdjustedPaperRect(page_format, &paper_rect);
120
121 // Device units are in points. Units per inch is 72.
122 gfx::Size physical_size_device_units(
123 (paper_rect.right - paper_rect.left),
124 (paper_rect.bottom - paper_rect.top));
125 DCHECK(settings_.device_units_per_inch() == kPointsPerInch);
Lei Zhang 2013/11/01 18:27:13 nit: DCHECK_EQ
Vitaly Buka (NO REVIEWS) 2013/11/01 19:46:29 Done.
126 return physical_size_device_units;
127 }
128
109 PrintingContext::Result PrintingContextMac::UseDefaultSettings() { 129 PrintingContext::Result PrintingContextMac::UseDefaultSettings() {
110 DCHECK(!in_print_job_); 130 DCHECK(!in_print_job_);
111 131
112 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); 132 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]);
113 settings_.set_ranges(GetPageRangesFromPrintInfo()); 133 settings_.set_ranges(GetPageRangesFromPrintInfo());
114 InitPrintSettingsFromPrintInfo(); 134 InitPrintSettingsFromPrintInfo();
115 135
116 return OK; 136 return OK;
117 } 137 }
118 138
119 PrintingContext::Result PrintingContextMac::UpdatePrinterSettings( 139 PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
120 bool target_is_pdf,
121 bool external_preview) { 140 bool external_preview) {
122 DCHECK(!in_print_job_); 141 DCHECK(!in_print_job_);
123 142
124 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start 143 // NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start
125 // with a clean slate. 144 // with a clean slate.
126 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); 145 print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]);
127 146
128 if (!target_is_pdf) { 147 if (external_preview) {
148 if (!SetPrintPreviewJob())
149 return OnError();
150 } else {
151 // Don't need this for preview.
129 if (!SetPrinter(UTF16ToUTF8(settings_.device_name())) || 152 if (!SetPrinter(UTF16ToUTF8(settings_.device_name())) ||
130 !SetCopiesInPrintSettings(settings_.copies()) || 153 !SetCopiesInPrintSettings(settings_.copies()) ||
131 !SetCollateInPrintSettings(settings_.collate()) || 154 !SetCollateInPrintSettings(settings_.collate()) ||
132 !SetDuplexModeInPrintSettings(settings_.duplex_mode()) || 155 !SetDuplexModeInPrintSettings(settings_.duplex_mode()) ||
133 !SetOutputColor(settings_.color())) { 156 !SetOutputColor(settings_.color())) {
134 return OnError(); 157 return OnError();
135 } 158 }
136 } 159 }
137 160
138 if ((external_preview && !SetPrintPreviewJob()) || 161 if (!UpdatePageFormatWithPaperInfo() ||
139 !UpdatePageFormatWithPaperInfo() ||
140 !SetOrientationIsLandscape(settings_.landscape())) { 162 !SetOrientationIsLandscape(settings_.landscape())) {
141 return OnError(); 163 return OnError();
142 } 164 }
143 165
144 [print_info_.get() updateFromPMPrintSettings]; 166 [print_info_.get() updateFromPMPrintSettings];
145 167
146 InitPrintSettingsFromPrintInfo(); 168 InitPrintSettingsFromPrintInfo();
147 return OK; 169 return OK;
148 } 170 }
149 171
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 void PrintingContextMac::ReleaseContext() { 500 void PrintingContextMac::ReleaseContext() {
479 print_info_.reset(); 501 print_info_.reset();
480 context_ = NULL; 502 context_ = NULL;
481 } 503 }
482 504
483 gfx::NativeDrawingContext PrintingContextMac::context() const { 505 gfx::NativeDrawingContext PrintingContextMac::context() const {
484 return context_; 506 return context_;
485 } 507 }
486 508
487 } // namespace printing 509 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698