| 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 // TODO(rltoscano): Move data/* into print_preview.data namespace | 5 // TODO(rltoscano): Move data/* into print_preview.data namespace |
| 6 | 6 |
| 7 // <include src="component.js"> | 7 // <include src="component.js"> |
| 8 // <include src="print_preview_focus_manager.js"> | 8 // <include src="print_preview_focus_manager.js"> |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 PrintPreview.prototype = { | 325 PrintPreview.prototype = { |
| 326 __proto__: print_preview.Component.prototype, | 326 __proto__: print_preview.Component.prototype, |
| 327 | 327 |
| 328 /** Sets up the page and print preview by getting the printer list. */ | 328 /** Sets up the page and print preview by getting the printer list. */ |
| 329 initialize: function() { | 329 initialize: function() { |
| 330 this.decorate($('print-preview')); | 330 this.decorate($('print-preview')); |
| 331 if (!this.previewArea_.hasCompatiblePlugin) { | 331 if (!this.previewArea_.hasCompatiblePlugin) { |
| 332 this.setIsEnabled_(false); | 332 this.setIsEnabled_(false); |
| 333 } | 333 } |
| 334 this.nativeLayer_.startGetInitialSettings(); | 334 this.nativeLayer_.getInitialSettings().then( |
| 335 /** |
| 336 * @param {!print_preview.NativeInitialSettings} settings |
| 337 * The print preview initial settings. |
| 338 */ |
| 339 function(settings) { |
| 340 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, |
| 341 'Updating initial settings when not in initializing ' + |
| 342 'state: ' + this.uiState_); |
| 343 this.uiState_ = PrintPreviewUiState_.READY; |
| 344 this.onInitialSettingsSet_(settings); |
| 345 }.bind(this)); |
| 335 print_preview.PrintPreviewFocusManager.getInstance().initialize(); | 346 print_preview.PrintPreviewFocusManager.getInstance().initialize(); |
| 336 cr.ui.FocusOutlineManager.forDocument(document); | 347 cr.ui.FocusOutlineManager.forDocument(document); |
| 337 }, | 348 }, |
| 338 | 349 |
| 339 /** @override */ | 350 /** @override */ |
| 340 enterDocument: function() { | 351 enterDocument: function() { |
| 341 // Native layer events. | 352 // Native layer events. |
| 353 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); |
| 342 this.tracker.add( | 354 this.tracker.add( |
| 343 this.nativeLayer_, | 355 nativeLayerEventTarget, |
| 344 print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET, | |
| 345 this.onInitialSettingsSet_.bind(this)); | |
| 346 this.tracker.add( | |
| 347 this.nativeLayer_, | |
| 348 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, | 356 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, |
| 349 this.onCloudPrintEnable_.bind(this)); | 357 this.onCloudPrintEnable_.bind(this)); |
| 350 this.tracker.add( | 358 this.tracker.add( |
| 351 this.nativeLayer_, | 359 nativeLayerEventTarget, |
| 352 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, | 360 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, |
| 353 this.onPrintToCloud_.bind(this)); | 361 this.onPrintToCloud_.bind(this)); |
| 354 this.tracker.add( | 362 this.tracker.add( |
| 355 this.nativeLayer_, | 363 nativeLayerEventTarget, |
| 356 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, | 364 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, |
| 357 this.onFileSelectionCancel_.bind(this)); | 365 this.onFileSelectionCancel_.bind(this)); |
| 358 this.tracker.add( | 366 this.tracker.add( |
| 359 this.nativeLayer_, | 367 nativeLayerEventTarget, |
| 360 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, | 368 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, |
| 361 this.onFileSelectionComplete_.bind(this)); | 369 this.onFileSelectionComplete_.bind(this)); |
| 362 this.tracker.add( | 370 this.tracker.add( |
| 363 this.nativeLayer_, | 371 nativeLayerEventTarget, |
| 364 print_preview.NativeLayer.EventType.SETTINGS_INVALID, | 372 print_preview.NativeLayer.EventType.SETTINGS_INVALID, |
| 365 this.onSettingsInvalid_.bind(this)); | 373 this.onSettingsInvalid_.bind(this)); |
| 366 this.tracker.add( | 374 this.tracker.add( |
| 367 this.nativeLayer_, | 375 nativeLayerEventTarget, |
| 368 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, | 376 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, |
| 369 this.onPrintPresetOptionsFromDocument_.bind(this)); | 377 this.onPrintPresetOptionsFromDocument_.bind(this)); |
| 370 this.tracker.add( | 378 this.tracker.add( |
| 371 this.nativeLayer_, | 379 nativeLayerEventTarget, |
| 372 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | 380 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, |
| 373 this.onPageCountReady_.bind(this)); | 381 this.onPageCountReady_.bind(this)); |
| 374 this.tracker.add( | 382 this.tracker.add( |
| 375 this.nativeLayer_, | 383 nativeLayerEventTarget, |
| 376 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, | 384 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, |
| 377 this.onPrivetPrintFailed_.bind(this)); | 385 this.onPrivetPrintFailed_.bind(this)); |
| 378 this.tracker.add( | 386 this.tracker.add( |
| 379 this.nativeLayer_, | 387 nativeLayerEventTarget, |
| 380 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | 388 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, |
| 381 this.onManipulateSettingsForTest_.bind(this)); | 389 this.onManipulateSettingsForTest_.bind(this)); |
| 382 | 390 |
| 383 if ($('system-dialog-link')) { | 391 if ($('system-dialog-link')) { |
| 384 this.tracker.add( | 392 this.tracker.add( |
| 385 getRequiredElement('system-dialog-link'), | 393 getRequiredElement('system-dialog-link'), |
| 386 'click', | 394 'click', |
| 387 this.openSystemPrintDialog_.bind(this)); | 395 this.openSystemPrintDialog_.bind(this)); |
| 388 } | 396 } |
| 389 if ($('open-pdf-in-preview-link')) { | 397 if ($('open-pdf-in-preview-link')) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 setIsVisible(getRequiredElement('system-dialog-throbber'), true); | 639 setIsVisible(getRequiredElement('system-dialog-throbber'), true); |
| 632 this.setIsEnabled_(false); | 640 this.setIsEnabled_(false); |
| 633 this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; | 641 this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; |
| 634 this.nativeLayer_.startShowSystemDialog(); | 642 this.nativeLayer_.startShowSystemDialog(); |
| 635 }, | 643 }, |
| 636 | 644 |
| 637 /** | 645 /** |
| 638 * Called when the native layer has initial settings to set. Sets the | 646 * Called when the native layer has initial settings to set. Sets the |
| 639 * initial settings of the print preview and begins fetching print | 647 * initial settings of the print preview and begins fetching print |
| 640 * destinations. | 648 * destinations. |
| 641 * @param {Event} event Contains the initial print preview settings | 649 * @param {!print_preview.NativeInitialSettings} settings The initial print |
| 642 * persisted through the session. | 650 * preview settings persisted through the session. |
| 643 * @private | 651 * @private |
| 644 */ | 652 */ |
| 645 onInitialSettingsSet_: function(event) { | 653 onInitialSettingsSet_: function(settings) { |
| 646 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, | |
| 647 'Updating initial settings when not in initializing state: ' + | |
| 648 this.uiState_); | |
| 649 this.uiState_ = PrintPreviewUiState_.READY; | |
| 650 | |
| 651 var settings = event.initialSettings; | |
| 652 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; | 654 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; |
| 653 this.isInAppKioskMode_ = settings.isInAppKioskMode; | 655 this.isInAppKioskMode_ = settings.isInAppKioskMode; |
| 654 | 656 |
| 655 // The following components must be initialized in this order. | 657 // The following components must be initialized in this order. |
| 656 this.appState_.init(settings.serializedAppStateStr); | 658 this.appState_.init(settings.serializedAppStateStr); |
| 657 this.documentInfo_.init( | 659 this.documentInfo_.init( |
| 658 settings.isDocumentModifiable, | 660 settings.isDocumentModifiable, |
| 659 settings.documentTitle, | 661 settings.documentTitle, |
| 660 settings.documentHasSelection); | 662 settings.documentHasSelection); |
| 661 this.printTicketStore_.init( | 663 this.printTicketStore_.init( |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 // <include src="previewarea/preview_area.js"> | 1346 // <include src="previewarea/preview_area.js"> |
| 1345 // <include src="preview_generator.js"> | 1347 // <include src="preview_generator.js"> |
| 1346 | 1348 |
| 1347 // <include src="search/destination_list.js"> | 1349 // <include src="search/destination_list.js"> |
| 1348 // <include src="search/cloud_destination_list.js"> | 1350 // <include src="search/cloud_destination_list.js"> |
| 1349 // <include src="search/recent_destination_list.js"> | 1351 // <include src="search/recent_destination_list.js"> |
| 1350 // <include src="search/destination_list_item.js"> | 1352 // <include src="search/destination_list_item.js"> |
| 1351 // <include src="search/destination_search.js"> | 1353 // <include src="search/destination_search.js"> |
| 1352 // <include src="search/provisional_destination_resolver.js"> | 1354 // <include src="search/provisional_destination_resolver.js"> |
| 1353 | 1355 |
| 1354 /** | |
| 1355 * Global instance of PrintPreview, used by browser tests. | |
| 1356 * @type {print_preview.PrintPreview} | |
| 1357 */ | |
| 1358 var printPreview; | |
| 1359 window.addEventListener('DOMContentLoaded', function() { | 1356 window.addEventListener('DOMContentLoaded', function() { |
| 1360 printPreview = new print_preview.PrintPreview(); | 1357 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
| 1361 printPreview.initialize(); | 1358 if (!previewWindow.isTest) { |
| 1359 var printPreview = new print_preview.PrintPreview(); |
| 1360 printPreview.initialize(); |
| 1361 } |
| 1362 }); | 1362 }); |
| OLD | NEW |