| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Scaling ticket item whose value is a {@code string} that indicates what the | 9 * Scaling ticket item whose value is a {@code string} that indicates what the |
| 10 * scaling (in percent) of the document should be. The ticket item is backed | 10 * scaling (in percent) of the document should be. The ticket item is backed |
| 11 * by a string since the user can textually input the scaling value. | 11 * by a string since the user can textually input the scaling value. |
| 12 * @param {!print_preview.AppState} appState App state to persist item value. | 12 * @param {!print_preview.AppState} appState App state to persist item value. |
| 13 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 13 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
| 14 * document to print. | 14 * document to print. |
| 15 * @param {!print_preview.DestinationStore} destinationStore Used to determine | 15 * @param {!print_preview.DestinationStore} destinationStore Used to determine |
| 16 * whether fit to page should be available. | 16 * whether fit to page should be available. |
| 17 * @constructor | 17 * @constructor |
| 18 * @extends {print_preview.ticket_items.TicketItem} | 18 * @extends {print_preview.ticket_items.TicketItem} |
| 19 */ | 19 */ |
| 20 function Scaling(appState, destinationStore, documentInfo) { | 20 function Scaling(appState, destinationStore, documentInfo) { |
| 21 print_preview.ticket_items.TicketItem.call( | 21 print_preview.ticket_items.TicketItem.call( |
| 22 this, | 22 this, |
| 23 appState, | 23 appState, |
| 24 print_preview.AppState.Field.SCALING, | 24 print_preview.AppState.Field.SCALING, |
| 25 destinationStore, | 25 destinationStore, |
| 26 documentInfo); | 26 documentInfo); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 /** | |
| 30 * Maximum scaling percentage | |
| 31 * @private {number} | |
| 32 * @const | |
| 33 */ | |
| 34 Scaling.MAX_VAL = 200; | |
| 35 | |
| 36 /** | |
| 37 * Minimum scaling percentage | |
| 38 * @private {number} | |
| 39 * @const | |
| 40 */ | |
| 41 Scaling.MIN_VAL = 10; | |
| 42 | |
| 43 Scaling.prototype = { | 29 Scaling.prototype = { |
| 44 __proto__: print_preview.ticket_items.TicketItem.prototype, | 30 __proto__: print_preview.ticket_items.TicketItem.prototype, |
| 45 | 31 |
| 46 /** @override */ | 32 /** @override */ |
| 47 wouldValueBeValid: function(value) { | 33 wouldValueBeValid: function(value) { |
| 48 if (/[^\d]+/.test(value)) { | 34 return true; |
| 49 return false; | 35 }, |
| 50 } | |
| 51 var scaling = parseInt(value, 10); | |
| 52 return scaling >= Scaling.MIN_VAL && scaling <= Scaling.MAX_VAL; | |
| 53 }, | |
| 54 | 36 |
| 55 /** @override */ | 37 /** @override */ |
| 56 isValueEqual: function(value) { | 38 isValueEqual: function(value) { |
| 57 return this.getValueAsNumber() == value; | 39 return this.getValueAsNumber() == value; |
| 58 }, | 40 }, |
| 59 | 41 |
| 60 /** | |
| 61 * @param {number} The desired scaling percentage. | |
| 62 * @return {number} Nearest valid scaling percentage | |
| 63 */ | |
| 64 getNearestValidValue: function(value) { | |
| 65 return Math.min(Math.max(value, Scaling.MIN_VAL), Scaling.MAX_VAL); | |
| 66 }, | |
| 67 | |
| 68 /** @override */ | 42 /** @override */ |
| 69 isCapabilityAvailable: function() { | 43 isCapabilityAvailable: function() { |
| 70 // This is not a function of the printer, but should be disabled if we are | 44 // This is not a function of the printer, but should be disabled if we are |
| 71 // saving a PDF to a PDF. | 45 // saving a PDF to a PDF. |
| 72 var knownSizeToSaveAsPdf = | 46 var knownSizeToSaveAsPdf = |
| 73 (!this.getDocumentInfoInternal().isModifiable || | 47 (!this.getDocumentInfoInternal().isModifiable || |
| 74 this.getDocumentInfoInternal().hasCssMediaStyles) && | 48 this.getDocumentInfoInternal().hasCssMediaStyles) && |
| 75 this.getSelectedDestInternal() && | 49 this.getSelectedDestInternal() && |
| 76 this.getSelectedDestInternal().id == | 50 this.getSelectedDestInternal().id == |
| 77 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; | 51 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 getCapabilityNotAvailableValueInternal: function() { | 66 getCapabilityNotAvailableValueInternal: function() { |
| 93 return '100'; | 67 return '100'; |
| 94 }, | 68 }, |
| 95 }; | 69 }; |
| 96 | 70 |
| 97 // Export | 71 // Export |
| 98 return { | 72 return { |
| 99 Scaling: Scaling | 73 Scaling: Scaling |
| 100 }; | 74 }; |
| 101 }); | 75 }); |
| OLD | NEW |