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