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

Side by Side Diff: printing/printing_context_mac.mm

Issue 6775013: PrintPreview: While printing the preview data, set the initiator tab title as print job name. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated the CL. Created 9 years, 8 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 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 NSPrintPanel* panel = [NSPrintPanel printPanel]; 46 NSPrintPanel* panel = [NSPrintPanel printPanel];
47 NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo]; 47 NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo];
48 48
49 NSPrintPanelOptions options = [panel options]; 49 NSPrintPanelOptions options = [panel options];
50 options |= NSPrintPanelShowsPaperSize; 50 options |= NSPrintPanelShowsPaperSize;
51 options |= NSPrintPanelShowsOrientation; 51 options |= NSPrintPanelShowsOrientation;
52 options |= NSPrintPanelShowsScaling; 52 options |= NSPrintPanelShowsScaling;
53 [panel setOptions:options]; 53 [panel setOptions:options];
54 54
55 // Set the print job title text. 55 // Set the print job title text.
56 if (parent_view) { 56 if (parent_view)
57 NSString* job_title = [[parent_view window] title]; 57 UpdatePrintInfoWithJobName(printInfo, [[parent_view window] title]);
58 if (job_title) {
59 PMPrintSettings printSettings =
60 (PMPrintSettings)[printInfo PMPrintSettings];
61 PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title);
62 [printInfo updateFromPMPrintSettings];
63 }
64 }
65 58
66 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window. 59 // TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
67 // Will require restructuring the PrintingContext API to use a callback. 60 // Will require restructuring the PrintingContext API to use a callback.
68 NSInteger selection = [panel runModalWithPrintInfo:printInfo]; 61 NSInteger selection = [panel runModalWithPrintInfo:printInfo];
69 if (selection == NSOKButton) { 62 if (selection == NSOKButton) {
70 ParsePrintInfo([panel printInfo]); 63 ParsePrintInfo([panel printInfo]);
71 callback->Run(OK); 64 callback->Run(OK);
72 } else { 65 } else {
73 callback->Run(CANCEL); 66 callback->Run(CANCEL);
74 } 67 }
(...skipping 22 matching lines...) Expand all
97 return OnError(); 90 return OnError();
98 settings_.SetOrientation(landscape); 91 settings_.SetOrientation(landscape);
99 92
100 std::string printer_name; 93 std::string printer_name;
101 if (!job_settings.GetString(kSettingPrinterName, &printer_name)) 94 if (!job_settings.GetString(kSettingPrinterName, &printer_name))
102 return OnError(); 95 return OnError();
103 96
104 if (!SetPrinter(printer_name)) 97 if (!SetPrinter(printer_name))
105 return OnError(); 98 return OnError();
106 99
100 string16 job_name;
101 if (!job_settings.GetString(kSettingPrintJobTitle, &job_name))
102 return OnError();
stuartmorgan 2011/03/30 22:59:17 It's not clear to me that not having/setting a job
103
104 if (!SetPrintJobName(job_name))
105 return OnError();
106
107 InitPrintSettingsFromPrintInfo(ranges); 107 InitPrintSettingsFromPrintInfo(ranges);
108 return OK; 108 return OK;
109 } 109 }
110 110
111 void PrintingContextMac::InitPrintSettingsFromPrintInfo( 111 void PrintingContextMac::InitPrintSettingsFromPrintInfo(
112 const PageRanges& ranges) { 112 const PageRanges& ranges) {
113 PMPrintSession print_session = 113 PMPrintSession print_session =
114 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); 114 static_cast<PMPrintSession>([print_info_.get() PMPrintSession]);
115 PMPageFormat page_format = 115 PMPageFormat page_format =
116 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); 116 static_cast<PMPageFormat>([print_info_.get() PMPageFormat]);
(...skipping 11 matching lines...) Expand all
128 if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) { 128 if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) {
129 NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name]; 129 NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name];
130 if (new_printer == nil) 130 if (new_printer == nil)
131 return false; 131 return false;
132 132
133 [print_info_.get() setPrinter:new_printer]; 133 [print_info_.get() setPrinter:new_printer];
134 } 134 }
135 return true; 135 return true;
136 } 136 }
137 137
138 bool PrintingContextMac::SetPrintJobName(const string16& job_name) {
139 NSString* print_job_name = base::SysUTF16ToNSString(job_name);
stuartmorgan 2011/03/30 22:59:17 Indentation is wrong here.
140 if (!print_job_name)
141 return false;
142 UpdatePrintInfoWithJobName(print_info_.get(), print_job_name);
143 return true;
144 }
145
146 void PrintingContextMac::UpdatePrintInfoWithJobName(
147 NSPrintInfo* printInfo, NSString* job_name) {
148 if (job_name) {
stuartmorgan 2011/03/30 22:59:17 Change to if (!job_name) return; so the core
149 PMPrintSettings settings = (PMPrintSettings)[printInfo PMPrintSettings];
150 PMPrintSettingsSetJobName(settings, (CFStringRef)job_name);
151 [printInfo updateFromPMPrintSettings];
152 }
153 }
154
138 void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { 155 void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) {
139 ResetSettings(); 156 ResetSettings();
140 print_info_.reset([print_info retain]); 157 print_info_.reset([print_info retain]);
141 PageRanges page_ranges; 158 PageRanges page_ranges;
142 NSDictionary* print_info_dict = [print_info_.get() dictionary]; 159 NSDictionary* print_info_dict = [print_info_.get() dictionary];
143 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { 160 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) {
144 PageRange range; 161 PageRange range;
145 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1; 162 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1;
146 range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; 163 range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1;
147 page_ranges.push_back(range); 164 page_ranges.push_back(range);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void PrintingContextMac::ReleaseContext() { 268 void PrintingContextMac::ReleaseContext() {
252 print_info_.reset(); 269 print_info_.reset();
253 context_ = NULL; 270 context_ = NULL;
254 } 271 }
255 272
256 gfx::NativeDrawingContext PrintingContextMac::context() const { 273 gfx::NativeDrawingContext PrintingContextMac::context() const {
257 return context_; 274 return context_;
258 } 275 }
259 276
260 } // namespace printing 277 } // namespace printing
OLDNEW
« printing/printing_context_mac.h ('K') | « printing/printing_context_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698