| 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 * Interface to the Chromium print preview generator. | 9 * Interface to the Chromium print preview generator. |
| 10 * @param {!print_preview.DestinationStore} destinationStore Used to get the | 10 * @param {!print_preview.DestinationStore} destinationStore Used to get the |
| 11 * currently selected destination. | 11 * currently selected destination. |
| 12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to read the | 12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to read the |
| 13 * state of the ticket and write document information. | 13 * state of the ticket and write document information. |
| 14 * @param {!print_preview.NativeLayer} nativeLayer Used to communicate to | 14 * @param {!print_preview.NativeLayer} nativeLayer Used to communicate to |
| 15 * Chromium's preview rendering system. | 15 * Chromium's preview rendering system. |
| 16 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 16 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| 17 * @param {!WebUIListenerTracker} listenerTracker Tracker for the WebUI |
| 18 * listeners added in the PreviewGenerator constructor. |
| 17 * @constructor | 19 * @constructor |
| 18 * @extends {cr.EventTarget} | 20 * @extends {cr.EventTarget} |
| 19 */ | 21 */ |
| 20 function PreviewGenerator( | 22 function PreviewGenerator( |
| 21 destinationStore, printTicketStore, nativeLayer, documentInfo) { | 23 destinationStore, printTicketStore, nativeLayer, documentInfo, |
| 24 listenerTracker) { |
| 22 cr.EventTarget.call(this); | 25 cr.EventTarget.call(this); |
| 23 | 26 |
| 24 /** | 27 /** |
| 25 * Used to get the currently selected destination. | 28 * Used to get the currently selected destination. |
| 26 * @type {!print_preview.DestinationStore} | 29 * @type {!print_preview.DestinationStore} |
| 27 * @private | 30 * @private |
| 28 */ | 31 */ |
| 29 this.destinationStore_ = destinationStore; | 32 this.destinationStore_ = destinationStore; |
| 30 | 33 |
| 31 /** | 34 /** |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * @private | 131 * @private |
| 129 */ | 132 */ |
| 130 this.isCssBackgroundEnabled_ = false; | 133 this.isCssBackgroundEnabled_ = false; |
| 131 | 134 |
| 132 /** | 135 /** |
| 133 * Destination that was selected for the last preview. | 136 * Destination that was selected for the last preview. |
| 134 * @type {print_preview.Destination} | 137 * @type {print_preview.Destination} |
| 135 * @private | 138 * @private |
| 136 */ | 139 */ |
| 137 this.selectedDestination_ = null; | 140 this.selectedDestination_ = null; |
| 141 |
| 142 this.addWebUIEventListeners_(listenerTracker); |
| 138 } | 143 } |
| 139 | 144 |
| 140 /** | 145 /** |
| 141 * Event types dispatched by the preview generator. | 146 * Event types dispatched by the preview generator. |
| 142 * @enum {string} | 147 * @enum {string} |
| 143 */ | 148 */ |
| 144 PreviewGenerator.EventType = { | 149 PreviewGenerator.EventType = { |
| 145 // Dispatched when the document can be printed. | 150 // Dispatched when the document can be printed. |
| 146 DOCUMENT_READY: 'print_preview.PreviewGenerator.DOCUMENT_READY', | 151 DOCUMENT_READY: 'print_preview.PreviewGenerator.DOCUMENT_READY', |
| 147 | 152 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 159 }; | 164 }; |
| 160 | 165 |
| 161 PreviewGenerator.prototype = { | 166 PreviewGenerator.prototype = { |
| 162 __proto__: cr.EventTarget.prototype, | 167 __proto__: cr.EventTarget.prototype, |
| 163 | 168 |
| 164 /** | 169 /** |
| 165 * Starts listening for relevant WebUI events and adds the listeners to | 170 * Starts listening for relevant WebUI events and adds the listeners to |
| 166 * |listenerTracker|. |listenerTracker| is responsible for removing the | 171 * |listenerTracker|. |listenerTracker| is responsible for removing the |
| 167 * listeners when necessary. | 172 * listeners when necessary. |
| 168 * @param {!WebUIListenerTracker} listenerTracker | 173 * @param {!WebUIListenerTracker} listenerTracker |
| 174 * @private |
| 169 */ | 175 */ |
| 170 addWebUIEventListeners: function(listenerTracker) { | 176 addWebUIEventListeners_: function(listenerTracker) { |
| 171 listenerTracker.add( | 177 listenerTracker.add( |
| 172 'page-count-ready', this.onPageCountReady_.bind(this)); | 178 'page-count-ready', this.onPageCountReady_.bind(this)); |
| 173 listenerTracker.add( | 179 listenerTracker.add( |
| 174 'page-layout-ready', this.onPageLayoutReady_.bind(this)); | 180 'page-layout-ready', this.onPageLayoutReady_.bind(this)); |
| 175 listenerTracker.add( | 181 listenerTracker.add( |
| 176 'page-preview-ready', this.onPagePreviewReady_.bind(this)); | 182 'page-preview-ready', this.onPagePreviewReady_.bind(this)); |
| 177 }, | 183 }, |
| 178 | 184 |
| 179 /** | 185 /** |
| 180 * Request that new preview be generated. A preview request will not be | 186 * Request that new preview be generated. A preview request will not be |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 onPreviewGenerationFail_: function() { | 418 onPreviewGenerationFail_: function() { |
| 413 // NOTE: No request ID is returned from Chromium so its assumed its the | 419 // NOTE: No request ID is returned from Chromium so its assumed its the |
| 414 // current one. | 420 // current one. |
| 415 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); | 421 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); |
| 416 } | 422 } |
| 417 }; | 423 }; |
| 418 | 424 |
| 419 // Export | 425 // Export |
| 420 return {PreviewGenerator: PreviewGenerator}; | 426 return {PreviewGenerator: PreviewGenerator}; |
| 421 }); | 427 }); |
| OLD | NEW |