OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * An interface to the native Chromium printing system layer. | 9 * An interface to the native Chromium printing system layer. |
10 * @constructor | 10 * @constructor |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 /** | 266 /** |
267 * Requests that the document be printed. | 267 * Requests that the document be printed. |
268 * @param {!print_preview.Destination} destination Destination to print to. | 268 * @param {!print_preview.Destination} destination Destination to print to. |
269 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 269 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
270 * state of the print ticket. | 270 * state of the print ticket. |
271 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface | 271 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface |
272 * to Google Cloud Print. | 272 * to Google Cloud Print. |
273 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 273 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
274 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the | 274 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the |
275 * system's preview application. | 275 * system's preview application. |
| 276 * @param {boolean=} opt_showSystemDialog Whether to open system dialog for |
| 277 * advanced settings. |
276 */ | 278 */ |
277 startPrint: function(destination, printTicketStore, cloudPrintInterface, | 279 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
278 documentInfo, opt_isOpenPdfInPreview) { | 280 documentInfo, opt_isOpenPdfInPreview, |
| 281 opt_showSystemDialog) { |
279 assert(printTicketStore.isTicketValid(), | 282 assert(printTicketStore.isTicketValid(), |
280 'Trying to print when ticket is not valid'); | 283 'Trying to print when ticket is not valid'); |
281 | 284 |
| 285 assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal), |
| 286 'Implemented for Windows only'); |
| 287 |
282 var ticket = { | 288 var ticket = { |
283 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 289 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
284 'mediaSize': printTicketStore.mediaSize.getValue(), | 290 'mediaSize': printTicketStore.mediaSize.getValue(), |
285 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, | 291 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, |
286 'landscape': printTicketStore.landscape.getValue(), | 292 'landscape': printTicketStore.landscape.getValue(), |
287 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 293 'color': this.getNativeColorModel_(destination, printTicketStore.color), |
288 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 294 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
289 'marginsType': printTicketStore.marginsType.getValue(), | 295 'marginsType': printTicketStore.marginsType.getValue(), |
290 'generateDraftData': true, // TODO(rltoscano): What should this be? | 296 'generateDraftData': true, // TODO(rltoscano): What should this be? |
291 'duplex': printTicketStore.duplex.getValue() ? | 297 'duplex': printTicketStore.duplex.getValue() ? |
292 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | 298 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
293 'copies': printTicketStore.copies.getValueAsNumber(), | 299 'copies': printTicketStore.copies.getValueAsNumber(), |
294 'collate': printTicketStore.collate.getValue(), | 300 'collate': printTicketStore.collate.getValue(), |
295 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), | 301 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), |
296 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), | 302 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), |
297 'previewModifiable': documentInfo.isModifiable, | 303 'previewModifiable': documentInfo.isModifiable, |
298 'printToPDF': destination.id == | 304 'printToPDF': destination.id == |
299 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 305 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
300 'printWithCloudPrint': !destination.isLocal, | 306 'printWithCloudPrint': !destination.isLocal, |
301 'printWithPrivet': destination.isPrivet, | 307 'printWithPrivet': destination.isPrivet, |
302 'deviceName': destination.id, | 308 'deviceName': destination.id, |
303 'isFirstRequest': false, | 309 'isFirstRequest': false, |
304 'requestID': -1, | 310 'requestID': -1, |
305 'fitToPageEnabled': printTicketStore.fitToPage.getValue(), | 311 'fitToPageEnabled': printTicketStore.fitToPage.getValue(), |
306 'pageWidth': documentInfo.pageSize.width, | 312 'pageWidth': documentInfo.pageSize.width, |
307 'pageHeight': documentInfo.pageSize.height | 313 'pageHeight': documentInfo.pageSize.height, |
| 314 'showSystemDialog': opt_showSystemDialog |
308 }; | 315 }; |
309 | 316 |
310 if (!destination.isLocal) { | 317 if (!destination.isLocal) { |
311 // We can't set cloudPrintID if the destination is "Print with Cloud | 318 // We can't set cloudPrintID if the destination is "Print with Cloud |
312 // Print" because the native system will try to print to Google Cloud | 319 // Print" because the native system will try to print to Google Cloud |
313 // Print with this ID instead of opening a Google Cloud Print dialog. | 320 // Print with this ID instead of opening a Google Cloud Print dialog. |
314 ticket['cloudPrintID'] = destination.id; | 321 ticket['cloudPrintID'] = destination.id; |
315 } | 322 } |
316 | 323 |
317 if (printTicketStore.marginsType.isCapabilityAvailable() && | 324 if (printTicketStore.marginsType.isCapabilityAvailable() && |
(...skipping 22 matching lines...) Expand all Loading... |
340 chrome.send('print', [JSON.stringify(ticket)]); | 347 chrome.send('print', [JSON.stringify(ticket)]); |
341 }, | 348 }, |
342 | 349 |
343 /** Requests that the current pending print request be cancelled. */ | 350 /** Requests that the current pending print request be cancelled. */ |
344 startCancelPendingPrint: function() { | 351 startCancelPendingPrint: function() { |
345 chrome.send('cancelPendingPrintRequest'); | 352 chrome.send('cancelPendingPrintRequest'); |
346 }, | 353 }, |
347 | 354 |
348 /** Shows the system's native printing dialog. */ | 355 /** Shows the system's native printing dialog. */ |
349 startShowSystemDialog: function() { | 356 startShowSystemDialog: function() { |
| 357 assert(!cr.isWindows); |
350 chrome.send('showSystemDialog'); | 358 chrome.send('showSystemDialog'); |
351 }, | 359 }, |
352 | 360 |
353 /** Shows Google Cloud Print's web-based print dialog. | 361 /** Shows Google Cloud Print's web-based print dialog. |
354 * @param {number} pageCount Number of pages to print. | 362 * @param {number} pageCount Number of pages to print. |
355 */ | 363 */ |
356 startShowCloudPrintDialog: function(pageCount) { | 364 startShowCloudPrintDialog: function(pageCount) { |
357 chrome.send('printWithCloudPrintDialog', [pageCount]); | 365 chrome.send('printWithCloudPrintDialog', [pageCount]); |
358 }, | 366 }, |
359 | 367 |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 return this.serializedAppStateStr_; | 941 return this.serializedAppStateStr_; |
934 } | 942 } |
935 }; | 943 }; |
936 | 944 |
937 // Export | 945 // Export |
938 return { | 946 return { |
939 NativeInitialSettings: NativeInitialSettings, | 947 NativeInitialSettings: NativeInitialSettings, |
940 NativeLayer: NativeLayer | 948 NativeLayer: NativeLayer |
941 }; | 949 }; |
942 }); | 950 }); |
OLD | NEW |