Chromium Code Reviews| 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(this); | 17 print_preview.ticket_items.TicketItem.call(this); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Information about the document to print. | 20 * Information about the document to print. |
| 21 * @type {!print_preview.DocumentInfo} | 21 * @type {!print_preview.DocumentInfo} |
| 22 * @private | 22 * @private |
| 23 */ | 23 */ |
| 24 this.documentInfo_ = documentInfo; | 24 this.documentInfo_ = documentInfo; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 /** | |
| 28 * Impossibly large page number. | |
| 29 * @type {number} | |
| 30 * @const | |
| 31 * @private | |
| 32 */ | |
| 33 PageRange.MAX_PAGE_NUMBER_ = 1000000000; | |
| 34 | |
| 27 PageRange.prototype = { | 35 PageRange.prototype = { |
| 28 __proto__: print_preview.ticket_items.TicketItem.prototype, | 36 __proto__: print_preview.ticket_items.TicketItem.prototype, |
| 29 | 37 |
| 30 /** @override */ | 38 /** @override */ |
| 31 wouldValueBeValid: function(value) { | 39 wouldValueBeValid: function(value) { |
| 32 return value == '' || | 40 return null != pageRangeTextToPageRanges(value, |
| 33 isPageRangeTextValid(value, this.documentInfo_.pageCount); | 41 this.documentInfo_.pageCount); |
| 34 }, | 42 }, |
| 35 | 43 |
| 36 /** | 44 /** |
| 37 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the | 45 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the |
| 38 * page range string. | 46 * page range string. |
| 39 */ | 47 */ |
| 40 getPageNumberSet: function() { | 48 getPageNumberSet: function() { |
|
Toscano
2013/02/12 01:39:05
Let's get rid of this method and expose only getPa
| |
| 41 if (this.isValid()) { | 49 var pageNumberList = pageRangeTextToPageList( |
| 42 return print_preview.PageNumberSet.parse( | 50 this.getValue(), this.documentInfo_.pageCount); |
| 43 this.getValue(), this.documentInfo_.pageCount); | 51 return new print_preview.PageNumberSet(pageNumberList); |
| 44 } else { | |
| 45 return print_preview.PageNumberSet.parse( | |
| 46 this.getDefaultValueInternal(), this.documentInfo_.pageCount); | |
| 47 } | |
| 48 }, | 52 }, |
| 49 | 53 |
| 50 /** @override */ | 54 /** @override */ |
| 51 isCapabilityAvailable: function() { | 55 isCapabilityAvailable: function() { |
| 52 return true; | 56 return true; |
| 53 }, | 57 }, |
| 54 | 58 |
| 55 /** @override */ | 59 /** @override */ |
| 56 getDefaultValueInternal: function() { | 60 getDefaultValueInternal: function() { |
| 57 return ''; | 61 return ''; |
| 58 }, | 62 }, |
| 59 | 63 |
| 60 /** @override */ | 64 /** @override */ |
| 61 getCapabilityNotAvailableValueInternal: function() { | 65 getCapabilityNotAvailableValueInternal: function() { |
| 62 return ''; | 66 return ''; |
| 63 } | 67 }, |
| 68 | |
| 69 /** | |
| 70 * @return {!Array.<object.<{from: number, to: number}>>} A list of page | |
| 71 * ranges. | |
| 72 */ | |
| 73 getPageRanges: function() { | |
| 74 var page_ranges = pageRangeTextToPageRanges(this.getValue()); | |
| 75 return page_ranges ? page_ranges : []; | |
| 76 }, | |
| 77 | |
| 78 /** | |
| 79 * @return {!Array.<object.<{from: number, to: number}>>} A list of page | |
| 80 * ranges suitable for use in the native layer. | |
| 81 * TODO(vitalybuka): this should be removed when native layer switched to | |
| 82 * page ranges. | |
| 83 */ | |
| 84 getDocumentPageRanges: function() { | |
|
Toscano
2013/02/12 01:39:05
We shouldn't need this one. A PageNumberSet produc
Vitaly Buka (NO REVIEWS)
2013/02/12 01:45:30
we still pass intervals to native code
On 2013/0
| |
| 85 var page_ranges = pageRangeTextToPageRanges(this.getValue(), | |
| 86 this.documentInfo_.pageCount); | |
| 87 return page_ranges ? page_ranges : []; | |
| 88 }, | |
| 64 }; | 89 }; |
| 65 | 90 |
| 66 // Export | 91 // Export |
| 67 return { | 92 return { |
| 68 PageRange: PageRange | 93 PageRange: PageRange |
| 69 }; | 94 }; |
| 70 }); | 95 }); |
| OLD | NEW |