| 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 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or | 8 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or |
| 9 // better yet, carry over any print ticket state that is possible. I.e. if | 9 // better yet, carry over any print ticket state that is possible. I.e. if |
| 10 // destination changes, the new destination might not support duplex anymore, | 10 // destination changes, the new destination might not support duplex anymore, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 */ | 62 */ |
| 63 this.measurementSystem_ = new print_preview.MeasurementSystem( | 63 this.measurementSystem_ = new print_preview.MeasurementSystem( |
| 64 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); | 64 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Collate ticket item. | 67 * Collate ticket item. |
| 68 * @type {!print_preview.ticket_items.Collate} | 68 * @type {!print_preview.ticket_items.Collate} |
| 69 * @private | 69 * @private |
| 70 */ | 70 */ |
| 71 this.collate_ = | 71 this.collate_ = |
| 72 new print_preview.ticket_items.Collate(this.capabilitiesHolder_); | 72 new print_preview.ticket_items.Collate(this.capabilitiesHolder_); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Color ticket item. | 75 * Color ticket item. |
| 76 * @type {!print_preview.ticket_items.Color} | 76 * @type {!print_preview.ticket_items.Color} |
| 77 * @private | 77 * @private |
| 78 */ | 78 */ |
| 79 this.color_ = new print_preview.ticket_items.Color( | 79 this.color_ = new print_preview.ticket_items.Color( |
| 80 this.capabilitiesHolder_, this.destinationStore_); | 80 this.capabilitiesHolder_, this.destinationStore_); |
| 81 | 81 |
| 82 /** | 82 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter( | 135 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter( |
| 136 this.documentInfo_, this.marginsType_, this.customMargins_); | 136 this.documentInfo_, this.marginsType_, this.customMargins_); |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * Fit-to-page ticket item. | 139 * Fit-to-page ticket item. |
| 140 * @type {!print_preview.ticket_items.FitToPage} | 140 * @type {!print_preview.ticket_items.FitToPage} |
| 141 * @private | 141 * @private |
| 142 */ | 142 */ |
| 143 this.fitToPage_ = new print_preview.ticket_items.FitToPage( | 143 this.fitToPage_ = new print_preview.ticket_items.FitToPage( |
| 144 this.documentInfo_, this.destinationStore_); | 144 this.documentInfo_, this.destinationStore_); |
| 145 |
| 146 /** |
| 147 * Keeps track of event listeners for the print ticket store. |
| 148 * @type {!EventTracker} |
| 149 * @private |
| 150 */ |
| 151 this.tracker_ = new EventTracker(); |
| 152 |
| 153 this.addEventListeners_(); |
| 145 }; | 154 }; |
| 146 | 155 |
| 147 /** | 156 /** |
| 148 * Event types dispatched by the print ticket store. | 157 * Event types dispatched by the print ticket store. |
| 149 * @enum {string} | 158 * @enum {string} |
| 150 */ | 159 */ |
| 151 PrintTicketStore.EventType = { | 160 PrintTicketStore.EventType = { |
| 152 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', | 161 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', |
| 153 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', | 162 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', |
| 154 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', | 163 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 this.duplex_.updateValue(isDuplexEnabled); | 278 this.duplex_.updateValue(isDuplexEnabled); |
| 270 this.headerFooter_.updateValue(isHeaderFooterEnabled); | 279 this.headerFooter_.updateValue(isHeaderFooterEnabled); |
| 271 if (marginsType != null) { | 280 if (marginsType != null) { |
| 272 this.marginsType_.updateValue(marginsType); | 281 this.marginsType_.updateValue(marginsType); |
| 273 } | 282 } |
| 274 if (customMargins != null) { | 283 if (customMargins != null) { |
| 275 this.customMargins_.updateValue(customMargins); | 284 this.customMargins_.updateValue(customMargins); |
| 276 } | 285 } |
| 277 }, | 286 }, |
| 278 | 287 |
| 279 /** | |
| 280 * Updates the capabilities of the destination the print ticket is for. | |
| 281 * Dispatches a CAPABILITIES_CHANGE event. | |
| 282 * @param {!print_preview.ChromiumCapabilities} caps New capabilities. | |
| 283 */ | |
| 284 updateDestinationCapabilities: function(caps) { | |
| 285 var isFirstUpdate = this.capabilitiesHolder_.get() == null; | |
| 286 this.capabilitiesHolder_.set(caps); | |
| 287 if (isFirstUpdate) { | |
| 288 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); | |
| 289 } else { | |
| 290 this.customMargins_.updateValue(null); | |
| 291 if (this.marginsType_.getValue() == | |
| 292 print_preview.ticket_items.MarginsType.Value.CUSTOM) { | |
| 293 this.marginsType_.updateValue( | |
| 294 print_preview.ticket_items.MarginsType.Value.DEFAULT); | |
| 295 } | |
| 296 cr.dispatchSimpleEvent( | |
| 297 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); | |
| 298 } | |
| 299 }, | |
| 300 | |
| 301 /** @return {boolean} Whether the ticket store has the copies capability. */ | 288 /** @return {boolean} Whether the ticket store has the copies capability. */ |
| 302 hasCopiesCapability: function() { | 289 hasCopiesCapability: function() { |
| 303 return this.copies_.isCapabilityAvailable(); | 290 return this.copies_.isCapabilityAvailable(); |
| 304 }, | 291 }, |
| 305 | 292 |
| 306 /** | 293 /** |
| 307 * @return {boolean} Whether the string representation of the copies value | 294 * @return {boolean} Whether the string representation of the copies value |
| 308 * currently in the ticket store is valid. | 295 * currently in the ticket store is valid. |
| 309 */ | 296 */ |
| 310 isCopiesValid: function() { | 297 isCopiesValid: function() { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 (!this.hasPageRangeCapability() || this.isPageRangeValid()); | 599 (!this.hasPageRangeCapability() || this.isPageRangeValid()); |
| 613 }, | 600 }, |
| 614 | 601 |
| 615 /** @return {boolean} Whether the ticket is valid for preview generation. */ | 602 /** @return {boolean} Whether the ticket is valid for preview generation. */ |
| 616 isTicketValidForPreview: function() { | 603 isTicketValidForPreview: function() { |
| 617 return (!this.hasCopiesCapability() || this.isCopiesValid()) && | 604 return (!this.hasCopiesCapability() || this.isCopiesValid()) && |
| 618 (!this.hasMarginsCapability() || | 605 (!this.hasMarginsCapability() || |
| 619 this.getMarginsType() != | 606 this.getMarginsType() != |
| 620 print_preview.ticket_items.MarginsType.Value.CUSTOM || | 607 print_preview.ticket_items.MarginsType.Value.CUSTOM || |
| 621 this.isCustomMarginsValid()); | 608 this.isCustomMarginsValid()); |
| 609 }, |
| 610 |
| 611 /** |
| 612 * Adds event listeners for the print ticket store. |
| 613 * @private |
| 614 */ |
| 615 addEventListeners_: function() { |
| 616 this.tracker_.add( |
| 617 this.destinationStore_, |
| 618 print_preview.DestinationStore.EventType. |
| 619 SELECTED_DESTINATION_CAPABILITIES_READY, |
| 620 this.onSelectedDestinationCapabilitiesReady_.bind(this)); |
| 621 }, |
| 622 |
| 623 /** |
| 624 * Called when the capabilities of the selected destination are ready. |
| 625 * @private |
| 626 */ |
| 627 onSelectedDestinationCapabilitiesReady_: function() { |
| 628 var caps = this.destinationStore_.selectedDestination.capabilities; |
| 629 var isFirstUpdate = this.capabilitiesHolder_.get() == null; |
| 630 this.capabilitiesHolder_.set(caps); |
| 631 if (isFirstUpdate) { |
| 632 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); |
| 633 } else { |
| 634 this.customMargins_.updateValue(null); |
| 635 if (this.marginsType_.getValue() == |
| 636 print_preview.ticket_items.MarginsType.Value.CUSTOM) { |
| 637 this.marginsType_.updateValue( |
| 638 print_preview.ticket_items.MarginsType.Value.DEFAULT); |
| 639 } |
| 640 cr.dispatchSimpleEvent( |
| 641 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); |
| 642 } |
| 622 } | 643 } |
| 623 }; | 644 }; |
| 624 | 645 |
| 625 // Export | 646 // Export |
| 626 return { | 647 return { |
| 627 PrintTicketStore: PrintTicketStore | 648 PrintTicketStore: PrintTicketStore |
| 628 }; | 649 }; |
| 629 }); | 650 }); |
| OLD | NEW |