OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * An interface to the native Chromium printing system layer. |
| 10 * @constructor |
| 11 * @extends {cr.EventTarget} |
| 12 */ |
| 13 function NativeLayer() { |
| 14 cr.EventTarget.call(this); |
| 15 |
| 16 // Bind global handlers |
| 17 global['setInitialSettings'] = this.onSetInitialSettings_.bind(this); |
| 18 global['setUseCloudPrint'] = this.onSetUseCloudPrint_.bind(this); |
| 19 global['setPrinters'] = this.onSetPrinters_.bind(this); |
| 20 global['updateWithPrinterCapabilities'] = |
| 21 this.onUpdateWithPrinterCapabilities_.bind(this); |
| 22 global['reloadPrintersList'] = this.onReloadPrintersList_.bind(this); |
| 23 global['printToCloud'] = this.onPrintToCloud_.bind(this); |
| 24 global['fileSelectionCancelled'] = |
| 25 this.onFileSelectionCancelled_.bind(this); |
| 26 global['fileSelectionCompleted'] = |
| 27 this.onFileSelectionCompleted_.bind(this); |
| 28 global['printPreviewFailed'] = this.onPrintPreviewFailed_.bind(this); |
| 29 global['invalidPrinterSettings'] = |
| 30 this.onInvalidPrinterSettings_.bind(this); |
| 31 global['onDidGetDefaultPageLayout'] = |
| 32 this.onDidGetDefaultPageLayout_.bind(this); |
| 33 global['onDidGetPreviewPageCount'] = |
| 34 this.onDidGetPreviewPageCount_.bind(this); |
| 35 global['reloadPreviewPages'] = this.onReloadPreviewPages_.bind(this); |
| 36 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); |
| 37 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); |
| 38 global['printScalingDisabledForSourcePDF'] = |
| 39 this.onPrintScalingDisabledForSourcePDF_.bind(this); |
| 40 }; |
| 41 |
| 42 /** |
| 43 * Event types dispatched from the Chromium native layer. |
| 44 * @enum {string} |
| 45 * @const |
| 46 */ |
| 47 NativeLayer.EventType = { |
| 48 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
| 49 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
| 50 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
| 51 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
| 52 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
| 53 FILE_SELECTION_COMPLETE: |
| 54 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
| 55 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', |
| 56 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', |
| 57 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
| 58 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
| 59 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
| 60 PREVIEW_GENERATION_DONE: |
| 61 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
| 62 PREVIEW_GENERATION_FAIL: |
| 63 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
| 64 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD', |
| 65 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
| 66 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID' |
| 67 }; |
| 68 |
| 69 /** |
| 70 * Constant values matching printing::DuplexMode enum. |
| 71 * @enum {number} |
| 72 */ |
| 73 NativeLayer.DuplexMode = { |
| 74 SIMPLEX: 0, |
| 75 LONG_EDGE: 1, |
| 76 UNKNOWN_DUPLEX_MODE: -1 |
| 77 }; |
| 78 |
| 79 /** |
| 80 * Enumeration of color modes used by Chromium. |
| 81 * @enum {number} |
| 82 * @private |
| 83 */ |
| 84 NativeLayer.ColorMode_ = { |
| 85 GRAY: 1, |
| 86 COLOR: 2 |
| 87 }; |
| 88 |
| 89 NativeLayer.prototype = { |
| 90 __proto__: cr.EventTarget.prototype, |
| 91 |
| 92 /** Gets the initial settings to initialize the print preview with. */ |
| 93 startGetInitialSettings: function() { |
| 94 chrome.send('getInitialSettings'); |
| 95 }, |
| 96 |
| 97 /** |
| 98 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET |
| 99 * event will be dispatched in response. |
| 100 */ |
| 101 startGetLocalDestinations: function() { |
| 102 chrome.send('getPrinters'); |
| 103 }, |
| 104 |
| 105 /** |
| 106 * Requests the destination's printing capabilities. A CAPABILITIES_SET |
| 107 * event will be dispatched in response. |
| 108 * @param {string} destinationId ID of the destination. |
| 109 */ |
| 110 startGetLocalDestinationCapabilities: function(destinationId) { |
| 111 chrome.send('getPrinterCapabilities', [destinationId]); |
| 112 }, |
| 113 |
| 114 /** |
| 115 * Requests that a preview be generated. The following events may be |
| 116 * dispatched in response: |
| 117 * - PAGE_COUNT_READY |
| 118 * - PAGE_LAYOUT_READY |
| 119 * - PAGE_PREVIEW_READY |
| 120 * - PREVIEW_GENERATION_DONE |
| 121 * - PREVIEW_GENERATION_FAIL |
| 122 * - PREVIEW_RELOAD |
| 123 * @param {print_preview.Destination} destination Destination to print to. |
| 124 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 125 * state of the print ticket. |
| 126 * @param {number} ID of the preview request. |
| 127 */ |
| 128 startGetPreview: function(destination, printTicketStore, requestId) { |
| 129 assert(printTicketStore.isTicketValidForPreview(), |
| 130 'Trying to generate preview when ticket is not valid'); |
| 131 |
| 132 var pageRanges = []; |
| 133 if (requestId > 0 && |
| 134 !printTicketStore.isDocumentModifiable && |
| 135 printTicketStore.hasPageRangeCapability()) { |
| 136 pageRanges = printTicketStore.getPageNumberSet().getPageRanges(); |
| 137 } |
| 138 |
| 139 var ticket = { |
| 140 'pageRange': pageRanges, // pageRanges, |
| 141 'landscape': printTicketStore.isLandscapeEnabled(), |
| 142 'color': printTicketStore.isColorEnabled() ? |
| 143 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, |
| 144 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(), |
| 145 'marginsType': printTicketStore.getMarginsType(), |
| 146 'isFirstRequest': requestId == 0, |
| 147 'requestID': requestId, |
| 148 'previewModifiable': printTicketStore.isDocumentModifiable, |
| 149 'printToPDF': |
| 150 destination != null && |
| 151 destination.id == |
| 152 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 153 'printWithCloudPrint': destination != null && !destination.isLocal, |
| 154 'deviceName': destination == null ? 'foo' : destination.id, |
| 155 'cloudPrintID': destination == null ? 'foo' : destination.id, |
| 156 'generateDraftData': printTicketStore.isDocumentModifiable, |
| 157 'fitToPageEnabled': printTicketStore.isFitToPageEnabled(), |
| 158 |
| 159 // NOTE: Even though the following fields don't directly relate to the |
| 160 // preview, they still need to be included. |
| 161 'duplex': printTicketStore.isDuplexEnabled() ? |
| 162 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
| 163 'copies': printTicketStore.getCopies(), |
| 164 'collate': printTicketStore.isCollateEnabled() |
| 165 }; |
| 166 |
| 167 if (printTicketStore.hasMarginsCapability() && |
| 168 printTicketStore.getMarginsType() == |
| 169 print_preview.ticket_items.MarginsType.Value.CUSTOM) { |
| 170 var customMargins = printTicketStore.getCustomMargins(); |
| 171 var orientationEnum = |
| 172 print_preview.ticket_items.CustomMargins.Orientation; |
| 173 ticket['marginsCustom'] = { |
| 174 'marginTop': customMargins.get(orientationEnum.TOP), |
| 175 'marginRight': customMargins.get(orientationEnum.RIGHT), |
| 176 'marginBottom': customMargins.get(orientationEnum.BOTTOM), |
| 177 'marginLeft': customMargins.get(orientationEnum.LEFT) |
| 178 }; |
| 179 } |
| 180 |
| 181 chrome.send( |
| 182 'getPreview', |
| 183 [JSON.stringify(ticket), -1, printTicketStore.isDocumentModifiable]); |
| 184 }, |
| 185 |
| 186 /** |
| 187 * Persists the selected destination and print ticket for the next print |
| 188 * session. |
| 189 * @param {!print_preview.Destination} destination Destination to save. |
| 190 * @param {!print_preview.PrintTicketStore} printTicketStore Used for |
| 191 * generating the serialized print ticket to persist. |
| 192 */ |
| 193 startSaveDestinationAndTicket: function(destination, printTicketStore) { |
| 194 chrome.send('saveLastPrinter', [destination.id, '' /*TODO(rltoscano)*/]); |
| 195 }, |
| 196 |
| 197 /** |
| 198 * Requests that the document be printed. |
| 199 * @param {!print_preview.Destination} destination Destination to print to. |
| 200 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 201 * state of the print ticket. |
| 202 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface |
| 203 * to Google Cloud Print. |
| 204 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the |
| 205 * system's preview application. |
| 206 */ |
| 207 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
| 208 opt_isOpenPdfInPreview) { |
| 209 assert(printTicketStore.isTicketValid(), |
| 210 'Trying to print when ticket is not valid'); |
| 211 |
| 212 var ticket = { |
| 213 'pageRange': printTicketStore.hasPageRangeCapability() ? |
| 214 printTicketStore.getPageNumberSet().getPageRanges() : [], |
| 215 'landscape': printTicketStore.isLandscapeEnabled(), |
| 216 'color': printTicketStore.isColorEnabled() ? |
| 217 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, |
| 218 'headerFooterEnabled': printTicketStore.isHeaderFooterEnabled(), |
| 219 'marginsType': printTicketStore.getMarginsType(), |
| 220 'generateDraftData': true, // TODO(rltoscano): What should this be? |
| 221 'duplex': printTicketStore.isDuplexEnabled() ? |
| 222 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
| 223 'copies': printTicketStore.getCopies(), |
| 224 'collate': printTicketStore.isCollateEnabled(), |
| 225 'previewModifiable': printTicketStore.isDocumentModifiable, |
| 226 'printToPDF': destination.id == |
| 227 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 228 'printWithCloudPrint': !destination.isLocal, |
| 229 'deviceName': destination.id, |
| 230 'isFirstRequest': false, |
| 231 'requestID': -1, |
| 232 'fitToPageEnabled': printTicketStore.isFitToPageEnabled() |
| 233 }; |
| 234 |
| 235 if (!destination.isLocal && !destination.isPrintWithCloudPrint) { |
| 236 // We can't set cloudPrintID if the destination is "Print with Cloud |
| 237 // Print" because the native system will try to print to Google Cloud |
| 238 // Print with this ID instead of opening a Google Cloud Print dialog. |
| 239 ticket['cloudPrintID'] = destination.id; |
| 240 } |
| 241 |
| 242 if (printTicketStore.hasMarginsCapability() && |
| 243 printTicketStore.getMarginsType() == |
| 244 print_preview.ticket_items.MarginsType.Value.CUSTOM) { |
| 245 var customMargins = printTicketStore.getCustomMargins(); |
| 246 var orientationEnum = |
| 247 print_preview.ticket_items.CustomMargins.Orientation; |
| 248 ticket['marginsCustom'] = { |
| 249 'marginTop': customMargins.get(orientationEnum.TOP), |
| 250 'marginRight': customMargins.get(orientationEnum.RIGHT), |
| 251 'marginBottom': customMargins.get(orientationEnum.BOTTOM), |
| 252 'marginLeft': customMargins.get(orientationEnum.LEFT) |
| 253 }; |
| 254 } |
| 255 |
| 256 if (opt_isOpenPdfInPreview) { |
| 257 ticket['OpenPDFInPreview'] = true; |
| 258 } |
| 259 |
| 260 var cloudTicket = null; |
| 261 if (!destination.isLocal) { |
| 262 assert(cloudPrintInterface != null, |
| 263 'Trying to print to a cloud destination but Google Cloud ' + |
| 264 'Print integration is disabled'); |
| 265 cloudTicket = cloudPrintInterface.createPrintTicket( |
| 266 destination, printTicketStore); |
| 267 cloudTicket = JSON.stringify(cloudTicket); |
| 268 } |
| 269 |
| 270 chrome.send('print', [JSON.stringify(ticket), cloudTicket]); |
| 271 }, |
| 272 |
| 273 /** Requests that the current pending print request be cancelled. */ |
| 274 startCancelPendingPrint: function() { |
| 275 chrome.send('cancelPendingPrintRequest'); |
| 276 }, |
| 277 |
| 278 /** Shows the system's native printing dialog. */ |
| 279 startShowSystemDialog: function() { |
| 280 chrome.send('showSystemDialog'); |
| 281 }, |
| 282 |
| 283 /** Closes the print preview dialog. */ |
| 284 startCloseDialog: function() { |
| 285 chrome.send('closePrintPreviewTab'); |
| 286 chrome.send('DialogClose'); |
| 287 }, |
| 288 |
| 289 /** Hide the print preview dialog and allow the native layer to close it. */ |
| 290 startHideDialog: function() { |
| 291 chrome.send('hidePreview'); |
| 292 }, |
| 293 |
| 294 /** |
| 295 * Opens the Google Cloud Print sign-in dialog. The DESTINATIONS_RELOAD |
| 296 * event will be dispatched in response. |
| 297 */ |
| 298 startCloudPrintSignIn: function() { |
| 299 chrome.send('signIn'); |
| 300 }, |
| 301 |
| 302 /** Navigates the user to the system printer settings interface. */ |
| 303 startManageLocalPrinters: function() { |
| 304 chrome.send('manageLocalPrinters'); |
| 305 }, |
| 306 |
| 307 /** Navigates the user to the Google Cloud Print management page. */ |
| 308 startManageCloudPrinters: function() { |
| 309 chrome.send('manageCloudPrinters'); |
| 310 }, |
| 311 |
| 312 /** |
| 313 * @param {object} initialSettings Object containing all initial settings. |
| 314 */ |
| 315 onSetInitialSettings_: function(initialSettings) { |
| 316 // TODO(rltoscano): Use initialSettings['cloudPrintData'] to prepopulate |
| 317 // destination and initial print ticket. |
| 318 var numberFormatSymbols = |
| 319 print_preview.MeasurementSystem.parseNumberFormat( |
| 320 initialSettings['numberFormat']); |
| 321 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; |
| 322 if (initialSettings['measurementSystem'] != null) { |
| 323 unitType = initialSettings['measurementSystem']; |
| 324 } |
| 325 var measurementSystem = new print_preview.MeasurementSystem( |
| 326 numberFormatSymbols[0], |
| 327 numberFormatSymbols[1], |
| 328 unitType); |
| 329 |
| 330 var customMargins = null; |
| 331 if (initialSettings.hasOwnProperty('marginTop') && |
| 332 initialSettings.hasOwnProperty('marginRight') && |
| 333 initialSettings.hasOwnProperty('marginBottom') && |
| 334 initialSettings.hasOwnProperty('marginLeft')) { |
| 335 customMargins = new print_preview.Margins( |
| 336 initialSettings['marginTop'] || 0, |
| 337 initialSettings['marginRight'] || 0, |
| 338 initialSettings['marginBottom'] || 0, |
| 339 initialSettings['marginLeft'] || 0); |
| 340 } |
| 341 |
| 342 var marginsType = null; |
| 343 if (initialSettings.hasOwnProperty('marginsType')) { |
| 344 marginsType = initialSettings['marginsType']; |
| 345 } |
| 346 |
| 347 var nativeInitialSettings = new print_preview.NativeInitialSettings( |
| 348 initialSettings['printAutomaticallyInKioskMode'] || false, |
| 349 numberFormatSymbols[0] || ',', |
| 350 numberFormatSymbols[1] || '.', |
| 351 unitType, |
| 352 initialSettings['previewModifiable'] || false, |
| 353 marginsType, |
| 354 customMargins, |
| 355 initialSettings['duplex'] || false, |
| 356 initialSettings['headerFooterEnabled'] || false, |
| 357 initialSettings['printerName'] || null); |
| 358 |
| 359 var initialSettingsSetEvent = new cr.Event( |
| 360 NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 361 initialSettingsSetEvent.initialSettings = nativeInitialSettings; |
| 362 this.dispatchEvent(initialSettingsSetEvent); |
| 363 }, |
| 364 |
| 365 /** |
| 366 * Turn on the integration of Cloud Print. |
| 367 * @param {string} cloudPrintURL The URL to use for cloud print servers. |
| 368 * @private |
| 369 */ |
| 370 onSetUseCloudPrint_: function(cloudPrintURL) { |
| 371 var cloudPrintEnableEvent = new cr.Event( |
| 372 NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 373 cloudPrintEnableEvent.baseCloudPrintUrl = cloudPrintURL; |
| 374 this.dispatchEvent(cloudPrintEnableEvent); |
| 375 }, |
| 376 |
| 377 /** |
| 378 * Updates the print preview with local printers. |
| 379 * Called from PrintPreviewHandler::SetupPrinterList(). |
| 380 * @param {Array} printers Array of printer info objects. |
| 381 * @private |
| 382 */ |
| 383 onSetPrinters_: function(printers) { |
| 384 var localDestsSetEvent = new cr.Event( |
| 385 NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
| 386 localDestsSetEvent.destinationInfos = printers; |
| 387 this.dispatchEvent(localDestsSetEvent); |
| 388 }, |
| 389 |
| 390 /** |
| 391 * Called when native layer gets settings information for a requested local |
| 392 * destination. |
| 393 * @param {Object} settingsInfo printer setting information. |
| 394 * @private |
| 395 */ |
| 396 onUpdateWithPrinterCapabilities_: function(settingsInfo) { |
| 397 var capsSetEvent = new cr.Event(NativeLayer.EventType.CAPABILITIES_SET); |
| 398 capsSetEvent.settingsInfo = settingsInfo; |
| 399 this.dispatchEvent(capsSetEvent); |
| 400 }, |
| 401 |
| 402 /** Reloads the printer list. */ |
| 403 onReloadPrintersList_: function() { |
| 404 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); |
| 405 }, |
| 406 |
| 407 /** |
| 408 * Called from the C++ layer. |
| 409 * Take the PDF data handed to us and submit it to the cloud, closing the |
| 410 * print preview tab once the upload is successful. |
| 411 * @param {string} data Data to send as the print job. |
| 412 * @private |
| 413 */ |
| 414 onPrintToCloud_: function(data) { |
| 415 var printToCloudEvent = new cr.Event( |
| 416 NativeLayer.EventType.PRINT_TO_CLOUD); |
| 417 printToCloudEvent.data = data; |
| 418 this.dispatchEvent(printToCloudEvent); |
| 419 }, |
| 420 |
| 421 /** |
| 422 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print |
| 423 * preview tab regarding the file selection cancel event. |
| 424 * @private |
| 425 */ |
| 426 onFileSelectionCancelled_: function() { |
| 427 cr.dispatchSimpleEvent(this, NativeLayer.EventType.FILE_SELECTION_CANCEL); |
| 428 }, |
| 429 |
| 430 /** |
| 431 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print |
| 432 * preview tab regarding the file selection completed event. |
| 433 * @private |
| 434 */ |
| 435 onFileSelectionCompleted_: function() { |
| 436 // If the file selection is completed and the tab is not already closed it |
| 437 // means that a pending print to pdf request exists. |
| 438 cr.dispatchSimpleEvent( |
| 439 this, NativeLayer.EventType.FILE_SELECTION_COMPLETE); |
| 440 }, |
| 441 |
| 442 /** |
| 443 * Display an error message when print preview fails. |
| 444 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). |
| 445 * @private |
| 446 */ |
| 447 onPrintPreviewFailed_: function() { |
| 448 cr.dispatchSimpleEvent( |
| 449 this, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); |
| 450 }, |
| 451 |
| 452 /** |
| 453 * Display an error message when encountered invalid printer settings. |
| 454 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). |
| 455 * @private |
| 456 */ |
| 457 onInvalidPrinterSettings_: function() { |
| 458 cr.dispatchSimpleEvent(this, NativeLayer.EventType.SETTINGS_INVALID); |
| 459 }, |
| 460 |
| 461 /** |
| 462 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, |
| 463 * marginRight: number, marginTop: number, marginBottom: number, |
| 464 * printableAreaX: number, printableAreaY: number, |
| 465 * printableAreaWidth: number, printableAreaHeight: number}} |
| 466 * pageLayout Specifies default page layout details in points. |
| 467 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed |
| 468 * document has a custom page size style. |
| 469 * @private |
| 470 */ |
| 471 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { |
| 472 var pageLayoutChangeEvent = new cr.Event( |
| 473 NativeLayer.EventType.PAGE_LAYOUT_READY); |
| 474 pageLayoutChangeEvent.pageLayout = pageLayout; |
| 475 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle; |
| 476 this.dispatchEvent(pageLayoutChangeEvent); |
| 477 }, |
| 478 |
| 479 /** |
| 480 * Update the page count and check the page range. |
| 481 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 482 * @param {number} pageCount The number of pages. |
| 483 * @param {number} previewResponseId The preview request id that resulted in |
| 484 * this response. |
| 485 * @private |
| 486 */ |
| 487 onDidGetPreviewPageCount_: function(pageCount, previewResponseId) { |
| 488 var pageCountChangeEvent = new cr.Event( |
| 489 NativeLayer.EventType.PAGE_COUNT_READY); |
| 490 pageCountChangeEvent.pageCount = pageCount; |
| 491 pageCountChangeEvent.previewResponseId = previewResponseId; |
| 492 this.dispatchEvent(pageCountChangeEvent); |
| 493 }, |
| 494 |
| 495 /** |
| 496 * Called when no pipelining previewed pages. |
| 497 * @param {string} previewUid Preview unique identifier. |
| 498 * @param {number} previewResponseId The preview request id that resulted in |
| 499 * this response. |
| 500 * @private |
| 501 */ |
| 502 onReloadPreviewPages_: function(previewUid, previewResponseId) { |
| 503 var previewReloadEvent = new cr.Event( |
| 504 NativeLayer.EventType.PREVIEW_RELOAD); |
| 505 previewReloadEvent.previewUid = previewUid; |
| 506 previewReloadEvent.previewResponseId = previewResponseId; |
| 507 this.dispatchEvent(previewReloadEvent); |
| 508 }, |
| 509 |
| 510 /** |
| 511 * Notification that a print preview page has been rendered. |
| 512 * Check if the settings have changed and request a regeneration if needed. |
| 513 * Called from PrintPreviewUI::OnDidPreviewPage(). |
| 514 * @param {number} pageNumber The page number, 0-based. |
| 515 * @param {string} previewUid Preview unique identifier. |
| 516 * @param {number} previewResponseId The preview request id that resulted in |
| 517 * this response. |
| 518 * @private |
| 519 */ |
| 520 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
| 521 var pagePreviewGenEvent = new cr.Event( |
| 522 NativeLayer.EventType.PAGE_PREVIEW_READY); |
| 523 pagePreviewGenEvent.pageIndex = pageNumber; |
| 524 pagePreviewGenEvent.previewUid = previewUid; |
| 525 pagePreviewGenEvent.previewResponseId = previewResponseId; |
| 526 this.dispatchEvent(pagePreviewGenEvent); |
| 527 }, |
| 528 |
| 529 /** |
| 530 * Update the print preview when new preview data is available. |
| 531 * Create the PDF plugin as needed. |
| 532 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 533 * @param {string} previewUid Preview unique identifier. |
| 534 * @param {number} previewResponseId The preview request id that resulted in |
| 535 * this response. |
| 536 * @private |
| 537 */ |
| 538 onUpdatePrintPreview_: function(previewUid, previewResponseId) { |
| 539 var previewGenDoneEvent = new cr.Event( |
| 540 NativeLayer.EventType.PREVIEW_GENERATION_DONE); |
| 541 previewGenDoneEvent.previewUid = previewUid; |
| 542 previewGenDoneEvent.previewResponseId = previewResponseId; |
| 543 this.dispatchEvent(previewGenDoneEvent); |
| 544 }, |
| 545 |
| 546 /** |
| 547 * Updates the fit to page option state based on the print scaling option of |
| 548 * source pdf. PDF's have an option to enable/disable print scaling. When we |
| 549 * find out that the print scaling option is disabled for the source pdf, we |
| 550 * uncheck the fitToPage_ to page checkbox. This function is called from C++ |
| 551 * code. |
| 552 * @private |
| 553 */ |
| 554 onPrintScalingDisabledForSourcePDF_: function() { |
| 555 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DISABLE_SCALING); |
| 556 } |
| 557 }; |
| 558 |
| 559 /** |
| 560 * Initial settings retrieved from the native layer. |
| 561 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
| 562 * in auto-print mode. |
| 563 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
| 564 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
| 565 * @param {print_preview.MeasurementSystem.UnitType} unitType Unit type of |
| 566 * local machine's measurement system. |
| 567 * @param {boolean} isDocumentModifiable Whether the document to print is |
| 568 * modifiable. |
| 569 * @param {?print_preview.ticket_items.MarginsType.Value} marginsType Initial |
| 570 * margins type. |
| 571 * @param {print_preview.Margins} customMargins Initial custom margins. |
| 572 * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled. |
| 573 * @param {boolean} isHeaderFooterEnabled Whether the header-footer is |
| 574 * initially enabled. |
| 575 * @param {?string} initialDestinationId ID of the destination to initially |
| 576 * select. |
| 577 * @constructor |
| 578 */ |
| 579 function NativeInitialSettings( |
| 580 isInKioskAutoPrintMode, |
| 581 thousandsDelimeter, |
| 582 decimalDelimeter, |
| 583 unitType, |
| 584 isDocumentModifiable, |
| 585 marginsType, |
| 586 customMargins, |
| 587 isDuplexEnabled, |
| 588 isHeaderFooterEnabled, |
| 589 initialDestinationId) { |
| 590 |
| 591 /** |
| 592 * Whether the print preview should be in auto-print mode. |
| 593 * @type {boolean} |
| 594 * @private |
| 595 */ |
| 596 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; |
| 597 |
| 598 /** |
| 599 * Character delimeter of thousands digits. |
| 600 * @type {string} |
| 601 * @private |
| 602 */ |
| 603 this.thousandsDelimeter_ = thousandsDelimeter; |
| 604 |
| 605 /** |
| 606 * Character delimeter of the decimal point. |
| 607 * @type {string} |
| 608 * @private |
| 609 */ |
| 610 this.decimalDelimeter_ = decimalDelimeter; |
| 611 |
| 612 /** |
| 613 * Unit type of local machine's measurement system. |
| 614 * @type {string} |
| 615 * @private |
| 616 */ |
| 617 this.unitType_ = unitType; |
| 618 |
| 619 /** |
| 620 * Whether the document to print is modifiable. |
| 621 * @type {boolean} |
| 622 * @private |
| 623 */ |
| 624 this.isDocumentModifiable_ = isDocumentModifiable; |
| 625 |
| 626 /** |
| 627 * Initial margins type. |
| 628 * @type {?print_preview.ticket_items.MarginsType.Value} |
| 629 * @private |
| 630 */ |
| 631 this.marginsType_ = marginsType; |
| 632 |
| 633 /** |
| 634 * Initial custom margins. |
| 635 * @type {print_preview.Margins} |
| 636 * @private |
| 637 */ |
| 638 this.customMargins_ = customMargins; |
| 639 |
| 640 /** |
| 641 * Whether duplexing is initially enabled. |
| 642 * @type {boolean} |
| 643 * @private |
| 644 */ |
| 645 this.isDuplexEnabled_ = isDuplexEnabled; |
| 646 |
| 647 /** |
| 648 * Whether the header-footer is initially enabled. |
| 649 * @type {boolean} |
| 650 * @private |
| 651 */ |
| 652 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; |
| 653 |
| 654 /** |
| 655 * ID of the initially selected destination. |
| 656 * @type {?string} |
| 657 * @private |
| 658 */ |
| 659 this.initialDestinationId_ = initialDestinationId; |
| 660 }; |
| 661 |
| 662 NativeInitialSettings.prototype = { |
| 663 /** |
| 664 * @return {boolean} Whether the print preview should be in auto-print mode. |
| 665 */ |
| 666 get isInKioskAutoPrintMode() { |
| 667 return this.isInKioskAutoPrintMode_; |
| 668 }, |
| 669 |
| 670 /** @return {string} Character delimeter of thousands digits. */ |
| 671 get thousandsDelimeter() { |
| 672 return this.thousandsDelimeter_; |
| 673 }, |
| 674 |
| 675 /** @return {string} Character delimeter of the decimal point. */ |
| 676 get decimalDelimeter() { |
| 677 return this.decimalDelimeter_; |
| 678 }, |
| 679 |
| 680 /** |
| 681 * @return {print_preview.MeasurementSystem.UnitType} Unit type of local |
| 682 * machine's measurement system. |
| 683 */ |
| 684 get unitType() { |
| 685 return this.unitType_; |
| 686 }, |
| 687 |
| 688 /** @return {boolean} Whether the document to print is modifiable. */ |
| 689 get isDocumentModifiable() { |
| 690 return this.isDocumentModifiable_; |
| 691 }, |
| 692 |
| 693 /** |
| 694 * @return {?print_preview.ticket_items.MarginsType.Value} Initial margins |
| 695 * type or {@code null} if not initially set. |
| 696 */ |
| 697 get marginsType() { |
| 698 return this.marginsType_; |
| 699 }, |
| 700 |
| 701 /** @return {print_preview.Margins} Initial custom margins. */ |
| 702 get customMargins() { |
| 703 return this.customMargins_; |
| 704 }, |
| 705 |
| 706 /** @return {boolean} Whether duplexing is initially enabled. */ |
| 707 get isDuplexEnabled() { |
| 708 return this.isDuplexEnabled_; |
| 709 }, |
| 710 |
| 711 /** @return {boolean} Whether the header-footer is initially enabled. */ |
| 712 get isHeaderFooterEnabled() { |
| 713 return this.isHeaderFooterEnabled_; |
| 714 }, |
| 715 |
| 716 /** @return {?string} ID of the initially selected destination. */ |
| 717 get initialDestinationId() { |
| 718 return this.initialDestinationId_; |
| 719 } |
| 720 }; |
| 721 |
| 722 // Export |
| 723 return { |
| 724 NativeInitialSettings: NativeInitialSettings, |
| 725 NativeLayer: NativeLayer |
| 726 }; |
| 727 }); |
OLD | NEW |