| 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Page range ticket item whose value is a {@code string} that represents | 9 * Page range ticket item whose value is a {@code string} that represents |
| 10 * which pages in the document should be printed. | 10 * which pages in the document should be printed. |
| 11 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 11 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
| 12 * document to print. | 12 * document to print. |
| 13 * @constructor | 13 * @constructor |
| 14 * @extends {print_preview.ticket_items.TicketItem} | 14 * @extends {print_preview.ticket_items.TicketItem} |
| 15 */ | 15 */ |
| 16 function PageRange(documentInfo) { | 16 function PageRange(documentInfo) { |
| 17 print_preview.ticket_items.TicketItem.call( | 17 print_preview.ticket_items.TicketItem.call( |
| 18 this, | 18 this, |
| 19 null /*appState*/, | 19 null /*appState*/, |
| 20 null /*field*/, | 20 null /*field*/, |
| 21 null /*destinationStore*/, | 21 null /*destinationStore*/, |
| 22 documentInfo); | 22 documentInfo); |
| 23 }; | 23 } |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Impossibly large page number. | 26 * Impossibly large page number. |
| 27 * @type {number} | 27 * @type {number} |
| 28 * @const | 28 * @const |
| 29 * @private | 29 * @private |
| 30 */ | 30 */ |
| 31 PageRange.MAX_PAGE_NUMBER_ = 1000000000; | 31 PageRange.MAX_PAGE_NUMBER_ = 1000000000; |
| 32 | 32 |
| 33 PageRange.prototype = { | 33 PageRange.prototype = { |
| 34 __proto__: print_preview.ticket_items.TicketItem.prototype, | 34 __proto__: print_preview.ticket_items.TicketItem.prototype, |
| 35 | 35 |
| 36 /** @override */ | 36 /** @override */ |
| 37 wouldValueBeValid: function(value) { | 37 wouldValueBeValid: function(value) { |
| 38 var result = pageRangeTextToPageRanges( | 38 var result = pageRangeTextToPageRanges( |
| 39 value, this.getDocumentInfoInternal().pageCount); | 39 value, this.getDocumentInfoInternal().pageCount); |
| 40 return result instanceof Array; | 40 return result instanceof Array; |
| 41 }, | 41 }, |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the | 44 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the |
| 45 * page range string. | 45 * page range string. |
| 46 */ | 46 */ |
| 47 getPageNumberSet: function() { | 47 getPageNumberSet: function() { |
| 48 var pageNumberList = pageRangeTextToPageList( | 48 var pageNumberList = pageRangeTextToPageList( |
| 49 this.getValue(), this.getDocumentInfoInternal().pageCount); | 49 this.getValueAsString_(), this.getDocumentInfoInternal().pageCount); |
| 50 return new print_preview.PageNumberSet(pageNumberList); | 50 return new print_preview.PageNumberSet(pageNumberList); |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 /** @override */ | 53 /** @override */ |
| 54 isCapabilityAvailable: function() { | 54 isCapabilityAvailable: function() { |
| 55 return true; | 55 return true; |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** @override */ | 58 /** @override */ |
| 59 getDefaultValueInternal: function() { | 59 getDefaultValueInternal: function() { |
| 60 return ''; | 60 return ''; |
| 61 }, | 61 }, |
| 62 | 62 |
| 63 /** @override */ | 63 /** @override */ |
| 64 getCapabilityNotAvailableValueInternal: function() { | 64 getCapabilityNotAvailableValueInternal: function() { |
| 65 return ''; | 65 return ''; |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * @return {string} The value of the ticket item as a string. |
| 70 * @private |
| 71 */ |
| 72 getValueAsString_: function() { |
| 73 return /** @type {string} */(this.getValue()); |
| 74 }, |
| 75 |
| 76 /** |
| 69 * @return {!Array<Object<{from: number, to: number}>>} A list of page | 77 * @return {!Array<Object<{from: number, to: number}>>} A list of page |
| 70 * ranges. | 78 * ranges. |
| 71 */ | 79 */ |
| 72 getPageRanges: function() { | 80 getPageRanges: function() { |
| 73 var pageRanges = pageRangeTextToPageRanges(this.getValue()); | 81 var pageRanges = pageRangeTextToPageRanges(this.getValueAsString_()); |
| 74 return pageRanges instanceof Array ? pageRanges : []; | 82 return pageRanges instanceof Array ? pageRanges : []; |
| 75 }, | 83 }, |
| 76 | 84 |
| 77 /** | 85 /** |
| 78 * @return {!Array<object<{from: number, to: number}>>} A list of page | 86 * @return {!Array<Object<{from: number, to: number}>>} A list of page |
| 79 * ranges suitable for use in the native layer. | 87 * ranges suitable for use in the native layer. |
| 80 * TODO(vitalybuka): this should be removed when native layer switched to | 88 * TODO(vitalybuka): this should be removed when native layer switched to |
| 81 * page ranges. | 89 * page ranges. |
| 82 */ | 90 */ |
| 83 getDocumentPageRanges: function() { | 91 getDocumentPageRanges: function() { |
| 84 var pageRanges = pageRangeTextToPageRanges( | 92 var pageRanges = pageRangeTextToPageRanges( |
| 85 this.getValue(), this.getDocumentInfoInternal().pageCount); | 93 this.getValueAsString_(), this.getDocumentInfoInternal().pageCount); |
| 86 return pageRanges instanceof Array ? pageRanges : []; | 94 return pageRanges instanceof Array ? pageRanges : []; |
| 87 }, | 95 }, |
| 88 | 96 |
| 89 /** | 97 /** |
| 90 * @return {!number} Number of pages reported by the document. | 98 * @return {!number} Number of pages reported by the document. |
| 91 */ | 99 */ |
| 92 getDocumentNumPages: function() { | 100 getDocumentNumPages: function() { |
| 93 return this.getDocumentInfoInternal().pageCount; | 101 return this.getDocumentInfoInternal().pageCount; |
| 94 }, | 102 }, |
| 95 | 103 |
| 96 /** | 104 /** |
| 97 * @return {!PageRangeStatus} | 105 * @return {!PageRangeStatus} |
| 98 */ | 106 */ |
| 99 checkValidity: function() { | 107 checkValidity: function() { |
| 100 var pageRanges = pageRangeTextToPageRanges( | 108 var pageRanges = pageRangeTextToPageRanges( |
| 101 this.getValue(), this.getDocumentInfoInternal().pageCount); | 109 this.getValueAsString_(), this.getDocumentInfoInternal().pageCount); |
| 102 return pageRanges instanceof Array ? | 110 return pageRanges instanceof Array ? |
| 103 PageRangeStatus.NO_ERROR : pageRanges; | 111 PageRangeStatus.NO_ERROR : pageRanges; |
| 104 }, | 112 }, |
| 105 }; | 113 }; |
| 106 | 114 |
| 107 // Export | 115 // Export |
| 108 return { | 116 return { |
| 109 PageRange: PageRange | 117 PageRange: PageRange |
| 110 }; | 118 }; |
| 111 }); | 119 }); |
| OLD | NEW |