| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 /** | 161 /** |
| 162 * Requests the destination's printing capabilities. A CAPABILITIES_SET | 162 * Requests the destination's printing capabilities. A CAPABILITIES_SET |
| 163 * event will be dispatched in response. | 163 * event will be dispatched in response. |
| 164 * @param {string} destinationId ID of the destination. | 164 * @param {string} destinationId ID of the destination. |
| 165 */ | 165 */ |
| 166 startGetLocalDestinationCapabilities: function(destinationId) { | 166 startGetLocalDestinationCapabilities: function(destinationId) { |
| 167 chrome.send('getPrinterCapabilities', [destinationId]); | 167 chrome.send('getPrinterCapabilities', [destinationId]); |
| 168 }, | 168 }, |
| 169 | 169 |
| 170 /** | 170 /** |
| 171 * @param {!print_preview.Destination} destination Destination to print to. | |
| 172 * @param {!print_preview.ticket_items.Color} color Color ticket item. | |
| 173 * @return {number} Native layer color model. | |
| 174 * @private | |
| 175 */ | |
| 176 getNativeColorModel_: function(destination, color) { | |
| 177 // For non-local printers native color model is ignored anyway. | |
| 178 var option = destination.isLocal ? color.getSelectedOption() : null; | |
| 179 var nativeColorModel = parseInt(option ? option.vendor_id : null); | |
| 180 if (isNaN(nativeColorModel)) { | |
| 181 return color.getValue() ? | |
| 182 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY; | |
| 183 } | |
| 184 return nativeColorModel; | |
| 185 }, | |
| 186 | |
| 187 /** | |
| 188 * Requests that a preview be generated. The following events may be | 171 * Requests that a preview be generated. The following events may be |
| 189 * dispatched in response: | 172 * dispatched in response: |
| 190 * - PAGE_COUNT_READY | 173 * - PAGE_COUNT_READY |
| 191 * - PAGE_LAYOUT_READY | 174 * - PAGE_LAYOUT_READY |
| 192 * - PAGE_PREVIEW_READY | 175 * - PAGE_PREVIEW_READY |
| 193 * - PREVIEW_GENERATION_DONE | 176 * - PREVIEW_GENERATION_DONE |
| 194 * - PREVIEW_GENERATION_FAIL | 177 * - PREVIEW_GENERATION_FAIL |
| 195 * @param {print_preview.Destination} destination Destination to print to. | 178 * @param {print_preview.Destination} destination Destination to print to. |
| 196 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 179 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 197 * state of the print ticket. | 180 * state of the print ticket. |
| 198 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 181 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| 199 * @param {number} ID of the preview request. | 182 * @param {number} ID of the preview request. |
| 200 */ | 183 */ |
| 201 startGetPreview: function( | 184 startGetPreview: function( |
| 202 destination, printTicketStore, documentInfo, requestId) { | 185 destination, printTicketStore, documentInfo, requestId) { |
| 203 assert(printTicketStore.isTicketValidForPreview(), | 186 assert(printTicketStore.isTicketValidForPreview(), |
| 204 'Trying to generate preview when ticket is not valid'); | 187 'Trying to generate preview when ticket is not valid'); |
| 205 | 188 |
| 206 var ticket = { | 189 var ticket = { |
| 207 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 190 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
| 208 'mediaSize': printTicketStore.mediaSize.getValue(), | 191 'mediaSize': printTicketStore.mediaSize.getValue(), |
| 209 'landscape': printTicketStore.landscape.getValue(), | 192 'landscape': printTicketStore.landscape.getValue(), |
| 210 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 193 'color': printTicketStore.color.getValue() ? |
| 194 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, |
| 211 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 195 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
| 212 'marginsType': printTicketStore.marginsType.getValue(), | 196 'marginsType': printTicketStore.marginsType.getValue(), |
| 213 'isFirstRequest': requestId == 0, | 197 'isFirstRequest': requestId == 0, |
| 214 'requestID': requestId, | 198 'requestID': requestId, |
| 215 'previewModifiable': documentInfo.isModifiable, | 199 'previewModifiable': documentInfo.isModifiable, |
| 216 'printToPDF': | 200 'printToPDF': |
| 217 destination != null && | 201 destination != null && |
| 218 destination.id == | 202 destination.id == |
| 219 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 203 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 220 'printWithCloudPrint': destination != null && !destination.isLocal, | 204 'printWithCloudPrint': destination != null && !destination.isLocal, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 */ | 256 */ |
| 273 startPrint: function(destination, printTicketStore, cloudPrintInterface, | 257 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
| 274 documentInfo, opt_isOpenPdfInPreview) { | 258 documentInfo, opt_isOpenPdfInPreview) { |
| 275 assert(printTicketStore.isTicketValid(), | 259 assert(printTicketStore.isTicketValid(), |
| 276 'Trying to print when ticket is not valid'); | 260 'Trying to print when ticket is not valid'); |
| 277 | 261 |
| 278 var ticket = { | 262 var ticket = { |
| 279 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 263 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
| 280 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, | 264 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, |
| 281 'landscape': printTicketStore.landscape.getValue(), | 265 'landscape': printTicketStore.landscape.getValue(), |
| 282 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 266 'color': printTicketStore.color.getValue() ? |
| 267 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, |
| 283 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 268 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
| 284 'marginsType': printTicketStore.marginsType.getValue(), | 269 'marginsType': printTicketStore.marginsType.getValue(), |
| 285 'generateDraftData': true, // TODO(rltoscano): What should this be? | 270 'generateDraftData': true, // TODO(rltoscano): What should this be? |
| 286 'duplex': printTicketStore.duplex.getValue() ? | 271 'duplex': printTicketStore.duplex.getValue() ? |
| 287 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | 272 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
| 288 'copies': printTicketStore.copies.getValueAsNumber(), | 273 'copies': printTicketStore.copies.getValueAsNumber(), |
| 289 'collate': printTicketStore.collate.getValue(), | 274 'collate': printTicketStore.collate.getValue(), |
| 290 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), | 275 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), |
| 291 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), | 276 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), |
| 292 'previewModifiable': documentInfo.isModifiable, | 277 'previewModifiable': documentInfo.isModifiable, |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 return this.serializedAppStateStr_; | 850 return this.serializedAppStateStr_; |
| 866 } | 851 } |
| 867 }; | 852 }; |
| 868 | 853 |
| 869 // Export | 854 // Export |
| 870 return { | 855 return { |
| 871 NativeInitialSettings: NativeInitialSettings, | 856 NativeInitialSettings: NativeInitialSettings, |
| 872 NativeLayer: NativeLayer | 857 NativeLayer: NativeLayer |
| 873 }; | 858 }; |
| 874 }); | 859 }); |
| OLD | NEW |